[Rcpp-commits] r2721 - in pkg/Rcpp: . inst/unitTests src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sun Dec 5 16:27:24 CET 2010


Author: edd
Date: 2010-12-05 16:27:24 +0100 (Sun, 05 Dec 2010)
New Revision: 2721

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/unitTests/runit.Date.R
   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


Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2010-12-05 08:37:49 UTC (rev 2720)
+++ pkg/Rcpp/ChangeLog	2010-12-05 15:27:24 UTC (rev 2721)
@@ -1,3 +1,8 @@
+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
+
 2010-12-04  Dirk Eddelbuettel  <edd at debian.org>
 
 	* inst/include/Rcpp/Date.h: Remove addition of 1900 in getYear()

Modified: pkg/Rcpp/inst/unitTests/runit.Date.R
===================================================================
--- pkg/Rcpp/inst/unitTests/runit.Date.R	2010-12-05 08:37:49 UTC (rev 2720)
+++ pkg/Rcpp/inst/unitTests/runit.Date.R	2010-12-05 15:27:24 UTC (rev 2721)
@@ -86,17 +86,26 @@
                     v[1] = Date(12,31,2005) ;
                     return wrap( v );')
 
+                  ,"Date_get_functions"=list(
+                   signature(x="Date"),
+                   'Date d = Date(x);
+		            return List::create(Named("year") = d.getYear(),
+    		                            Named("month") = d.getMonth(),
+    		                            Named("day") = d.getDay(),
+    		                            Named("wday") = d.getWeekday(),
+    		                            Named("yday") = d.getYearday());')
+
                   ,"Datetime_get_functions"=list(
                    signature(x="Datetime"),
                    'Datetime dt = Datetime(x);
 		            return List::create(Named("year") = dt.getYear(),
     		                            Named("month") = dt.getMonth(),
-    		                                Named("day") = dt.getDay(),
-    		                                Named("wday") = dt.getWeekday(),
-    		                                Named("hour") = dt.getHours(),
-    		                                Named("minute") = dt.getMinutes(),
-    		                                Named("second") = dt.getSeconds(),
-    		                                Named("microsec") = dt.getMicroSeconds());')
+    		                            Named("day") = dt.getDay(),
+    		                            Named("wday") = dt.getWeekday(),
+    		                            Named("hour") = dt.getHours(),
+    		                            Named("minute") = dt.getMinutes(),
+    		                            Named("second") = dt.getSeconds(),
+    		                            Named("microsec") = dt.getMicroSeconds());')
 
                   ,"Datetime_operators"=list(
                    signature(),
@@ -182,6 +191,16 @@
     checkEquals(fun(), rep(as.Date("2005-12-31"),2), msg = "DateVector.SEXP")
 }
 
+test.Date.getFunctions <- function(){
+    fun <- .Rcpp.Date$Date_get_functions
+    checkEquals(fun(as.Date("2010-12-04")),
+                list(year=2010, month=12, day=4, wday=7, yday=338), msg = "Date.get.functions.1")
+    checkEquals(fun(as.Date("2010-01-01")),
+                list(year=2010, month=1, day=1, wday=6, yday=1), msg = "Date.get.functions.2")
+    checkEquals(fun(as.Date("2009-12-31")),
+                list(year=2009, month=12, day=31, wday=5, yday=365), msg = "Date.get.functions.3")
+}
+
 test.Datetime.get.functions <- function() {
     fun <- .Rcpp.Date$Datetime_get_functions
     checkEquals(fun(as.numeric(as.POSIXct("2001-02-03 01:02:03.123456", tz="UTC"))),

Modified: pkg/Rcpp/src/Date.cpp
===================================================================
--- pkg/Rcpp/src/Date.cpp	2010-12-05 08:37:49 UTC (rev 2720)
+++ pkg/Rcpp/src/Date.cpp	2010-12-05 15:27:24 UTC (rev 2721)
@@ -72,6 +72,7 @@
 	    m_tm.tm_year  = year - 1900;
 	}
 	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_d = tmp/(24*60*60);
     }
 



More information about the Rcpp-commits mailing list