Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(379)

Side by Side Diff: chrome/browser/sync/notifier/base/time.h

Issue 194065: Initial commit of sync engine code to browser/sync.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Fixes to gtest include path, reverted syncapi. Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
Property Changes:
Added: svn:eol-style
+ LF
OLDNEW
(Empty)
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef CHROME_BROWSER_SYNC_NOTIFIER_BASE_TIME_H_
6 #define CHROME_BROWSER_SYNC_NOTIFIER_BASE_TIME_H_
7
8 #include <time.h>
9
10 #include "talk/base/basictypes.h"
11
12 typedef uint64 time64;
13
14 #define kMicrosecsTo100ns (static_cast<time64>(10))
15 #define kMillisecsTo100ns (static_cast<time64>(10000))
16 #define kSecsTo100ns (1000 * kMillisecsTo100ns)
17 #define kMinsTo100ns (60 * kSecsTo100ns)
18 #define kHoursTo100ns (60 * kMinsTo100ns)
19 #define kDaysTo100ns (24 * kHoursTo100ns)
20 const time64 kMaxTime100ns = UINT64_C(9223372036854775807);
21
22 // Time difference in 100NS granularity between platform-dependent starting
23 // time and Jan 1, 1970.
24 #ifdef WIN32
25 // On Windows time64 is seconds since Jan 1, 1601.
26 #define kStart100NsTimeToEpoch (116444736000000000uI64) // Jan 1, 1970 in time64
27 #else
28 // On Unix time64 is seconds since Jan 1, 1970.
29 #define kStart100NsTimeToEpoch (0) // Jan 1, 1970 in time64
30 #endif
31
32 // Time difference in 100NS granularity between platform-dependent starting
33 // time and Jan 1, 1980.
34 #define kStart100NsTimeTo1980 \
35 kStart100NsTimeToEpoch + UINT64_C(3155328000000000)
36
37 #define kTimeGranularity (kDaysTo100ns)
38
39 namespace notifier {
40
41 // Get the current time represented in 100NS granularity
42 // Different platform might return the value since different starting time.
43 // Win32 platform returns the value since Jan 1, 1601.
44 time64 GetCurrent100NSTime();
45
46 // Get the current time represented in 100NS granularity since epoch
47 // (Jan 1, 1970).
48 time64 GetCurrent100NSTimeSinceEpoch();
49
50 // Convert from struct tm to time64.
51 time64 TmToTime64(const struct tm& tm);
52
53 // Convert from time64 to struct tm.
54 bool Time64ToTm(time64 t, struct tm* tm);
55
56 // Convert from UTC time to local time.
57 bool UtcTimeToLocalTime(struct tm* tm);
58
59 // Convert from local time to UTC time.
60 bool LocalTimeToUtcTime(struct tm* tm);
61
62 // Returns the local time as a string suitable for logging
63 // Note: This is *not* threadsafe, so only call it from the main thread.
64 char* GetLocalTimeAsString();
65
66 // Parses RFC 822 Date/Time format
67 // 5. DATE AND TIME SPECIFICATION
68 // 5.1. SYNTAX
69 //
70 // date-time = [ day "," ] date time ; dd mm yy
71 // ; hh:mm:ss zzz
72 // day = "Mon" / "Tue" / "Wed" / "Thu"
73 // / "Fri" / "Sat" / "Sun"
74 //
75 // date = 1*2DIGIT month 2DIGIT ; day month year
76 // ; e.g. 20 Jun 82
77 //
78 // month = "Jan" / "Feb" / "Mar" / "Apr"
79 // / "May" / "Jun" / "Jul" / "Aug"
80 // / "Sep" / "Oct" / "Nov" / "Dec"
81 //
82 // time = hour zone ; ANSI and Military
83 //
84 // hour = 2DIGIT ":" 2DIGIT [":" 2DIGIT]
85 // ; 00:00:00 - 23:59:59
86 //
87 // zone = "UT" / "GMT" ; Universal Time
88 // ; North American : UT
89 // / "EST" / "EDT" ; Eastern: - 5/ - 4
90 // / "CST" / "CDT" ; Central: - 6/ - 5
91 // / "MST" / "MDT" ; Mountain: - 7/ - 6
92 // / "PST" / "PDT" ; Pacific: - 8/ - 7
93 // / 1ALPHA ; Military: Z = UT;
94 // ; A:-1; (J not used)
95 // ; M:-12; N:+1; Y:+12
96 // / ( ("+" / "-") 4DIGIT ) ; Local differential
97 // ; hours+min. (HHMM)
98 // Return local time if ret_local_time == true, return UTC time otherwise
99 bool ParseRFC822DateTime(const char* str, struct tm* time, bool ret_local_time);
100
101 // Parse a string to time span.
102 //
103 // A TimeSpan value can be represented as
104 // [d.]hh:mm:ss
105 //
106 // d = days (optional)
107 // hh = hours as measured on a 24-hour clock
108 // mm = minutes
109 // ss = seconds
110 bool ParseStringToTimeSpan(const char* str, time64* time_span);
111
112 } // namespace notifier
113
114 #endif // CHROME_BROWSER_SYNC_NOTIFIER_BASE_TIME_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698