Commit 163cade8 by Abseil Team Committed by Copybara-Service

Import of CCTZ from GitHub.

PiperOrigin-RevId: 539104398
Change-Id: I6385662e0c5694d40c57887f983b16adc9eced14
parent 87ce3903
...@@ -13,8 +13,10 @@ ...@@ -13,8 +13,10 @@
// limitations under the License. // limitations under the License.
#if !defined(HAS_STRPTIME) #if !defined(HAS_STRPTIME)
#if !defined(_MSC_VER) && !defined(__MINGW32__) #if !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__VXWORKS__)
#define HAS_STRPTIME 1 // assume everyone has strptime() except windows #define HAS_STRPTIME \
1 // assume everyone has strptime() except windows
// and VxWorks
#endif #endif
#endif #endif
......
...@@ -71,6 +71,16 @@ auto tm_zone(const std::tm& tm) -> decltype(tzname[0]) { ...@@ -71,6 +71,16 @@ auto tm_zone(const std::tm& tm) -> decltype(tzname[0]) {
const bool is_dst = tm.tm_isdst > 0; const bool is_dst = tm.tm_isdst > 0;
return tzname[is_dst]; 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 #else
// Adapt to different spellings of the struct std::tm extension fields. // Adapt to different spellings of the struct std::tm extension fields.
#if defined(tm_gmtoff) #if defined(tm_gmtoff)
...@@ -108,6 +118,7 @@ auto tm_zone(const T& tm) -> decltype(tm.__tm_zone) { ...@@ -108,6 +118,7 @@ auto tm_zone(const T& tm) -> decltype(tm.__tm_zone) {
} }
#endif // tm_zone #endif // tm_zone
#endif #endif
using tm_gmtoff_t = decltype(tm_gmtoff(std::tm{}));
inline std::tm* gm_time(const std::time_t* timep, std::tm* result) { inline std::tm* gm_time(const std::time_t* timep, std::tm* result) {
#if defined(_WIN32) || defined(_WIN64) #if defined(_WIN32) || defined(_WIN64)
...@@ -154,7 +165,7 @@ bool make_time(const civil_second& cs, int is_dst, std::time_t* t, ...@@ -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: // 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. // (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; std::tm tm;
while (lo + 1 != hi) { while (lo + 1 != hi) {
const std::time_t mid = lo + (hi - lo) / 2; const std::time_t mid = lo + (hi - lo) / 2;
...@@ -265,7 +276,7 @@ time_zone::civil_lookup TimeZoneLibC::MakeTime(const civil_second& cs) const { ...@@ -265,7 +276,7 @@ time_zone::civil_lookup TimeZoneLibC::MakeTime(const civil_second& cs) const {
return {time_zone::civil_lookup::UNIQUE, tp, tp, tp}; 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 if (t0 < t1) { // negative DST
std::swap(t0, t1); std::swap(t0, t1);
offset = tm_gmtoff(tm1); offset = tm_gmtoff(tm1);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment