summaryrefslogtreecommitdiffstats
path: root/base/third_party
diff options
context:
space:
mode:
authorpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-11 23:07:19 +0000
committerpinkerton@google.com <pinkerton@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-08-11 23:07:19 +0000
commit0d6033c1c7a482b4152e365b0bf9fe82f446aa6f (patch)
treeb9ee477289ac3695a8d101ab2c12ca1e85a20481 /base/third_party
parent8bcab70c11559b92b87df23cf279e3f2e5229670 (diff)
downloadchromium_src-0d6033c1c7a482b4152e365b0bf9fe82f446aa6f.zip
chromium_src-0d6033c1c7a482b4152e365b0bf9fe82f446aa6f.tar.gz
chromium_src-0d6033c1c7a482b4152e365b0bf9fe82f446aa6f.tar.bz2
Fix unit tests for posix, fix up mac implementation to work correctly. Add prtime unit test to mac project.
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@680 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/third_party')
-rw-r--r--base/third_party/nspr/prtime.cc46
1 files changed, 43 insertions, 3 deletions
diff --git a/base/third_party/nspr/prtime.cc b/base/third_party/nspr/prtime.cc
index a5e851c..b3d6db6 100644
--- a/base/third_party/nspr/prtime.cc
+++ b/base/third_party/nspr/prtime.cc
@@ -62,9 +62,22 @@
* 3. prlong.h
*/
+#include "base/third_party/nspr/prtime.h"
+#include "build/build_config.h"
+
+#if defined(OS_WIN)
#include <windows.h>
+#elif defined(OS_MACOSX)
+#include <CoreFoundation/CoreFoundation.h>
+#endif
#include <time.h>
-#include "base/third_party/nspr/prtime.h"
+
+/* Implements the Unix localtime_r() function for windows */
+#if defined(OS_WIN)
+static void localtime_r(const time_t* secs, struct tm* time) {
+ (void) localtime_s(time, secs);
+}
+#endif
/*
*------------------------------------------------------------------------
@@ -79,6 +92,7 @@
PRTime
PR_ImplodeTime(const PRExplodedTime *exploded)
{
+#if defined(OS_WIN)
// Create the system struct representing our exploded time.
SYSTEMTIME st = {0};
FILETIME ft = {0};
@@ -108,6 +122,32 @@ PR_ImplodeTime(const PRExplodedTime *exploded)
uli.QuadPart -= 116444736000000000i64; // from Windows epoch to NSPR epoch
uli.QuadPart /= 10; // from 100-nanosecond to microsecond
return (PRTime)uli.QuadPart;
+#elif defined(OS_MACOSX)
+ // Create the system struct representing our exploded time.
+ CFGregorianDate gregorian_date;
+ gregorian_date.year = exploded->tm_year;
+ gregorian_date.month = exploded->tm_month + 1;
+ gregorian_date.day = exploded->tm_mday;
+ gregorian_date.hour = exploded->tm_hour;
+ gregorian_date.minute = exploded->tm_min;
+ gregorian_date.second = exploded->tm_sec;
+
+ // Compute |absolute_time| in seconds, correct for gmt and dst
+ // (note the combined offset will be negative when we need to add it), then
+ // convert to microseconds which is what PRTime expects.
+ CFAbsoluteTime absolute_time =
+ CFGregorianDateGetAbsoluteTime(gregorian_date, NULL);
+ PRTime result = static_cast<PRTime>(absolute_time);
+ result -= exploded->tm_params.tp_gmt_offset +
+ exploded->tm_params.tp_dst_offset;
+ result += kCFAbsoluteTimeIntervalSince1970; // PRTime epoch is 1970
+ result *= 1000000L; // Seconds to microseconds
+ result += exploded->tm_usec;
+ return result;
+#else
+ NOTREACHED();
+ memset(time, 0, sizeof(*time));
+#endif
}
/*
@@ -824,7 +864,7 @@ PR_ParseTimeString(
zone_offset for the date we are parsing is the same as
the zone offset on 00:00:00 2 Jan 1970 GMT. */
secs = 86400;
- (void) localtime_s(&localTime, &secs);
+ localtime_r(&secs, &localTime);
zone_offset = localTime.tm_min
+ 60 * localTime.tm_hour
+ 1440 * (localTime.tm_mday - 2);
@@ -835,4 +875,4 @@ PR_ParseTimeString(
*result = PR_ImplodeTime(&tm);
return PR_SUCCESS;
-} \ No newline at end of file
+}