diff options
author | Abseil Team <absl-team@google.com> | 2023-06-09 09:37:27 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-06-09 09:38:12 -0700 |
commit | 163cade8645fad00682b6829b4eac92be9e71b89 (patch) | |
tree | c7dc96c1d5e8b35b3544a54bad7cc299e277f5ab /absl/time | |
parent | 87ce390379440febee9caa500e527afa3fa55bef (diff) |
Import of CCTZ from GitHub.
PiperOrigin-RevId: 539104398
Change-Id: I6385662e0c5694d40c57887f983b16adc9eced14
Diffstat (limited to 'absl/time')
-rw-r--r-- | absl/time/internal/cctz/src/time_zone_format.cc | 6 | ||||
-rw-r--r-- | absl/time/internal/cctz/src/time_zone_libc.cc | 15 |
2 files changed, 17 insertions, 4 deletions
diff --git a/absl/time/internal/cctz/src/time_zone_format.cc b/absl/time/internal/cctz/src/time_zone_format.cc index 2e5f5329..0bea75a4 100644 --- a/absl/time/internal/cctz/src/time_zone_format.cc +++ b/absl/time/internal/cctz/src/time_zone_format.cc @@ -13,8 +13,10 @@ // limitations under the License. #if !defined(HAS_STRPTIME) -#if !defined(_MSC_VER) && !defined(__MINGW32__) -#define HAS_STRPTIME 1 // assume everyone has strptime() except windows +#if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__VXWORKS__) +#define HAS_STRPTIME \ + 1 // assume everyone has strptime() except windows + // and VxWorks #endif #endif diff --git a/absl/time/internal/cctz/src/time_zone_libc.cc b/absl/time/internal/cctz/src/time_zone_libc.cc index af9f063e..e503a858 100644 --- a/absl/time/internal/cctz/src/time_zone_libc.cc +++ b/absl/time/internal/cctz/src/time_zone_libc.cc @@ -71,6 +71,16 @@ auto tm_zone(const std::tm& tm) -> decltype(tzname[0]) { const bool is_dst = tm.tm_isdst > 0; return tzname[is_dst]; } +#elif defined(__VXWORKS__) +// Uses the globals: 'timezone' and 'tzname'. +auto tm_gmtoff(const std::tm& tm) -> decltype(timezone + 0) { + const bool is_dst = tm.tm_isdst > 0; + return timezone + (is_dst ? 60 * 60 : 0); +} +auto tm_zone(const std::tm& tm) -> decltype(tzname[0]) { + const bool is_dst = tm.tm_isdst > 0; + return tzname[is_dst]; +} #else // Adapt to different spellings of the struct std::tm extension fields. #if defined(tm_gmtoff) @@ -108,6 +118,7 @@ auto tm_zone(const T& tm) -> decltype(tm.__tm_zone) { } #endif // tm_zone #endif +using tm_gmtoff_t = decltype(tm_gmtoff(std::tm{})); inline std::tm* gm_time(const std::time_t* timep, std::tm* result) { #if defined(_WIN32) || defined(_WIN64) @@ -154,7 +165,7 @@ bool make_time(const civil_second& cs, int is_dst, std::time_t* t, // Find the least time_t in [lo:hi] where local time matches offset, given: // (1) lo doesn't match, (2) hi does, and (3) there is only one transition. -std::time_t find_trans(std::time_t lo, std::time_t hi, int offset) { +std::time_t find_trans(std::time_t lo, std::time_t hi, tm_gmtoff_t offset) { std::tm tm; while (lo + 1 != hi) { const std::time_t mid = lo + (hi - lo) / 2; @@ -265,7 +276,7 @@ time_zone::civil_lookup TimeZoneLibC::MakeTime(const civil_second& cs) const { return {time_zone::civil_lookup::UNIQUE, tp, tp, tp}; } - int offset = tm_gmtoff(tm0); + tm_gmtoff_t offset = tm_gmtoff(tm0); if (t0 < t1) { // negative DST std::swap(t0, t1); offset = tm_gmtoff(tm1); |