[Rcpp-commits] r3742 - in pkg/RcppBDT: . inst src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Thu Aug 23 05:04:59 CEST 2012


Author: edd
Date: 2012-08-23 05:04:59 +0200 (Thu, 23 Aug 2012)
New Revision: 3742

Modified:
   pkg/RcppBDT/ChangeLog
   pkg/RcppBDT/DESCRIPTION
   pkg/RcppBDT/inst/NEWS.Rd
   pkg/RcppBDT/src/RcppBDTtz.cpp
Log:
reorganized new module


Modified: pkg/RcppBDT/ChangeLog
===================================================================
--- pkg/RcppBDT/ChangeLog	2012-08-21 14:55:24 UTC (rev 3741)
+++ pkg/RcppBDT/ChangeLog	2012-08-23 03:04:59 UTC (rev 3742)
@@ -1,3 +1,9 @@
+2012-08-22  Dirk Eddelbuettel  <edd at dexter>
+
+	* src/RcppBDTtz.cpp: Rewritten bdtTz to be based on small class
+	wrapping tz_db object plus one pointer but of which are initialized
+	from the constructor
+
 2012-08-20  Dirk Eddelbuettel  <edd at dexter>
 
 	* src/RcppBDTtz.cpp: New modules 'bdtTz' for time zone functionality

Modified: pkg/RcppBDT/DESCRIPTION
===================================================================
--- pkg/RcppBDT/DESCRIPTION	2012-08-21 14:55:24 UTC (rev 3741)
+++ pkg/RcppBDT/DESCRIPTION	2012-08-23 03:04:59 UTC (rev 3742)
@@ -1,7 +1,7 @@
 Package: RcppBDT
 Type: Package
 Title: Rcpp bindings for the Boost Date_Time library 
-Version: 0.2.1.1
+Version: 0.2.1.2
 Date: $Date$
 Author: Dirk Eddelbuettel and Romain Francois
 Maintainer: Dirk Eddelbuettel <edd at debian.org>

Modified: pkg/RcppBDT/inst/NEWS.Rd
===================================================================
--- pkg/RcppBDT/inst/NEWS.Rd	2012-08-21 14:55:24 UTC (rev 3741)
+++ pkg/RcppBDT/inst/NEWS.Rd	2012-08-23 03:04:59 UTC (rev 3742)
@@ -2,6 +2,12 @@
 \title{News for Package \pkg{RcppBDT}}
 \newcommand{\cpkg}{\href{http://CRAN.R-project.org/package=#1}{\pkg{#1}}}
 
+\section{Changes in version 0.x.y (2012-xx-yy)}{
+  \itemize{
+    \item New module providing time zone information such as offset to
+    UTC, amount of DST, abbreviated and full timezone names.
+  }
+}
 \section{Changes in version 0.2.1 (2012-08-08)}{
   \itemize{
     \item Bug for getEndOfBizWeek() and getEndOfMonth() who were lacking

Modified: pkg/RcppBDT/src/RcppBDTtz.cpp
===================================================================
--- pkg/RcppBDT/src/RcppBDTtz.cpp	2012-08-21 14:55:24 UTC (rev 3741)
+++ pkg/RcppBDT/src/RcppBDTtz.cpp	2012-08-23 03:04:59 UTC (rev 3742)
@@ -21,49 +21,60 @@
 
 #include <RcppBDT.h>
 
-void tzSetDB(boost::local_time::tz_database *tz, std::string file) {
-    tz->load_from_file(file);
-}
+class bdtTz {
 
-Rcpp::CharacterVector tzGetRegions(boost::local_time::tz_database *tz) {
-    std::vector<std::string> regions = tz->region_list();
-    Rcpp::StringVector vec(regions.begin(), regions.end());
-    return(vec);		// Rcpp::wrap() called implicitly
-}
+public:
 
-SEXP tzGetTotalSecondsFromUTC(boost::local_time::tz_database *tz, std::string region) {
-    boost::local_time::time_zone_ptr tzp = tz->time_zone_from_region(region);
-    boost::posix_time::time_duration tdt = tzp->base_utc_offset();
-    long offset = tdt.total_seconds();
-    //std::cout << tdt << " -- " << offset << std::endl;
-    return(Rcpp::wrap(offset));
-}
+    bdtTz(std::string zonefile, std::string region) {
+    	m_tz.load_from_file(zonefile); 			// load db from csv zonefile
+    	m_tzp = m_tz.time_zone_from_region(region);	// init with given region
+    }
 
-SEXP tzGetDstTotalSeconds(boost::local_time::tz_database *tz, std::string region) {
-    boost::local_time::time_zone_ptr tzp = tz->time_zone_from_region(region);
-    boost::posix_time::time_duration tdt = tzp->dst_offset();
-    long offset = tdt.total_seconds();
-    //std::cout << tdt << " -- " << offset << std::endl;
-    return(Rcpp::wrap(offset));
-}
+    std::vector<std::string> getRegions() { return( m_tz.region_list() ); }
 
+    long getUtcTotalSec() {
+	boost::posix_time::time_duration tdt = m_tzp->base_utc_offset();
+	return(tdt.total_seconds());
+    }
+
+    long getDstTotalSec() {
+	boost::posix_time::time_duration tdt = m_tzp->dst_offset();
+	return(tdt.total_seconds());
+    }
+
+    std::string getDstZoneAbbrev() { return(m_tzp->dst_zone_abbrev()); }
+    std::string getStdZoneAbbrev() { return(m_tzp->std_zone_abbrev()); }
+    std::string getDstZoneName()   { return(m_tzp->dst_zone_name());   }
+    std::string getStdZoneName()   { return(m_tzp->std_zone_name());   }
+    bool        hasDst()           { return(m_tzp->has_dst());         }
+    std::string getPosixString()   { return(m_tzp->to_posix_string()); }
+
+private:
+
+    bdtTz() {};			// hide default constructor
+
+    boost::local_time::tz_database m_tz;
+    boost::local_time::time_zone_ptr m_tzp;
+};
+
+
 RCPP_MODULE(bdtTzMod) {
 
-    using namespace boost::local_time;
-    using namespace Rcpp;
-
-    // exposing a class (boost::gregorian::)date as "bdtTz" on the R side
-    class_<tz_database>("bdtTz")
+    Rcpp::class_<bdtTz>("bdtTz")   
 	
-    // constructors
-    .constructor("default constructor")  // needs to invalidate as we need a tz file
+    .constructor<std::string,std::string>("constructor with zonefile and region")  
 
-    .method("setDB", &tzSetDB, "load time zone database from file")
+    .method("getRegions",       &bdtTz::getRegions,       "get vector of TZ region names")
 
-    .method("getRegions", &tzGetRegions, "get vector of TZ region names")
+    .method("getUtcOffset",     &bdtTz::getUtcTotalSec,   "get seconds from UTC")
+    .method("getDstOffset",     &bdtTz::getDstTotalSec  , "get DST offset in seconds")
 
-    .method("getUtcOffsetInSeconds", &tzGetTotalSecondsFromUTC)
-    .method("getDstOffsetInSeconds", &tzGetDstTotalSeconds)
+    .method("getDstZoneAbbrev", &bdtTz::getDstZoneAbbrev, "get DST zone abbreviation")
+    .method("getStdZoneAbbrev", &bdtTz::getStdZoneAbbrev, "get standard zone abbreviation")
+    .method("getDstZoneName",   &bdtTz::getDstZoneName,   "get DST zone name")
+    .method("getStdZoneName",   &bdtTz::getStdZoneName,   "get standard zone name")
+    .method("hasDst",           &bdtTz::hasDst,           "true if timezone has daylight savings")
+    .method("getPosixString",   &bdtTz::getPosixString,   "get posix time zone representation")
 
     ;
 



More information about the Rcpp-commits mailing list