diff options
author | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-11 00:50:59 +0000 |
---|---|---|
committer | erg@google.com <erg@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-01-11 00:50:59 +0000 |
commit | eae9c0623d1800201739b4be146649103a45cd93 (patch) | |
tree | 2ce42f83e18d8a0a618ffd6dbe69b1acade5bda4 /base/time_posix.cc | |
parent | 26f0821d0a34a79e551213d56054366aab6c70f7 (diff) | |
download | chromium_src-eae9c0623d1800201739b4be146649103a45cd93.zip chromium_src-eae9c0623d1800201739b4be146649103a45cd93.tar.gz chromium_src-eae9c0623d1800201739b4be146649103a45cd93.tar.bz2 |
Order function definitions in base/ according to the header.
BUG=68682
TEST=compiles
Review URL: http://codereview.chromium.org/6085015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@70975 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/time_posix.cc')
-rw-r--r-- | base/time_posix.cc | 74 |
1 files changed, 37 insertions, 37 deletions
diff --git a/base/time_posix.cc b/base/time_posix.cc index 2490315..c2750b8 100644 --- a/base/time_posix.cc +++ b/base/time_posix.cc @@ -14,6 +14,19 @@ namespace base { +struct timespec TimeDelta::ToTimeSpec() const { + int64 microseconds = InMicroseconds(); + time_t seconds = 0; + if (microseconds >= Time::kMicrosecondsPerSecond) { + seconds = InSeconds(); + microseconds -= seconds * Time::kMicrosecondsPerSecond; + } + struct timespec result = + {seconds, + microseconds * Time::kNanosecondsPerMicrosecond}; + return result; +} + #if !defined(OS_MACOSX) // The Time routines in this file use standard POSIX routines, or almost- // standard routines in the case of timegm. We need to use a Mach-specific @@ -60,6 +73,30 @@ Time Time::NowFromSystemTime() { return Now(); } +void Time::Explode(bool is_local, Exploded* exploded) const { + // Time stores times with microsecond resolution, but Exploded only carries + // millisecond resolution, so begin by being lossy. Adjust from Windows + // epoch (1601) to Unix epoch (1970); + int64 milliseconds = (us_ - kWindowsEpochDeltaMicroseconds) / + kMicrosecondsPerMillisecond; + time_t seconds = milliseconds / kMillisecondsPerSecond; + + struct tm timestruct; + if (is_local) + localtime_r(&seconds, ×truct); + else + gmtime_r(&seconds, ×truct); + + exploded->year = timestruct.tm_year + 1900; + exploded->month = timestruct.tm_mon + 1; + exploded->day_of_week = timestruct.tm_wday; + exploded->day_of_month = timestruct.tm_mday; + exploded->hour = timestruct.tm_hour; + exploded->minute = timestruct.tm_min; + exploded->second = timestruct.tm_sec; + exploded->millisecond = milliseconds % kMillisecondsPerSecond; +} + // static Time Time::FromExploded(bool is_local, const Exploded& exploded) { struct tm timestruct; @@ -119,30 +156,6 @@ Time Time::FromExploded(bool is_local, const Exploded& exploded) { kWindowsEpochDeltaMicroseconds); } -void Time::Explode(bool is_local, Exploded* exploded) const { - // Time stores times with microsecond resolution, but Exploded only carries - // millisecond resolution, so begin by being lossy. Adjust from Windows - // epoch (1601) to Unix epoch (1970); - int64 milliseconds = (us_ - kWindowsEpochDeltaMicroseconds) / - kMicrosecondsPerMillisecond; - time_t seconds = milliseconds / kMillisecondsPerSecond; - - struct tm timestruct; - if (is_local) - localtime_r(&seconds, ×truct); - else - gmtime_r(&seconds, ×truct); - - exploded->year = timestruct.tm_year + 1900; - exploded->month = timestruct.tm_mon + 1; - exploded->day_of_week = timestruct.tm_wday; - exploded->day_of_month = timestruct.tm_mday; - exploded->hour = timestruct.tm_hour; - exploded->minute = timestruct.tm_min; - exploded->second = timestruct.tm_sec; - exploded->millisecond = milliseconds % kMillisecondsPerSecond; -} - // TimeTicks ------------------------------------------------------------------ // FreeBSD 6 has CLOCK_MONOLITHIC but defines _POSIX_MONOTONIC_CLOCK to -1. #if (defined(OS_POSIX) && \ @@ -177,19 +190,6 @@ TimeTicks TimeTicks::HighResNow() { #endif // !OS_MACOSX -struct timespec TimeDelta::ToTimeSpec() const { - int64 microseconds = InMicroseconds(); - time_t seconds = 0; - if (microseconds >= Time::kMicrosecondsPerSecond) { - seconds = InSeconds(); - microseconds -= seconds * Time::kMicrosecondsPerSecond; - } - struct timespec result = - {seconds, - microseconds * Time::kNanosecondsPerMicrosecond}; - return result; -} - struct timeval Time::ToTimeVal() const { struct timeval result; int64 us = us_ - kTimeTToMicrosecondsOffset; |