MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / getCurrentTimeStamp

Method getCurrentTimeStamp

src/common/classes/NoThrowTimeStamp.cpp:52–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50 {1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000};
51
52NoThrowTimeStamp NoThrowTimeStamp::getCurrentTimeStamp(const char** error) throw()
53{
54 if (error)
55 *error = NULL;
56 NoThrowTimeStamp result;
57
58 // NS: We round generated timestamps to whole millisecond.
59 // Not many applications can deal with fractional milliseconds properly and
60 // we do not use high resolution timers either so actual time granularity
61 // is going to to be somewhere in range between 1 ms (like on UNIX/Risc)
62 // and 53 ms (such as Win9X)
63
64 int milliseconds;
65
66#ifdef WIN_NT
67 FILETIME ftUtc, ftLocal;
68 SYSTEMTIME stLocal;
69
70 GetSystemTimeAsFileTime(&ftUtc);
71 if (!FileTimeToLocalFileTime(&ftUtc, &ftLocal))
72 {
73 if (error)
74 *error = "FileTimeToLocalFileTime";
75 return result;
76 }
77 if (!FileTimeToSystemTime(&ftLocal, &stLocal))
78 {
79 if (error)
80 *error = "FileTimeToSystemTime";
81 return result;
82 }
83
84 milliseconds = stLocal.wMilliseconds;
85#else
86 time_t seconds; // UTC time
87
88#ifdef HAVE_GETTIMEOFDAY
89 struct timeval tp;
90 GETTIMEOFDAY(&tp);
91 seconds = tp.tv_sec;
92 milliseconds = tp.tv_usec / 1000;
93#else
94 struct timeb time_buffer;
95 ftime(&time_buffer);
96 seconds = time_buffer.time;
97 milliseconds = time_buffer.millitm;
98#endif
99#endif // WIN_NT
100
101 // NS: Current FB behavior of using server time zone is not appropriate for
102 // distributed applications. We should be storing UTC times everywhere and
103 // convert timestamps to client timezone as necessary. Replace localtime stuff
104 // with these lines as soon as the appropriate functionality is implemented
105 //
106 // mValue.timestamp_date = seconds / 86400 + GDS_EPOCH_START;
107 // mValue.timestamp_time = (seconds % 86400) * ISC_TIME_SECONDS_PRECISION;
108
109 const int fractions = milliseconds * ISC_TIME_SECONDS_PRECISION / 1000;

Callers

nothing calls this directly

Calls 4

GetSystemTimeAsFileTimeFunction · 0.85
FileTimeToLocalFileTimeFunction · 0.85
FileTimeToSystemTimeFunction · 0.85
encodeMethod · 0.45

Tested by

no test coverage detected