| 806 | } |
| 807 | |
| 808 | ISC_TIMESTAMP_TZ TimeZoneUtil::getCurrentGmtTimeStamp() |
| 809 | { |
| 810 | NoThrowTimeStamp now; |
| 811 | |
| 812 | // ASF: This comment is copied from NoThrowTimeStamp::getCurrentTimeStamp. |
| 813 | // NS: We round generated timestamps to whole millisecond. |
| 814 | // Not many applications can deal with fractional milliseconds properly and |
| 815 | // we do not use high resolution timers either so actual time granularity |
| 816 | // is going to to be somewhere in range between 1 ms (like on UNIX/Risc) |
| 817 | // and 53 ms (such as Win9X) |
| 818 | |
| 819 | int milliseconds; |
| 820 | |
| 821 | #ifdef WIN_NT |
| 822 | SYSTEMTIME stUtc; |
| 823 | GetSystemTime(&stUtc); |
| 824 | milliseconds = stUtc.wMilliseconds; |
| 825 | #else |
| 826 | time_t seconds; // UTC time |
| 827 | |
| 828 | #ifdef HAVE_GETTIMEOFDAY |
| 829 | struct timeval tp; |
| 830 | GETTIMEOFDAY(&tp); |
| 831 | seconds = tp.tv_sec; |
| 832 | milliseconds = tp.tv_usec / 1000; |
| 833 | #else |
| 834 | struct timeb time_buffer; |
| 835 | ftime(&time_buffer); |
| 836 | seconds = time_buffer.time; |
| 837 | milliseconds = time_buffer.millitm; |
| 838 | #endif |
| 839 | #endif // WIN_NT |
| 840 | |
| 841 | const int fractions = milliseconds * ISC_TIME_SECONDS_PRECISION / 1000; |
| 842 | |
| 843 | #ifdef WIN_NT |
| 844 | // Manually convert SYSTEMTIME to "struct tm" used below |
| 845 | |
| 846 | struct tm times, *ptimes = × |
| 847 | |
| 848 | times.tm_sec = stUtc.wSecond; // seconds after the minute - [0,59] |
| 849 | times.tm_min = stUtc.wMinute; // minutes after the hour - [0,59] |
| 850 | times.tm_hour = stUtc.wHour; // hours since midnight - [0,23] |
| 851 | times.tm_mday = stUtc.wDay; // day of the month - [1,31] |
| 852 | times.tm_mon = stUtc.wMonth - 1; // months since January - [0,11] |
| 853 | times.tm_year = stUtc.wYear - 1900; // years since 1900 |
| 854 | times.tm_wday = stUtc.wDayOfWeek; // days since Sunday - [0,6] |
| 855 | |
| 856 | // --- no used for encoding below |
| 857 | times.tm_yday = 0; // days since January 1 - [0,365] |
| 858 | times.tm_isdst = -1; // daylight savings time flag |
| 859 | #else |
| 860 | #ifdef HAVE_GMTIME_R |
| 861 | struct tm times, *ptimes = × |
| 862 | if (!gmtime_r(&seconds, ×)) |
| 863 | system_call_failed::raise("gmtime_r"); |
| 864 | #else |
| 865 | struct tm *ptimes = gmtime(&seconds); |
nothing calls this directly
no test coverage detected