[Rcpp-commits] r2726 - in pkg/Rcpp: . inst/include/Rcpp src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Dec 5 19:44:53 CET 2010


Author: edd
Date: 2010-12-05 19:44:53 +0100 (Sun, 05 Dec 2010)
New Revision: 2726

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/include/Rcpp/Date.h
   pkg/Rcpp/src/Date.cpp
Log:
fix Date's year field after mktime00 call as we now assume 1900 baked in
more unit test for Date get* function added using normal Date-based constructor
a few more edits to Date.h / Date.cpp
also ran M-q to reindent ChangeLog because they have different TAB size in Montpellier :)


Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2010-12-05 18:27:19 UTC (rev 2725)
+++ pkg/Rcpp/ChangeLog	2010-12-05 18:44:53 UTC (rev 2726)
@@ -1,17 +1,23 @@
 2010-12-05  Romain Francois <romain at r-enthusiasts.com>
 
-    * inst/include/Rcpp/module/Module_generated_class_constructor.h: the default 
-    constructor was always considered valid because of the use of &yes instead
-    of &yes_arity<0>
-    
-    * R/Rcpp.package.skeleton.R: Rcpp.package.skeleton( "foo", example_code = FALSE)
-    did not work properly. Rcpp.package.skeleton gains some arguments
+	* inst/include/Rcpp/module/Module_generated_class_constructor.h: the
+	default constructor was always considered valid because of the use of
+	&yes instead of &yes_arity<0>
 
+	* R/Rcpp.package.skeleton.R: Rcpp.package.skeleton( "foo",
+	example_code = FALSE) did not work properly. Rcpp.package.skeleton
+	gains some arguments
+
 2010-12-05  Dirk Eddelbuettel  <edd at debian.org>
 
-	* inst/unitTests/runit.Date.R (test.Date.getFunctions): Added a unit
-	test for the get* functions of the Date class
+	* src/Date.cpp: Add 1900 to tm.year after mktime00() call as we now
+	no longer assume the field is '1900-less'
+	* src/Date.cpp: Define new static const variable baseYear as 1900
+	and use throughout
 
+	* inst/unitTests/runit.Date.R (test.Date.getFunctions): Added unit
+	tests for the get* functions of the Date class
+
 2010-12-04  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/include/Rcpp/Date.h: Remove addition of 1900 in getYear()

Modified: pkg/Rcpp/inst/include/Rcpp/Date.h
===================================================================
--- pkg/Rcpp/inst/include/Rcpp/Date.h	2010-12-05 18:27:19 UTC (rev 2725)
+++ pkg/Rcpp/inst/include/Rcpp/Date.h	2010-12-05 18:44:53 UTC (rev 2726)
@@ -44,13 +44,14 @@
 		//int getHours()   const { return m_tm.tm_hour; }
 		int getDay()     const { return m_tm.tm_mday; }
 		int getMonth()   const { return m_tm.tm_mon + 1; } 		// makes it 1 .. 12
-		int getYear()    const { return m_tm.tm_year; }	
+		int getYear()    const { return m_tm.tm_year; }			// does include 1900 (see Date.cpp)
 		int getWeekday() const { return m_tm.tm_wday + 1; } 	// makes it 1 .. 7
 		int getYearday() const { return m_tm.tm_yday + 1; }     // makes it 1 .. 366
 
-		static const int QLtoJan1970Offset;  // Offset between R / Unix epoch date and the QL base date
+		static const unsigned int QLtoJan1970Offset;  			// Offset between R / Unix epoch date and the QL base date
+		static const unsigned int baseYear;						// 1900 as per POSIX mktime() et al
 
-		Date & operator=(const Date &newdate); 		// copy assignment operator 
+		Date & operator=(const Date &newdate); 					// copy assignment operator 
 
 		// Minimal set of date operations.
 		friend Date  operator+(const Date &date, int offset);

Modified: pkg/Rcpp/src/Date.cpp
===================================================================
--- pkg/Rcpp/src/Date.cpp	2010-12-05 18:27:19 UTC (rev 2725)
+++ pkg/Rcpp/src/Date.cpp	2010-12-05 18:44:53 UTC (rev 2726)
@@ -31,10 +31,11 @@
 
 namespace Rcpp {
 
-    static struct tm * gmtime_(const time_t * const	timep); // see below
+    static struct tm * gmtime_(const time_t * const timep); 	// see below
 
 
-    const int Date::QLtoJan1970Offset = 25569;  // Offset between R / Unix epoch date and the QL base date
+    const unsigned int Date::QLtoJan1970Offset = 25569;  	// Offset between R / Unix epoch date and the QL base date
+    const unsigned int Date::baseYear = 1900;			// because we hate macros
 
     Date::Date() {
 	m_d = 0; 
@@ -62,17 +63,17 @@
 	m_tm.tm_sec = m_tm.tm_min = m_tm.tm_hour = m_tm.tm_isdst = 0;
 
 	// allow for ISO-notation case (yyyy, mm, dd) which we prefer over (mm, dd, year)
-	if (mon >= 1900 && day <= 12 && year <= 31) {
-	    m_tm.tm_year = mon - 1900;
+	if (mon >= baseYear && day <= 12 && year <= 31) {
+	    m_tm.tm_year = mon - baseYear;
 	    m_tm.tm_mon  = day - 1;     // range 0 to 11
 	    m_tm.tm_mday = year;
 	} else {
 	    m_tm.tm_mday  = day;
 	    m_tm.tm_mon   = mon - 1;	// range 0 to 11
-	    m_tm.tm_year  = year - 1900;
+	    m_tm.tm_year  = year - baseYear;
 	}
 	double tmp = mktime00(m_tm); 	// use mktime() replacement borrowed from R
-	m_tm.tm_year += 1900;		// we'd rather keep it as a normal year
+	m_tm.tm_year += baseYear;	// we'd rather keep it as a normal year
 	m_d = tmp/(24*60*60);
     }
 
@@ -109,7 +110,7 @@
 	double excess = 0.0;
 
 	day = tm.tm_mday - 1;
-	year0 = 1900 + tm.tm_year;
+	year0 = baseYear + tm.tm_year;
 	/* safety check for unbounded loops */
 	if (year0 > 3000) {
 	    excess = (int)(year0/2000) - 1;
@@ -347,7 +348,7 @@
 #define TM_NOVEMBER	10
 #define TM_DECEMBER	11
 
-#define TM_YEAR_BASE	1900
+#define TM_YEAR_BASE	baseYear 	// was: 1900, baseYear defined above
 
 #define EPOCH_YEAR	1970
 #define EPOCH_WDAY	TM_THURSDAY



More information about the Rcpp-commits mailing list