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

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Sat Oct 6 19:02:25 CEST 2012


Author: edd
Date: 2012-10-06 19:02:25 +0200 (Sat, 06 Oct 2012)
New Revision: 3791

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/NEWS.Rd
   pkg/Rcpp/src/Datetime.cpp
Log:
Datetimes now cope with NA, NaN and Inf representation too


Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2012-10-06 16:49:46 UTC (rev 3790)
+++ pkg/Rcpp/ChangeLog	2012-10-06 17:02:25 UTC (rev 3791)
@@ -9,6 +9,8 @@
 
 	* src/DateVector.cpp: Instantiate Date types as double
 
+	* src/Datetime.cpp: Also added support for NA, NaN and Inf values
+
 2012-10-05  Dirk Eddelbuettel  <edd at debian.org>
 
 	* src/exceptions.cpp: Applied patch by Martin Morgan which untangles

Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd	2012-10-06 16:49:46 UTC (rev 3790)
+++ pkg/Rcpp/inst/NEWS.Rd	2012-10-06 17:02:25 UTC (rev 3791)
@@ -8,8 +8,8 @@
     exceptions header by directly checking for the include file -- an
     approach provided by Martin Morgan in a kindly contributed patch
     as unit tests for them.
-    \item The \code{Date} type now correctly handles \code{NA},
-    \code{NaN} and \code{Inf} representation
+    \item The \code{Date} and \code{Datetime} types now correctly
+    handles \code{NA}, \code{NaN} and \code{Inf} representation
   }
 }
 

Modified: pkg/Rcpp/src/Datetime.cpp
===================================================================
--- pkg/Rcpp/src/Datetime.cpp	2012-10-06 16:49:46 UTC (rev 3790)
+++ pkg/Rcpp/src/Datetime.cpp	2012-10-06 17:02:25 UTC (rev 3791)
@@ -2,7 +2,7 @@
 //
 // Datetime.h: Rcpp R/C++ interface class library -- Datetime (POSIXct)
 //
-// Copyright (C) 2010 - 2011 Dirk Eddelbuettel and Romain Francois
+// Copyright (C) 2010 - 2012  Dirk Eddelbuettel and Romain Francois
 //
 // The mktime00() function is
 // Copyright (C) 2000 - 2010  The R Development Core Team.
@@ -67,11 +67,17 @@
     }
 
     void Datetime::update_tm() {
-		time_t t = static_cast<time_t>(floor(m_dt));	
-		m_tm = *gmtime(&t);		// this may need a Windows fix, re-check R's datetime.c
-		// m_us is fractional (micro)secs as diff. between (fractional) m_dt and m_tm
-		m_us = static_cast<int>(::Rf_fround( (m_dt - t) * 1.0e6, 0.0));	
-    }
+        if (R_FINITE(m_dt)) {
+			time_t t = static_cast<time_t>(floor(m_dt));	
+			m_tm = *gmtime(&t);		// this may need a Windows fix, re-check R's datetime.c
+			// m_us is fractional (micro)secs as diff. between (fractional) m_dt and m_tm
+			m_us = static_cast<int>(::Rf_fround( (m_dt - t) * 1.0e6, 0.0));	
+        } else {
+            m_tm.tm_sec = m_tm.tm_min = m_tm.tm_hour = m_tm.tm_isdst = NA_INTEGER;
+            m_tm.tm_min = m_tm.tm_hour = m_tm.tm_mday = m_tm.tm_mon  = m_tm.tm_year = NA_INTEGER;
+			m_us = NA_INTEGER;
+        }
+	}
 
     Datetime operator+(const Datetime &datetime, double offset) {
 		Datetime newdt(datetime.m_dt);



More information about the Rcpp-commits mailing list