diff options
author | Ivan Komarov <Ivan.Komarov@dfyz.info> | 2022-02-10 16:46:48 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:48 +0300 |
commit | 4de97ab2fe437cbe83e4c63234e809ddd5ac34f2 (patch) | |
tree | ff8fb38b661955e6c99d1d000d6c72f739199590 | |
parent | 9abfb1a53b7f7b791444d1378e645d8fad9b06ed (diff) | |
download | ydb-4de97ab2fe437cbe83e4c63234e809ddd5ac34f2.tar.gz |
Restoring authorship annotation for Ivan Komarov <Ivan.Komarov@dfyz.info>. Commit 1 of 2.
40 files changed, 2907 insertions, 2907 deletions
diff --git a/contrib/libs/cctz/README b/contrib/libs/cctz/README index 8cdda27da8..f01f1e5d61 100644 --- a/contrib/libs/cctz/README +++ b/contrib/libs/cctz/README @@ -1,8 +1,8 @@ -A Google timezone library. - -This version is based on commit 2e86a776379ec6f2a60f4a6595a3b68cd3961cb4 from https://github.com/google/cctz.git - -The following changes were made compared to the vanilla Google code: - * the Time Zone Database may optionally be compiled into the library (just add a PEERDIR() to contrib/libs/cctz/tzdata subdirectory in your code); - * some minor cleanups to avoid clang warnings; +A Google timezone library. + +This version is based on commit 2e86a776379ec6f2a60f4a6595a3b68cd3961cb4 from https://github.com/google/cctz.git + +The following changes were made compared to the vanilla Google code: + * the Time Zone Database may optionally be compiled into the library (just add a PEERDIR() to contrib/libs/cctz/tzdata subdirectory in your code); + * some minor cleanups to avoid clang warnings; * the tests were modified to work with library/cpp/testing/unittest. diff --git a/contrib/libs/cctz/src/tzfile.h b/contrib/libs/cctz/src/tzfile.h index ee91104443..7403fce5fa 100644 --- a/contrib/libs/cctz/src/tzfile.h +++ b/contrib/libs/cctz/src/tzfile.h @@ -1,48 +1,48 @@ /* Layout and location of TZif files. */ #ifndef TZFILE_H - + #define TZFILE_H -/* -** This file is in the public domain, so clarified as of -** 1996-06-05 by Arthur David Olson. -*/ - -/* -** This header is for use ONLY with the time conversion code. -** There is no guarantee that it will remain unchanged, -** or that it will remain at all. -** Do NOT copy it to any system include directory. -** Thank you! -*/ - -/* -** Information about time zone files. -*/ - -#ifndef TZDIR +/* +** This file is in the public domain, so clarified as of +** 1996-06-05 by Arthur David Olson. +*/ + +/* +** This header is for use ONLY with the time conversion code. +** There is no guarantee that it will remain unchanged, +** or that it will remain at all. +** Do NOT copy it to any system include directory. +** Thank you! +*/ + +/* +** Information about time zone files. +*/ + +#ifndef TZDIR #define TZDIR "/usr/share/zoneinfo" /* Time zone object file directory */ -#endif /* !defined TZDIR */ - -#ifndef TZDEFAULT +#endif /* !defined TZDIR */ + +#ifndef TZDEFAULT #define TZDEFAULT "/etc/localtime" -#endif /* !defined TZDEFAULT */ - -#ifndef TZDEFRULES +#endif /* !defined TZDEFAULT */ + +#ifndef TZDEFRULES #define TZDEFRULES "posixrules" -#endif /* !defined TZDEFRULES */ - +#endif /* !defined TZDEFRULES */ + /* See Internet RFC 8536 for more details about the following format. */ -/* -** Each file begins with. . . -*/ - +/* +** Each file begins with. . . +*/ + #define TZ_MAGIC "TZif" - -struct tzhead { + +struct tzhead { char tzh_magic[4]; /* TZ_MAGIC */ char tzh_version[1]; /* '\0' or '2' or '3' as of 2013 */ char tzh_reserved[15]; /* reserved; must be zero */ @@ -52,11 +52,11 @@ struct tzhead { char tzh_timecnt[4]; /* coded number of transition times */ char tzh_typecnt[4]; /* coded number of local time types */ char tzh_charcnt[4]; /* coded number of abbr. chars */ -}; - -/* -** . . .followed by. . . -** +}; + +/* +** . . .followed by. . . +** ** tzh_timecnt (char [4])s coded transition times a la time(2) ** tzh_timecnt (unsigned char)s types of local time starting at above ** tzh_typecnt repetitions of @@ -78,46 +78,46 @@ struct tzhead { ** times are assumed to be local time. ** When this is 1, the corresponding ** std/wall indicator must also be 1. -*/ - -/* -** If tzh_version is '2' or greater, the above is followed by a second instance -** of tzhead and a second instance of the data in which each coded transition -** time uses 8 rather than 4 chars, -** then a POSIX-TZ-environment-variable-style string for use in handling -** instants after the last transition time stored in the file -** (with nothing between the newlines if there is no POSIX representation for -** such instants). -** -** If tz_version is '3' or greater, the above is extended as follows. -** First, the POSIX TZ string's hour offset may range from -167 -** through 167 as compared to the POSIX-required 0 through 24. -** Second, its DST start time may be January 1 at 00:00 and its stop -** time December 31 at 24:00 plus the difference between DST and -** standard time, indicating DST all year. -*/ - -/* -** In the current implementation, "tzset()" refuses to deal with files that -** exceed any of the limits below. -*/ - -#ifndef TZ_MAX_TIMES +*/ + +/* +** If tzh_version is '2' or greater, the above is followed by a second instance +** of tzhead and a second instance of the data in which each coded transition +** time uses 8 rather than 4 chars, +** then a POSIX-TZ-environment-variable-style string for use in handling +** instants after the last transition time stored in the file +** (with nothing between the newlines if there is no POSIX representation for +** such instants). +** +** If tz_version is '3' or greater, the above is extended as follows. +** First, the POSIX TZ string's hour offset may range from -167 +** through 167 as compared to the POSIX-required 0 through 24. +** Second, its DST start time may be January 1 at 00:00 and its stop +** time December 31 at 24:00 plus the difference between DST and +** standard time, indicating DST all year. +*/ + +/* +** In the current implementation, "tzset()" refuses to deal with files that +** exceed any of the limits below. +*/ + +#ifndef TZ_MAX_TIMES #define TZ_MAX_TIMES 2000 -#endif /* !defined TZ_MAX_TIMES */ - -#ifndef TZ_MAX_TYPES -/* This must be at least 17 for Europe/Samara and Europe/Vilnius. */ +#endif /* !defined TZ_MAX_TIMES */ + +#ifndef TZ_MAX_TYPES +/* This must be at least 17 for Europe/Samara and Europe/Vilnius. */ #define TZ_MAX_TYPES 256 /* Limited by what (unsigned char)'s can hold */ -#endif /* !defined TZ_MAX_TYPES */ - -#ifndef TZ_MAX_CHARS +#endif /* !defined TZ_MAX_TYPES */ + +#ifndef TZ_MAX_CHARS #define TZ_MAX_CHARS 50 /* Maximum number of abbreviation characters */ /* (limited by what unsigned chars can hold) */ -#endif /* !defined TZ_MAX_CHARS */ - -#ifndef TZ_MAX_LEAPS +#endif /* !defined TZ_MAX_CHARS */ + +#ifndef TZ_MAX_LEAPS #define TZ_MAX_LEAPS 50 /* Maximum number of leap second corrections */ -#endif /* !defined TZ_MAX_LEAPS */ - +#endif /* !defined TZ_MAX_LEAPS */ + #endif /* !defined TZFILE_H */ diff --git a/contrib/libs/cctz/test/civil_time_test.cc b/contrib/libs/cctz/test/civil_time_test.cc index 5ec0ca8d38..aa4000c3f6 100644 --- a/contrib/libs/cctz/test/civil_time_test.cc +++ b/contrib/libs/cctz/test/civil_time_test.cc @@ -1,236 +1,236 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// // https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include "cctz/civil_time.h" - -#include <iomanip> -#include <limits> -#include <sstream> -#include <string> -#include <type_traits> - + +#include <iomanip> +#include <limits> +#include <sstream> +#include <string> +#include <type_traits> + #include "gtest/gtest.h" - -namespace cctz { - -namespace { - -template <typename T> -std::string Format(const T& t) { - std::stringstream ss; - ss << t; - return ss.str(); -} - -} // namespace - + +namespace cctz { + +namespace { + +template <typename T> +std::string Format(const T& t) { + std::stringstream ss; + ss << t; + return ss.str(); +} + +} // namespace + #if __cpp_constexpr >= 201304 || (defined(_MSC_VER) && _MSC_VER >= 1910) -// Construction constexpr tests - -TEST(CivilTime, Normal) { - constexpr civil_second css(2016, 1, 28, 17, 14, 12); - static_assert(css.second() == 12, "Normal.second"); - constexpr civil_minute cmm(2016, 1, 28, 17, 14); - static_assert(cmm.minute() == 14, "Normal.minute"); - constexpr civil_hour chh(2016, 1, 28, 17); - static_assert(chh.hour() == 17, "Normal.hour"); - constexpr civil_day cd(2016, 1, 28); - static_assert(cd.day() == 28, "Normal.day"); - constexpr civil_month cm(2016, 1); - static_assert(cm.month() == 1, "Normal.month"); - constexpr civil_year cy(2016); - static_assert(cy.year() == 2016, "Normal.year"); -} - -TEST(CivilTime, Conversion) { - constexpr civil_year cy(2016); - static_assert(cy.year() == 2016, "Conversion.year"); - constexpr civil_month cm(cy); - static_assert(cm.month() == 1, "Conversion.month"); - constexpr civil_day cd(cm); - static_assert(cd.day() == 1, "Conversion.day"); - constexpr civil_hour chh(cd); - static_assert(chh.hour() == 0, "Conversion.hour"); - constexpr civil_minute cmm(chh); - static_assert(cmm.minute() == 0, "Conversion.minute"); - constexpr civil_second css(cmm); - static_assert(css.second() == 0, "Conversion.second"); -} - -// Normalization constexpr tests - -TEST(CivilTime, Normalized) { - constexpr civil_second cs(2016, 1, 28, 17, 14, 12); - static_assert(cs.year() == 2016, "Normalized.year"); - static_assert(cs.month() == 1, "Normalized.month"); - static_assert(cs.day() == 28, "Normalized.day"); - static_assert(cs.hour() == 17, "Normalized.hour"); - static_assert(cs.minute() == 14, "Normalized.minute"); - static_assert(cs.second() == 12, "Normalized.second"); -} - -TEST(CivilTime, SecondOverflow) { - constexpr civil_second cs(2016, 1, 28, 17, 14, 121); - static_assert(cs.year() == 2016, "SecondOverflow.year"); - static_assert(cs.month() == 1, "SecondOverflow.month"); - static_assert(cs.day() == 28, "SecondOverflow.day"); - static_assert(cs.hour() == 17, "SecondOverflow.hour"); - static_assert(cs.minute() == 16, "SecondOverflow.minute"); - static_assert(cs.second() == 1, "SecondOverflow.second"); -} - -TEST(CivilTime, SecondUnderflow) { - constexpr civil_second cs(2016, 1, 28, 17, 14, -121); - static_assert(cs.year() == 2016, "SecondUnderflow.year"); - static_assert(cs.month() == 1, "SecondUnderflow.month"); - static_assert(cs.day() == 28, "SecondUnderflow.day"); - static_assert(cs.hour() == 17, "SecondUnderflow.hour"); - static_assert(cs.minute() == 11, "SecondUnderflow.minute"); - static_assert(cs.second() == 59, "SecondUnderflow.second"); -} - -TEST(CivilTime, MinuteOverflow) { - constexpr civil_second cs(2016, 1, 28, 17, 121, 12); - static_assert(cs.year() == 2016, "MinuteOverflow.year"); - static_assert(cs.month() == 1, "MinuteOverflow.month"); - static_assert(cs.day() == 28, "MinuteOverflow.day"); - static_assert(cs.hour() == 19, "MinuteOverflow.hour"); - static_assert(cs.minute() == 1, "MinuteOverflow.minute"); - static_assert(cs.second() == 12, "MinuteOverflow.second"); -} - -TEST(CivilTime, MinuteUnderflow) { - constexpr civil_second cs(2016, 1, 28, 17, -121, 12); - static_assert(cs.year() == 2016, "MinuteUnderflow.year"); - static_assert(cs.month() == 1, "MinuteUnderflow.month"); - static_assert(cs.day() == 28, "MinuteUnderflow.day"); - static_assert(cs.hour() == 14, "MinuteUnderflow.hour"); - static_assert(cs.minute() == 59, "MinuteUnderflow.minute"); - static_assert(cs.second() == 12, "MinuteUnderflow.second"); -} - -TEST(CivilTime, HourOverflow) { - constexpr civil_second cs(2016, 1, 28, 49, 14, 12); - static_assert(cs.year() == 2016, "HourOverflow.year"); - static_assert(cs.month() == 1, "HourOverflow.month"); - static_assert(cs.day() == 30, "HourOverflow.day"); - static_assert(cs.hour() == 1, "HourOverflow.hour"); - static_assert(cs.minute() == 14, "HourOverflow.minute"); - static_assert(cs.second() == 12, "HourOverflow.second"); -} - -TEST(CivilTime, HourUnderflow) { - constexpr civil_second cs(2016, 1, 28, -49, 14, 12); - static_assert(cs.year() == 2016, "HourUnderflow.year"); - static_assert(cs.month() == 1, "HourUnderflow.month"); - static_assert(cs.day() == 25, "HourUnderflow.day"); - static_assert(cs.hour() == 23, "HourUnderflow.hour"); - static_assert(cs.minute() == 14, "HourUnderflow.minute"); - static_assert(cs.second() == 12, "HourUnderflow.second"); -} - -TEST(CivilTime, MonthOverflow) { - constexpr civil_second cs(2016, 25, 28, 17, 14, 12); - static_assert(cs.year() == 2018, "MonthOverflow.year"); - static_assert(cs.month() == 1, "MonthOverflow.month"); - static_assert(cs.day() == 28, "MonthOverflow.day"); - static_assert(cs.hour() == 17, "MonthOverflow.hour"); - static_assert(cs.minute() == 14, "MonthOverflow.minute"); - static_assert(cs.second() == 12, "MonthOverflow.second"); -} - -TEST(CivilTime, MonthUnderflow) { - constexpr civil_second cs(2016, -25, 28, 17, 14, 12); - static_assert(cs.year() == 2013, "MonthUnderflow.year"); - static_assert(cs.month() == 11, "MonthUnderflow.month"); - static_assert(cs.day() == 28, "MonthUnderflow.day"); - static_assert(cs.hour() == 17, "MonthUnderflow.hour"); - static_assert(cs.minute() == 14, "MonthUnderflow.minute"); - static_assert(cs.second() == 12, "MonthUnderflow.second"); -} - -TEST(CivilTime, C4Overflow) { - constexpr civil_second cs(2016, 1, 292195, 17, 14, 12); - static_assert(cs.year() == 2816, "C4Overflow.year"); - static_assert(cs.month() == 1, "C4Overflow.month"); - static_assert(cs.day() == 1, "C4Overflow.day"); - static_assert(cs.hour() == 17, "C4Overflow.hour"); - static_assert(cs.minute() == 14, "C4Overflow.minute"); - static_assert(cs.second() == 12, "C4Overflow.second"); -} - -TEST(CivilTime, C4Underflow) { - constexpr civil_second cs(2016, 1, -292195, 17, 14, 12); - static_assert(cs.year() == 1215, "C4Underflow.year"); - static_assert(cs.month() == 12, "C4Underflow.month"); - static_assert(cs.day() == 30, "C4Underflow.day"); - static_assert(cs.hour() == 17, "C4Underflow.hour"); - static_assert(cs.minute() == 14, "C4Underflow.minute"); - static_assert(cs.second() == 12, "C4Underflow.second"); -} - -TEST(CivilTime, MixedNormalization) { - constexpr civil_second cs(2016, -42, 122, 99, -147, 4949); - static_assert(cs.year() == 2012, "MixedNormalization.year"); - static_assert(cs.month() == 10, "MixedNormalization.month"); - static_assert(cs.day() == 4, "MixedNormalization.day"); - static_assert(cs.hour() == 1, "MixedNormalization.hour"); - static_assert(cs.minute() == 55, "MixedNormalization.minute"); - static_assert(cs.second() == 29, "MixedNormalization.second"); -} - -// Relational constexpr tests - -TEST(CivilTime, Less) { - constexpr civil_second cs1(2016, 1, 28, 17, 14, 12); - constexpr civil_second cs2(2016, 1, 28, 17, 14, 13); - constexpr bool less = cs1 < cs2; - static_assert(less, "Less"); -} - -// Arithmetic constexpr tests - -TEST(CivilTime, Addition) { - constexpr civil_second cs1(2016, 1, 28, 17, 14, 12); - constexpr civil_second cs2 = cs1 + 50; - static_assert(cs2.year() == 2016, "Addition.year"); - static_assert(cs2.month() == 1, "Addition.month"); - static_assert(cs2.day() == 28, "Addition.day"); - static_assert(cs2.hour() == 17, "Addition.hour"); - static_assert(cs2.minute() == 15, "Addition.minute"); - static_assert(cs2.second() == 2, "Addition.second"); -} - -TEST(CivilTime, Subtraction) { - constexpr civil_second cs1(2016, 1, 28, 17, 14, 12); - constexpr civil_second cs2 = cs1 - 50; - static_assert(cs2.year() == 2016, "Subtraction.year"); - static_assert(cs2.month() == 1, "Subtraction.month"); - static_assert(cs2.day() == 28, "Subtraction.day"); - static_assert(cs2.hour() == 17, "Subtraction.hour"); - static_assert(cs2.minute() == 13, "Subtraction.minute"); - static_assert(cs2.second() == 22, "Subtraction.second"); -} - +// Construction constexpr tests + +TEST(CivilTime, Normal) { + constexpr civil_second css(2016, 1, 28, 17, 14, 12); + static_assert(css.second() == 12, "Normal.second"); + constexpr civil_minute cmm(2016, 1, 28, 17, 14); + static_assert(cmm.minute() == 14, "Normal.minute"); + constexpr civil_hour chh(2016, 1, 28, 17); + static_assert(chh.hour() == 17, "Normal.hour"); + constexpr civil_day cd(2016, 1, 28); + static_assert(cd.day() == 28, "Normal.day"); + constexpr civil_month cm(2016, 1); + static_assert(cm.month() == 1, "Normal.month"); + constexpr civil_year cy(2016); + static_assert(cy.year() == 2016, "Normal.year"); +} + +TEST(CivilTime, Conversion) { + constexpr civil_year cy(2016); + static_assert(cy.year() == 2016, "Conversion.year"); + constexpr civil_month cm(cy); + static_assert(cm.month() == 1, "Conversion.month"); + constexpr civil_day cd(cm); + static_assert(cd.day() == 1, "Conversion.day"); + constexpr civil_hour chh(cd); + static_assert(chh.hour() == 0, "Conversion.hour"); + constexpr civil_minute cmm(chh); + static_assert(cmm.minute() == 0, "Conversion.minute"); + constexpr civil_second css(cmm); + static_assert(css.second() == 0, "Conversion.second"); +} + +// Normalization constexpr tests + +TEST(CivilTime, Normalized) { + constexpr civil_second cs(2016, 1, 28, 17, 14, 12); + static_assert(cs.year() == 2016, "Normalized.year"); + static_assert(cs.month() == 1, "Normalized.month"); + static_assert(cs.day() == 28, "Normalized.day"); + static_assert(cs.hour() == 17, "Normalized.hour"); + static_assert(cs.minute() == 14, "Normalized.minute"); + static_assert(cs.second() == 12, "Normalized.second"); +} + +TEST(CivilTime, SecondOverflow) { + constexpr civil_second cs(2016, 1, 28, 17, 14, 121); + static_assert(cs.year() == 2016, "SecondOverflow.year"); + static_assert(cs.month() == 1, "SecondOverflow.month"); + static_assert(cs.day() == 28, "SecondOverflow.day"); + static_assert(cs.hour() == 17, "SecondOverflow.hour"); + static_assert(cs.minute() == 16, "SecondOverflow.minute"); + static_assert(cs.second() == 1, "SecondOverflow.second"); +} + +TEST(CivilTime, SecondUnderflow) { + constexpr civil_second cs(2016, 1, 28, 17, 14, -121); + static_assert(cs.year() == 2016, "SecondUnderflow.year"); + static_assert(cs.month() == 1, "SecondUnderflow.month"); + static_assert(cs.day() == 28, "SecondUnderflow.day"); + static_assert(cs.hour() == 17, "SecondUnderflow.hour"); + static_assert(cs.minute() == 11, "SecondUnderflow.minute"); + static_assert(cs.second() == 59, "SecondUnderflow.second"); +} + +TEST(CivilTime, MinuteOverflow) { + constexpr civil_second cs(2016, 1, 28, 17, 121, 12); + static_assert(cs.year() == 2016, "MinuteOverflow.year"); + static_assert(cs.month() == 1, "MinuteOverflow.month"); + static_assert(cs.day() == 28, "MinuteOverflow.day"); + static_assert(cs.hour() == 19, "MinuteOverflow.hour"); + static_assert(cs.minute() == 1, "MinuteOverflow.minute"); + static_assert(cs.second() == 12, "MinuteOverflow.second"); +} + +TEST(CivilTime, MinuteUnderflow) { + constexpr civil_second cs(2016, 1, 28, 17, -121, 12); + static_assert(cs.year() == 2016, "MinuteUnderflow.year"); + static_assert(cs.month() == 1, "MinuteUnderflow.month"); + static_assert(cs.day() == 28, "MinuteUnderflow.day"); + static_assert(cs.hour() == 14, "MinuteUnderflow.hour"); + static_assert(cs.minute() == 59, "MinuteUnderflow.minute"); + static_assert(cs.second() == 12, "MinuteUnderflow.second"); +} + +TEST(CivilTime, HourOverflow) { + constexpr civil_second cs(2016, 1, 28, 49, 14, 12); + static_assert(cs.year() == 2016, "HourOverflow.year"); + static_assert(cs.month() == 1, "HourOverflow.month"); + static_assert(cs.day() == 30, "HourOverflow.day"); + static_assert(cs.hour() == 1, "HourOverflow.hour"); + static_assert(cs.minute() == 14, "HourOverflow.minute"); + static_assert(cs.second() == 12, "HourOverflow.second"); +} + +TEST(CivilTime, HourUnderflow) { + constexpr civil_second cs(2016, 1, 28, -49, 14, 12); + static_assert(cs.year() == 2016, "HourUnderflow.year"); + static_assert(cs.month() == 1, "HourUnderflow.month"); + static_assert(cs.day() == 25, "HourUnderflow.day"); + static_assert(cs.hour() == 23, "HourUnderflow.hour"); + static_assert(cs.minute() == 14, "HourUnderflow.minute"); + static_assert(cs.second() == 12, "HourUnderflow.second"); +} + +TEST(CivilTime, MonthOverflow) { + constexpr civil_second cs(2016, 25, 28, 17, 14, 12); + static_assert(cs.year() == 2018, "MonthOverflow.year"); + static_assert(cs.month() == 1, "MonthOverflow.month"); + static_assert(cs.day() == 28, "MonthOverflow.day"); + static_assert(cs.hour() == 17, "MonthOverflow.hour"); + static_assert(cs.minute() == 14, "MonthOverflow.minute"); + static_assert(cs.second() == 12, "MonthOverflow.second"); +} + +TEST(CivilTime, MonthUnderflow) { + constexpr civil_second cs(2016, -25, 28, 17, 14, 12); + static_assert(cs.year() == 2013, "MonthUnderflow.year"); + static_assert(cs.month() == 11, "MonthUnderflow.month"); + static_assert(cs.day() == 28, "MonthUnderflow.day"); + static_assert(cs.hour() == 17, "MonthUnderflow.hour"); + static_assert(cs.minute() == 14, "MonthUnderflow.minute"); + static_assert(cs.second() == 12, "MonthUnderflow.second"); +} + +TEST(CivilTime, C4Overflow) { + constexpr civil_second cs(2016, 1, 292195, 17, 14, 12); + static_assert(cs.year() == 2816, "C4Overflow.year"); + static_assert(cs.month() == 1, "C4Overflow.month"); + static_assert(cs.day() == 1, "C4Overflow.day"); + static_assert(cs.hour() == 17, "C4Overflow.hour"); + static_assert(cs.minute() == 14, "C4Overflow.minute"); + static_assert(cs.second() == 12, "C4Overflow.second"); +} + +TEST(CivilTime, C4Underflow) { + constexpr civil_second cs(2016, 1, -292195, 17, 14, 12); + static_assert(cs.year() == 1215, "C4Underflow.year"); + static_assert(cs.month() == 12, "C4Underflow.month"); + static_assert(cs.day() == 30, "C4Underflow.day"); + static_assert(cs.hour() == 17, "C4Underflow.hour"); + static_assert(cs.minute() == 14, "C4Underflow.minute"); + static_assert(cs.second() == 12, "C4Underflow.second"); +} + +TEST(CivilTime, MixedNormalization) { + constexpr civil_second cs(2016, -42, 122, 99, -147, 4949); + static_assert(cs.year() == 2012, "MixedNormalization.year"); + static_assert(cs.month() == 10, "MixedNormalization.month"); + static_assert(cs.day() == 4, "MixedNormalization.day"); + static_assert(cs.hour() == 1, "MixedNormalization.hour"); + static_assert(cs.minute() == 55, "MixedNormalization.minute"); + static_assert(cs.second() == 29, "MixedNormalization.second"); +} + +// Relational constexpr tests + +TEST(CivilTime, Less) { + constexpr civil_second cs1(2016, 1, 28, 17, 14, 12); + constexpr civil_second cs2(2016, 1, 28, 17, 14, 13); + constexpr bool less = cs1 < cs2; + static_assert(less, "Less"); +} + +// Arithmetic constexpr tests + +TEST(CivilTime, Addition) { + constexpr civil_second cs1(2016, 1, 28, 17, 14, 12); + constexpr civil_second cs2 = cs1 + 50; + static_assert(cs2.year() == 2016, "Addition.year"); + static_assert(cs2.month() == 1, "Addition.month"); + static_assert(cs2.day() == 28, "Addition.day"); + static_assert(cs2.hour() == 17, "Addition.hour"); + static_assert(cs2.minute() == 15, "Addition.minute"); + static_assert(cs2.second() == 2, "Addition.second"); +} + +TEST(CivilTime, Subtraction) { + constexpr civil_second cs1(2016, 1, 28, 17, 14, 12); + constexpr civil_second cs2 = cs1 - 50; + static_assert(cs2.year() == 2016, "Subtraction.year"); + static_assert(cs2.month() == 1, "Subtraction.month"); + static_assert(cs2.day() == 28, "Subtraction.day"); + static_assert(cs2.hour() == 17, "Subtraction.hour"); + static_assert(cs2.minute() == 13, "Subtraction.minute"); + static_assert(cs2.second() == 22, "Subtraction.second"); +} + TEST(CivilTime, Difference) { - constexpr civil_day cd1(2016, 1, 28); - constexpr civil_day cd2(2015, 1, 28); - constexpr int diff = cd1 - cd2; - static_assert(diff == 365, "Difference"); -} - -// NOTE: Run this with --copt=-ftrapv to detect overflow problems. + constexpr civil_day cd1(2016, 1, 28); + constexpr civil_day cd2(2015, 1, 28); + constexpr int diff = cd1 - cd2; + static_assert(diff == 365, "Difference"); +} + +// NOTE: Run this with --copt=-ftrapv to detect overflow problems. TEST(CivilTime, ConstructionWithHugeYear) { constexpr civil_hour h(-9223372036854775807, 1, 1, -1); static_assert(h.year() == -9223372036854775807 - 1, @@ -241,825 +241,825 @@ TEST(CivilTime, ConstructionWithHugeYear) { } // NOTE: Run this with --copt=-ftrapv to detect overflow problems. -TEST(CivilTime, DifferenceWithHugeYear) { - { - constexpr civil_day d1(9223372036854775807, 1, 1); - constexpr civil_day d2(9223372036854775807, 12, 31); - static_assert(d2 - d1 == 364, "DifferenceWithHugeYear"); - } - { - constexpr civil_day d1(-9223372036854775807 - 1, 1, 1); - constexpr civil_day d2(-9223372036854775807 - 1, 12, 31); - static_assert(d2 - d1 == 365, "DifferenceWithHugeYear"); - } - { - // Check the limits of the return value at the end of the year range. - constexpr civil_day d1(9223372036854775807, 1, 1); - constexpr civil_day d2(9198119301927009252, 6, 6); - static_assert(d1 - d2 == 9223372036854775807, "DifferenceWithHugeYear"); - static_assert((d2 - 1) - d1 == -9223372036854775807 - 1, - "DifferenceWithHugeYear"); - } - { - // Check the limits of the return value at the start of the year range. - constexpr civil_day d1(-9223372036854775807 - 1, 1, 1); - constexpr civil_day d2(-9198119301927009254, 7, 28); - static_assert(d2 - d1 == 9223372036854775807, "DifferenceWithHugeYear"); - static_assert(d1 - (d2 + 1) == -9223372036854775807 - 1, - "DifferenceWithHugeYear"); - } - { - // Check the limits of the return value from either side of year 0. - constexpr civil_day d1(-12626367463883278, 9, 3); - constexpr civil_day d2(12626367463883277, 3, 28); - static_assert(d2 - d1 == 9223372036854775807, "DifferenceWithHugeYear"); - static_assert(d1 - (d2 + 1) == -9223372036854775807 - 1, - "DifferenceWithHugeYear"); - } -} - -// NOTE: Run this with --copt=-ftrapv to detect overflow problems. -TEST(CivilTime, DifferenceNoIntermediateOverflow) { - { - // The difference up to the minute field would be below the minimum - // diff_t, but the 52 extra seconds brings us back to the minimum. - constexpr civil_second s1(-292277022657, 1, 27, 8, 29 - 1, 52); - constexpr civil_second s2(1970, 1, 1, 0, 0 - 1, 0); - static_assert(s1 - s2 == -9223372036854775807 - 1, - "DifferenceNoIntermediateOverflow"); - } - { - // The difference up to the minute field would be above the maximum - // diff_t, but the -53 extra seconds brings us back to the maximum. - constexpr civil_second s1(292277026596, 12, 4, 15, 30, 7 - 7); - constexpr civil_second s2(1970, 1, 1, 0, 0, 0 - 7); - static_assert(s1 - s2 == 9223372036854775807, - "DifferenceNoIntermediateOverflow"); - } -} - -// Helper constexpr tests - -TEST(CivilTime, WeekDay) { - constexpr civil_day cd(2016, 1, 28); - constexpr weekday wd = get_weekday(cd); - static_assert(wd == weekday::thursday, "Weekday"); -} - -TEST(CivilTime, NextWeekDay) { - constexpr civil_day cd(2016, 1, 28); - constexpr civil_day next = next_weekday(cd, weekday::thursday); - static_assert(next.year() == 2016, "NextWeekDay.year"); - static_assert(next.month() == 2, "NextWeekDay.month"); - static_assert(next.day() == 4, "NextWeekDay.day"); -} - -TEST(CivilTime, PrevWeekDay) { - constexpr civil_day cd(2016, 1, 28); - constexpr civil_day prev = prev_weekday(cd, weekday::thursday); - static_assert(prev.year() == 2016, "PrevWeekDay.year"); - static_assert(prev.month() == 1, "PrevWeekDay.month"); - static_assert(prev.day() == 21, "PrevWeekDay.day"); -} - -TEST(CivilTime, YearDay) { - constexpr civil_day cd(2016, 1, 28); - constexpr int yd = get_yearday(cd); - static_assert(yd == 28, "YearDay"); -} +TEST(CivilTime, DifferenceWithHugeYear) { + { + constexpr civil_day d1(9223372036854775807, 1, 1); + constexpr civil_day d2(9223372036854775807, 12, 31); + static_assert(d2 - d1 == 364, "DifferenceWithHugeYear"); + } + { + constexpr civil_day d1(-9223372036854775807 - 1, 1, 1); + constexpr civil_day d2(-9223372036854775807 - 1, 12, 31); + static_assert(d2 - d1 == 365, "DifferenceWithHugeYear"); + } + { + // Check the limits of the return value at the end of the year range. + constexpr civil_day d1(9223372036854775807, 1, 1); + constexpr civil_day d2(9198119301927009252, 6, 6); + static_assert(d1 - d2 == 9223372036854775807, "DifferenceWithHugeYear"); + static_assert((d2 - 1) - d1 == -9223372036854775807 - 1, + "DifferenceWithHugeYear"); + } + { + // Check the limits of the return value at the start of the year range. + constexpr civil_day d1(-9223372036854775807 - 1, 1, 1); + constexpr civil_day d2(-9198119301927009254, 7, 28); + static_assert(d2 - d1 == 9223372036854775807, "DifferenceWithHugeYear"); + static_assert(d1 - (d2 + 1) == -9223372036854775807 - 1, + "DifferenceWithHugeYear"); + } + { + // Check the limits of the return value from either side of year 0. + constexpr civil_day d1(-12626367463883278, 9, 3); + constexpr civil_day d2(12626367463883277, 3, 28); + static_assert(d2 - d1 == 9223372036854775807, "DifferenceWithHugeYear"); + static_assert(d1 - (d2 + 1) == -9223372036854775807 - 1, + "DifferenceWithHugeYear"); + } +} + +// NOTE: Run this with --copt=-ftrapv to detect overflow problems. +TEST(CivilTime, DifferenceNoIntermediateOverflow) { + { + // The difference up to the minute field would be below the minimum + // diff_t, but the 52 extra seconds brings us back to the minimum. + constexpr civil_second s1(-292277022657, 1, 27, 8, 29 - 1, 52); + constexpr civil_second s2(1970, 1, 1, 0, 0 - 1, 0); + static_assert(s1 - s2 == -9223372036854775807 - 1, + "DifferenceNoIntermediateOverflow"); + } + { + // The difference up to the minute field would be above the maximum + // diff_t, but the -53 extra seconds brings us back to the maximum. + constexpr civil_second s1(292277026596, 12, 4, 15, 30, 7 - 7); + constexpr civil_second s2(1970, 1, 1, 0, 0, 0 - 7); + static_assert(s1 - s2 == 9223372036854775807, + "DifferenceNoIntermediateOverflow"); + } +} + +// Helper constexpr tests + +TEST(CivilTime, WeekDay) { + constexpr civil_day cd(2016, 1, 28); + constexpr weekday wd = get_weekday(cd); + static_assert(wd == weekday::thursday, "Weekday"); +} + +TEST(CivilTime, NextWeekDay) { + constexpr civil_day cd(2016, 1, 28); + constexpr civil_day next = next_weekday(cd, weekday::thursday); + static_assert(next.year() == 2016, "NextWeekDay.year"); + static_assert(next.month() == 2, "NextWeekDay.month"); + static_assert(next.day() == 4, "NextWeekDay.day"); +} + +TEST(CivilTime, PrevWeekDay) { + constexpr civil_day cd(2016, 1, 28); + constexpr civil_day prev = prev_weekday(cd, weekday::thursday); + static_assert(prev.year() == 2016, "PrevWeekDay.year"); + static_assert(prev.month() == 1, "PrevWeekDay.month"); + static_assert(prev.day() == 21, "PrevWeekDay.day"); +} + +TEST(CivilTime, YearDay) { + constexpr civil_day cd(2016, 1, 28); + constexpr int yd = get_yearday(cd); + static_assert(yd == 28, "YearDay"); +} #endif // __cpp_constexpr >= 201304 || (defined(_MSC_VER) && _MSC_VER >= 1910) - -// The remaining tests do not use constexpr. - -TEST(CivilTime, DefaultConstruction) { - civil_second ss; - EXPECT_EQ("1970-01-01T00:00:00", Format(ss)); - - civil_minute mm; - EXPECT_EQ("1970-01-01T00:00", Format(mm)); - - civil_hour hh; - EXPECT_EQ("1970-01-01T00", Format(hh)); - - civil_day d; - EXPECT_EQ("1970-01-01", Format(d)); - - civil_month m; - EXPECT_EQ("1970-01", Format(m)); - - civil_year y; - EXPECT_EQ("1970", Format(y)); -} - -TEST(CivilTime, StructMember) { - struct S { - civil_day day; - }; - S s = {}; - EXPECT_EQ(civil_day{}, s.day); -} - -TEST(CivilTime, FieldsConstruction) { - EXPECT_EQ("2015-01-02T03:04:05", Format(civil_second(2015, 1, 2, 3, 4, 5))); - EXPECT_EQ("2015-01-02T03:04:00", Format(civil_second(2015, 1, 2, 3, 4))); - EXPECT_EQ("2015-01-02T03:00:00", Format(civil_second(2015, 1, 2, 3))); - EXPECT_EQ("2015-01-02T00:00:00", Format(civil_second(2015, 1, 2))); - EXPECT_EQ("2015-01-01T00:00:00", Format(civil_second(2015, 1))); - EXPECT_EQ("2015-01-01T00:00:00", Format(civil_second(2015))); - - EXPECT_EQ("2015-01-02T03:04", Format(civil_minute(2015, 1, 2, 3, 4, 5))); - EXPECT_EQ("2015-01-02T03:04", Format(civil_minute(2015, 1, 2, 3, 4))); - EXPECT_EQ("2015-01-02T03:00", Format(civil_minute(2015, 1, 2, 3))); - EXPECT_EQ("2015-01-02T00:00", Format(civil_minute(2015, 1, 2))); - EXPECT_EQ("2015-01-01T00:00", Format(civil_minute(2015, 1))); - EXPECT_EQ("2015-01-01T00:00", Format(civil_minute(2015))); - - EXPECT_EQ("2015-01-02T03", Format(civil_hour(2015, 1, 2, 3, 4, 5))); - EXPECT_EQ("2015-01-02T03", Format(civil_hour(2015, 1, 2, 3, 4))); - EXPECT_EQ("2015-01-02T03", Format(civil_hour(2015, 1, 2, 3))); - EXPECT_EQ("2015-01-02T00", Format(civil_hour(2015, 1, 2))); - EXPECT_EQ("2015-01-01T00", Format(civil_hour(2015, 1))); - EXPECT_EQ("2015-01-01T00", Format(civil_hour(2015))); - - EXPECT_EQ("2015-01-02", Format(civil_day(2015, 1, 2, 3, 4, 5))); - EXPECT_EQ("2015-01-02", Format(civil_day(2015, 1, 2, 3, 4))); - EXPECT_EQ("2015-01-02", Format(civil_day(2015, 1, 2, 3))); - EXPECT_EQ("2015-01-02", Format(civil_day(2015, 1, 2))); - EXPECT_EQ("2015-01-01", Format(civil_day(2015, 1))); - EXPECT_EQ("2015-01-01", Format(civil_day(2015))); - - EXPECT_EQ("2015-01", Format(civil_month(2015, 1, 2, 3, 4, 5))); - EXPECT_EQ("2015-01", Format(civil_month(2015, 1, 2, 3, 4))); - EXPECT_EQ("2015-01", Format(civil_month(2015, 1, 2, 3))); - EXPECT_EQ("2015-01", Format(civil_month(2015, 1, 2))); - EXPECT_EQ("2015-01", Format(civil_month(2015, 1))); - EXPECT_EQ("2015-01", Format(civil_month(2015))); - - EXPECT_EQ("2015", Format(civil_year(2015, 1, 2, 3, 4, 5))); - EXPECT_EQ("2015", Format(civil_year(2015, 1, 2, 3, 4))); - EXPECT_EQ("2015", Format(civil_year(2015, 1, 2, 3))); - EXPECT_EQ("2015", Format(civil_year(2015, 1, 2))); - EXPECT_EQ("2015", Format(civil_year(2015, 1))); - EXPECT_EQ("2015", Format(civil_year(2015))); -} - -TEST(CivilTime, FieldsConstructionLimits) { - const int kIntMax = std::numeric_limits<int>::max(); - EXPECT_EQ("2038-01-19T03:14:07", - Format(civil_second(1970, 1, 1, 0, 0, kIntMax))); - EXPECT_EQ("6121-02-11T05:21:07", - Format(civil_second(1970, 1, 1, 0, kIntMax, kIntMax))); - EXPECT_EQ("251104-11-20T12:21:07", - Format(civil_second(1970, 1, 1, kIntMax, kIntMax, kIntMax))); - EXPECT_EQ("6130715-05-30T12:21:07", - Format(civil_second(1970, 1, kIntMax, kIntMax, kIntMax, kIntMax))); - EXPECT_EQ( - "185087685-11-26T12:21:07", - Format(civil_second(1970, kIntMax, kIntMax, kIntMax, kIntMax, kIntMax))); - - const int kIntMin = std::numeric_limits<int>::min(); - EXPECT_EQ("1901-12-13T20:45:52", - Format(civil_second(1970, 1, 1, 0, 0, kIntMin))); - EXPECT_EQ("-2182-11-20T18:37:52", - Format(civil_second(1970, 1, 1, 0, kIntMin, kIntMin))); - EXPECT_EQ("-247165-02-11T10:37:52", - Format(civil_second(1970, 1, 1, kIntMin, kIntMin, kIntMin))); - EXPECT_EQ("-6126776-08-01T10:37:52", - Format(civil_second(1970, 1, kIntMin, kIntMin, kIntMin, kIntMin))); - EXPECT_EQ( - "-185083747-10-31T10:37:52", - Format(civil_second(1970, kIntMin, kIntMin, kIntMin, kIntMin, kIntMin))); -} - -TEST(CivilTime, ImplicitCrossAlignment) { - civil_year year(2015); - civil_month month = year; - civil_day day = month; - civil_hour hour = day; - civil_minute minute = hour; - civil_second second = minute; - - second = year; - EXPECT_EQ(second, year); - second = month; - EXPECT_EQ(second, month); - second = day; - EXPECT_EQ(second, day); - second = hour; - EXPECT_EQ(second, hour); - second = minute; - EXPECT_EQ(second, minute); - - minute = year; - EXPECT_EQ(minute, year); - minute = month; - EXPECT_EQ(minute, month); - minute = day; - EXPECT_EQ(minute, day); - minute = hour; - EXPECT_EQ(minute, hour); - - hour = year; - EXPECT_EQ(hour, year); - hour = month; - EXPECT_EQ(hour, month); - hour = day; - EXPECT_EQ(hour, day); - - day = year; - EXPECT_EQ(day, year); - day = month; - EXPECT_EQ(day, month); - - month = year; - EXPECT_EQ(month, year); - - // Ensures unsafe conversions are not allowed. - EXPECT_FALSE((std::is_convertible<civil_second, civil_minute>::value)); - EXPECT_FALSE((std::is_convertible<civil_second, civil_hour>::value)); - EXPECT_FALSE((std::is_convertible<civil_second, civil_day>::value)); - EXPECT_FALSE((std::is_convertible<civil_second, civil_month>::value)); - EXPECT_FALSE((std::is_convertible<civil_second, civil_year>::value)); - - EXPECT_FALSE((std::is_convertible<civil_minute, civil_hour>::value)); - EXPECT_FALSE((std::is_convertible<civil_minute, civil_day>::value)); - EXPECT_FALSE((std::is_convertible<civil_minute, civil_month>::value)); - EXPECT_FALSE((std::is_convertible<civil_minute, civil_year>::value)); - - EXPECT_FALSE((std::is_convertible<civil_hour, civil_day>::value)); - EXPECT_FALSE((std::is_convertible<civil_hour, civil_month>::value)); - EXPECT_FALSE((std::is_convertible<civil_hour, civil_year>::value)); - - EXPECT_FALSE((std::is_convertible<civil_day, civil_month>::value)); - EXPECT_FALSE((std::is_convertible<civil_day, civil_year>::value)); - - EXPECT_FALSE((std::is_convertible<civil_month, civil_year>::value)); -} - -TEST(CivilTime, ExplicitCrossAlignment) { - // - // Assign from smaller units -> larger units - // - - civil_second second(2015, 1, 2, 3, 4, 5); - EXPECT_EQ("2015-01-02T03:04:05", Format(second)); - - civil_minute minute(second); - EXPECT_EQ("2015-01-02T03:04", Format(minute)); - - civil_hour hour(minute); - EXPECT_EQ("2015-01-02T03", Format(hour)); - - civil_day day(hour); - EXPECT_EQ("2015-01-02", Format(day)); - - civil_month month(day); - EXPECT_EQ("2015-01", Format(month)); - - civil_year year(month); - EXPECT_EQ("2015", Format(year)); - - // - // Now assign from larger units -> smaller units - // - - month = civil_month(year); - EXPECT_EQ("2015-01", Format(month)); - - day = civil_day(month); - EXPECT_EQ("2015-01-01", Format(day)); - - hour = civil_hour(day); - EXPECT_EQ("2015-01-01T00", Format(hour)); - - minute = civil_minute(hour); - EXPECT_EQ("2015-01-01T00:00", Format(minute)); - - second = civil_second(minute); - EXPECT_EQ("2015-01-01T00:00:00", Format(second)); -} - -// Metafunction to test whether difference is allowed between two types. -template <typename T1, typename T2> -struct HasDifference { - template <typename U1, typename U2> - static std::false_type test(...); - template <typename U1, typename U2> - static std::true_type test(decltype(std::declval<U1>() - std::declval<U2>())); - static constexpr bool value = decltype(test<T1, T2>(0))::value; -}; - -TEST(CivilTime, DisallowCrossAlignedDifference) { - // Difference is allowed between types with the same alignment. - static_assert(HasDifference<civil_second, civil_second>::value, ""); - static_assert(HasDifference<civil_minute, civil_minute>::value, ""); - static_assert(HasDifference<civil_hour, civil_hour>::value, ""); - static_assert(HasDifference<civil_day, civil_day>::value, ""); - static_assert(HasDifference<civil_month, civil_month>::value, ""); - static_assert(HasDifference<civil_year, civil_year>::value, ""); - - // Difference is disallowed between types with different alignments. - static_assert(!HasDifference<civil_second, civil_minute>::value, ""); - static_assert(!HasDifference<civil_second, civil_hour>::value, ""); - static_assert(!HasDifference<civil_second, civil_day>::value, ""); - static_assert(!HasDifference<civil_second, civil_month>::value, ""); - static_assert(!HasDifference<civil_second, civil_year>::value, ""); - - static_assert(!HasDifference<civil_minute, civil_hour>::value, ""); - static_assert(!HasDifference<civil_minute, civil_day>::value, ""); - static_assert(!HasDifference<civil_minute, civil_month>::value, ""); - static_assert(!HasDifference<civil_minute, civil_year>::value, ""); - - static_assert(!HasDifference<civil_hour, civil_day>::value, ""); - static_assert(!HasDifference<civil_hour, civil_month>::value, ""); - static_assert(!HasDifference<civil_hour, civil_year>::value, ""); - - static_assert(!HasDifference<civil_day, civil_month>::value, ""); - static_assert(!HasDifference<civil_day, civil_year>::value, ""); - - static_assert(!HasDifference<civil_month, civil_year>::value, ""); -} - -TEST(CivilTime, ValueSemantics) { - const civil_hour a(2015, 1, 2, 3); - const civil_hour b = a; - const civil_hour c(b); - civil_hour d; - d = c; - EXPECT_EQ("2015-01-02T03", Format(d)); -} - -TEST(CivilTime, Relational) { - // Tests that the alignment unit is ignored in comparison. - const civil_year year(2014); - const civil_month month(year); - EXPECT_EQ(year, month); - -#define TEST_RELATIONAL(OLDER, YOUNGER) \ - do { \ - EXPECT_FALSE(OLDER < OLDER); \ - EXPECT_FALSE(OLDER > OLDER); \ - EXPECT_TRUE(OLDER >= OLDER); \ - EXPECT_TRUE(OLDER <= OLDER); \ - EXPECT_FALSE(YOUNGER < YOUNGER); \ - EXPECT_FALSE(YOUNGER > YOUNGER); \ - EXPECT_TRUE(YOUNGER >= YOUNGER); \ - EXPECT_TRUE(YOUNGER <= YOUNGER); \ - EXPECT_EQ(OLDER, OLDER); \ - EXPECT_NE(OLDER, YOUNGER); \ - EXPECT_LT(OLDER, YOUNGER); \ - EXPECT_LE(OLDER, YOUNGER); \ - EXPECT_GT(YOUNGER, OLDER); \ - EXPECT_GE(YOUNGER, OLDER); \ - } while (0) - - // Alignment is ignored in comparison (verified above), so kSecond is used - // to test comparison in all field positions. - TEST_RELATIONAL(civil_second(2014, 1, 1, 0, 0, 0), - civil_second(2015, 1, 1, 0, 0, 0)); - TEST_RELATIONAL(civil_second(2014, 1, 1, 0, 0, 0), - civil_second(2014, 2, 1, 0, 0, 0)); - TEST_RELATIONAL(civil_second(2014, 1, 1, 0, 0, 0), - civil_second(2014, 1, 2, 0, 0, 0)); - TEST_RELATIONAL(civil_second(2014, 1, 1, 0, 0, 0), - civil_second(2014, 1, 1, 1, 0, 0)); - TEST_RELATIONAL(civil_second(2014, 1, 1, 1, 0, 0), - civil_second(2014, 1, 1, 1, 1, 0)); - TEST_RELATIONAL(civil_second(2014, 1, 1, 1, 1, 0), - civil_second(2014, 1, 1, 1, 1, 1)); - + +// The remaining tests do not use constexpr. + +TEST(CivilTime, DefaultConstruction) { + civil_second ss; + EXPECT_EQ("1970-01-01T00:00:00", Format(ss)); + + civil_minute mm; + EXPECT_EQ("1970-01-01T00:00", Format(mm)); + + civil_hour hh; + EXPECT_EQ("1970-01-01T00", Format(hh)); + + civil_day d; + EXPECT_EQ("1970-01-01", Format(d)); + + civil_month m; + EXPECT_EQ("1970-01", Format(m)); + + civil_year y; + EXPECT_EQ("1970", Format(y)); +} + +TEST(CivilTime, StructMember) { + struct S { + civil_day day; + }; + S s = {}; + EXPECT_EQ(civil_day{}, s.day); +} + +TEST(CivilTime, FieldsConstruction) { + EXPECT_EQ("2015-01-02T03:04:05", Format(civil_second(2015, 1, 2, 3, 4, 5))); + EXPECT_EQ("2015-01-02T03:04:00", Format(civil_second(2015, 1, 2, 3, 4))); + EXPECT_EQ("2015-01-02T03:00:00", Format(civil_second(2015, 1, 2, 3))); + EXPECT_EQ("2015-01-02T00:00:00", Format(civil_second(2015, 1, 2))); + EXPECT_EQ("2015-01-01T00:00:00", Format(civil_second(2015, 1))); + EXPECT_EQ("2015-01-01T00:00:00", Format(civil_second(2015))); + + EXPECT_EQ("2015-01-02T03:04", Format(civil_minute(2015, 1, 2, 3, 4, 5))); + EXPECT_EQ("2015-01-02T03:04", Format(civil_minute(2015, 1, 2, 3, 4))); + EXPECT_EQ("2015-01-02T03:00", Format(civil_minute(2015, 1, 2, 3))); + EXPECT_EQ("2015-01-02T00:00", Format(civil_minute(2015, 1, 2))); + EXPECT_EQ("2015-01-01T00:00", Format(civil_minute(2015, 1))); + EXPECT_EQ("2015-01-01T00:00", Format(civil_minute(2015))); + + EXPECT_EQ("2015-01-02T03", Format(civil_hour(2015, 1, 2, 3, 4, 5))); + EXPECT_EQ("2015-01-02T03", Format(civil_hour(2015, 1, 2, 3, 4))); + EXPECT_EQ("2015-01-02T03", Format(civil_hour(2015, 1, 2, 3))); + EXPECT_EQ("2015-01-02T00", Format(civil_hour(2015, 1, 2))); + EXPECT_EQ("2015-01-01T00", Format(civil_hour(2015, 1))); + EXPECT_EQ("2015-01-01T00", Format(civil_hour(2015))); + + EXPECT_EQ("2015-01-02", Format(civil_day(2015, 1, 2, 3, 4, 5))); + EXPECT_EQ("2015-01-02", Format(civil_day(2015, 1, 2, 3, 4))); + EXPECT_EQ("2015-01-02", Format(civil_day(2015, 1, 2, 3))); + EXPECT_EQ("2015-01-02", Format(civil_day(2015, 1, 2))); + EXPECT_EQ("2015-01-01", Format(civil_day(2015, 1))); + EXPECT_EQ("2015-01-01", Format(civil_day(2015))); + + EXPECT_EQ("2015-01", Format(civil_month(2015, 1, 2, 3, 4, 5))); + EXPECT_EQ("2015-01", Format(civil_month(2015, 1, 2, 3, 4))); + EXPECT_EQ("2015-01", Format(civil_month(2015, 1, 2, 3))); + EXPECT_EQ("2015-01", Format(civil_month(2015, 1, 2))); + EXPECT_EQ("2015-01", Format(civil_month(2015, 1))); + EXPECT_EQ("2015-01", Format(civil_month(2015))); + + EXPECT_EQ("2015", Format(civil_year(2015, 1, 2, 3, 4, 5))); + EXPECT_EQ("2015", Format(civil_year(2015, 1, 2, 3, 4))); + EXPECT_EQ("2015", Format(civil_year(2015, 1, 2, 3))); + EXPECT_EQ("2015", Format(civil_year(2015, 1, 2))); + EXPECT_EQ("2015", Format(civil_year(2015, 1))); + EXPECT_EQ("2015", Format(civil_year(2015))); +} + +TEST(CivilTime, FieldsConstructionLimits) { + const int kIntMax = std::numeric_limits<int>::max(); + EXPECT_EQ("2038-01-19T03:14:07", + Format(civil_second(1970, 1, 1, 0, 0, kIntMax))); + EXPECT_EQ("6121-02-11T05:21:07", + Format(civil_second(1970, 1, 1, 0, kIntMax, kIntMax))); + EXPECT_EQ("251104-11-20T12:21:07", + Format(civil_second(1970, 1, 1, kIntMax, kIntMax, kIntMax))); + EXPECT_EQ("6130715-05-30T12:21:07", + Format(civil_second(1970, 1, kIntMax, kIntMax, kIntMax, kIntMax))); + EXPECT_EQ( + "185087685-11-26T12:21:07", + Format(civil_second(1970, kIntMax, kIntMax, kIntMax, kIntMax, kIntMax))); + + const int kIntMin = std::numeric_limits<int>::min(); + EXPECT_EQ("1901-12-13T20:45:52", + Format(civil_second(1970, 1, 1, 0, 0, kIntMin))); + EXPECT_EQ("-2182-11-20T18:37:52", + Format(civil_second(1970, 1, 1, 0, kIntMin, kIntMin))); + EXPECT_EQ("-247165-02-11T10:37:52", + Format(civil_second(1970, 1, 1, kIntMin, kIntMin, kIntMin))); + EXPECT_EQ("-6126776-08-01T10:37:52", + Format(civil_second(1970, 1, kIntMin, kIntMin, kIntMin, kIntMin))); + EXPECT_EQ( + "-185083747-10-31T10:37:52", + Format(civil_second(1970, kIntMin, kIntMin, kIntMin, kIntMin, kIntMin))); +} + +TEST(CivilTime, ImplicitCrossAlignment) { + civil_year year(2015); + civil_month month = year; + civil_day day = month; + civil_hour hour = day; + civil_minute minute = hour; + civil_second second = minute; + + second = year; + EXPECT_EQ(second, year); + second = month; + EXPECT_EQ(second, month); + second = day; + EXPECT_EQ(second, day); + second = hour; + EXPECT_EQ(second, hour); + second = minute; + EXPECT_EQ(second, minute); + + minute = year; + EXPECT_EQ(minute, year); + minute = month; + EXPECT_EQ(minute, month); + minute = day; + EXPECT_EQ(minute, day); + minute = hour; + EXPECT_EQ(minute, hour); + + hour = year; + EXPECT_EQ(hour, year); + hour = month; + EXPECT_EQ(hour, month); + hour = day; + EXPECT_EQ(hour, day); + + day = year; + EXPECT_EQ(day, year); + day = month; + EXPECT_EQ(day, month); + + month = year; + EXPECT_EQ(month, year); + + // Ensures unsafe conversions are not allowed. + EXPECT_FALSE((std::is_convertible<civil_second, civil_minute>::value)); + EXPECT_FALSE((std::is_convertible<civil_second, civil_hour>::value)); + EXPECT_FALSE((std::is_convertible<civil_second, civil_day>::value)); + EXPECT_FALSE((std::is_convertible<civil_second, civil_month>::value)); + EXPECT_FALSE((std::is_convertible<civil_second, civil_year>::value)); + + EXPECT_FALSE((std::is_convertible<civil_minute, civil_hour>::value)); + EXPECT_FALSE((std::is_convertible<civil_minute, civil_day>::value)); + EXPECT_FALSE((std::is_convertible<civil_minute, civil_month>::value)); + EXPECT_FALSE((std::is_convertible<civil_minute, civil_year>::value)); + + EXPECT_FALSE((std::is_convertible<civil_hour, civil_day>::value)); + EXPECT_FALSE((std::is_convertible<civil_hour, civil_month>::value)); + EXPECT_FALSE((std::is_convertible<civil_hour, civil_year>::value)); + + EXPECT_FALSE((std::is_convertible<civil_day, civil_month>::value)); + EXPECT_FALSE((std::is_convertible<civil_day, civil_year>::value)); + + EXPECT_FALSE((std::is_convertible<civil_month, civil_year>::value)); +} + +TEST(CivilTime, ExplicitCrossAlignment) { + // + // Assign from smaller units -> larger units + // + + civil_second second(2015, 1, 2, 3, 4, 5); + EXPECT_EQ("2015-01-02T03:04:05", Format(second)); + + civil_minute minute(second); + EXPECT_EQ("2015-01-02T03:04", Format(minute)); + + civil_hour hour(minute); + EXPECT_EQ("2015-01-02T03", Format(hour)); + + civil_day day(hour); + EXPECT_EQ("2015-01-02", Format(day)); + + civil_month month(day); + EXPECT_EQ("2015-01", Format(month)); + + civil_year year(month); + EXPECT_EQ("2015", Format(year)); + + // + // Now assign from larger units -> smaller units + // + + month = civil_month(year); + EXPECT_EQ("2015-01", Format(month)); + + day = civil_day(month); + EXPECT_EQ("2015-01-01", Format(day)); + + hour = civil_hour(day); + EXPECT_EQ("2015-01-01T00", Format(hour)); + + minute = civil_minute(hour); + EXPECT_EQ("2015-01-01T00:00", Format(minute)); + + second = civil_second(minute); + EXPECT_EQ("2015-01-01T00:00:00", Format(second)); +} + +// Metafunction to test whether difference is allowed between two types. +template <typename T1, typename T2> +struct HasDifference { + template <typename U1, typename U2> + static std::false_type test(...); + template <typename U1, typename U2> + static std::true_type test(decltype(std::declval<U1>() - std::declval<U2>())); + static constexpr bool value = decltype(test<T1, T2>(0))::value; +}; + +TEST(CivilTime, DisallowCrossAlignedDifference) { + // Difference is allowed between types with the same alignment. + static_assert(HasDifference<civil_second, civil_second>::value, ""); + static_assert(HasDifference<civil_minute, civil_minute>::value, ""); + static_assert(HasDifference<civil_hour, civil_hour>::value, ""); + static_assert(HasDifference<civil_day, civil_day>::value, ""); + static_assert(HasDifference<civil_month, civil_month>::value, ""); + static_assert(HasDifference<civil_year, civil_year>::value, ""); + + // Difference is disallowed between types with different alignments. + static_assert(!HasDifference<civil_second, civil_minute>::value, ""); + static_assert(!HasDifference<civil_second, civil_hour>::value, ""); + static_assert(!HasDifference<civil_second, civil_day>::value, ""); + static_assert(!HasDifference<civil_second, civil_month>::value, ""); + static_assert(!HasDifference<civil_second, civil_year>::value, ""); + + static_assert(!HasDifference<civil_minute, civil_hour>::value, ""); + static_assert(!HasDifference<civil_minute, civil_day>::value, ""); + static_assert(!HasDifference<civil_minute, civil_month>::value, ""); + static_assert(!HasDifference<civil_minute, civil_year>::value, ""); + + static_assert(!HasDifference<civil_hour, civil_day>::value, ""); + static_assert(!HasDifference<civil_hour, civil_month>::value, ""); + static_assert(!HasDifference<civil_hour, civil_year>::value, ""); + + static_assert(!HasDifference<civil_day, civil_month>::value, ""); + static_assert(!HasDifference<civil_day, civil_year>::value, ""); + + static_assert(!HasDifference<civil_month, civil_year>::value, ""); +} + +TEST(CivilTime, ValueSemantics) { + const civil_hour a(2015, 1, 2, 3); + const civil_hour b = a; + const civil_hour c(b); + civil_hour d; + d = c; + EXPECT_EQ("2015-01-02T03", Format(d)); +} + +TEST(CivilTime, Relational) { + // Tests that the alignment unit is ignored in comparison. + const civil_year year(2014); + const civil_month month(year); + EXPECT_EQ(year, month); + +#define TEST_RELATIONAL(OLDER, YOUNGER) \ + do { \ + EXPECT_FALSE(OLDER < OLDER); \ + EXPECT_FALSE(OLDER > OLDER); \ + EXPECT_TRUE(OLDER >= OLDER); \ + EXPECT_TRUE(OLDER <= OLDER); \ + EXPECT_FALSE(YOUNGER < YOUNGER); \ + EXPECT_FALSE(YOUNGER > YOUNGER); \ + EXPECT_TRUE(YOUNGER >= YOUNGER); \ + EXPECT_TRUE(YOUNGER <= YOUNGER); \ + EXPECT_EQ(OLDER, OLDER); \ + EXPECT_NE(OLDER, YOUNGER); \ + EXPECT_LT(OLDER, YOUNGER); \ + EXPECT_LE(OLDER, YOUNGER); \ + EXPECT_GT(YOUNGER, OLDER); \ + EXPECT_GE(YOUNGER, OLDER); \ + } while (0) + + // Alignment is ignored in comparison (verified above), so kSecond is used + // to test comparison in all field positions. + TEST_RELATIONAL(civil_second(2014, 1, 1, 0, 0, 0), + civil_second(2015, 1, 1, 0, 0, 0)); + TEST_RELATIONAL(civil_second(2014, 1, 1, 0, 0, 0), + civil_second(2014, 2, 1, 0, 0, 0)); + TEST_RELATIONAL(civil_second(2014, 1, 1, 0, 0, 0), + civil_second(2014, 1, 2, 0, 0, 0)); + TEST_RELATIONAL(civil_second(2014, 1, 1, 0, 0, 0), + civil_second(2014, 1, 1, 1, 0, 0)); + TEST_RELATIONAL(civil_second(2014, 1, 1, 1, 0, 0), + civil_second(2014, 1, 1, 1, 1, 0)); + TEST_RELATIONAL(civil_second(2014, 1, 1, 1, 1, 0), + civil_second(2014, 1, 1, 1, 1, 1)); + // Tests the relational operators of two different civil-time types. - TEST_RELATIONAL(civil_day(2014, 1, 1), civil_minute(2014, 1, 1, 1, 1)); - TEST_RELATIONAL(civil_day(2014, 1, 1), civil_month(2014, 2)); - -#undef TEST_RELATIONAL -} - -TEST(CivilTime, Arithmetic) { - civil_second second(2015, 1, 2, 3, 4, 5); - EXPECT_EQ("2015-01-02T03:04:06", Format(second += 1)); - EXPECT_EQ("2015-01-02T03:04:07", Format(second + 1)); - EXPECT_EQ("2015-01-02T03:04:08", Format(2 + second)); - EXPECT_EQ("2015-01-02T03:04:05", Format(second - 1)); - EXPECT_EQ("2015-01-02T03:04:05", Format(second -= 1)); - EXPECT_EQ("2015-01-02T03:04:05", Format(second++)); - EXPECT_EQ("2015-01-02T03:04:07", Format(++second)); - EXPECT_EQ("2015-01-02T03:04:07", Format(second--)); - EXPECT_EQ("2015-01-02T03:04:05", Format(--second)); - - civil_minute minute(2015, 1, 2, 3, 4); - EXPECT_EQ("2015-01-02T03:05", Format(minute += 1)); - EXPECT_EQ("2015-01-02T03:06", Format(minute + 1)); - EXPECT_EQ("2015-01-02T03:07", Format(2 + minute)); - EXPECT_EQ("2015-01-02T03:04", Format(minute - 1)); - EXPECT_EQ("2015-01-02T03:04", Format(minute -= 1)); - EXPECT_EQ("2015-01-02T03:04", Format(minute++)); - EXPECT_EQ("2015-01-02T03:06", Format(++minute)); - EXPECT_EQ("2015-01-02T03:06", Format(minute--)); - EXPECT_EQ("2015-01-02T03:04", Format(--minute)); - - civil_hour hour(2015, 1, 2, 3); - EXPECT_EQ("2015-01-02T04", Format(hour += 1)); - EXPECT_EQ("2015-01-02T05", Format(hour + 1)); - EXPECT_EQ("2015-01-02T06", Format(2 + hour)); - EXPECT_EQ("2015-01-02T03", Format(hour - 1)); - EXPECT_EQ("2015-01-02T03", Format(hour -= 1)); - EXPECT_EQ("2015-01-02T03", Format(hour++)); - EXPECT_EQ("2015-01-02T05", Format(++hour)); - EXPECT_EQ("2015-01-02T05", Format(hour--)); - EXPECT_EQ("2015-01-02T03", Format(--hour)); - - civil_day day(2015, 1, 2); - EXPECT_EQ("2015-01-03", Format(day += 1)); - EXPECT_EQ("2015-01-04", Format(day + 1)); - EXPECT_EQ("2015-01-05", Format(2 + day)); - EXPECT_EQ("2015-01-02", Format(day - 1)); - EXPECT_EQ("2015-01-02", Format(day -= 1)); - EXPECT_EQ("2015-01-02", Format(day++)); - EXPECT_EQ("2015-01-04", Format(++day)); - EXPECT_EQ("2015-01-04", Format(day--)); - EXPECT_EQ("2015-01-02", Format(--day)); - - civil_month month(2015, 1); - EXPECT_EQ("2015-02", Format(month += 1)); - EXPECT_EQ("2015-03", Format(month + 1)); - EXPECT_EQ("2015-04", Format(2 + month)); - EXPECT_EQ("2015-01", Format(month - 1)); - EXPECT_EQ("2015-01", Format(month -= 1)); - EXPECT_EQ("2015-01", Format(month++)); - EXPECT_EQ("2015-03", Format(++month)); - EXPECT_EQ("2015-03", Format(month--)); - EXPECT_EQ("2015-01", Format(--month)); - - civil_year year(2015); - EXPECT_EQ("2016", Format(year += 1)); - EXPECT_EQ("2017", Format(year + 1)); - EXPECT_EQ("2018", Format(2 + year)); - EXPECT_EQ("2015", Format(year - 1)); - EXPECT_EQ("2015", Format(year -= 1)); - EXPECT_EQ("2015", Format(year++)); - EXPECT_EQ("2017", Format(++year)); - EXPECT_EQ("2017", Format(year--)); - EXPECT_EQ("2015", Format(--year)); -} - -TEST(CivilTime, ArithmeticLimits) { - const int kIntMax = std::numeric_limits<int>::max(); - const int kIntMin = std::numeric_limits<int>::min(); - - civil_second second(1970, 1, 1, 0, 0, 0); - second += kIntMax; - EXPECT_EQ("2038-01-19T03:14:07", Format(second)); - second -= kIntMax; - EXPECT_EQ("1970-01-01T00:00:00", Format(second)); - second += kIntMin; - EXPECT_EQ("1901-12-13T20:45:52", Format(second)); - second -= kIntMin; - EXPECT_EQ("1970-01-01T00:00:00", Format(second)); - - civil_minute minute(1970, 1, 1, 0, 0); - minute += kIntMax; - EXPECT_EQ("6053-01-23T02:07", Format(minute)); - minute -= kIntMax; - EXPECT_EQ("1970-01-01T00:00", Format(minute)); - minute += kIntMin; - EXPECT_EQ("-2114-12-08T21:52", Format(minute)); - minute -= kIntMin; - EXPECT_EQ("1970-01-01T00:00", Format(minute)); - - civil_hour hour(1970, 1, 1, 0); - hour += kIntMax; - EXPECT_EQ("246953-10-09T07", Format(hour)); - hour -= kIntMax; - EXPECT_EQ("1970-01-01T00", Format(hour)); - hour += kIntMin; - EXPECT_EQ("-243014-03-24T16", Format(hour)); - hour -= kIntMin; - EXPECT_EQ("1970-01-01T00", Format(hour)); - - civil_day day(1970, 1, 1); - day += kIntMax; - EXPECT_EQ("5881580-07-11", Format(day)); - day -= kIntMax; - EXPECT_EQ("1970-01-01", Format(day)); - day += kIntMin; - EXPECT_EQ("-5877641-06-23", Format(day)); - day -= kIntMin; - EXPECT_EQ("1970-01-01", Format(day)); - - civil_month month(1970, 1); - month += kIntMax; - EXPECT_EQ("178958940-08", Format(month)); - month -= kIntMax; - EXPECT_EQ("1970-01", Format(month)); - month += kIntMin; - EXPECT_EQ("-178955001-05", Format(month)); - month -= kIntMin; - EXPECT_EQ("1970-01", Format(month)); - - civil_year year(0); - year += kIntMax; - EXPECT_EQ("2147483647", Format(year)); - year -= kIntMax; - EXPECT_EQ("0", Format(year)); - year += kIntMin; - EXPECT_EQ("-2147483648", Format(year)); - year -= kIntMin; - EXPECT_EQ("0", Format(year)); -} - + TEST_RELATIONAL(civil_day(2014, 1, 1), civil_minute(2014, 1, 1, 1, 1)); + TEST_RELATIONAL(civil_day(2014, 1, 1), civil_month(2014, 2)); + +#undef TEST_RELATIONAL +} + +TEST(CivilTime, Arithmetic) { + civil_second second(2015, 1, 2, 3, 4, 5); + EXPECT_EQ("2015-01-02T03:04:06", Format(second += 1)); + EXPECT_EQ("2015-01-02T03:04:07", Format(second + 1)); + EXPECT_EQ("2015-01-02T03:04:08", Format(2 + second)); + EXPECT_EQ("2015-01-02T03:04:05", Format(second - 1)); + EXPECT_EQ("2015-01-02T03:04:05", Format(second -= 1)); + EXPECT_EQ("2015-01-02T03:04:05", Format(second++)); + EXPECT_EQ("2015-01-02T03:04:07", Format(++second)); + EXPECT_EQ("2015-01-02T03:04:07", Format(second--)); + EXPECT_EQ("2015-01-02T03:04:05", Format(--second)); + + civil_minute minute(2015, 1, 2, 3, 4); + EXPECT_EQ("2015-01-02T03:05", Format(minute += 1)); + EXPECT_EQ("2015-01-02T03:06", Format(minute + 1)); + EXPECT_EQ("2015-01-02T03:07", Format(2 + minute)); + EXPECT_EQ("2015-01-02T03:04", Format(minute - 1)); + EXPECT_EQ("2015-01-02T03:04", Format(minute -= 1)); + EXPECT_EQ("2015-01-02T03:04", Format(minute++)); + EXPECT_EQ("2015-01-02T03:06", Format(++minute)); + EXPECT_EQ("2015-01-02T03:06", Format(minute--)); + EXPECT_EQ("2015-01-02T03:04", Format(--minute)); + + civil_hour hour(2015, 1, 2, 3); + EXPECT_EQ("2015-01-02T04", Format(hour += 1)); + EXPECT_EQ("2015-01-02T05", Format(hour + 1)); + EXPECT_EQ("2015-01-02T06", Format(2 + hour)); + EXPECT_EQ("2015-01-02T03", Format(hour - 1)); + EXPECT_EQ("2015-01-02T03", Format(hour -= 1)); + EXPECT_EQ("2015-01-02T03", Format(hour++)); + EXPECT_EQ("2015-01-02T05", Format(++hour)); + EXPECT_EQ("2015-01-02T05", Format(hour--)); + EXPECT_EQ("2015-01-02T03", Format(--hour)); + + civil_day day(2015, 1, 2); + EXPECT_EQ("2015-01-03", Format(day += 1)); + EXPECT_EQ("2015-01-04", Format(day + 1)); + EXPECT_EQ("2015-01-05", Format(2 + day)); + EXPECT_EQ("2015-01-02", Format(day - 1)); + EXPECT_EQ("2015-01-02", Format(day -= 1)); + EXPECT_EQ("2015-01-02", Format(day++)); + EXPECT_EQ("2015-01-04", Format(++day)); + EXPECT_EQ("2015-01-04", Format(day--)); + EXPECT_EQ("2015-01-02", Format(--day)); + + civil_month month(2015, 1); + EXPECT_EQ("2015-02", Format(month += 1)); + EXPECT_EQ("2015-03", Format(month + 1)); + EXPECT_EQ("2015-04", Format(2 + month)); + EXPECT_EQ("2015-01", Format(month - 1)); + EXPECT_EQ("2015-01", Format(month -= 1)); + EXPECT_EQ("2015-01", Format(month++)); + EXPECT_EQ("2015-03", Format(++month)); + EXPECT_EQ("2015-03", Format(month--)); + EXPECT_EQ("2015-01", Format(--month)); + + civil_year year(2015); + EXPECT_EQ("2016", Format(year += 1)); + EXPECT_EQ("2017", Format(year + 1)); + EXPECT_EQ("2018", Format(2 + year)); + EXPECT_EQ("2015", Format(year - 1)); + EXPECT_EQ("2015", Format(year -= 1)); + EXPECT_EQ("2015", Format(year++)); + EXPECT_EQ("2017", Format(++year)); + EXPECT_EQ("2017", Format(year--)); + EXPECT_EQ("2015", Format(--year)); +} + +TEST(CivilTime, ArithmeticLimits) { + const int kIntMax = std::numeric_limits<int>::max(); + const int kIntMin = std::numeric_limits<int>::min(); + + civil_second second(1970, 1, 1, 0, 0, 0); + second += kIntMax; + EXPECT_EQ("2038-01-19T03:14:07", Format(second)); + second -= kIntMax; + EXPECT_EQ("1970-01-01T00:00:00", Format(second)); + second += kIntMin; + EXPECT_EQ("1901-12-13T20:45:52", Format(second)); + second -= kIntMin; + EXPECT_EQ("1970-01-01T00:00:00", Format(second)); + + civil_minute minute(1970, 1, 1, 0, 0); + minute += kIntMax; + EXPECT_EQ("6053-01-23T02:07", Format(minute)); + minute -= kIntMax; + EXPECT_EQ("1970-01-01T00:00", Format(minute)); + minute += kIntMin; + EXPECT_EQ("-2114-12-08T21:52", Format(minute)); + minute -= kIntMin; + EXPECT_EQ("1970-01-01T00:00", Format(minute)); + + civil_hour hour(1970, 1, 1, 0); + hour += kIntMax; + EXPECT_EQ("246953-10-09T07", Format(hour)); + hour -= kIntMax; + EXPECT_EQ("1970-01-01T00", Format(hour)); + hour += kIntMin; + EXPECT_EQ("-243014-03-24T16", Format(hour)); + hour -= kIntMin; + EXPECT_EQ("1970-01-01T00", Format(hour)); + + civil_day day(1970, 1, 1); + day += kIntMax; + EXPECT_EQ("5881580-07-11", Format(day)); + day -= kIntMax; + EXPECT_EQ("1970-01-01", Format(day)); + day += kIntMin; + EXPECT_EQ("-5877641-06-23", Format(day)); + day -= kIntMin; + EXPECT_EQ("1970-01-01", Format(day)); + + civil_month month(1970, 1); + month += kIntMax; + EXPECT_EQ("178958940-08", Format(month)); + month -= kIntMax; + EXPECT_EQ("1970-01", Format(month)); + month += kIntMin; + EXPECT_EQ("-178955001-05", Format(month)); + month -= kIntMin; + EXPECT_EQ("1970-01", Format(month)); + + civil_year year(0); + year += kIntMax; + EXPECT_EQ("2147483647", Format(year)); + year -= kIntMax; + EXPECT_EQ("0", Format(year)); + year += kIntMin; + EXPECT_EQ("-2147483648", Format(year)); + year -= kIntMin; + EXPECT_EQ("0", Format(year)); +} + TEST(CivilTime, ArithmeticDifference) { - civil_second second(2015, 1, 2, 3, 4, 5); - EXPECT_EQ(0, second - second); - EXPECT_EQ(10, (second + 10) - second); - EXPECT_EQ(-10, (second - 10) - second); - - civil_minute minute(2015, 1, 2, 3, 4); - EXPECT_EQ(0, minute - minute); - EXPECT_EQ(10, (minute + 10) - minute); - EXPECT_EQ(-10, (minute - 10) - minute); - - civil_hour hour(2015, 1, 2, 3); - EXPECT_EQ(0, hour - hour); - EXPECT_EQ(10, (hour + 10) - hour); - EXPECT_EQ(-10, (hour - 10) - hour); - - civil_day day(2015, 1, 2); - EXPECT_EQ(0, day - day); - EXPECT_EQ(10, (day + 10) - day); - EXPECT_EQ(-10, (day - 10) - day); - - civil_month month(2015, 1); - EXPECT_EQ(0, month - month); - EXPECT_EQ(10, (month + 10) - month); - EXPECT_EQ(-10, (month - 10) - month); - - civil_year year(2015); - EXPECT_EQ(0, year - year); - EXPECT_EQ(10, (year + 10) - year); - EXPECT_EQ(-10, (year - 10) - year); -} - -TEST(CivilTime, DifferenceLimits) { - const int kIntMax = std::numeric_limits<int>::max(); - const int kIntMin = std::numeric_limits<int>::min(); - - // Check day arithmetic at the end of the year range. - const civil_day max_day(kIntMax, 12, 31); - EXPECT_EQ(1, max_day - (max_day - 1)); - EXPECT_EQ(-1, (max_day - 1) - max_day); - - // Check day arithmetic at the end of the year range. - const civil_day min_day(kIntMin, 1, 1); - EXPECT_EQ(1, (min_day + 1) - min_day); - EXPECT_EQ(-1, min_day - (min_day + 1)); - - // Check the limits of the return value. - const civil_day d1(1970, 1, 1); - const civil_day d2(5881580, 7, 11); - EXPECT_EQ(kIntMax, d2 - d1); - EXPECT_EQ(kIntMin, d1 - (d2 + 1)); -} - -TEST(CivilTime, Properties) { - civil_second ss(2015, 2, 3, 4, 5, 6); - EXPECT_EQ(2015, ss.year()); - EXPECT_EQ(2, ss.month()); - EXPECT_EQ(3, ss.day()); - EXPECT_EQ(4, ss.hour()); - EXPECT_EQ(5, ss.minute()); - EXPECT_EQ(6, ss.second()); + civil_second second(2015, 1, 2, 3, 4, 5); + EXPECT_EQ(0, second - second); + EXPECT_EQ(10, (second + 10) - second); + EXPECT_EQ(-10, (second - 10) - second); + + civil_minute minute(2015, 1, 2, 3, 4); + EXPECT_EQ(0, minute - minute); + EXPECT_EQ(10, (minute + 10) - minute); + EXPECT_EQ(-10, (minute - 10) - minute); + + civil_hour hour(2015, 1, 2, 3); + EXPECT_EQ(0, hour - hour); + EXPECT_EQ(10, (hour + 10) - hour); + EXPECT_EQ(-10, (hour - 10) - hour); + + civil_day day(2015, 1, 2); + EXPECT_EQ(0, day - day); + EXPECT_EQ(10, (day + 10) - day); + EXPECT_EQ(-10, (day - 10) - day); + + civil_month month(2015, 1); + EXPECT_EQ(0, month - month); + EXPECT_EQ(10, (month + 10) - month); + EXPECT_EQ(-10, (month - 10) - month); + + civil_year year(2015); + EXPECT_EQ(0, year - year); + EXPECT_EQ(10, (year + 10) - year); + EXPECT_EQ(-10, (year - 10) - year); +} + +TEST(CivilTime, DifferenceLimits) { + const int kIntMax = std::numeric_limits<int>::max(); + const int kIntMin = std::numeric_limits<int>::min(); + + // Check day arithmetic at the end of the year range. + const civil_day max_day(kIntMax, 12, 31); + EXPECT_EQ(1, max_day - (max_day - 1)); + EXPECT_EQ(-1, (max_day - 1) - max_day); + + // Check day arithmetic at the end of the year range. + const civil_day min_day(kIntMin, 1, 1); + EXPECT_EQ(1, (min_day + 1) - min_day); + EXPECT_EQ(-1, min_day - (min_day + 1)); + + // Check the limits of the return value. + const civil_day d1(1970, 1, 1); + const civil_day d2(5881580, 7, 11); + EXPECT_EQ(kIntMax, d2 - d1); + EXPECT_EQ(kIntMin, d1 - (d2 + 1)); +} + +TEST(CivilTime, Properties) { + civil_second ss(2015, 2, 3, 4, 5, 6); + EXPECT_EQ(2015, ss.year()); + EXPECT_EQ(2, ss.month()); + EXPECT_EQ(3, ss.day()); + EXPECT_EQ(4, ss.hour()); + EXPECT_EQ(5, ss.minute()); + EXPECT_EQ(6, ss.second()); EXPECT_EQ(weekday::tuesday, get_weekday(ss)); EXPECT_EQ(34, get_yearday(ss)); - - civil_minute mm(2015, 2, 3, 4, 5, 6); - EXPECT_EQ(2015, mm.year()); - EXPECT_EQ(2, mm.month()); - EXPECT_EQ(3, mm.day()); - EXPECT_EQ(4, mm.hour()); - EXPECT_EQ(5, mm.minute()); - EXPECT_EQ(0, mm.second()); + + civil_minute mm(2015, 2, 3, 4, 5, 6); + EXPECT_EQ(2015, mm.year()); + EXPECT_EQ(2, mm.month()); + EXPECT_EQ(3, mm.day()); + EXPECT_EQ(4, mm.hour()); + EXPECT_EQ(5, mm.minute()); + EXPECT_EQ(0, mm.second()); EXPECT_EQ(weekday::tuesday, get_weekday(mm)); EXPECT_EQ(34, get_yearday(mm)); - - civil_hour hh(2015, 2, 3, 4, 5, 6); - EXPECT_EQ(2015, hh.year()); - EXPECT_EQ(2, hh.month()); - EXPECT_EQ(3, hh.day()); - EXPECT_EQ(4, hh.hour()); - EXPECT_EQ(0, hh.minute()); - EXPECT_EQ(0, hh.second()); + + civil_hour hh(2015, 2, 3, 4, 5, 6); + EXPECT_EQ(2015, hh.year()); + EXPECT_EQ(2, hh.month()); + EXPECT_EQ(3, hh.day()); + EXPECT_EQ(4, hh.hour()); + EXPECT_EQ(0, hh.minute()); + EXPECT_EQ(0, hh.second()); EXPECT_EQ(weekday::tuesday, get_weekday(hh)); EXPECT_EQ(34, get_yearday(hh)); - - civil_day d(2015, 2, 3, 4, 5, 6); - EXPECT_EQ(2015, d.year()); - EXPECT_EQ(2, d.month()); - EXPECT_EQ(3, d.day()); - EXPECT_EQ(0, d.hour()); - EXPECT_EQ(0, d.minute()); - EXPECT_EQ(0, d.second()); - EXPECT_EQ(weekday::tuesday, get_weekday(d)); - EXPECT_EQ(34, get_yearday(d)); - - civil_month m(2015, 2, 3, 4, 5, 6); - EXPECT_EQ(2015, m.year()); - EXPECT_EQ(2, m.month()); - EXPECT_EQ(1, m.day()); - EXPECT_EQ(0, m.hour()); - EXPECT_EQ(0, m.minute()); - EXPECT_EQ(0, m.second()); + + civil_day d(2015, 2, 3, 4, 5, 6); + EXPECT_EQ(2015, d.year()); + EXPECT_EQ(2, d.month()); + EXPECT_EQ(3, d.day()); + EXPECT_EQ(0, d.hour()); + EXPECT_EQ(0, d.minute()); + EXPECT_EQ(0, d.second()); + EXPECT_EQ(weekday::tuesday, get_weekday(d)); + EXPECT_EQ(34, get_yearday(d)); + + civil_month m(2015, 2, 3, 4, 5, 6); + EXPECT_EQ(2015, m.year()); + EXPECT_EQ(2, m.month()); + EXPECT_EQ(1, m.day()); + EXPECT_EQ(0, m.hour()); + EXPECT_EQ(0, m.minute()); + EXPECT_EQ(0, m.second()); EXPECT_EQ(weekday::sunday, get_weekday(m)); EXPECT_EQ(32, get_yearday(m)); - - civil_year y(2015, 2, 3, 4, 5, 6); - EXPECT_EQ(2015, y.year()); - EXPECT_EQ(1, y.month()); - EXPECT_EQ(1, y.day()); - EXPECT_EQ(0, y.hour()); - EXPECT_EQ(0, y.minute()); - EXPECT_EQ(0, y.second()); + + civil_year y(2015, 2, 3, 4, 5, 6); + EXPECT_EQ(2015, y.year()); + EXPECT_EQ(1, y.month()); + EXPECT_EQ(1, y.day()); + EXPECT_EQ(0, y.hour()); + EXPECT_EQ(0, y.minute()); + EXPECT_EQ(0, y.second()); EXPECT_EQ(weekday::thursday, get_weekday(y)); EXPECT_EQ(1, get_yearday(y)); -} - -TEST(CivilTime, OutputStream) { - // Tests formatting of civil_year, which does not pad. - EXPECT_EQ("2016", Format(civil_year(2016))); - EXPECT_EQ("123", Format(civil_year(123))); - EXPECT_EQ("0", Format(civil_year(0))); - EXPECT_EQ("-1", Format(civil_year(-1))); - - // Tests formatting of sub-year types, which pad to 2 digits - EXPECT_EQ("2016-02", Format(civil_month(2016, 2))); - EXPECT_EQ("2016-02-03", Format(civil_day(2016, 2, 3))); - EXPECT_EQ("2016-02-03T04", Format(civil_hour(2016, 2, 3, 4))); - EXPECT_EQ("2016-02-03T04:05", Format(civil_minute(2016, 2, 3, 4, 5))); - EXPECT_EQ("2016-02-03T04:05:06", Format(civil_second(2016, 2, 3, 4, 5, 6))); - - // Tests formatting of weekday. - EXPECT_EQ("Monday", Format(weekday::monday)); - EXPECT_EQ("Tuesday", Format(weekday::tuesday)); - EXPECT_EQ("Wednesday", Format(weekday::wednesday)); - EXPECT_EQ("Thursday", Format(weekday::thursday)); - EXPECT_EQ("Friday", Format(weekday::friday)); - EXPECT_EQ("Saturday", Format(weekday::saturday)); - EXPECT_EQ("Sunday", Format(weekday::sunday)); -} - -TEST(CivilTime, OutputStreamLeftFillWidth) { - civil_second cs(2016, 2, 3, 4, 5, 6); - { - std::stringstream ss; - ss << std::left << std::setfill('.'); - ss << std::setw(3) << 'X'; - ss << std::setw(21) << civil_year(cs); - ss << std::setw(3) << 'X'; - EXPECT_EQ("X..2016.................X..", ss.str()); - } - { - std::stringstream ss; - ss << std::left << std::setfill('.'); - ss << std::setw(3) << 'X'; - ss << std::setw(21) << civil_month(cs); - ss << std::setw(3) << 'X'; - EXPECT_EQ("X..2016-02..............X..", ss.str()); - } - { - std::stringstream ss; - ss << std::left << std::setfill('.'); - ss << std::setw(3) << 'X'; - ss << std::setw(21) << civil_day(cs); - ss << std::setw(3) << 'X'; - EXPECT_EQ("X..2016-02-03...........X..", ss.str()); - } - { - std::stringstream ss; - ss << std::left << std::setfill('.'); - ss << std::setw(3) << 'X'; - ss << std::setw(21) << civil_hour(cs); - ss << std::setw(3) << 'X'; - EXPECT_EQ("X..2016-02-03T04........X..", ss.str()); - } - { - std::stringstream ss; - ss << std::left << std::setfill('.'); - ss << std::setw(3) << 'X'; - ss << std::setw(21) << civil_minute(cs); - ss << std::setw(3) << 'X'; - EXPECT_EQ("X..2016-02-03T04:05.....X..", ss.str()); - } - { - std::stringstream ss; - ss << std::left << std::setfill('.'); - ss << std::setw(3) << 'X'; - ss << std::setw(21) << civil_second(cs); - ss << std::setw(3) << 'X'; - EXPECT_EQ("X..2016-02-03T04:05:06..X..", ss.str()); - } -} - -TEST(CivilTime, NextPrevWeekday) { - // Jan 1, 1970 was a Thursday. - const civil_day thursday(1970, 1, 1); - EXPECT_EQ(weekday::thursday, get_weekday(thursday)); - - // Thursday -> Thursday - civil_day d = next_weekday(thursday, weekday::thursday); +} + +TEST(CivilTime, OutputStream) { + // Tests formatting of civil_year, which does not pad. + EXPECT_EQ("2016", Format(civil_year(2016))); + EXPECT_EQ("123", Format(civil_year(123))); + EXPECT_EQ("0", Format(civil_year(0))); + EXPECT_EQ("-1", Format(civil_year(-1))); + + // Tests formatting of sub-year types, which pad to 2 digits + EXPECT_EQ("2016-02", Format(civil_month(2016, 2))); + EXPECT_EQ("2016-02-03", Format(civil_day(2016, 2, 3))); + EXPECT_EQ("2016-02-03T04", Format(civil_hour(2016, 2, 3, 4))); + EXPECT_EQ("2016-02-03T04:05", Format(civil_minute(2016, 2, 3, 4, 5))); + EXPECT_EQ("2016-02-03T04:05:06", Format(civil_second(2016, 2, 3, 4, 5, 6))); + + // Tests formatting of weekday. + EXPECT_EQ("Monday", Format(weekday::monday)); + EXPECT_EQ("Tuesday", Format(weekday::tuesday)); + EXPECT_EQ("Wednesday", Format(weekday::wednesday)); + EXPECT_EQ("Thursday", Format(weekday::thursday)); + EXPECT_EQ("Friday", Format(weekday::friday)); + EXPECT_EQ("Saturday", Format(weekday::saturday)); + EXPECT_EQ("Sunday", Format(weekday::sunday)); +} + +TEST(CivilTime, OutputStreamLeftFillWidth) { + civil_second cs(2016, 2, 3, 4, 5, 6); + { + std::stringstream ss; + ss << std::left << std::setfill('.'); + ss << std::setw(3) << 'X'; + ss << std::setw(21) << civil_year(cs); + ss << std::setw(3) << 'X'; + EXPECT_EQ("X..2016.................X..", ss.str()); + } + { + std::stringstream ss; + ss << std::left << std::setfill('.'); + ss << std::setw(3) << 'X'; + ss << std::setw(21) << civil_month(cs); + ss << std::setw(3) << 'X'; + EXPECT_EQ("X..2016-02..............X..", ss.str()); + } + { + std::stringstream ss; + ss << std::left << std::setfill('.'); + ss << std::setw(3) << 'X'; + ss << std::setw(21) << civil_day(cs); + ss << std::setw(3) << 'X'; + EXPECT_EQ("X..2016-02-03...........X..", ss.str()); + } + { + std::stringstream ss; + ss << std::left << std::setfill('.'); + ss << std::setw(3) << 'X'; + ss << std::setw(21) << civil_hour(cs); + ss << std::setw(3) << 'X'; + EXPECT_EQ("X..2016-02-03T04........X..", ss.str()); + } + { + std::stringstream ss; + ss << std::left << std::setfill('.'); + ss << std::setw(3) << 'X'; + ss << std::setw(21) << civil_minute(cs); + ss << std::setw(3) << 'X'; + EXPECT_EQ("X..2016-02-03T04:05.....X..", ss.str()); + } + { + std::stringstream ss; + ss << std::left << std::setfill('.'); + ss << std::setw(3) << 'X'; + ss << std::setw(21) << civil_second(cs); + ss << std::setw(3) << 'X'; + EXPECT_EQ("X..2016-02-03T04:05:06..X..", ss.str()); + } +} + +TEST(CivilTime, NextPrevWeekday) { + // Jan 1, 1970 was a Thursday. + const civil_day thursday(1970, 1, 1); + EXPECT_EQ(weekday::thursday, get_weekday(thursday)); + + // Thursday -> Thursday + civil_day d = next_weekday(thursday, weekday::thursday); EXPECT_EQ(7, d - thursday) << Format(d); - EXPECT_EQ(d - 14, prev_weekday(thursday, weekday::thursday)); - - // Thursday -> Friday - d = next_weekday(thursday, weekday::friday); + EXPECT_EQ(d - 14, prev_weekday(thursday, weekday::thursday)); + + // Thursday -> Friday + d = next_weekday(thursday, weekday::friday); EXPECT_EQ(1, d - thursday) << Format(d); - EXPECT_EQ(d - 7, prev_weekday(thursday, weekday::friday)); - - // Thursday -> Saturday - d = next_weekday(thursday, weekday::saturday); + EXPECT_EQ(d - 7, prev_weekday(thursday, weekday::friday)); + + // Thursday -> Saturday + d = next_weekday(thursday, weekday::saturday); EXPECT_EQ(2, d - thursday) << Format(d); - EXPECT_EQ(d - 7, prev_weekday(thursday, weekday::saturday)); - - // Thursday -> Sunday - d = next_weekday(thursday, weekday::sunday); + EXPECT_EQ(d - 7, prev_weekday(thursday, weekday::saturday)); + + // Thursday -> Sunday + d = next_weekday(thursday, weekday::sunday); EXPECT_EQ(3, d - thursday) << Format(d); - EXPECT_EQ(d - 7, prev_weekday(thursday, weekday::sunday)); - - // Thursday -> Monday - d = next_weekday(thursday, weekday::monday); + EXPECT_EQ(d - 7, prev_weekday(thursday, weekday::sunday)); + + // Thursday -> Monday + d = next_weekday(thursday, weekday::monday); EXPECT_EQ(4, d - thursday) << Format(d); - EXPECT_EQ(d - 7, prev_weekday(thursday, weekday::monday)); - - // Thursday -> Tuesday - d = next_weekday(thursday, weekday::tuesday); + EXPECT_EQ(d - 7, prev_weekday(thursday, weekday::monday)); + + // Thursday -> Tuesday + d = next_weekday(thursday, weekday::tuesday); EXPECT_EQ(5, d - thursday) << Format(d); - EXPECT_EQ(d - 7, prev_weekday(thursday, weekday::tuesday)); - - // Thursday -> Wednesday - d = next_weekday(thursday, weekday::wednesday); + EXPECT_EQ(d - 7, prev_weekday(thursday, weekday::tuesday)); + + // Thursday -> Wednesday + d = next_weekday(thursday, weekday::wednesday); EXPECT_EQ(6, d - thursday) << Format(d); - EXPECT_EQ(d - 7, prev_weekday(thursday, weekday::wednesday)); -} - -TEST(CivilTime, NormalizeWithHugeYear) { - civil_month c(9223372036854775807, 1); - EXPECT_EQ("9223372036854775807-01", Format(c)); - c = c - 1; // Causes normalization - EXPECT_EQ("9223372036854775806-12", Format(c)); - - c = civil_month(-9223372036854775807 - 1, 1); - EXPECT_EQ("-9223372036854775808-01", Format(c)); - c = c + 12; // Causes normalization - EXPECT_EQ("-9223372036854775807-01", Format(c)); -} - -TEST(CivilTime, LeapYears) { - // Test data for leap years. - const struct { - int year; - int days; - struct { - int month; - int day; - } leap_day; // The date of the day after Feb 28. - } kLeapYearTable[]{ - {1900, 365, {3, 1}}, - {1999, 365, {3, 1}}, - {2000, 366, {2, 29}}, // leap year - {2001, 365, {3, 1}}, - {2002, 365, {3, 1}}, - {2003, 365, {3, 1}}, - {2004, 366, {2, 29}}, // leap year - {2005, 365, {3, 1}}, - {2006, 365, {3, 1}}, - {2007, 365, {3, 1}}, - {2008, 366, {2, 29}}, // leap year - {2009, 365, {3, 1}}, - {2100, 365, {3, 1}}, - }; - - for (const auto& e : kLeapYearTable) { - // Tests incrementing through the leap day. - const civil_day feb28(e.year, 2, 28); - const civil_day next_day = feb28 + 1; - EXPECT_EQ(e.leap_day.month, next_day.month()); - EXPECT_EQ(e.leap_day.day, next_day.day()); - - // Tests difference in days of leap years. - const civil_year year(feb28); - const civil_year next_year = year + 1; - EXPECT_EQ(e.days, civil_day(next_year) - civil_day(year)); - } -} - -TEST(CivilTime, FirstThursdayInMonth) { - const civil_day nov1(2014, 11, 1); + EXPECT_EQ(d - 7, prev_weekday(thursday, weekday::wednesday)); +} + +TEST(CivilTime, NormalizeWithHugeYear) { + civil_month c(9223372036854775807, 1); + EXPECT_EQ("9223372036854775807-01", Format(c)); + c = c - 1; // Causes normalization + EXPECT_EQ("9223372036854775806-12", Format(c)); + + c = civil_month(-9223372036854775807 - 1, 1); + EXPECT_EQ("-9223372036854775808-01", Format(c)); + c = c + 12; // Causes normalization + EXPECT_EQ("-9223372036854775807-01", Format(c)); +} + +TEST(CivilTime, LeapYears) { + // Test data for leap years. + const struct { + int year; + int days; + struct { + int month; + int day; + } leap_day; // The date of the day after Feb 28. + } kLeapYearTable[]{ + {1900, 365, {3, 1}}, + {1999, 365, {3, 1}}, + {2000, 366, {2, 29}}, // leap year + {2001, 365, {3, 1}}, + {2002, 365, {3, 1}}, + {2003, 365, {3, 1}}, + {2004, 366, {2, 29}}, // leap year + {2005, 365, {3, 1}}, + {2006, 365, {3, 1}}, + {2007, 365, {3, 1}}, + {2008, 366, {2, 29}}, // leap year + {2009, 365, {3, 1}}, + {2100, 365, {3, 1}}, + }; + + for (const auto& e : kLeapYearTable) { + // Tests incrementing through the leap day. + const civil_day feb28(e.year, 2, 28); + const civil_day next_day = feb28 + 1; + EXPECT_EQ(e.leap_day.month, next_day.month()); + EXPECT_EQ(e.leap_day.day, next_day.day()); + + // Tests difference in days of leap years. + const civil_year year(feb28); + const civil_year next_year = year + 1; + EXPECT_EQ(e.days, civil_day(next_year) - civil_day(year)); + } +} + +TEST(CivilTime, FirstThursdayInMonth) { + const civil_day nov1(2014, 11, 1); const civil_day thursday = next_weekday(nov1 - 1, weekday::thursday); - EXPECT_EQ("2014-11-06", Format(thursday)); - - // Bonus: Date of Thanksgiving in the United States - // Rule: Fourth Thursday of November - const civil_day thanksgiving = thursday + 7 * 3; - EXPECT_EQ("2014-11-27", Format(thanksgiving)); -} - -} // namespace cctz + EXPECT_EQ("2014-11-06", Format(thursday)); + + // Bonus: Date of Thanksgiving in the United States + // Rule: Fourth Thursday of November + const civil_day thanksgiving = thursday + 7 * 3; + EXPECT_EQ("2014-11-27", Format(thanksgiving)); +} + +} // namespace cctz diff --git a/contrib/libs/cctz/test/time_zone_lookup_test.cc b/contrib/libs/cctz/test/time_zone_lookup_test.cc index 991d7af1c8..b013e1e90c 100644 --- a/contrib/libs/cctz/test/time_zone_lookup_test.cc +++ b/contrib/libs/cctz/test/time_zone_lookup_test.cc @@ -1,658 +1,658 @@ -// Copyright 2016 Google Inc. All Rights Reserved. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// +// Copyright 2016 Google Inc. All Rights Reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// // https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. - +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + #include "cctz/time_zone.h" - -#include <chrono> -#include <cstddef> + +#include <chrono> +#include <cstddef> #include <cstdlib> -#include <future> +#include <future> #include <limits> -#include <string> -#include <thread> -#include <vector> - +#include <string> +#include <thread> +#include <vector> + #include "cctz/civil_time.h" #include "gtest/gtest.h" - + namespace chrono = std::chrono; - -namespace cctz { - -namespace { - -// A list of known time-zone names. -const char* const kTimeZoneNames[] = { - "Africa/Abidjan", - "Africa/Accra", - "Africa/Addis_Ababa", - "Africa/Algiers", - "Africa/Asmara", - "Africa/Asmera", - "Africa/Bamako", - "Africa/Bangui", - "Africa/Banjul", - "Africa/Bissau", - "Africa/Blantyre", - "Africa/Brazzaville", - "Africa/Bujumbura", - "Africa/Cairo", - "Africa/Casablanca", - "Africa/Ceuta", - "Africa/Conakry", - "Africa/Dakar", - "Africa/Dar_es_Salaam", - "Africa/Djibouti", - "Africa/Douala", - "Africa/El_Aaiun", - "Africa/Freetown", - "Africa/Gaborone", - "Africa/Harare", - "Africa/Johannesburg", - "Africa/Juba", - "Africa/Kampala", - "Africa/Khartoum", - "Africa/Kigali", - "Africa/Kinshasa", - "Africa/Lagos", - "Africa/Libreville", - "Africa/Lome", - "Africa/Luanda", - "Africa/Lubumbashi", - "Africa/Lusaka", - "Africa/Malabo", - "Africa/Maputo", - "Africa/Maseru", - "Africa/Mbabane", - "Africa/Mogadishu", - "Africa/Monrovia", - "Africa/Nairobi", - "Africa/Ndjamena", - "Africa/Niamey", - "Africa/Nouakchott", - "Africa/Ouagadougou", - "Africa/Porto-Novo", - "Africa/Sao_Tome", - "Africa/Timbuktu", - "Africa/Tripoli", - "Africa/Tunis", - "Africa/Windhoek", - "America/Adak", - "America/Anchorage", - "America/Anguilla", - "America/Antigua", - "America/Araguaina", - "America/Argentina/Buenos_Aires", - "America/Argentina/Catamarca", - "America/Argentina/ComodRivadavia", - "America/Argentina/Cordoba", - "America/Argentina/Jujuy", - "America/Argentina/La_Rioja", - "America/Argentina/Mendoza", - "America/Argentina/Rio_Gallegos", - "America/Argentina/Salta", - "America/Argentina/San_Juan", - "America/Argentina/San_Luis", - "America/Argentina/Tucuman", - "America/Argentina/Ushuaia", - "America/Aruba", - "America/Asuncion", - "America/Atikokan", - "America/Atka", - "America/Bahia", - "America/Bahia_Banderas", - "America/Barbados", - "America/Belem", - "America/Belize", - "America/Blanc-Sablon", - "America/Boa_Vista", - "America/Bogota", - "America/Boise", - "America/Buenos_Aires", - "America/Cambridge_Bay", - "America/Campo_Grande", - "America/Cancun", - "America/Caracas", - "America/Catamarca", - "America/Cayenne", - "America/Cayman", - "America/Chicago", - "America/Chihuahua", - "America/Coral_Harbour", - "America/Cordoba", - "America/Costa_Rica", - "America/Creston", - "America/Cuiaba", - "America/Curacao", - "America/Danmarkshavn", - "America/Dawson", - "America/Dawson_Creek", - "America/Denver", - "America/Detroit", - "America/Dominica", - "America/Edmonton", - "America/Eirunepe", - "America/El_Salvador", - "America/Ensenada", - "America/Fort_Nelson", - "America/Fort_Wayne", - "America/Fortaleza", - "America/Glace_Bay", - "America/Godthab", - "America/Goose_Bay", - "America/Grand_Turk", - "America/Grenada", - "America/Guadeloupe", - "America/Guatemala", - "America/Guayaquil", - "America/Guyana", - "America/Halifax", - "America/Havana", - "America/Hermosillo", - "America/Indiana/Indianapolis", - "America/Indiana/Knox", - "America/Indiana/Marengo", - "America/Indiana/Petersburg", - "America/Indiana/Tell_City", - "America/Indiana/Vevay", - "America/Indiana/Vincennes", - "America/Indiana/Winamac", - "America/Indianapolis", - "America/Inuvik", - "America/Iqaluit", - "America/Jamaica", - "America/Jujuy", - "America/Juneau", - "America/Kentucky/Louisville", - "America/Kentucky/Monticello", - "America/Knox_IN", - "America/Kralendijk", - "America/La_Paz", - "America/Lima", - "America/Los_Angeles", - "America/Louisville", - "America/Lower_Princes", - "America/Maceio", - "America/Managua", - "America/Manaus", - "America/Marigot", - "America/Martinique", - "America/Matamoros", - "America/Mazatlan", - "America/Mendoza", - "America/Menominee", - "America/Merida", - "America/Metlakatla", - "America/Mexico_City", - "America/Miquelon", - "America/Moncton", - "America/Monterrey", - "America/Montevideo", - "America/Montreal", - "America/Montserrat", - "America/Nassau", - "America/New_York", - "America/Nipigon", - "America/Nome", - "America/Noronha", - "America/North_Dakota/Beulah", - "America/North_Dakota/Center", - "America/North_Dakota/New_Salem", + +namespace cctz { + +namespace { + +// A list of known time-zone names. +const char* const kTimeZoneNames[] = { + "Africa/Abidjan", + "Africa/Accra", + "Africa/Addis_Ababa", + "Africa/Algiers", + "Africa/Asmara", + "Africa/Asmera", + "Africa/Bamako", + "Africa/Bangui", + "Africa/Banjul", + "Africa/Bissau", + "Africa/Blantyre", + "Africa/Brazzaville", + "Africa/Bujumbura", + "Africa/Cairo", + "Africa/Casablanca", + "Africa/Ceuta", + "Africa/Conakry", + "Africa/Dakar", + "Africa/Dar_es_Salaam", + "Africa/Djibouti", + "Africa/Douala", + "Africa/El_Aaiun", + "Africa/Freetown", + "Africa/Gaborone", + "Africa/Harare", + "Africa/Johannesburg", + "Africa/Juba", + "Africa/Kampala", + "Africa/Khartoum", + "Africa/Kigali", + "Africa/Kinshasa", + "Africa/Lagos", + "Africa/Libreville", + "Africa/Lome", + "Africa/Luanda", + "Africa/Lubumbashi", + "Africa/Lusaka", + "Africa/Malabo", + "Africa/Maputo", + "Africa/Maseru", + "Africa/Mbabane", + "Africa/Mogadishu", + "Africa/Monrovia", + "Africa/Nairobi", + "Africa/Ndjamena", + "Africa/Niamey", + "Africa/Nouakchott", + "Africa/Ouagadougou", + "Africa/Porto-Novo", + "Africa/Sao_Tome", + "Africa/Timbuktu", + "Africa/Tripoli", + "Africa/Tunis", + "Africa/Windhoek", + "America/Adak", + "America/Anchorage", + "America/Anguilla", + "America/Antigua", + "America/Araguaina", + "America/Argentina/Buenos_Aires", + "America/Argentina/Catamarca", + "America/Argentina/ComodRivadavia", + "America/Argentina/Cordoba", + "America/Argentina/Jujuy", + "America/Argentina/La_Rioja", + "America/Argentina/Mendoza", + "America/Argentina/Rio_Gallegos", + "America/Argentina/Salta", + "America/Argentina/San_Juan", + "America/Argentina/San_Luis", + "America/Argentina/Tucuman", + "America/Argentina/Ushuaia", + "America/Aruba", + "America/Asuncion", + "America/Atikokan", + "America/Atka", + "America/Bahia", + "America/Bahia_Banderas", + "America/Barbados", + "America/Belem", + "America/Belize", + "America/Blanc-Sablon", + "America/Boa_Vista", + "America/Bogota", + "America/Boise", + "America/Buenos_Aires", + "America/Cambridge_Bay", + "America/Campo_Grande", + "America/Cancun", + "America/Caracas", + "America/Catamarca", + "America/Cayenne", + "America/Cayman", + "America/Chicago", + "America/Chihuahua", + "America/Coral_Harbour", + "America/Cordoba", + "America/Costa_Rica", + "America/Creston", + "America/Cuiaba", + "America/Curacao", + "America/Danmarkshavn", + "America/Dawson", + "America/Dawson_Creek", + "America/Denver", + "America/Detroit", + "America/Dominica", + "America/Edmonton", + "America/Eirunepe", + "America/El_Salvador", + "America/Ensenada", + "America/Fort_Nelson", + "America/Fort_Wayne", + "America/Fortaleza", + "America/Glace_Bay", + "America/Godthab", + "America/Goose_Bay", + "America/Grand_Turk", + "America/Grenada", + "America/Guadeloupe", + "America/Guatemala", + "America/Guayaquil", + "America/Guyana", + "America/Halifax", + "America/Havana", + "America/Hermosillo", + "America/Indiana/Indianapolis", + "America/Indiana/Knox", + "America/Indiana/Marengo", + "America/Indiana/Petersburg", + "America/Indiana/Tell_City", + "America/Indiana/Vevay", + "America/Indiana/Vincennes", + "America/Indiana/Winamac", + "America/Indianapolis", + "America/Inuvik", + "America/Iqaluit", + "America/Jamaica", + "America/Jujuy", + "America/Juneau", + "America/Kentucky/Louisville", + "America/Kentucky/Monticello", + "America/Knox_IN", + "America/Kralendijk", + "America/La_Paz", + "America/Lima", + "America/Los_Angeles", + "America/Louisville", + "America/Lower_Princes", + "America/Maceio", + "America/Managua", + "America/Manaus", + "America/Marigot", + "America/Martinique", + "America/Matamoros", + "America/Mazatlan", + "America/Mendoza", + "America/Menominee", + "America/Merida", + "America/Metlakatla", + "America/Mexico_City", + "America/Miquelon", + "America/Moncton", + "America/Monterrey", + "America/Montevideo", + "America/Montreal", + "America/Montserrat", + "America/Nassau", + "America/New_York", + "America/Nipigon", + "America/Nome", + "America/Noronha", + "America/North_Dakota/Beulah", + "America/North_Dakota/Center", + "America/North_Dakota/New_Salem", "America/Nuuk", - "America/Ojinaga", - "America/Panama", - "America/Pangnirtung", - "America/Paramaribo", - "America/Phoenix", - "America/Port-au-Prince", - "America/Port_of_Spain", - "America/Porto_Acre", - "America/Porto_Velho", - "America/Puerto_Rico", - "America/Punta_Arenas", - "America/Rainy_River", - "America/Rankin_Inlet", - "America/Recife", - "America/Regina", - "America/Resolute", - "America/Rio_Branco", - "America/Rosario", - "America/Santa_Isabel", - "America/Santarem", - "America/Santiago", - "America/Santo_Domingo", - "America/Sao_Paulo", - "America/Scoresbysund", - "America/Shiprock", - "America/Sitka", - "America/St_Barthelemy", - "America/St_Johns", - "America/St_Kitts", - "America/St_Lucia", - "America/St_Thomas", - "America/St_Vincent", - "America/Swift_Current", - "America/Tegucigalpa", - "America/Thule", - "America/Thunder_Bay", - "America/Tijuana", - "America/Toronto", - "America/Tortola", - "America/Vancouver", - "America/Virgin", - "America/Whitehorse", - "America/Winnipeg", - "America/Yakutat", - "America/Yellowknife", - "Antarctica/Casey", - "Antarctica/Davis", - "Antarctica/DumontDUrville", - "Antarctica/Macquarie", - "Antarctica/Mawson", - "Antarctica/McMurdo", - "Antarctica/Palmer", - "Antarctica/Rothera", - "Antarctica/South_Pole", - "Antarctica/Syowa", - "Antarctica/Troll", - "Antarctica/Vostok", - "Arctic/Longyearbyen", - "Asia/Aden", - "Asia/Almaty", - "Asia/Amman", - "Asia/Anadyr", - "Asia/Aqtau", - "Asia/Aqtobe", - "Asia/Ashgabat", - "Asia/Ashkhabad", - "Asia/Atyrau", - "Asia/Baghdad", - "Asia/Bahrain", - "Asia/Baku", - "Asia/Bangkok", - "Asia/Barnaul", - "Asia/Beirut", - "Asia/Bishkek", - "Asia/Brunei", - "Asia/Calcutta", - "Asia/Chita", - "Asia/Choibalsan", - "Asia/Chongqing", - "Asia/Chungking", - "Asia/Colombo", - "Asia/Dacca", - "Asia/Damascus", - "Asia/Dhaka", - "Asia/Dili", - "Asia/Dubai", - "Asia/Dushanbe", - "Asia/Famagusta", - "Asia/Gaza", - "Asia/Harbin", - "Asia/Hebron", - "Asia/Ho_Chi_Minh", - "Asia/Hong_Kong", - "Asia/Hovd", - "Asia/Irkutsk", - "Asia/Istanbul", - "Asia/Jakarta", - "Asia/Jayapura", - "Asia/Jerusalem", - "Asia/Kabul", - "Asia/Kamchatka", - "Asia/Karachi", - "Asia/Kashgar", - "Asia/Kathmandu", - "Asia/Katmandu", - "Asia/Khandyga", - "Asia/Kolkata", - "Asia/Krasnoyarsk", - "Asia/Kuala_Lumpur", - "Asia/Kuching", - "Asia/Kuwait", - "Asia/Macao", - "Asia/Macau", - "Asia/Magadan", - "Asia/Makassar", - "Asia/Manila", - "Asia/Muscat", - "Asia/Nicosia", - "Asia/Novokuznetsk", - "Asia/Novosibirsk", - "Asia/Omsk", - "Asia/Oral", - "Asia/Phnom_Penh", - "Asia/Pontianak", - "Asia/Pyongyang", - "Asia/Qatar", + "America/Ojinaga", + "America/Panama", + "America/Pangnirtung", + "America/Paramaribo", + "America/Phoenix", + "America/Port-au-Prince", + "America/Port_of_Spain", + "America/Porto_Acre", + "America/Porto_Velho", + "America/Puerto_Rico", + "America/Punta_Arenas", + "America/Rainy_River", + "America/Rankin_Inlet", + "America/Recife", + "America/Regina", + "America/Resolute", + "America/Rio_Branco", + "America/Rosario", + "America/Santa_Isabel", + "America/Santarem", + "America/Santiago", + "America/Santo_Domingo", + "America/Sao_Paulo", + "America/Scoresbysund", + "America/Shiprock", + "America/Sitka", + "America/St_Barthelemy", + "America/St_Johns", + "America/St_Kitts", + "America/St_Lucia", + "America/St_Thomas", + "America/St_Vincent", + "America/Swift_Current", + "America/Tegucigalpa", + "America/Thule", + "America/Thunder_Bay", + "America/Tijuana", + "America/Toronto", + "America/Tortola", + "America/Vancouver", + "America/Virgin", + "America/Whitehorse", + "America/Winnipeg", + "America/Yakutat", + "America/Yellowknife", + "Antarctica/Casey", + "Antarctica/Davis", + "Antarctica/DumontDUrville", + "Antarctica/Macquarie", + "Antarctica/Mawson", + "Antarctica/McMurdo", + "Antarctica/Palmer", + "Antarctica/Rothera", + "Antarctica/South_Pole", + "Antarctica/Syowa", + "Antarctica/Troll", + "Antarctica/Vostok", + "Arctic/Longyearbyen", + "Asia/Aden", + "Asia/Almaty", + "Asia/Amman", + "Asia/Anadyr", + "Asia/Aqtau", + "Asia/Aqtobe", + "Asia/Ashgabat", + "Asia/Ashkhabad", + "Asia/Atyrau", + "Asia/Baghdad", + "Asia/Bahrain", + "Asia/Baku", + "Asia/Bangkok", + "Asia/Barnaul", + "Asia/Beirut", + "Asia/Bishkek", + "Asia/Brunei", + "Asia/Calcutta", + "Asia/Chita", + "Asia/Choibalsan", + "Asia/Chongqing", + "Asia/Chungking", + "Asia/Colombo", + "Asia/Dacca", + "Asia/Damascus", + "Asia/Dhaka", + "Asia/Dili", + "Asia/Dubai", + "Asia/Dushanbe", + "Asia/Famagusta", + "Asia/Gaza", + "Asia/Harbin", + "Asia/Hebron", + "Asia/Ho_Chi_Minh", + "Asia/Hong_Kong", + "Asia/Hovd", + "Asia/Irkutsk", + "Asia/Istanbul", + "Asia/Jakarta", + "Asia/Jayapura", + "Asia/Jerusalem", + "Asia/Kabul", + "Asia/Kamchatka", + "Asia/Karachi", + "Asia/Kashgar", + "Asia/Kathmandu", + "Asia/Katmandu", + "Asia/Khandyga", + "Asia/Kolkata", + "Asia/Krasnoyarsk", + "Asia/Kuala_Lumpur", + "Asia/Kuching", + "Asia/Kuwait", + "Asia/Macao", + "Asia/Macau", + "Asia/Magadan", + "Asia/Makassar", + "Asia/Manila", + "Asia/Muscat", + "Asia/Nicosia", + "Asia/Novokuznetsk", + "Asia/Novosibirsk", + "Asia/Omsk", + "Asia/Oral", + "Asia/Phnom_Penh", + "Asia/Pontianak", + "Asia/Pyongyang", + "Asia/Qatar", "Asia/Qostanay", - "Asia/Qyzylorda", - "Asia/Rangoon", - "Asia/Riyadh", - "Asia/Saigon", - "Asia/Sakhalin", - "Asia/Samarkand", - "Asia/Seoul", - "Asia/Shanghai", - "Asia/Singapore", - "Asia/Srednekolymsk", - "Asia/Taipei", - "Asia/Tashkent", - "Asia/Tbilisi", - "Asia/Tehran", - "Asia/Tel_Aviv", - "Asia/Thimbu", - "Asia/Thimphu", - "Asia/Tokyo", - "Asia/Tomsk", - "Asia/Ujung_Pandang", - "Asia/Ulaanbaatar", - "Asia/Ulan_Bator", - "Asia/Urumqi", - "Asia/Ust-Nera", - "Asia/Vientiane", - "Asia/Vladivostok", - "Asia/Yakutsk", - "Asia/Yangon", - "Asia/Yekaterinburg", - "Asia/Yerevan", - "Atlantic/Azores", - "Atlantic/Bermuda", - "Atlantic/Canary", - "Atlantic/Cape_Verde", - "Atlantic/Faeroe", - "Atlantic/Faroe", - "Atlantic/Jan_Mayen", - "Atlantic/Madeira", - "Atlantic/Reykjavik", - "Atlantic/South_Georgia", - "Atlantic/St_Helena", - "Atlantic/Stanley", - "Australia/ACT", - "Australia/Adelaide", - "Australia/Brisbane", - "Australia/Broken_Hill", - "Australia/Canberra", - "Australia/Currie", - "Australia/Darwin", - "Australia/Eucla", - "Australia/Hobart", - "Australia/LHI", - "Australia/Lindeman", - "Australia/Lord_Howe", - "Australia/Melbourne", - "Australia/NSW", - "Australia/North", - "Australia/Perth", - "Australia/Queensland", - "Australia/South", - "Australia/Sydney", - "Australia/Tasmania", - "Australia/Victoria", - "Australia/West", - "Australia/Yancowinna", - "Brazil/Acre", - "Brazil/DeNoronha", - "Brazil/East", - "Brazil/West", - "CET", - "CST6CDT", - "Canada/Atlantic", - "Canada/Central", - "Canada/Eastern", - "Canada/Mountain", - "Canada/Newfoundland", - "Canada/Pacific", - "Canada/Saskatchewan", - "Canada/Yukon", - "Chile/Continental", - "Chile/EasterIsland", - "Cuba", - "EET", - "EST", - "EST5EDT", - "Egypt", - "Eire", - "Etc/GMT", - "Etc/GMT+0", - "Etc/GMT+1", - "Etc/GMT+10", - "Etc/GMT+11", - "Etc/GMT+12", - "Etc/GMT+2", - "Etc/GMT+3", - "Etc/GMT+4", - "Etc/GMT+5", - "Etc/GMT+6", - "Etc/GMT+7", - "Etc/GMT+8", - "Etc/GMT+9", - "Etc/GMT-0", - "Etc/GMT-1", - "Etc/GMT-10", - "Etc/GMT-11", - "Etc/GMT-12", - "Etc/GMT-13", - "Etc/GMT-14", - "Etc/GMT-2", - "Etc/GMT-3", - "Etc/GMT-4", - "Etc/GMT-5", - "Etc/GMT-6", - "Etc/GMT-7", - "Etc/GMT-8", - "Etc/GMT-9", - "Etc/GMT0", - "Etc/Greenwich", - "Etc/UCT", - "Etc/UTC", - "Etc/Universal", - "Etc/Zulu", - "Europe/Amsterdam", - "Europe/Andorra", - "Europe/Astrakhan", - "Europe/Athens", - "Europe/Belfast", - "Europe/Belgrade", - "Europe/Berlin", - "Europe/Bratislava", - "Europe/Brussels", - "Europe/Bucharest", - "Europe/Budapest", - "Europe/Busingen", - "Europe/Chisinau", - "Europe/Copenhagen", - "Europe/Dublin", - "Europe/Gibraltar", - "Europe/Guernsey", - "Europe/Helsinki", - "Europe/Isle_of_Man", - "Europe/Istanbul", - "Europe/Jersey", - "Europe/Kaliningrad", - "Europe/Kiev", - "Europe/Kirov", - "Europe/Lisbon", - "Europe/Ljubljana", - "Europe/London", - "Europe/Luxembourg", - "Europe/Madrid", - "Europe/Malta", - "Europe/Mariehamn", - "Europe/Minsk", - "Europe/Monaco", - "Europe/Moscow", - "Europe/Nicosia", - "Europe/Oslo", - "Europe/Paris", - "Europe/Podgorica", - "Europe/Prague", - "Europe/Riga", - "Europe/Rome", - "Europe/Samara", - "Europe/San_Marino", - "Europe/Sarajevo", - "Europe/Saratov", - "Europe/Simferopol", - "Europe/Skopje", - "Europe/Sofia", - "Europe/Stockholm", - "Europe/Tallinn", - "Europe/Tirane", - "Europe/Tiraspol", - "Europe/Ulyanovsk", - "Europe/Uzhgorod", - "Europe/Vaduz", - "Europe/Vatican", - "Europe/Vienna", - "Europe/Vilnius", - "Europe/Volgograd", - "Europe/Warsaw", - "Europe/Zagreb", - "Europe/Zaporozhye", - "Europe/Zurich", - "GB", - "GB-Eire", - "GMT", - "GMT+0", - "GMT-0", - "GMT0", - "Greenwich", - "HST", - "Hongkong", - "Iceland", - "Indian/Antananarivo", - "Indian/Chagos", - "Indian/Christmas", - "Indian/Cocos", - "Indian/Comoro", - "Indian/Kerguelen", - "Indian/Mahe", - "Indian/Maldives", - "Indian/Mauritius", - "Indian/Mayotte", - "Indian/Reunion", - "Iran", - "Israel", - "Jamaica", - "Japan", - "Kwajalein", - "Libya", - "MET", - "MST", - "MST7MDT", - "Mexico/BajaNorte", - "Mexico/BajaSur", - "Mexico/General", - "NZ", - "NZ-CHAT", - "Navajo", - "PRC", - "PST8PDT", - "Pacific/Apia", - "Pacific/Auckland", - "Pacific/Bougainville", - "Pacific/Chatham", - "Pacific/Chuuk", - "Pacific/Easter", - "Pacific/Efate", - "Pacific/Enderbury", - "Pacific/Fakaofo", - "Pacific/Fiji", - "Pacific/Funafuti", - "Pacific/Galapagos", - "Pacific/Gambier", - "Pacific/Guadalcanal", - "Pacific/Guam", - "Pacific/Honolulu", - "Pacific/Johnston", - "Pacific/Kiritimati", - "Pacific/Kosrae", - "Pacific/Kwajalein", - "Pacific/Majuro", - "Pacific/Marquesas", - "Pacific/Midway", - "Pacific/Nauru", - "Pacific/Niue", - "Pacific/Norfolk", - "Pacific/Noumea", - "Pacific/Pago_Pago", - "Pacific/Palau", - "Pacific/Pitcairn", - "Pacific/Pohnpei", - "Pacific/Ponape", - "Pacific/Port_Moresby", - "Pacific/Rarotonga", - "Pacific/Saipan", - "Pacific/Samoa", - "Pacific/Tahiti", - "Pacific/Tarawa", - "Pacific/Tongatapu", - "Pacific/Truk", - "Pacific/Wake", - "Pacific/Wallis", - "Pacific/Yap", - "Poland", - "Portugal", - "ROC", - "ROK", - "Singapore", - "Turkey", - "UCT", - "US/Alaska", - "US/Aleutian", - "US/Arizona", - "US/Central", - "US/East-Indiana", - "US/Eastern", - "US/Hawaii", - "US/Indiana-Starke", - "US/Michigan", - "US/Mountain", - "US/Pacific", - "US/Samoa", - "UTC", - "Universal", - "W-SU", - "WET", - "Zulu", - nullptr -}; - -// Helper to return a loaded time zone by value (UTC on error). -time_zone LoadZone(const std::string& name) { - time_zone tz; - load_time_zone(name, &tz); - return tz; -} - -// This helper is a macro so that failed expectations show up with the -// correct line numbers. -#define ExpectTime(tp, tz, y, m, d, hh, mm, ss, off, isdst, zone) \ - do { \ - time_zone::absolute_lookup al = tz.lookup(tp); \ - EXPECT_EQ(y, al.cs.year()); \ - EXPECT_EQ(m, al.cs.month()); \ - EXPECT_EQ(d, al.cs.day()); \ - EXPECT_EQ(hh, al.cs.hour()); \ - EXPECT_EQ(mm, al.cs.minute()); \ - EXPECT_EQ(ss, al.cs.second()); \ - EXPECT_EQ(off, al.offset); \ - EXPECT_TRUE(isdst == al.is_dst); \ - /* EXPECT_STREQ(zone, al.abbr); */ \ - } while (0) - + "Asia/Qyzylorda", + "Asia/Rangoon", + "Asia/Riyadh", + "Asia/Saigon", + "Asia/Sakhalin", + "Asia/Samarkand", + "Asia/Seoul", + "Asia/Shanghai", + "Asia/Singapore", + "Asia/Srednekolymsk", + "Asia/Taipei", + "Asia/Tashkent", + "Asia/Tbilisi", + "Asia/Tehran", + "Asia/Tel_Aviv", + "Asia/Thimbu", + "Asia/Thimphu", + "Asia/Tokyo", + "Asia/Tomsk", + "Asia/Ujung_Pandang", + "Asia/Ulaanbaatar", + "Asia/Ulan_Bator", + "Asia/Urumqi", + "Asia/Ust-Nera", + "Asia/Vientiane", + "Asia/Vladivostok", + "Asia/Yakutsk", + "Asia/Yangon", + "Asia/Yekaterinburg", + "Asia/Yerevan", + "Atlantic/Azores", + "Atlantic/Bermuda", + "Atlantic/Canary", + "Atlantic/Cape_Verde", + "Atlantic/Faeroe", + "Atlantic/Faroe", + "Atlantic/Jan_Mayen", + "Atlantic/Madeira", + "Atlantic/Reykjavik", + "Atlantic/South_Georgia", + "Atlantic/St_Helena", + "Atlantic/Stanley", + "Australia/ACT", + "Australia/Adelaide", + "Australia/Brisbane", + "Australia/Broken_Hill", + "Australia/Canberra", + "Australia/Currie", + "Australia/Darwin", + "Australia/Eucla", + "Australia/Hobart", + "Australia/LHI", + "Australia/Lindeman", + "Australia/Lord_Howe", + "Australia/Melbourne", + "Australia/NSW", + "Australia/North", + "Australia/Perth", + "Australia/Queensland", + "Australia/South", + "Australia/Sydney", + "Australia/Tasmania", + "Australia/Victoria", + "Australia/West", + "Australia/Yancowinna", + "Brazil/Acre", + "Brazil/DeNoronha", + "Brazil/East", + "Brazil/West", + "CET", + "CST6CDT", + "Canada/Atlantic", + "Canada/Central", + "Canada/Eastern", + "Canada/Mountain", + "Canada/Newfoundland", + "Canada/Pacific", + "Canada/Saskatchewan", + "Canada/Yukon", + "Chile/Continental", + "Chile/EasterIsland", + "Cuba", + "EET", + "EST", + "EST5EDT", + "Egypt", + "Eire", + "Etc/GMT", + "Etc/GMT+0", + "Etc/GMT+1", + "Etc/GMT+10", + "Etc/GMT+11", + "Etc/GMT+12", + "Etc/GMT+2", + "Etc/GMT+3", + "Etc/GMT+4", + "Etc/GMT+5", + "Etc/GMT+6", + "Etc/GMT+7", + "Etc/GMT+8", + "Etc/GMT+9", + "Etc/GMT-0", + "Etc/GMT-1", + "Etc/GMT-10", + "Etc/GMT-11", + "Etc/GMT-12", + "Etc/GMT-13", + "Etc/GMT-14", + "Etc/GMT-2", + "Etc/GMT-3", + "Etc/GMT-4", + "Etc/GMT-5", + "Etc/GMT-6", + "Etc/GMT-7", + "Etc/GMT-8", + "Etc/GMT-9", + "Etc/GMT0", + "Etc/Greenwich", + "Etc/UCT", + "Etc/UTC", + "Etc/Universal", + "Etc/Zulu", + "Europe/Amsterdam", + "Europe/Andorra", + "Europe/Astrakhan", + "Europe/Athens", + "Europe/Belfast", + "Europe/Belgrade", + "Europe/Berlin", + "Europe/Bratislava", + "Europe/Brussels", + "Europe/Bucharest", + "Europe/Budapest", + "Europe/Busingen", + "Europe/Chisinau", + "Europe/Copenhagen", + "Europe/Dublin", + "Europe/Gibraltar", + "Europe/Guernsey", + "Europe/Helsinki", + "Europe/Isle_of_Man", + "Europe/Istanbul", + "Europe/Jersey", + "Europe/Kaliningrad", + "Europe/Kiev", + "Europe/Kirov", + "Europe/Lisbon", + "Europe/Ljubljana", + "Europe/London", + "Europe/Luxembourg", + "Europe/Madrid", + "Europe/Malta", + "Europe/Mariehamn", + "Europe/Minsk", + "Europe/Monaco", + "Europe/Moscow", + "Europe/Nicosia", + "Europe/Oslo", + "Europe/Paris", + "Europe/Podgorica", + "Europe/Prague", + "Europe/Riga", + "Europe/Rome", + "Europe/Samara", + "Europe/San_Marino", + "Europe/Sarajevo", + "Europe/Saratov", + "Europe/Simferopol", + "Europe/Skopje", + "Europe/Sofia", + "Europe/Stockholm", + "Europe/Tallinn", + "Europe/Tirane", + "Europe/Tiraspol", + "Europe/Ulyanovsk", + "Europe/Uzhgorod", + "Europe/Vaduz", + "Europe/Vatican", + "Europe/Vienna", + "Europe/Vilnius", + "Europe/Volgograd", + "Europe/Warsaw", + "Europe/Zagreb", + "Europe/Zaporozhye", + "Europe/Zurich", + "GB", + "GB-Eire", + "GMT", + "GMT+0", + "GMT-0", + "GMT0", + "Greenwich", + "HST", + "Hongkong", + "Iceland", + "Indian/Antananarivo", + "Indian/Chagos", + "Indian/Christmas", + "Indian/Cocos", + "Indian/Comoro", + "Indian/Kerguelen", + "Indian/Mahe", + "Indian/Maldives", + "Indian/Mauritius", + "Indian/Mayotte", + "Indian/Reunion", + "Iran", + "Israel", + "Jamaica", + "Japan", + "Kwajalein", + "Libya", + "MET", + "MST", + "MST7MDT", + "Mexico/BajaNorte", + "Mexico/BajaSur", + "Mexico/General", + "NZ", + "NZ-CHAT", + "Navajo", + "PRC", + "PST8PDT", + "Pacific/Apia", + "Pacific/Auckland", + "Pacific/Bougainville", + "Pacific/Chatham", + "Pacific/Chuuk", + "Pacific/Easter", + "Pacific/Efate", + "Pacific/Enderbury", + "Pacific/Fakaofo", + "Pacific/Fiji", + "Pacific/Funafuti", + "Pacific/Galapagos", + "Pacific/Gambier", + "Pacific/Guadalcanal", + "Pacific/Guam", + "Pacific/Honolulu", + "Pacific/Johnston", + "Pacific/Kiritimati", + "Pacific/Kosrae", + "Pacific/Kwajalein", + "Pacific/Majuro", + "Pacific/Marquesas", + "Pacific/Midway", + "Pacific/Nauru", + "Pacific/Niue", + "Pacific/Norfolk", + "Pacific/Noumea", + "Pacific/Pago_Pago", + "Pacific/Palau", + "Pacific/Pitcairn", + "Pacific/Pohnpei", + "Pacific/Ponape", + "Pacific/Port_Moresby", + "Pacific/Rarotonga", + "Pacific/Saipan", + "Pacific/Samoa", + "Pacific/Tahiti", + "Pacific/Tarawa", + "Pacific/Tongatapu", + "Pacific/Truk", + "Pacific/Wake", + "Pacific/Wallis", + "Pacific/Yap", + "Poland", + "Portugal", + "ROC", + "ROK", + "Singapore", + "Turkey", + "UCT", + "US/Alaska", + "US/Aleutian", + "US/Arizona", + "US/Central", + "US/East-Indiana", + "US/Eastern", + "US/Hawaii", + "US/Indiana-Starke", + "US/Michigan", + "US/Mountain", + "US/Pacific", + "US/Samoa", + "UTC", + "Universal", + "W-SU", + "WET", + "Zulu", + nullptr +}; + +// Helper to return a loaded time zone by value (UTC on error). +time_zone LoadZone(const std::string& name) { + time_zone tz; + load_time_zone(name, &tz); + return tz; +} + +// This helper is a macro so that failed expectations show up with the +// correct line numbers. +#define ExpectTime(tp, tz, y, m, d, hh, mm, ss, off, isdst, zone) \ + do { \ + time_zone::absolute_lookup al = tz.lookup(tp); \ + EXPECT_EQ(y, al.cs.year()); \ + EXPECT_EQ(m, al.cs.month()); \ + EXPECT_EQ(d, al.cs.day()); \ + EXPECT_EQ(hh, al.cs.hour()); \ + EXPECT_EQ(mm, al.cs.minute()); \ + EXPECT_EQ(ss, al.cs.second()); \ + EXPECT_EQ(off, al.offset); \ + EXPECT_TRUE(isdst == al.is_dst); \ + /* EXPECT_STREQ(zone, al.abbr); */ \ + } while (0) + // These tests sometimes run on platforms that have zoneinfo data so old // that the transition we are attempting to check does not exist, most // notably Android emulators. Fortunately, AndroidZoneInfoSource supports @@ -664,333 +664,333 @@ int VersionCmp(time_zone tz, const std::string& target) { return version.compare(target); } -} // namespace - -TEST(TimeZones, LoadZonesConcurrently) { - std::promise<void> ready_promise; - std::shared_future<void> ready_future(ready_promise.get_future()); - auto load_zones = [ready_future](std::promise<void>* started, - std::set<std::string>* failures) { - started->set_value(); - ready_future.wait(); - for (const char* const* np = kTimeZoneNames; *np != nullptr; ++np) { - std::string zone = *np; - time_zone tz; - if (load_time_zone(zone, &tz)) { - EXPECT_EQ(zone, tz.name()); - } else { - failures->insert(zone); - } - } - }; - +} // namespace + +TEST(TimeZones, LoadZonesConcurrently) { + std::promise<void> ready_promise; + std::shared_future<void> ready_future(ready_promise.get_future()); + auto load_zones = [ready_future](std::promise<void>* started, + std::set<std::string>* failures) { + started->set_value(); + ready_future.wait(); + for (const char* const* np = kTimeZoneNames; *np != nullptr; ++np) { + std::string zone = *np; + time_zone tz; + if (load_time_zone(zone, &tz)) { + EXPECT_EQ(zone, tz.name()); + } else { + failures->insert(zone); + } + } + }; + const std::size_t n_threads = 128; - std::vector<std::thread> threads; - std::vector<std::set<std::string>> thread_failures(n_threads); - for (std::size_t i = 0; i != n_threads; ++i) { - std::promise<void> started; - threads.emplace_back(load_zones, &started, &thread_failures[i]); - started.get_future().wait(); - } - ready_promise.set_value(); - for (auto& thread : threads) { - thread.join(); - } - - // Allow a small number of failures to account for skew between - // the contents of kTimeZoneNames and the zoneinfo data source. + std::vector<std::thread> threads; + std::vector<std::set<std::string>> thread_failures(n_threads); + for (std::size_t i = 0; i != n_threads; ++i) { + std::promise<void> started; + threads.emplace_back(load_zones, &started, &thread_failures[i]); + started.get_future().wait(); + } + ready_promise.set_value(); + for (auto& thread : threads) { + thread.join(); + } + + // Allow a small number of failures to account for skew between + // the contents of kTimeZoneNames and the zoneinfo data source. #if defined(__ANDROID__) // Cater to the possibility of using an even older zoneinfo data // source when running on Android, where it is difficult to override // the bionic tzdata provided by the test environment. const std::size_t max_failures = 20; #else - const std::size_t max_failures = 3; + const std::size_t max_failures = 3; #endif - std::set<std::string> failures; - for (const auto& thread_failure : thread_failures) { - failures.insert(thread_failure.begin(), thread_failure.end()); - } + std::set<std::string> failures; + for (const auto& thread_failure : thread_failures) { + failures.insert(thread_failure.begin(), thread_failure.end()); + } EXPECT_LE(failures.size(), max_failures) << testing::PrintToString(failures); -} - -TEST(TimeZone, NamedTimeZones) { - const time_zone utc = utc_time_zone(); - EXPECT_EQ("UTC", utc.name()); - const time_zone nyc = LoadZone("America/New_York"); - EXPECT_EQ("America/New_York", nyc.name()); - const time_zone syd = LoadZone("Australia/Sydney"); - EXPECT_EQ("Australia/Sydney", syd.name()); +} + +TEST(TimeZone, NamedTimeZones) { + const time_zone utc = utc_time_zone(); + EXPECT_EQ("UTC", utc.name()); + const time_zone nyc = LoadZone("America/New_York"); + EXPECT_EQ("America/New_York", nyc.name()); + const time_zone syd = LoadZone("Australia/Sydney"); + EXPECT_EQ("Australia/Sydney", syd.name()); const time_zone fixed0 = fixed_time_zone(cctz::seconds::zero()); - EXPECT_EQ("UTC", fixed0.name()); + EXPECT_EQ("UTC", fixed0.name()); const time_zone fixed_pos = fixed_time_zone( chrono::hours(3) + chrono::minutes(25) + chrono::seconds(45)); - EXPECT_EQ("Fixed/UTC+03:25:45", fixed_pos.name()); + EXPECT_EQ("Fixed/UTC+03:25:45", fixed_pos.name()); const time_zone fixed_neg = fixed_time_zone( -(chrono::hours(12) + chrono::minutes(34) + chrono::seconds(56))); - EXPECT_EQ("Fixed/UTC-12:34:56", fixed_neg.name()); -} - -TEST(TimeZone, Failures) { - time_zone tz; - EXPECT_FALSE(load_time_zone(":America/Los_Angeles", &tz)); - - tz = LoadZone("America/Los_Angeles"); - EXPECT_FALSE(load_time_zone("Invalid/TimeZone", &tz)); + EXPECT_EQ("Fixed/UTC-12:34:56", fixed_neg.name()); +} + +TEST(TimeZone, Failures) { + time_zone tz; + EXPECT_FALSE(load_time_zone(":America/Los_Angeles", &tz)); + + tz = LoadZone("America/Los_Angeles"); + EXPECT_FALSE(load_time_zone("Invalid/TimeZone", &tz)); EXPECT_EQ(chrono::system_clock::from_time_t(0), - convert(civil_second(1970, 1, 1, 0, 0, 0), tz)); // UTC - - // Ensures that the load still fails on a subsequent attempt. - tz = LoadZone("America/Los_Angeles"); - EXPECT_FALSE(load_time_zone("Invalid/TimeZone", &tz)); + convert(civil_second(1970, 1, 1, 0, 0, 0), tz)); // UTC + + // Ensures that the load still fails on a subsequent attempt. + tz = LoadZone("America/Los_Angeles"); + EXPECT_FALSE(load_time_zone("Invalid/TimeZone", &tz)); EXPECT_EQ(chrono::system_clock::from_time_t(0), - convert(civil_second(1970, 1, 1, 0, 0, 0), tz)); // UTC - - // Loading an empty string timezone should fail. - tz = LoadZone("America/Los_Angeles"); - EXPECT_FALSE(load_time_zone("", &tz)); + convert(civil_second(1970, 1, 1, 0, 0, 0), tz)); // UTC + + // Loading an empty string timezone should fail. + tz = LoadZone("America/Los_Angeles"); + EXPECT_FALSE(load_time_zone("", &tz)); EXPECT_EQ(chrono::system_clock::from_time_t(0), - convert(civil_second(1970, 1, 1, 0, 0, 0), tz)); // UTC -} - -TEST(TimeZone, Equality) { + convert(civil_second(1970, 1, 1, 0, 0, 0), tz)); // UTC +} + +TEST(TimeZone, Equality) { const time_zone a; const time_zone b; - EXPECT_EQ(a, b); - EXPECT_EQ(a.name(), b.name()); - + EXPECT_EQ(a, b); + EXPECT_EQ(a.name(), b.name()); + const time_zone implicit_utc; - const time_zone explicit_utc = utc_time_zone(); - EXPECT_EQ(implicit_utc, explicit_utc); - EXPECT_EQ(implicit_utc.name(), explicit_utc.name()); - + const time_zone explicit_utc = utc_time_zone(); + EXPECT_EQ(implicit_utc, explicit_utc); + EXPECT_EQ(implicit_utc.name(), explicit_utc.name()); + const time_zone fixed_zero = fixed_time_zone(cctz::seconds::zero()); - EXPECT_EQ(fixed_zero, LoadZone(fixed_zero.name())); - EXPECT_EQ(fixed_zero, explicit_utc); - - const time_zone fixed_utc = LoadZone("Fixed/UTC+00:00:00"); - EXPECT_EQ(fixed_utc, LoadZone(fixed_utc.name())); - EXPECT_EQ(fixed_utc, explicit_utc); - + EXPECT_EQ(fixed_zero, LoadZone(fixed_zero.name())); + EXPECT_EQ(fixed_zero, explicit_utc); + + const time_zone fixed_utc = LoadZone("Fixed/UTC+00:00:00"); + EXPECT_EQ(fixed_utc, LoadZone(fixed_utc.name())); + EXPECT_EQ(fixed_utc, explicit_utc); + const time_zone fixed_pos = fixed_time_zone( chrono::hours(3) + chrono::minutes(25) + chrono::seconds(45)); - EXPECT_EQ(fixed_pos, LoadZone(fixed_pos.name())); - EXPECT_NE(fixed_pos, explicit_utc); + EXPECT_EQ(fixed_pos, LoadZone(fixed_pos.name())); + EXPECT_NE(fixed_pos, explicit_utc); const time_zone fixed_neg = fixed_time_zone( -(chrono::hours(12) + chrono::minutes(34) + chrono::seconds(56))); - EXPECT_EQ(fixed_neg, LoadZone(fixed_neg.name())); - EXPECT_NE(fixed_neg, explicit_utc); - + EXPECT_EQ(fixed_neg, LoadZone(fixed_neg.name())); + EXPECT_NE(fixed_neg, explicit_utc); + const time_zone fixed_lim = fixed_time_zone(chrono::hours(24)); - EXPECT_EQ(fixed_lim, LoadZone(fixed_lim.name())); - EXPECT_NE(fixed_lim, explicit_utc); + EXPECT_EQ(fixed_lim, LoadZone(fixed_lim.name())); + EXPECT_NE(fixed_lim, explicit_utc); const time_zone fixed_ovfl = fixed_time_zone(chrono::hours(24) + chrono::seconds(1)); - EXPECT_EQ(fixed_ovfl, LoadZone(fixed_ovfl.name())); - EXPECT_EQ(fixed_ovfl, explicit_utc); - + EXPECT_EQ(fixed_ovfl, LoadZone(fixed_ovfl.name())); + EXPECT_EQ(fixed_ovfl, explicit_utc); + EXPECT_EQ(fixed_time_zone(chrono::seconds(1)), fixed_time_zone(chrono::seconds(1))); - - const time_zone local = local_time_zone(); - EXPECT_EQ(local, LoadZone(local.name())); - - time_zone la = LoadZone("America/Los_Angeles"); - time_zone nyc = LoadZone("America/New_York"); - EXPECT_NE(la, nyc); -} - -TEST(StdChronoTimePoint, TimeTAlignment) { - // Ensures that the Unix epoch and the system clock epoch are an integral - // number of seconds apart. This simplifies conversions to/from time_t. + + const time_zone local = local_time_zone(); + EXPECT_EQ(local, LoadZone(local.name())); + + time_zone la = LoadZone("America/Los_Angeles"); + time_zone nyc = LoadZone("America/New_York"); + EXPECT_NE(la, nyc); +} + +TEST(StdChronoTimePoint, TimeTAlignment) { + // Ensures that the Unix epoch and the system clock epoch are an integral + // number of seconds apart. This simplifies conversions to/from time_t. auto diff = chrono::system_clock::time_point() - chrono::system_clock::from_time_t(0); EXPECT_EQ(chrono::system_clock::time_point::duration::zero(), diff % chrono::seconds(1)); -} - -TEST(BreakTime, TimePointResolution) { - const time_zone utc = utc_time_zone(); +} + +TEST(BreakTime, TimePointResolution) { + const time_zone utc = utc_time_zone(); const auto t0 = chrono::system_clock::from_time_t(0); - + ExpectTime(chrono::time_point_cast<chrono::nanoseconds>(t0), utc, - 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); + 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); ExpectTime(chrono::time_point_cast<chrono::microseconds>(t0), utc, - 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); + 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); ExpectTime(chrono::time_point_cast<chrono::milliseconds>(t0), utc, - 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); + 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); ExpectTime(chrono::time_point_cast<chrono::seconds>(t0), utc, - 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); + 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); ExpectTime(chrono::time_point_cast<cctz::seconds>(t0), utc, - 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); + 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); ExpectTime(chrono::time_point_cast<chrono::minutes>(t0), utc, - 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); + 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); ExpectTime(chrono::time_point_cast<chrono::hours>(t0), utc, - 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); -} - -TEST(BreakTime, LocalTimeInUTC) { - const time_zone tz = utc_time_zone(); + 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); +} + +TEST(BreakTime, LocalTimeInUTC) { + const time_zone tz = utc_time_zone(); const auto tp = chrono::system_clock::from_time_t(0); - ExpectTime(tp, tz, 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); + ExpectTime(tp, tz, 1970, 1, 1, 0, 0, 0, 0, false, "UTC"); EXPECT_EQ(weekday::thursday, get_weekday(convert(tp, tz))); -} - -TEST(BreakTime, LocalTimeInUTCUnaligned) { - const time_zone tz = utc_time_zone(); +} + +TEST(BreakTime, LocalTimeInUTCUnaligned) { + const time_zone tz = utc_time_zone(); const auto tp = chrono::system_clock::from_time_t(0) - chrono::milliseconds(500); - ExpectTime(tp, tz, 1969, 12, 31, 23, 59, 59, 0, false, "UTC"); + ExpectTime(tp, tz, 1969, 12, 31, 23, 59, 59, 0, false, "UTC"); EXPECT_EQ(weekday::wednesday, get_weekday(convert(tp, tz))); -} - -TEST(BreakTime, LocalTimePosix) { - // See IEEE Std 1003.1-1988 B.2.3 General Terms, Epoch. - const time_zone tz = utc_time_zone(); +} + +TEST(BreakTime, LocalTimePosix) { + // See IEEE Std 1003.1-1988 B.2.3 General Terms, Epoch. + const time_zone tz = utc_time_zone(); const auto tp = chrono::system_clock::from_time_t(536457599); - ExpectTime(tp, tz, 1986, 12, 31, 23, 59, 59, 0, false, "UTC"); + ExpectTime(tp, tz, 1986, 12, 31, 23, 59, 59, 0, false, "UTC"); EXPECT_EQ(weekday::wednesday, get_weekday(convert(tp, tz))); -} - -TEST(TimeZoneImpl, LocalTimeInFixed) { +} + +TEST(TimeZoneImpl, LocalTimeInFixed) { const cctz::seconds offset = -(chrono::hours(8) + chrono::minutes(33) + chrono::seconds(47)); - const time_zone tz = fixed_time_zone(offset); + const time_zone tz = fixed_time_zone(offset); const auto tp = chrono::system_clock::from_time_t(0); - ExpectTime(tp, tz, 1969, 12, 31, 15, 26, 13, offset.count(), false, + ExpectTime(tp, tz, 1969, 12, 31, 15, 26, 13, offset.count(), false, "-083347"); EXPECT_EQ(weekday::wednesday, get_weekday(convert(tp, tz))); -} - -TEST(BreakTime, LocalTimeInNewYork) { - const time_zone tz = LoadZone("America/New_York"); +} + +TEST(BreakTime, LocalTimeInNewYork) { + const time_zone tz = LoadZone("America/New_York"); const auto tp = chrono::system_clock::from_time_t(45); - ExpectTime(tp, tz, 1969, 12, 31, 19, 0, 45, -5 * 60 * 60, false, "EST"); + ExpectTime(tp, tz, 1969, 12, 31, 19, 0, 45, -5 * 60 * 60, false, "EST"); EXPECT_EQ(weekday::wednesday, get_weekday(convert(tp, tz))); -} - -TEST(BreakTime, LocalTimeInMTV) { - const time_zone tz = LoadZone("America/Los_Angeles"); +} + +TEST(BreakTime, LocalTimeInMTV) { + const time_zone tz = LoadZone("America/Los_Angeles"); const auto tp = chrono::system_clock::from_time_t(1380855729); - ExpectTime(tp, tz, 2013, 10, 3, 20, 2, 9, -7 * 60 * 60, true, "PDT"); + ExpectTime(tp, tz, 2013, 10, 3, 20, 2, 9, -7 * 60 * 60, true, "PDT"); EXPECT_EQ(weekday::thursday, get_weekday(convert(tp, tz))); -} - -TEST(BreakTime, LocalTimeInSydney) { - const time_zone tz = LoadZone("Australia/Sydney"); +} + +TEST(BreakTime, LocalTimeInSydney) { + const time_zone tz = LoadZone("Australia/Sydney"); const auto tp = chrono::system_clock::from_time_t(90); - ExpectTime(tp, tz, 1970, 1, 1, 10, 1, 30, 10 * 60 * 60, false, "AEST"); + ExpectTime(tp, tz, 1970, 1, 1, 10, 1, 30, 10 * 60 * 60, false, "AEST"); EXPECT_EQ(weekday::thursday, get_weekday(convert(tp, tz))); -} - -TEST(MakeTime, TimePointResolution) { - const time_zone utc = utc_time_zone(); +} + +TEST(MakeTime, TimePointResolution) { + const time_zone utc = utc_time_zone(); const time_point<chrono::nanoseconds> tp_ns = - convert(civil_second(2015, 1, 2, 3, 4, 5), utc); - EXPECT_EQ("04:05", format("%M:%E*S", tp_ns, utc)); + convert(civil_second(2015, 1, 2, 3, 4, 5), utc); + EXPECT_EQ("04:05", format("%M:%E*S", tp_ns, utc)); const time_point<chrono::microseconds> tp_us = - convert(civil_second(2015, 1, 2, 3, 4, 5), utc); - EXPECT_EQ("04:05", format("%M:%E*S", tp_us, utc)); + convert(civil_second(2015, 1, 2, 3, 4, 5), utc); + EXPECT_EQ("04:05", format("%M:%E*S", tp_us, utc)); const time_point<chrono::milliseconds> tp_ms = - convert(civil_second(2015, 1, 2, 3, 4, 5), utc); - EXPECT_EQ("04:05", format("%M:%E*S", tp_ms, utc)); + convert(civil_second(2015, 1, 2, 3, 4, 5), utc); + EXPECT_EQ("04:05", format("%M:%E*S", tp_ms, utc)); const time_point<chrono::seconds> tp_s = - convert(civil_second(2015, 1, 2, 3, 4, 5), utc); - EXPECT_EQ("04:05", format("%M:%E*S", tp_s, utc)); + convert(civil_second(2015, 1, 2, 3, 4, 5), utc); + EXPECT_EQ("04:05", format("%M:%E*S", tp_s, utc)); const time_point<cctz::seconds> tp_s64 = - convert(civil_second(2015, 1, 2, 3, 4, 5), utc); - EXPECT_EQ("04:05", format("%M:%E*S", tp_s64, utc)); - + convert(civil_second(2015, 1, 2, 3, 4, 5), utc); + EXPECT_EQ("04:05", format("%M:%E*S", tp_s64, utc)); + // These next two require chrono::time_point_cast because the conversion // from a resolution of seconds (the return value of convert()) to a // coarser resolution requires an explicit cast. const time_point<chrono::minutes> tp_m = chrono::time_point_cast<chrono::minutes>( - convert(civil_second(2015, 1, 2, 3, 4, 5), utc)); - EXPECT_EQ("04:00", format("%M:%E*S", tp_m, utc)); + convert(civil_second(2015, 1, 2, 3, 4, 5), utc)); + EXPECT_EQ("04:00", format("%M:%E*S", tp_m, utc)); const time_point<chrono::hours> tp_h = chrono::time_point_cast<chrono::hours>( - convert(civil_second(2015, 1, 2, 3, 4, 5), utc)); - EXPECT_EQ("00:00", format("%M:%E*S", tp_h, utc)); -} - -TEST(MakeTime, Normalization) { - const time_zone tz = LoadZone("America/New_York"); - const auto tp = convert(civil_second(2009, 2, 13, 18, 31, 30), tz); + convert(civil_second(2015, 1, 2, 3, 4, 5), utc)); + EXPECT_EQ("00:00", format("%M:%E*S", tp_h, utc)); +} + +TEST(MakeTime, Normalization) { + const time_zone tz = LoadZone("America/New_York"); + const auto tp = convert(civil_second(2009, 2, 13, 18, 31, 30), tz); EXPECT_EQ(chrono::system_clock::from_time_t(1234567890), tp); - - // Now requests for the same time_point but with out-of-range fields. - EXPECT_EQ(tp, convert(civil_second(2008, 14, 13, 18, 31, 30), tz)); // month - EXPECT_EQ(tp, convert(civil_second(2009, 1, 44, 18, 31, 30), tz)); // day - EXPECT_EQ(tp, convert(civil_second(2009, 2, 12, 42, 31, 30), tz)); // hour - EXPECT_EQ(tp, convert(civil_second(2009, 2, 13, 17, 91, 30), tz)); // minute - EXPECT_EQ(tp, convert(civil_second(2009, 2, 13, 18, 30, 90), tz)); // second -} - + + // Now requests for the same time_point but with out-of-range fields. + EXPECT_EQ(tp, convert(civil_second(2008, 14, 13, 18, 31, 30), tz)); // month + EXPECT_EQ(tp, convert(civil_second(2009, 1, 44, 18, 31, 30), tz)); // day + EXPECT_EQ(tp, convert(civil_second(2009, 2, 12, 42, 31, 30), tz)); // hour + EXPECT_EQ(tp, convert(civil_second(2009, 2, 13, 17, 91, 30), tz)); // minute + EXPECT_EQ(tp, convert(civil_second(2009, 2, 13, 18, 30, 90), tz)); // second +} + // NOTE: Run this with -ftrapv to detect overflow problems. -TEST(MakeTime, SysSecondsLimits) { +TEST(MakeTime, SysSecondsLimits) { const char RFC3339[] = "%Y-%m-%d%ET%H:%M:%S%Ez"; - const time_zone utc = utc_time_zone(); + const time_zone utc = utc_time_zone(); const time_zone east = fixed_time_zone(chrono::hours(14)); const time_zone west = fixed_time_zone(-chrono::hours(14)); time_point<cctz::seconds> tp; - + // Approach the maximal time_point<cctz::seconds> value from below. - tp = convert(civil_second(292277026596, 12, 4, 15, 30, 6), utc); - EXPECT_EQ("292277026596-12-04T15:30:06+00:00", format(RFC3339, tp, utc)); - tp = convert(civil_second(292277026596, 12, 4, 15, 30, 7), utc); - EXPECT_EQ("292277026596-12-04T15:30:07+00:00", format(RFC3339, tp, utc)); + tp = convert(civil_second(292277026596, 12, 4, 15, 30, 6), utc); + EXPECT_EQ("292277026596-12-04T15:30:06+00:00", format(RFC3339, tp, utc)); + tp = convert(civil_second(292277026596, 12, 4, 15, 30, 7), utc); + EXPECT_EQ("292277026596-12-04T15:30:07+00:00", format(RFC3339, tp, utc)); EXPECT_EQ(time_point<cctz::seconds>::max(), tp); - tp = convert(civil_second(292277026596, 12, 4, 15, 30, 8), utc); + tp = convert(civil_second(292277026596, 12, 4, 15, 30, 8), utc); EXPECT_EQ(time_point<cctz::seconds>::max(), tp); - tp = convert(civil_second::max(), utc); + tp = convert(civil_second::max(), utc); EXPECT_EQ(time_point<cctz::seconds>::max(), tp); - - // Checks that we can also get the maximal value for a far-east zone. - tp = convert(civil_second(292277026596, 12, 5, 5, 30, 7), east); - EXPECT_EQ("292277026596-12-05T05:30:07+14:00", format(RFC3339, tp, east)); + + // Checks that we can also get the maximal value for a far-east zone. + tp = convert(civil_second(292277026596, 12, 5, 5, 30, 7), east); + EXPECT_EQ("292277026596-12-05T05:30:07+14:00", format(RFC3339, tp, east)); EXPECT_EQ(time_point<cctz::seconds>::max(), tp); - tp = convert(civil_second(292277026596, 12, 5, 5, 30, 8), east); + tp = convert(civil_second(292277026596, 12, 5, 5, 30, 8), east); EXPECT_EQ(time_point<cctz::seconds>::max(), tp); - tp = convert(civil_second::max(), east); + tp = convert(civil_second::max(), east); EXPECT_EQ(time_point<cctz::seconds>::max(), tp); - - // Checks that we can also get the maximal value for a far-west zone. - tp = convert(civil_second(292277026596, 12, 4, 1, 30, 7), west); - EXPECT_EQ("292277026596-12-04T01:30:07-14:00", format(RFC3339, tp, west)); + + // Checks that we can also get the maximal value for a far-west zone. + tp = convert(civil_second(292277026596, 12, 4, 1, 30, 7), west); + EXPECT_EQ("292277026596-12-04T01:30:07-14:00", format(RFC3339, tp, west)); EXPECT_EQ(time_point<cctz::seconds>::max(), tp); - tp = convert(civil_second(292277026596, 12, 4, 7, 30, 8), west); + tp = convert(civil_second(292277026596, 12, 4, 7, 30, 8), west); EXPECT_EQ(time_point<cctz::seconds>::max(), tp); - tp = convert(civil_second::max(), west); + tp = convert(civil_second::max(), west); EXPECT_EQ(time_point<cctz::seconds>::max(), tp); - + // Approach the minimal time_point<cctz::seconds> value from above. - tp = convert(civil_second(-292277022657, 1, 27, 8, 29, 53), utc); - EXPECT_EQ("-292277022657-01-27T08:29:53+00:00", format(RFC3339, tp, utc)); - tp = convert(civil_second(-292277022657, 1, 27, 8, 29, 52), utc); - EXPECT_EQ("-292277022657-01-27T08:29:52+00:00", format(RFC3339, tp, utc)); + tp = convert(civil_second(-292277022657, 1, 27, 8, 29, 53), utc); + EXPECT_EQ("-292277022657-01-27T08:29:53+00:00", format(RFC3339, tp, utc)); + tp = convert(civil_second(-292277022657, 1, 27, 8, 29, 52), utc); + EXPECT_EQ("-292277022657-01-27T08:29:52+00:00", format(RFC3339, tp, utc)); EXPECT_EQ(time_point<cctz::seconds>::min(), tp); - tp = convert(civil_second(-292277022657, 1, 27, 8, 29, 51), utc); + tp = convert(civil_second(-292277022657, 1, 27, 8, 29, 51), utc); EXPECT_EQ(time_point<cctz::seconds>::min(), tp); - tp = convert(civil_second::min(), utc); + tp = convert(civil_second::min(), utc); EXPECT_EQ(time_point<cctz::seconds>::min(), tp); - - // Checks that we can also get the minimal value for a far-east zone. - tp = convert(civil_second(-292277022657, 1, 27, 22, 29, 52), east); - EXPECT_EQ("-292277022657-01-27T22:29:52+14:00", format(RFC3339, tp, east)); + + // Checks that we can also get the minimal value for a far-east zone. + tp = convert(civil_second(-292277022657, 1, 27, 22, 29, 52), east); + EXPECT_EQ("-292277022657-01-27T22:29:52+14:00", format(RFC3339, tp, east)); EXPECT_EQ(time_point<cctz::seconds>::min(), tp); - tp = convert(civil_second(-292277022657, 1, 27, 22, 29, 51), east); + tp = convert(civil_second(-292277022657, 1, 27, 22, 29, 51), east); EXPECT_EQ(time_point<cctz::seconds>::min(), tp); - tp = convert(civil_second::min(), east); + tp = convert(civil_second::min(), east); EXPECT_EQ(time_point<cctz::seconds>::min(), tp); - - // Checks that we can also get the minimal value for a far-west zone. - tp = convert(civil_second(-292277022657, 1, 26, 18, 29, 52), west); - EXPECT_EQ("-292277022657-01-26T18:29:52-14:00", format(RFC3339, tp, west)); + + // Checks that we can also get the minimal value for a far-west zone. + tp = convert(civil_second(-292277022657, 1, 26, 18, 29, 52), west); + EXPECT_EQ("-292277022657-01-26T18:29:52-14:00", format(RFC3339, tp, west)); EXPECT_EQ(time_point<cctz::seconds>::min(), tp); - tp = convert(civil_second(-292277022657, 1, 26, 18, 29, 51), west); + tp = convert(civil_second(-292277022657, 1, 26, 18, 29, 51), west); EXPECT_EQ(time_point<cctz::seconds>::min(), tp); - tp = convert(civil_second::min(), west); + tp = convert(civil_second::min(), west); EXPECT_EQ(time_point<cctz::seconds>::min(), tp); // Some similar checks for the "libc" time-zone implementation. @@ -1013,8 +1013,8 @@ TEST(MakeTime, SysSecondsLimits) { EXPECT_EQ("-2147481748-01-01T00:00:00+00:00", format(RFC3339, tp, cut)); #endif } -} - +} + TEST(MakeTime, LocalTimeLibC) { // Checks that cctz and libc agree on transition points in [1970:2037]. // @@ -1161,129 +1161,129 @@ TEST(PrevTransition, AmericaNewYork) { // We have a transition but we don't know which one. } -TEST(TimeZoneEdgeCase, AmericaNewYork) { - const time_zone tz = LoadZone("America/New_York"); - - // Spring 1:59:59 -> 3:00:00 - auto tp = convert(civil_second(2013, 3, 10, 1, 59, 59), tz); - ExpectTime(tp, tz, 2013, 3, 10, 1, 59, 59, -5 * 3600, false, "EST"); +TEST(TimeZoneEdgeCase, AmericaNewYork) { + const time_zone tz = LoadZone("America/New_York"); + + // Spring 1:59:59 -> 3:00:00 + auto tp = convert(civil_second(2013, 3, 10, 1, 59, 59), tz); + ExpectTime(tp, tz, 2013, 3, 10, 1, 59, 59, -5 * 3600, false, "EST"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 2013, 3, 10, 3, 0, 0, -4 * 3600, true, "EDT"); - - // Fall 1:59:59 -> 1:00:00 - tp = convert(civil_second(2013, 11, 3, 1, 59, 59), tz); - ExpectTime(tp, tz, 2013, 11, 3, 1, 59, 59, -4 * 3600, true, "EDT"); + ExpectTime(tp, tz, 2013, 3, 10, 3, 0, 0, -4 * 3600, true, "EDT"); + + // Fall 1:59:59 -> 1:00:00 + tp = convert(civil_second(2013, 11, 3, 1, 59, 59), tz); + ExpectTime(tp, tz, 2013, 11, 3, 1, 59, 59, -4 * 3600, true, "EDT"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 2013, 11, 3, 1, 0, 0, -5 * 3600, false, "EST"); -} - -TEST(TimeZoneEdgeCase, AmericaLosAngeles) { - const time_zone tz = LoadZone("America/Los_Angeles"); - - // Spring 1:59:59 -> 3:00:00 - auto tp = convert(civil_second(2013, 3, 10, 1, 59, 59), tz); - ExpectTime(tp, tz, 2013, 3, 10, 1, 59, 59, -8 * 3600, false, "PST"); + ExpectTime(tp, tz, 2013, 11, 3, 1, 0, 0, -5 * 3600, false, "EST"); +} + +TEST(TimeZoneEdgeCase, AmericaLosAngeles) { + const time_zone tz = LoadZone("America/Los_Angeles"); + + // Spring 1:59:59 -> 3:00:00 + auto tp = convert(civil_second(2013, 3, 10, 1, 59, 59), tz); + ExpectTime(tp, tz, 2013, 3, 10, 1, 59, 59, -8 * 3600, false, "PST"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 2013, 3, 10, 3, 0, 0, -7 * 3600, true, "PDT"); - - // Fall 1:59:59 -> 1:00:00 - tp = convert(civil_second(2013, 11, 3, 1, 59, 59), tz); - ExpectTime(tp, tz, 2013, 11, 3, 1, 59, 59, -7 * 3600, true, "PDT"); + ExpectTime(tp, tz, 2013, 3, 10, 3, 0, 0, -7 * 3600, true, "PDT"); + + // Fall 1:59:59 -> 1:00:00 + tp = convert(civil_second(2013, 11, 3, 1, 59, 59), tz); + ExpectTime(tp, tz, 2013, 11, 3, 1, 59, 59, -7 * 3600, true, "PDT"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 2013, 11, 3, 1, 0, 0, -8 * 3600, false, "PST"); -} - -TEST(TimeZoneEdgeCase, ArizonaNoTransition) { - const time_zone tz = LoadZone("America/Phoenix"); - - // No transition in Spring. - auto tp = convert(civil_second(2013, 3, 10, 1, 59, 59), tz); - ExpectTime(tp, tz, 2013, 3, 10, 1, 59, 59, -7 * 3600, false, "MST"); + ExpectTime(tp, tz, 2013, 11, 3, 1, 0, 0, -8 * 3600, false, "PST"); +} + +TEST(TimeZoneEdgeCase, ArizonaNoTransition) { + const time_zone tz = LoadZone("America/Phoenix"); + + // No transition in Spring. + auto tp = convert(civil_second(2013, 3, 10, 1, 59, 59), tz); + ExpectTime(tp, tz, 2013, 3, 10, 1, 59, 59, -7 * 3600, false, "MST"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 2013, 3, 10, 2, 0, 0, -7 * 3600, false, "MST"); - - // No transition in Fall. - tp = convert(civil_second(2013, 11, 3, 1, 59, 59), tz); - ExpectTime(tp, tz, 2013, 11, 3, 1, 59, 59, -7 * 3600, false, "MST"); + ExpectTime(tp, tz, 2013, 3, 10, 2, 0, 0, -7 * 3600, false, "MST"); + + // No transition in Fall. + tp = convert(civil_second(2013, 11, 3, 1, 59, 59), tz); + ExpectTime(tp, tz, 2013, 11, 3, 1, 59, 59, -7 * 3600, false, "MST"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 2013, 11, 3, 2, 0, 0, -7 * 3600, false, "MST"); -} - -TEST(TimeZoneEdgeCase, AsiaKathmandu) { - const time_zone tz = LoadZone("Asia/Kathmandu"); - - // A non-DST offset change from +0530 to +0545 - // - // 504901799 == Tue, 31 Dec 1985 23:59:59 +0530 (+0530) - // 504901800 == Wed, 1 Jan 1986 00:15:00 +0545 (+0545) - auto tp = convert(civil_second(1985, 12, 31, 23, 59, 59), tz); - ExpectTime(tp, tz, 1985, 12, 31, 23, 59, 59, 5.5 * 3600, false, "+0530"); + ExpectTime(tp, tz, 2013, 11, 3, 2, 0, 0, -7 * 3600, false, "MST"); +} + +TEST(TimeZoneEdgeCase, AsiaKathmandu) { + const time_zone tz = LoadZone("Asia/Kathmandu"); + + // A non-DST offset change from +0530 to +0545 + // + // 504901799 == Tue, 31 Dec 1985 23:59:59 +0530 (+0530) + // 504901800 == Wed, 1 Jan 1986 00:15:00 +0545 (+0545) + auto tp = convert(civil_second(1985, 12, 31, 23, 59, 59), tz); + ExpectTime(tp, tz, 1985, 12, 31, 23, 59, 59, 5.5 * 3600, false, "+0530"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 1986, 1, 1, 0, 15, 0, 5.75 * 3600, false, "+0545"); -} - -TEST(TimeZoneEdgeCase, PacificChatham) { - const time_zone tz = LoadZone("Pacific/Chatham"); - - // One-hour DST offset changes, but at atypical values - // - // 1365256799 == Sun, 7 Apr 2013 03:44:59 +1345 (+1345) - // 1365256800 == Sun, 7 Apr 2013 02:45:00 +1245 (+1245) - auto tp = convert(civil_second(2013, 4, 7, 3, 44, 59), tz); - ExpectTime(tp, tz, 2013, 4, 7, 3, 44, 59, 13.75 * 3600, true, "+1345"); + ExpectTime(tp, tz, 1986, 1, 1, 0, 15, 0, 5.75 * 3600, false, "+0545"); +} + +TEST(TimeZoneEdgeCase, PacificChatham) { + const time_zone tz = LoadZone("Pacific/Chatham"); + + // One-hour DST offset changes, but at atypical values + // + // 1365256799 == Sun, 7 Apr 2013 03:44:59 +1345 (+1345) + // 1365256800 == Sun, 7 Apr 2013 02:45:00 +1245 (+1245) + auto tp = convert(civil_second(2013, 4, 7, 3, 44, 59), tz); + ExpectTime(tp, tz, 2013, 4, 7, 3, 44, 59, 13.75 * 3600, true, "+1345"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 2013, 4, 7, 2, 45, 0, 12.75 * 3600, false, "+1245"); - - // 1380376799 == Sun, 29 Sep 2013 02:44:59 +1245 (+1245) - // 1380376800 == Sun, 29 Sep 2013 03:45:00 +1345 (+1345) - tp = convert(civil_second(2013, 9, 29, 2, 44, 59), tz); - ExpectTime(tp, tz, 2013, 9, 29, 2, 44, 59, 12.75 * 3600, false, "+1245"); + ExpectTime(tp, tz, 2013, 4, 7, 2, 45, 0, 12.75 * 3600, false, "+1245"); + + // 1380376799 == Sun, 29 Sep 2013 02:44:59 +1245 (+1245) + // 1380376800 == Sun, 29 Sep 2013 03:45:00 +1345 (+1345) + tp = convert(civil_second(2013, 9, 29, 2, 44, 59), tz); + ExpectTime(tp, tz, 2013, 9, 29, 2, 44, 59, 12.75 * 3600, false, "+1245"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 2013, 9, 29, 3, 45, 0, 13.75 * 3600, true, "+1345"); -} - -TEST(TimeZoneEdgeCase, AustraliaLordHowe) { - const time_zone tz = LoadZone("Australia/Lord_Howe"); - - // Half-hour DST offset changes - // - // 1365260399 == Sun, 7 Apr 2013 01:59:59 +1100 (+11) - // 1365260400 == Sun, 7 Apr 2013 01:30:00 +1030 (+1030) - auto tp = convert(civil_second(2013, 4, 7, 1, 59, 59), tz); - ExpectTime(tp, tz, 2013, 4, 7, 1, 59, 59, 11 * 3600, true, "+11"); + ExpectTime(tp, tz, 2013, 9, 29, 3, 45, 0, 13.75 * 3600, true, "+1345"); +} + +TEST(TimeZoneEdgeCase, AustraliaLordHowe) { + const time_zone tz = LoadZone("Australia/Lord_Howe"); + + // Half-hour DST offset changes + // + // 1365260399 == Sun, 7 Apr 2013 01:59:59 +1100 (+11) + // 1365260400 == Sun, 7 Apr 2013 01:30:00 +1030 (+1030) + auto tp = convert(civil_second(2013, 4, 7, 1, 59, 59), tz); + ExpectTime(tp, tz, 2013, 4, 7, 1, 59, 59, 11 * 3600, true, "+11"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 2013, 4, 7, 1, 30, 0, 10.5 * 3600, false, "+1030"); - - // 1380986999 == Sun, 6 Oct 2013 01:59:59 +1030 (+1030) - // 1380987000 == Sun, 6 Oct 2013 02:30:00 +1100 (+11) - tp = convert(civil_second(2013, 10, 6, 1, 59, 59), tz); - ExpectTime(tp, tz, 2013, 10, 6, 1, 59, 59, 10.5 * 3600, false, "+1030"); + ExpectTime(tp, tz, 2013, 4, 7, 1, 30, 0, 10.5 * 3600, false, "+1030"); + + // 1380986999 == Sun, 6 Oct 2013 01:59:59 +1030 (+1030) + // 1380987000 == Sun, 6 Oct 2013 02:30:00 +1100 (+11) + tp = convert(civil_second(2013, 10, 6, 1, 59, 59), tz); + ExpectTime(tp, tz, 2013, 10, 6, 1, 59, 59, 10.5 * 3600, false, "+1030"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 2013, 10, 6, 2, 30, 0, 11 * 3600, true, "+11"); -} - -TEST(TimeZoneEdgeCase, PacificApia) { - const time_zone tz = LoadZone("Pacific/Apia"); - - // At the end of December 2011, Samoa jumped forward by one day, - // skipping 30 December from the local calendar, when the nation - // moved to the west of the International Date Line. - // - // A one-day, non-DST offset change - // - // 1325239199 == Thu, 29 Dec 2011 23:59:59 -1000 (-10) - // 1325239200 == Sat, 31 Dec 2011 00:00:00 +1400 (+14) - auto tp = convert(civil_second(2011, 12, 29, 23, 59, 59), tz); - ExpectTime(tp, tz, 2011, 12, 29, 23, 59, 59, -10 * 3600, true, "-10"); + ExpectTime(tp, tz, 2013, 10, 6, 2, 30, 0, 11 * 3600, true, "+11"); +} + +TEST(TimeZoneEdgeCase, PacificApia) { + const time_zone tz = LoadZone("Pacific/Apia"); + + // At the end of December 2011, Samoa jumped forward by one day, + // skipping 30 December from the local calendar, when the nation + // moved to the west of the International Date Line. + // + // A one-day, non-DST offset change + // + // 1325239199 == Thu, 29 Dec 2011 23:59:59 -1000 (-10) + // 1325239200 == Sat, 31 Dec 2011 00:00:00 +1400 (+14) + auto tp = convert(civil_second(2011, 12, 29, 23, 59, 59), tz); + ExpectTime(tp, tz, 2011, 12, 29, 23, 59, 59, -10 * 3600, true, "-10"); EXPECT_EQ(363, get_yearday(convert(tp, tz))); tp += cctz::seconds(1); - ExpectTime(tp, tz, 2011, 12, 31, 0, 0, 0, 14 * 3600, true, "+14"); + ExpectTime(tp, tz, 2011, 12, 31, 0, 0, 0, 14 * 3600, true, "+14"); EXPECT_EQ(365, get_yearday(convert(tp, tz))); -} - -TEST(TimeZoneEdgeCase, AfricaCairo) { - const time_zone tz = LoadZone("Africa/Cairo"); - +} + +TEST(TimeZoneEdgeCase, AfricaCairo) { + const time_zone tz = LoadZone("Africa/Cairo"); + if (VersionCmp(tz, "2014c") >= 0) { // An interesting case of midnight not existing. // @@ -1294,11 +1294,11 @@ TEST(TimeZoneEdgeCase, AfricaCairo) { tp += cctz::seconds(1); ExpectTime(tp, tz, 2014, 5, 16, 1, 0, 0, 3 * 3600, true, "EEST"); } -} - -TEST(TimeZoneEdgeCase, AfricaMonrovia) { - const time_zone tz = LoadZone("Africa/Monrovia"); - +} + +TEST(TimeZoneEdgeCase, AfricaMonrovia) { + const time_zone tz = LoadZone("Africa/Monrovia"); + if (VersionCmp(tz, "2017b") >= 0) { // Strange offset change -00:44:30 -> +00:00:00 (non-DST) // @@ -1309,17 +1309,17 @@ TEST(TimeZoneEdgeCase, AfricaMonrovia) { tp += cctz::seconds(1); ExpectTime(tp, tz, 1972, 1, 7, 0, 44, 30, 0 * 60, false, "GMT"); } -} - -TEST(TimeZoneEdgeCase, AmericaJamaica) { - // Jamaica discontinued DST transitions in 1983, and is now at a - // constant -0500. This makes it an interesting edge-case target. - // Note that the 32-bit times used in a (tzh_version == 0) zoneinfo - // file cannot represent the abbreviation-only transition of 1890, - // so we ignore the abbreviation by expecting what we received. - const time_zone tz = LoadZone("America/Jamaica"); - - // Before the first transition. +} + +TEST(TimeZoneEdgeCase, AmericaJamaica) { + // Jamaica discontinued DST transitions in 1983, and is now at a + // constant -0500. This makes it an interesting edge-case target. + // Note that the 32-bit times used in a (tzh_version == 0) zoneinfo + // file cannot represent the abbreviation-only transition of 1890, + // so we ignore the abbreviation by expecting what we received. + const time_zone tz = LoadZone("America/Jamaica"); + + // Before the first transition. if (!tz.version().empty() && VersionCmp(tz, "2018d") >= 0) { // We avoid the expectations on the -18430 offset below unless we are // certain we have commit 907241e (Fix off-by-1 error for Jamaica and @@ -1328,7 +1328,7 @@ TEST(TimeZoneEdgeCase, AmericaJamaica) { auto tp = convert(civil_second(1889, 12, 31, 0, 0, 0), tz); ExpectTime(tp, tz, 1889, 12, 31, 0, 0, 0, -18430, false, tz.lookup(tp).abbr); - + // Over the first (abbreviation-change only) transition. // -2524503170 == Tue, 31 Dec 1889 23:59:59 -0507 (LMT) // -2524503169 == Wed, 1 Jan 1890 00:00:00 -0507 (KMT) @@ -1338,98 +1338,98 @@ TEST(TimeZoneEdgeCase, AmericaJamaica) { tp += cctz::seconds(1); ExpectTime(tp, tz, 1890, 1, 1, 0, 0, 0, -18430, false, "KMT"); } - - // Over the last (DST) transition. - // 436341599 == Sun, 30 Oct 1983 01:59:59 -0400 (EDT) - // 436341600 == Sun, 30 Oct 1983 01:00:00 -0500 (EST) + + // Over the last (DST) transition. + // 436341599 == Sun, 30 Oct 1983 01:59:59 -0400 (EDT) + // 436341600 == Sun, 30 Oct 1983 01:00:00 -0500 (EST) auto tp = convert(civil_second(1983, 10, 30, 1, 59, 59), tz); - ExpectTime(tp, tz, 1983, 10, 30, 1, 59, 59, -4 * 3600, true, "EDT"); + ExpectTime(tp, tz, 1983, 10, 30, 1, 59, 59, -4 * 3600, true, "EDT"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 1983, 10, 30, 1, 0, 0, -5 * 3600, false, "EST"); - - // After the last transition. - tp = convert(civil_second(1983, 12, 31, 23, 59, 59), tz); - ExpectTime(tp, tz, 1983, 12, 31, 23, 59, 59, -5 * 3600, false, "EST"); -} - -TEST(TimeZoneEdgeCase, WET) { - // Cover some non-existent times within forward transitions. - const time_zone tz = LoadZone("WET"); - - // Before the first transition. - auto tp = convert(civil_second(1977, 1, 1, 0, 0, 0), tz); - ExpectTime(tp, tz, 1977, 1, 1, 0, 0, 0, 0, false, "WET"); - - // Over the first transition. - // 228877199 == Sun, 3 Apr 1977 00:59:59 +0000 (WET) - // 228877200 == Sun, 3 Apr 1977 02:00:00 +0100 (WEST) - tp = convert(civil_second(1977, 4, 3, 0, 59, 59), tz); - ExpectTime(tp, tz, 1977, 4, 3, 0, 59, 59, 0, false, "WET"); + ExpectTime(tp, tz, 1983, 10, 30, 1, 0, 0, -5 * 3600, false, "EST"); + + // After the last transition. + tp = convert(civil_second(1983, 12, 31, 23, 59, 59), tz); + ExpectTime(tp, tz, 1983, 12, 31, 23, 59, 59, -5 * 3600, false, "EST"); +} + +TEST(TimeZoneEdgeCase, WET) { + // Cover some non-existent times within forward transitions. + const time_zone tz = LoadZone("WET"); + + // Before the first transition. + auto tp = convert(civil_second(1977, 1, 1, 0, 0, 0), tz); + ExpectTime(tp, tz, 1977, 1, 1, 0, 0, 0, 0, false, "WET"); + + // Over the first transition. + // 228877199 == Sun, 3 Apr 1977 00:59:59 +0000 (WET) + // 228877200 == Sun, 3 Apr 1977 02:00:00 +0100 (WEST) + tp = convert(civil_second(1977, 4, 3, 0, 59, 59), tz); + ExpectTime(tp, tz, 1977, 4, 3, 0, 59, 59, 0, false, "WET"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 1977, 4, 3, 2, 0, 0, 1 * 3600, true, "WEST"); - - // A non-existent time within the first transition. - time_zone::civil_lookup cl1 = tz.lookup(civil_second(1977, 4, 3, 1, 15, 0)); - EXPECT_EQ(time_zone::civil_lookup::SKIPPED, cl1.kind); - ExpectTime(cl1.pre, tz, 1977, 4, 3, 2, 15, 0, 1 * 3600, true, "WEST"); - ExpectTime(cl1.trans, tz, 1977, 4, 3, 2, 0, 0, 1 * 3600, true, "WEST"); - ExpectTime(cl1.post, tz, 1977, 4, 3, 0, 15, 0, 0 * 3600, false, "WET"); - - // A non-existent time within the second forward transition. - time_zone::civil_lookup cl2 = tz.lookup(civil_second(1978, 4, 2, 1, 15, 0)); - EXPECT_EQ(time_zone::civil_lookup::SKIPPED, cl2.kind); - ExpectTime(cl2.pre, tz, 1978, 4, 2, 2, 15, 0, 1 * 3600, true, "WEST"); - ExpectTime(cl2.trans, tz, 1978, 4, 2, 2, 0, 0, 1 * 3600, true, "WEST"); - ExpectTime(cl2.post, tz, 1978, 4, 2, 0, 15, 0, 0 * 3600, false, "WET"); -} - -TEST(TimeZoneEdgeCase, FixedOffsets) { - const time_zone gmtm5 = LoadZone("Etc/GMT+5"); // -0500 - auto tp = convert(civil_second(1970, 1, 1, 0, 0, 0), gmtm5); - ExpectTime(tp, gmtm5, 1970, 1, 1, 0, 0, 0, -5 * 3600, false, "-05"); + ExpectTime(tp, tz, 1977, 4, 3, 2, 0, 0, 1 * 3600, true, "WEST"); + + // A non-existent time within the first transition. + time_zone::civil_lookup cl1 = tz.lookup(civil_second(1977, 4, 3, 1, 15, 0)); + EXPECT_EQ(time_zone::civil_lookup::SKIPPED, cl1.kind); + ExpectTime(cl1.pre, tz, 1977, 4, 3, 2, 15, 0, 1 * 3600, true, "WEST"); + ExpectTime(cl1.trans, tz, 1977, 4, 3, 2, 0, 0, 1 * 3600, true, "WEST"); + ExpectTime(cl1.post, tz, 1977, 4, 3, 0, 15, 0, 0 * 3600, false, "WET"); + + // A non-existent time within the second forward transition. + time_zone::civil_lookup cl2 = tz.lookup(civil_second(1978, 4, 2, 1, 15, 0)); + EXPECT_EQ(time_zone::civil_lookup::SKIPPED, cl2.kind); + ExpectTime(cl2.pre, tz, 1978, 4, 2, 2, 15, 0, 1 * 3600, true, "WEST"); + ExpectTime(cl2.trans, tz, 1978, 4, 2, 2, 0, 0, 1 * 3600, true, "WEST"); + ExpectTime(cl2.post, tz, 1978, 4, 2, 0, 15, 0, 0 * 3600, false, "WET"); +} + +TEST(TimeZoneEdgeCase, FixedOffsets) { + const time_zone gmtm5 = LoadZone("Etc/GMT+5"); // -0500 + auto tp = convert(civil_second(1970, 1, 1, 0, 0, 0), gmtm5); + ExpectTime(tp, gmtm5, 1970, 1, 1, 0, 0, 0, -5 * 3600, false, "-05"); EXPECT_EQ(chrono::system_clock::from_time_t(5 * 3600), tp); - - const time_zone gmtp5 = LoadZone("Etc/GMT-5"); // +0500 - tp = convert(civil_second(1970, 1, 1, 0, 0, 0), gmtp5); - ExpectTime(tp, gmtp5, 1970, 1, 1, 0, 0, 0, 5 * 3600, false, "+05"); + + const time_zone gmtp5 = LoadZone("Etc/GMT-5"); // +0500 + tp = convert(civil_second(1970, 1, 1, 0, 0, 0), gmtp5); + ExpectTime(tp, gmtp5, 1970, 1, 1, 0, 0, 0, 5 * 3600, false, "+05"); EXPECT_EQ(chrono::system_clock::from_time_t(-5 * 3600), tp); -} - -TEST(TimeZoneEdgeCase, NegativeYear) { - // Tests transition from year 0 (aka 1BCE) to year -1. - const time_zone tz = utc_time_zone(); - auto tp = convert(civil_second(0, 1, 1, 0, 0, 0), tz); - ExpectTime(tp, tz, 0, 1, 1, 0, 0, 0, 0 * 3600, false, "UTC"); +} + +TEST(TimeZoneEdgeCase, NegativeYear) { + // Tests transition from year 0 (aka 1BCE) to year -1. + const time_zone tz = utc_time_zone(); + auto tp = convert(civil_second(0, 1, 1, 0, 0, 0), tz); + ExpectTime(tp, tz, 0, 1, 1, 0, 0, 0, 0 * 3600, false, "UTC"); EXPECT_EQ(weekday::saturday, get_weekday(convert(tp, tz))); tp -= cctz::seconds(1); - ExpectTime(tp, tz, -1, 12, 31, 23, 59, 59, 0 * 3600, false, "UTC"); + ExpectTime(tp, tz, -1, 12, 31, 23, 59, 59, 0 * 3600, false, "UTC"); EXPECT_EQ(weekday::friday, get_weekday(convert(tp, tz))); -} - -TEST(TimeZoneEdgeCase, UTC32bitLimit) { - const time_zone tz = utc_time_zone(); - - // Limits of signed 32-bit time_t - // - // 2147483647 == Tue, 19 Jan 2038 03:14:07 +0000 (UTC) - // 2147483648 == Tue, 19 Jan 2038 03:14:08 +0000 (UTC) - auto tp = convert(civil_second(2038, 1, 19, 3, 14, 7), tz); - ExpectTime(tp, tz, 2038, 1, 19, 3, 14, 7, 0 * 3600, false, "UTC"); +} + +TEST(TimeZoneEdgeCase, UTC32bitLimit) { + const time_zone tz = utc_time_zone(); + + // Limits of signed 32-bit time_t + // + // 2147483647 == Tue, 19 Jan 2038 03:14:07 +0000 (UTC) + // 2147483648 == Tue, 19 Jan 2038 03:14:08 +0000 (UTC) + auto tp = convert(civil_second(2038, 1, 19, 3, 14, 7), tz); + ExpectTime(tp, tz, 2038, 1, 19, 3, 14, 7, 0 * 3600, false, "UTC"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 2038, 1, 19, 3, 14, 8, 0 * 3600, false, "UTC"); -} - -TEST(TimeZoneEdgeCase, UTC5DigitYear) { - const time_zone tz = utc_time_zone(); - - // Rollover to 5-digit year - // - // 253402300799 == Fri, 31 Dec 9999 23:59:59 +0000 (UTC) - // 253402300800 == Sat, 1 Jan 1000 00:00:00 +0000 (UTC) - auto tp = convert(civil_second(9999, 12, 31, 23, 59, 59), tz); - ExpectTime(tp, tz, 9999, 12, 31, 23, 59, 59, 0 * 3600, false, "UTC"); + ExpectTime(tp, tz, 2038, 1, 19, 3, 14, 8, 0 * 3600, false, "UTC"); +} + +TEST(TimeZoneEdgeCase, UTC5DigitYear) { + const time_zone tz = utc_time_zone(); + + // Rollover to 5-digit year + // + // 253402300799 == Fri, 31 Dec 9999 23:59:59 +0000 (UTC) + // 253402300800 == Sat, 1 Jan 1000 00:00:00 +0000 (UTC) + auto tp = convert(civil_second(9999, 12, 31, 23, 59, 59), tz); + ExpectTime(tp, tz, 9999, 12, 31, 23, 59, 59, 0 * 3600, false, "UTC"); tp += cctz::seconds(1); - ExpectTime(tp, tz, 10000, 1, 1, 0, 0, 0, 0 * 3600, false, "UTC"); -} - -} // namespace cctz + ExpectTime(tp, tz, 10000, 1, 1, 0, 0, 0, 0 * 3600, false, "UTC"); +} + +} // namespace cctz diff --git a/contrib/libs/cctz/test/ya.make b/contrib/libs/cctz/test/ya.make index 8815f9769d..de8eaed1fc 100644 --- a/contrib/libs/cctz/test/ya.make +++ b/contrib/libs/cctz/test/ya.make @@ -1,5 +1,5 @@ GTEST() - + LICENSE(Apache-2.0) LICENSE_TEXTS(.yandex_meta/licenses.list.txt) @@ -8,12 +8,12 @@ OWNER( dfyz petrk ) - -PEERDIR( + +PEERDIR( contrib/libs/cctz - contrib/libs/cctz/tzdata -) - + contrib/libs/cctz/tzdata +) + ADDINCL( contrib/libs/cctz/include ) @@ -27,10 +27,10 @@ IF (NOT AUTOCHECK) ) ENDIF() -SRCS( - civil_time_test.cc +SRCS( + civil_time_test.cc time_zone_format_test.cc - time_zone_lookup_test.cc -) - -END() + time_zone_lookup_test.cc +) + +END() diff --git a/contrib/libs/cctz/tzdata/README b/contrib/libs/cctz/tzdata/README index 031fe514c6..f24ee192bf 100644 --- a/contrib/libs/cctz/tzdata/README +++ b/contrib/libs/cctz/tzdata/README @@ -1,4 +1,4 @@ -A standalone distribution of tzdata. Run 'cat VERSION' in this directory to find out which IANA version it's based on. - -When a new version of tzdata is released, run ./update_tzdata.py from this directory -to regenerate the CMakeLists.txt and the corresponding resources from a newer tzdata version. +A standalone distribution of tzdata. Run 'cat VERSION' in this directory to find out which IANA version it's based on. + +When a new version of tzdata is released, run ./update_tzdata.py from this directory +to regenerate the CMakeLists.txt and the corresponding resources from a newer tzdata version. diff --git a/contrib/libs/cctz/tzdata/update_tzdata.py b/contrib/libs/cctz/tzdata/update_tzdata.py index 9c3cd07352..74cd84ef17 100755 --- a/contrib/libs/cctz/tzdata/update_tzdata.py +++ b/contrib/libs/cctz/tzdata/update_tzdata.py @@ -1,112 +1,112 @@ -#!/usr/bin/env python - -import glob -import hashlib -import os -import re -import shutil -import string -import subprocess -import sys -import tarfile -import tempfile -import urllib2 - -def create_cmakelists(zoneinfo_dir): - tz_to_hash = {} - hash_to_content = {} - total_size = 0 - for dirpath, _, filenames in os.walk(zoneinfo_dir): - for fn in filenames: - tz_file_name = os.path.join(dirpath, fn) - with open(tz_file_name) as f: - tz_content = f.read() - if not tz_content.startswith('TZif'): - continue - tz_hash = hashlib.md5(tz_content).hexdigest() - tz_name = tz_file_name.replace(zoneinfo_dir, '').lstrip('/') - tz_to_hash[tz_name] = tz_hash - hash_to_content[tz_hash] = tz_content - total_size += len(tz_content) - print 'Total data size in bytes:', total_size - - generated_dir = 'generated' - if not os.path.isdir(generated_dir): - os.mkdir(generated_dir) - for tz_hash, tz_content in hash_to_content.iteritems(): - with open(os.path.join(generated_dir, tz_hash), 'w') as f: - f.write(tz_content) - +#!/usr/bin/env python + +import glob +import hashlib +import os +import re +import shutil +import string +import subprocess +import sys +import tarfile +import tempfile +import urllib2 + +def create_cmakelists(zoneinfo_dir): + tz_to_hash = {} + hash_to_content = {} + total_size = 0 + for dirpath, _, filenames in os.walk(zoneinfo_dir): + for fn in filenames: + tz_file_name = os.path.join(dirpath, fn) + with open(tz_file_name) as f: + tz_content = f.read() + if not tz_content.startswith('TZif'): + continue + tz_hash = hashlib.md5(tz_content).hexdigest() + tz_name = tz_file_name.replace(zoneinfo_dir, '').lstrip('/') + tz_to_hash[tz_name] = tz_hash + hash_to_content[tz_hash] = tz_content + total_size += len(tz_content) + print 'Total data size in bytes:', total_size + + generated_dir = 'generated' + if not os.path.isdir(generated_dir): + os.mkdir(generated_dir) + for tz_hash, tz_content in hash_to_content.iteritems(): + with open(os.path.join(generated_dir, tz_hash), 'w') as f: + f.write(tz_content) + yamake_template = ( 'RESOURCE(\n' '{}\n' ')' ) - resources = '\n'.join(' generated/{} /cctz/tzdata/{}'.format(tz_hash, tz_name) for tz_name, tz_hash in sorted(tz_to_hash.iteritems())) - - all_hashes = set(tz_to_hash.values()) - hash_pattern = os.path.join('generated', '[{}]'.format(string.hexdigits) * 32) - for fn in glob.glob(hash_pattern): - cmd = 'add' if os.path.basename(fn) in all_hashes else 'remove' - subprocess.check_call(['svn', cmd, '--force', fn]) - + resources = '\n'.join(' generated/{} /cctz/tzdata/{}'.format(tz_hash, tz_name) for tz_name, tz_hash in sorted(tz_to_hash.iteritems())) + + all_hashes = set(tz_to_hash.values()) + hash_pattern = os.path.join('generated', '[{}]'.format(string.hexdigits) * 32) + for fn in glob.glob(hash_pattern): + cmd = 'add' if os.path.basename(fn) in all_hashes else 'remove' + subprocess.check_call(['svn', cmd, '--force', fn]) + with open('ya.make.resources', 'w') as f: print >>f, yamake_template.format(resources) - -def get_latest_iana_version(): - index_html = urllib2.urlopen('http://www.iana.org/time-zones').read() - version_match = re.search('<a href="[^"]*">tzdata(.*).tar.gz</a>', index_html) - if not version_match: - raise Exception('Failed to determine the latest tzdata version') - return version_match.group(1) - -def get_current_version(): + +def get_latest_iana_version(): + index_html = urllib2.urlopen('http://www.iana.org/time-zones').read() + version_match = re.search('<a href="[^"]*">tzdata(.*).tar.gz</a>', index_html) + if not version_match: + raise Exception('Failed to determine the latest tzdata version') + return version_match.group(1) + +def get_current_version(): try: with open('VERSION') as f: return f.read() except: return 0 - -def prepare_tzdata(version): - temp_dir = tempfile.mkdtemp() - try: - for file_type in ('data', 'code'): - file_name = 'tz{}{}.tar.gz'.format(file_type, version) - full_url = 'http://www.iana.org/time-zones/repository/releases/{}'.format(file_name) - print 'Downloading {}'.format(full_url) - - local_file_name = os.path.join(temp_dir, file_name) - with open(local_file_name, 'w') as f: - f.write(urllib2.urlopen(full_url).read()) - - print 'Extracting {}'.format(local_file_name) - with tarfile.open(local_file_name) as f: - f.extractall(path=temp_dir) - - print 'Converting tzdata to binary format' - subprocess.check_call(['make', '-s', '-C', temp_dir, 'TOPDIR={}'.format(temp_dir), 'install']) - + +def prepare_tzdata(version): + temp_dir = tempfile.mkdtemp() + try: + for file_type in ('data', 'code'): + file_name = 'tz{}{}.tar.gz'.format(file_type, version) + full_url = 'http://www.iana.org/time-zones/repository/releases/{}'.format(file_name) + print 'Downloading {}'.format(full_url) + + local_file_name = os.path.join(temp_dir, file_name) + with open(local_file_name, 'w') as f: + f.write(urllib2.urlopen(full_url).read()) + + print 'Extracting {}'.format(local_file_name) + with tarfile.open(local_file_name) as f: + f.extractall(path=temp_dir) + + print 'Converting tzdata to binary format' + subprocess.check_call(['make', '-s', '-C', temp_dir, 'TOPDIR={}'.format(temp_dir), 'install']) + print 'Preparing ya.make.resources' - zoneinfo_dir = os.path.join(temp_dir, 'usr', 'share', 'zoneinfo') - create_cmakelists(zoneinfo_dir) - finally: - shutil.rmtree(temp_dir) - -def main(): - current_version, latest_version = get_current_version(), get_latest_iana_version() - print 'The current version of tzdata is {}'.format(current_version) - print 'The latest version of tzdata on the IANA site is {}'.format(latest_version) - if current_version == latest_version: - print 'You already have the latest version' - return - print 'Updating from {} to {}'.format(current_version, latest_version) - prepare_tzdata(latest_version) - - with open('VERSION', 'w') as f: - f.write(latest_version) - - print 'All good! Now make sure the tests pass, and run this:' - print 'svn ci -m "Updated tzdata to {}"'.format(latest_version) - -if __name__ == '__main__': - main() + zoneinfo_dir = os.path.join(temp_dir, 'usr', 'share', 'zoneinfo') + create_cmakelists(zoneinfo_dir) + finally: + shutil.rmtree(temp_dir) + +def main(): + current_version, latest_version = get_current_version(), get_latest_iana_version() + print 'The current version of tzdata is {}'.format(current_version) + print 'The latest version of tzdata on the IANA site is {}'.format(latest_version) + if current_version == latest_version: + print 'You already have the latest version' + return + print 'Updating from {} to {}'.format(current_version, latest_version) + prepare_tzdata(latest_version) + + with open('VERSION', 'w') as f: + f.write(latest_version) + + print 'All good! Now make sure the tests pass, and run this:' + print 'svn ci -m "Updated tzdata to {}"'.format(latest_version) + +if __name__ == '__main__': + main() diff --git a/contrib/libs/cctz/tzdata/ya.make b/contrib/libs/cctz/tzdata/ya.make index 3b9ff5cc67..636174368e 100644 --- a/contrib/libs/cctz/tzdata/ya.make +++ b/contrib/libs/cctz/tzdata/ya.make @@ -1,5 +1,5 @@ -LIBRARY() - +LIBRARY() + WITHOUT_LICENSE_TEXTS() LICENSE(Apache-2.0) @@ -8,7 +8,7 @@ OWNER( dfyz petrk ) - + PEERDIR( contrib/libs/cctz ) @@ -17,6 +17,6 @@ INCLUDE(ya.make.resources) SRCS( GLOBAL factory.cpp -) - -END() +) + +END() diff --git a/contrib/libs/cctz/ya.make b/contrib/libs/cctz/ya.make index 954d24908f..78e5efbe56 100644 --- a/contrib/libs/cctz/ya.make +++ b/contrib/libs/cctz/ya.make @@ -1,21 +1,21 @@ # Generated by devtools/yamaker from nixpkgs 5852a21819542e6809f68ba5a798600e69874e76. -LIBRARY() - +LIBRARY() + OWNER( dfyz petrk ) VERSION(2020-11-11) - + ORIGINAL_SOURCE(https://github.com/google/cctz/archive/98fb541c6f0f35cf0dffcbc3777d8385bbd5b4c1.tar.gz) LICENSE( Apache-2.0 AND Public-Domain ) - + LICENSE_TEXTS(.yandex_meta/licenses.list.txt) ADDINCL( @@ -33,7 +33,7 @@ IF (OS_DARWIN) ) ENDIF() -SRCS( +SRCS( src/civil_time_detail.cc src/time_zone_fixed.cc src/time_zone_format.cc @@ -44,10 +44,10 @@ SRCS( src/time_zone_lookup.cc src/time_zone_posix.cc src/zone_info_source.cc -) - +) + END() - + RECURSE( test tzdata diff --git a/contrib/libs/cxxsupp/openmp/kmp_config.h b/contrib/libs/cxxsupp/openmp/kmp_config.h index 35d10e2bfd..99a53b8f46 100644 --- a/contrib/libs/cxxsupp/openmp/kmp_config.h +++ b/contrib/libs/cxxsupp/openmp/kmp_config.h @@ -18,7 +18,7 @@ // cmakedefine MACRO 1 will define MACRO as 1 or leave undefined #define DEBUG_BUILD 0 #define RELWITHDEBINFO_BUILD 0 -#define LIBOMP_USE_ITT_NOTIFY 0 +#define LIBOMP_USE_ITT_NOTIFY 0 #define USE_ITT_NOTIFY LIBOMP_USE_ITT_NOTIFY #if ! LIBOMP_USE_ITT_NOTIFY # define INTEL_NO_ITTNOTIFY_API diff --git a/contrib/libs/cxxsupp/openmp/kmp_utility.c b/contrib/libs/cxxsupp/openmp/kmp_utility.c index c777d7dc0c..81b1be5819 100644 --- a/contrib/libs/cxxsupp/openmp/kmp_utility.c +++ b/contrib/libs/cxxsupp/openmp/kmp_utility.c @@ -288,8 +288,8 @@ __kmp_query_cpuid( kmp_cpuinfo_t *p ) { // Parse CPU brand string for frequency. union kmp_cpu_brand_string { - ui32 buf[ 12 ]; - char string[ sizeof( ui32 ) * 12 + 1 ]; + ui32 buf[ 12 ]; + char string[ sizeof( ui32 ) * 12 + 1 ]; }; // union kmp_cpu_brand_string union kmp_cpu_brand_string brand; @@ -298,7 +298,7 @@ __kmp_query_cpuid( kmp_cpuinfo_t *p ) p->frequency = 0; // Get CPU brand string. - CpuBrand(brand.buf); + CpuBrand(brand.buf); brand.string[ sizeof( brand.string ) - 1 ] = 0; // Just in case. ;-) KA_TRACE( trace_level, ( "cpu brand string: \"%s\"\n", brand.string ) ); diff --git a/contrib/libs/ya.make b/contrib/libs/ya.make index 9c4640fdcf..d413c41cde 100644 --- a/contrib/libs/ya.make +++ b/contrib/libs/ya.make @@ -27,7 +27,7 @@ RECURSE( cairo cbc cctools - cctz + cctz cereal ceres-solver chromaprint diff --git a/contrib/tools/bison/gnulib/platform/posix/config.h b/contrib/tools/bison/gnulib/platform/posix/config.h index 8fa4b4f092..e7c53f5cce 100644 --- a/contrib/tools/bison/gnulib/platform/posix/config.h +++ b/contrib/tools/bison/gnulib/platform/posix/config.h @@ -1327,7 +1327,7 @@ /* #undef PACKAGE_PACKAGER_VERSION */ /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "GNU M4 3.0.0" +#define PACKAGE_STRING "GNU M4 3.0.0" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "m4" @@ -1336,7 +1336,7 @@ #define PACKAGE_URL "http://www.gnu.org/software/m4/" /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.0.0" +#define PACKAGE_VERSION "3.0.0" /* the number of pending output bytes on stream 'fp' */ /* #undef PENDING_OUTPUT_N_BYTES */ @@ -1502,7 +1502,7 @@ /* #undef USE_WINDOWS_THREADS */ /* Version number of package */ -#define VERSION "3.0.0" +#define VERSION "3.0.0" /* Define to 1 if unsetenv returns void instead of int. */ /* #undef VOID_UNSETENV */ diff --git a/contrib/tools/bison/gnulib/platform/win64/config.h b/contrib/tools/bison/gnulib/platform/win64/config.h index cf3d366e18..5653f2b4a3 100644 --- a/contrib/tools/bison/gnulib/platform/win64/config.h +++ b/contrib/tools/bison/gnulib/platform/win64/config.h @@ -1228,7 +1228,7 @@ char *strsignal (int signum); /* #undef PACKAGE_PACKAGER_VERSION */ /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "GNU M4 3.0.0" +#define PACKAGE_STRING "GNU M4 3.0.0" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "m4" @@ -1237,7 +1237,7 @@ char *strsignal (int signum); #define PACKAGE_URL "http://www.gnu.org/software/m4/" /* Define to the version of this package. */ -#define PACKAGE_VERSION "3.0.0" +#define PACKAGE_VERSION "3.0.0" /* the number of pending output bytes on stream 'fp' */ #if WIN_SDK10 @@ -1407,7 +1407,7 @@ char *strsignal (int signum); /* #undef USE_WINDOWS_THREADS */ /* Version number of package */ -#define VERSION "3.0.0" +#define VERSION "3.0.0" /* Define to 1 if unsetenv returns void instead of int. */ /* #undef VOID_UNSETENV */ diff --git a/library/cpp/containers/bitseq/bitvector.h b/library/cpp/containers/bitseq/bitvector.h index 3f8fd81ee5..5c6495d1bd 100644 --- a/library/cpp/containers/bitseq/bitvector.h +++ b/library/cpp/containers/bitseq/bitvector.h @@ -8,16 +8,16 @@ #include <util/ysaveload.h> template <typename T> -class TReadonlyBitVector; - -template <typename T> +class TReadonlyBitVector; + +template <typename T> class TBitVector { public: using TWord = T; using TTraits = TBitSeqTraits<TWord>; private: - friend class TReadonlyBitVector<T>; + friend class TReadonlyBitVector<T>; ui64 Size_; TVector<TWord> Data_; @@ -61,7 +61,7 @@ public: } bool Test(ui64 pos) const { - return TTraits::Test(Data(), pos, Size_); + return TTraits::Test(Data(), pos, Size_); } void Reset(ui64 pos) { @@ -70,7 +70,7 @@ public: } TWord Get(ui64 pos, ui8 width, TWord mask) const { - return TTraits::Get(Data(), pos, width, mask, Size_); + return TTraits::Get(Data(), pos, width, mask, Size_); } TWord Get(ui64 pos, ui8 width) const { @@ -127,7 +127,7 @@ public: } const TWord* Data() const { - return Data_.data(); + return Data_.data(); } void Save(IOutputStream* out) const { diff --git a/library/cpp/containers/bitseq/bitvector_ut.cpp b/library/cpp/containers/bitseq/bitvector_ut.cpp index 6137adab1e..3ba2791354 100644 --- a/library/cpp/containers/bitseq/bitvector_ut.cpp +++ b/library/cpp/containers/bitseq/bitvector_ut.cpp @@ -1,11 +1,11 @@ #include "bitvector.h" -#include "readonly_bitvector.h" +#include "readonly_bitvector.h" #include <library/cpp/testing/unittest/registar.h> -#include <util/memory/blob.h> -#include <util/stream/buffer.h> - +#include <util/memory/blob.h> +#include <util/stream/buffer.h> + Y_UNIT_TEST_SUITE(TBitVectorTest) { Y_UNIT_TEST(TestEmpty) { TBitVector<ui64> v64; @@ -66,21 +66,21 @@ Y_UNIT_TEST_SUITE(TBitVectorTest) { v.Set(10 * 32, 100500, 32); UNIT_ASSERT_EQUAL(v.Get(10 * 32, 32), 100500); } - + Y_UNIT_TEST(TestReadonlyVector) { - TBitVector<ui64> v(100); - for (ui64 i = 0; i < v.Size(); ++i) { - if (i % 3 == 0) { - v.Set(i); - } - } - TBufferStream bs; - TReadonlyBitVector<ui64>::SaveForReadonlyAccess(&bs, v); - const auto blob = TBlob::FromBuffer(bs.Buffer()); - TReadonlyBitVector<ui64> rv; - rv.LoadFromBlob(blob); - for (ui64 i = 0; i < rv.Size(); ++i) { - UNIT_ASSERT_VALUES_EQUAL(rv.Test(i), i % 3 == 0); - } - } + TBitVector<ui64> v(100); + for (ui64 i = 0; i < v.Size(); ++i) { + if (i % 3 == 0) { + v.Set(i); + } + } + TBufferStream bs; + TReadonlyBitVector<ui64>::SaveForReadonlyAccess(&bs, v); + const auto blob = TBlob::FromBuffer(bs.Buffer()); + TReadonlyBitVector<ui64> rv; + rv.LoadFromBlob(blob); + for (ui64 i = 0; i < rv.Size(); ++i) { + UNIT_ASSERT_VALUES_EQUAL(rv.Test(i), i % 3 == 0); + } + } } diff --git a/library/cpp/containers/bitseq/readonly_bitvector.cpp b/library/cpp/containers/bitseq/readonly_bitvector.cpp index 891aa7cde2..e38b381838 100644 --- a/library/cpp/containers/bitseq/readonly_bitvector.cpp +++ b/library/cpp/containers/bitseq/readonly_bitvector.cpp @@ -1 +1 @@ -#include "readonly_bitvector.h" +#include "readonly_bitvector.h" diff --git a/library/cpp/containers/bitseq/readonly_bitvector.h b/library/cpp/containers/bitseq/readonly_bitvector.h index 8612739c3f..bed2cfc061 100644 --- a/library/cpp/containers/bitseq/readonly_bitvector.h +++ b/library/cpp/containers/bitseq/readonly_bitvector.h @@ -1,76 +1,76 @@ -#pragma once - -#include "bitvector.h" -#include "traits.h" - -#include <util/memory/blob.h> - -#include <cstring> - -template <typename T> -class TReadonlyBitVector { -public: - using TWord = T; - using TTraits = TBitSeqTraits<TWord>; - - TReadonlyBitVector() - : Size_() - , Data_() +#pragma once + +#include "bitvector.h" +#include "traits.h" + +#include <util/memory/blob.h> + +#include <cstring> + +template <typename T> +class TReadonlyBitVector { +public: + using TWord = T; + using TTraits = TBitSeqTraits<TWord>; + + TReadonlyBitVector() + : Size_() + , Data_() { } - + explicit TReadonlyBitVector(const TBitVector<T>& vector) : Size_(vector.Size_) , Data_(vector.Data_.data()) { } - bool Test(ui64 pos) const { - return TTraits::Test(Data_, pos, Size_); - } - - TWord Get(ui64 pos, ui8 width, TWord mask) const { - return TTraits::Get(Data_, pos, width, mask, Size_); - } - - TWord Get(ui64 pos, ui8 width) const { - return Get(pos, width, TTraits::ElemMask(width)); - } - - ui64 Size() const { - return Size_; - } - - const T* Data() const { - return Data_; - } - - static void SaveForReadonlyAccess(IOutputStream* out, const TBitVector<T>& bv) { - ::Save(out, bv.Size_); - ::Save(out, static_cast<ui64>(bv.Data_.size())); - ::SavePodArray(out, bv.Data_.data(), bv.Data_.size()); - } - - virtual TBlob LoadFromBlob(const TBlob& blob) { - size_t read = 0; - auto cursor = [&]() { return blob.AsUnsignedCharPtr() + read; }; - auto readToPtr = [&](auto* ptr) { - memcpy(ptr, cursor(), sizeof(*ptr)); - read += sizeof(*ptr); - }; - - readToPtr(&Size_); - - ui64 wordCount{}; - readToPtr(&wordCount); - - Data_ = reinterpret_cast<const T*>(cursor()); - read += wordCount * sizeof(T); - - return blob.SubBlob(read, blob.Size()); - } - -private: - ui64 Size_; - const T* Data_; -}; + bool Test(ui64 pos) const { + return TTraits::Test(Data_, pos, Size_); + } + + TWord Get(ui64 pos, ui8 width, TWord mask) const { + return TTraits::Get(Data_, pos, width, mask, Size_); + } + + TWord Get(ui64 pos, ui8 width) const { + return Get(pos, width, TTraits::ElemMask(width)); + } + + ui64 Size() const { + return Size_; + } + + const T* Data() const { + return Data_; + } + + static void SaveForReadonlyAccess(IOutputStream* out, const TBitVector<T>& bv) { + ::Save(out, bv.Size_); + ::Save(out, static_cast<ui64>(bv.Data_.size())); + ::SavePodArray(out, bv.Data_.data(), bv.Data_.size()); + } + + virtual TBlob LoadFromBlob(const TBlob& blob) { + size_t read = 0; + auto cursor = [&]() { return blob.AsUnsignedCharPtr() + read; }; + auto readToPtr = [&](auto* ptr) { + memcpy(ptr, cursor(), sizeof(*ptr)); + read += sizeof(*ptr); + }; + + readToPtr(&Size_); + + ui64 wordCount{}; + readToPtr(&wordCount); + + Data_ = reinterpret_cast<const T*>(cursor()); + read += wordCount * sizeof(T); + + return blob.SubBlob(read, blob.Size()); + } + +private: + ui64 Size_; + const T* Data_; +}; diff --git a/library/cpp/containers/bitseq/traits.h b/library/cpp/containers/bitseq/traits.h index 2330b1b4f2..99047363de 100644 --- a/library/cpp/containers/bitseq/traits.h +++ b/library/cpp/containers/bitseq/traits.h @@ -2,7 +2,7 @@ #include <util/generic/bitops.h> #include <util/generic/typetraits.h> -#include <util/system/yassert.h> +#include <util/system/yassert.h> template <typename TWord> struct TBitSeqTraits { @@ -25,25 +25,25 @@ struct TBitSeqTraits { return (bits + NumBits - 1) >> DivShift; } - static bool Test(const TWord* data, ui64 pos, ui64 size) { - Y_ASSERT(pos < size); - return data[pos >> DivShift] & BitMask(pos & ModMask); - } - - static TWord Get(const TWord* data, ui64 pos, ui8 width, TWord mask, ui64 size) { - if (!width) - return 0; - Y_ASSERT((pos + width) <= size); - size_t word = pos >> DivShift; - TWord shift1 = pos & ModMask; - TWord shift2 = NumBits - shift1; - TWord res = data[word] >> shift1 & mask; - if (shift2 < width) { - res |= data[word + 1] << shift2 & mask; - } - return res; - } - + static bool Test(const TWord* data, ui64 pos, ui64 size) { + Y_ASSERT(pos < size); + return data[pos >> DivShift] & BitMask(pos & ModMask); + } + + static TWord Get(const TWord* data, ui64 pos, ui8 width, TWord mask, ui64 size) { + if (!width) + return 0; + Y_ASSERT((pos + width) <= size); + size_t word = pos >> DivShift; + TWord shift1 = pos & ModMask; + TWord shift2 = NumBits - shift1; + TWord res = data[word] >> shift1 & mask; + if (shift2 < width) { + res |= data[word + 1] << shift2 & mask; + } + return res; + } + static_assert(std::is_unsigned<TWord>::value, "Expected std::is_unsigned<T>::value."); static_assert((NumBits & (NumBits - 1)) == 0, "NumBits should be a power of 2."); }; diff --git a/library/cpp/containers/bitseq/ya.make b/library/cpp/containers/bitseq/ya.make index 7090956c55..c69d13b721 100644 --- a/library/cpp/containers/bitseq/ya.make +++ b/library/cpp/containers/bitseq/ya.make @@ -9,7 +9,7 @@ PEERDIR( SRCS( bitvector.cpp - readonly_bitvector.cpp + readonly_bitvector.cpp ) END() diff --git a/library/cpp/pop_count/popcount.h b/library/cpp/pop_count/popcount.h index 3d67737ed2..0aa063d488 100644 --- a/library/cpp/pop_count/popcount.h +++ b/library/cpp/pop_count/popcount.h @@ -66,7 +66,7 @@ static inline ui32 PopCountImpl(ui32 n) { } static inline ui32 PopCountImpl(ui64 n) { -#if defined(_MSC_VER) && !defined(_i386_) +#if defined(_MSC_VER) && !defined(_i386_) return __popcnt64(n); #else #if defined(_x86_64_) diff --git a/library/cpp/string_utils/base64/base64_decode_uneven_ut.cpp b/library/cpp/string_utils/base64/base64_decode_uneven_ut.cpp index c3ed068a37..4d482168ad 100644 --- a/library/cpp/string_utils/base64/base64_decode_uneven_ut.cpp +++ b/library/cpp/string_utils/base64/base64_decode_uneven_ut.cpp @@ -38,7 +38,7 @@ Y_UNIT_TEST_SUITE(TBase64DecodeUneven) { const TString lp = "Linkin Park"; UNIT_ASSERT_VALUES_EQUAL(lp, Base64DecodeUneven(Base64Encode(lp))); UNIT_ASSERT_VALUES_EQUAL(lp, Base64DecodeUneven(Base64EncodeUrl(lp))); - + const TString dp = "ADP GmbH\nAnalyse Design & Programmierung\nGesellschaft mit beschränkter Haftung"; UNIT_ASSERT_VALUES_EQUAL(dp, Base64DecodeUneven(Base64Encode(dp))); UNIT_ASSERT_VALUES_EQUAL(dp, Base64DecodeUneven(Base64EncodeUrl(dp))); diff --git a/library/cpp/testing/unittest/gtest.h b/library/cpp/testing/unittest/gtest.h index b6768b1bf0..3818b2096d 100644 --- a/library/cpp/testing/unittest/gtest.h +++ b/library/cpp/testing/unittest/gtest.h @@ -80,7 +80,7 @@ namespace testing { #define EXPECT_NE(A, B) UNIT_ASSERT_UNEQUAL(A, B) #define EXPECT_LE(A, B) UNIT_ASSERT((A) <= (B)) #define EXPECT_LT(A, B) UNIT_ASSERT((A) < (B)) -#define EXPECT_GE(A, B) UNIT_ASSERT((A) >= (B)) +#define EXPECT_GE(A, B) UNIT_ASSERT((A) >= (B)) #define EXPECT_GT(A, B) UNIT_ASSERT((A) > (B)) #define EXPECT_NO_THROW(A) UNIT_ASSERT_NO_EXCEPTION(A) #define EXPECT_THROW(A, B) UNIT_ASSERT_EXCEPTION(A, B) diff --git a/library/cpp/testing/unittest/registar.h b/library/cpp/testing/unittest/registar.h index 44517a0092..4965e0bbb7 100644 --- a/library/cpp/testing/unittest/registar.h +++ b/library/cpp/testing/unittest/registar.h @@ -383,9 +383,9 @@ public: \ } while (false) //doubles -// UNIT_ASSERT_DOUBLES_EQUAL_DEPRECATED* macros do not handle NaNs correctly (see IGNIETFERRO-1419) and are for backward compatibility -// only. Consider switching to regular UNIT_ASSERT_DOUBLES_EQUAL* macros if you're still using the deprecated version. -#define UNIT_ASSERT_DOUBLES_EQUAL_DEPRECATED_C(E, A, D, C) \ +// UNIT_ASSERT_DOUBLES_EQUAL_DEPRECATED* macros do not handle NaNs correctly (see IGNIETFERRO-1419) and are for backward compatibility +// only. Consider switching to regular UNIT_ASSERT_DOUBLES_EQUAL* macros if you're still using the deprecated version. +#define UNIT_ASSERT_DOUBLES_EQUAL_DEPRECATED_C(E, A, D, C) \ do { \ if (std::abs((E) - (A)) > (D)) { \ const auto _es = ToString((long double)(E)); \ @@ -396,32 +396,32 @@ public: \ } \ } while (false) -#define UNIT_ASSERT_DOUBLES_EQUAL_DEPRECATED(E, A, D) UNIT_ASSERT_DOUBLES_EQUAL_DEPRECATED_C(E, A, D, "") - -#define UNIT_ASSERT_DOUBLES_EQUAL_C(E, A, D, C) \ - do { \ - const auto _ed = (E); \ - const auto _ad = (A); \ - const auto _dd = (D); \ +#define UNIT_ASSERT_DOUBLES_EQUAL_DEPRECATED(E, A, D) UNIT_ASSERT_DOUBLES_EQUAL_DEPRECATED_C(E, A, D, "") + +#define UNIT_ASSERT_DOUBLES_EQUAL_C(E, A, D, C) \ + do { \ + const auto _ed = (E); \ + const auto _ad = (A); \ + const auto _dd = (D); \ if (std::isnan((long double)_ed) && !std::isnan((long double)_ad)) { \ const auto _as = ToString((long double)_ad); \ auto&& failMsg = Sprintf("expected NaN, got %s %s", _as.data(), (::TStringBuilder() << C).data()); \ - UNIT_FAIL_IMPL("assertion failure", failMsg); \ - } \ + UNIT_FAIL_IMPL("assertion failure", failMsg); \ + } \ if (!std::isnan((long double)_ed) && std::isnan((long double)_ad)) { \ const auto _es = ToString((long double)_ed); \ auto&& failMsg = Sprintf("expected %s, got NaN %s", _es.data(), (::TStringBuilder() << C).data()); \ - UNIT_FAIL_IMPL("assertion failure", failMsg); \ - } \ - if (std::abs((_ed) - (_ad)) > (_dd)) { \ - const auto _es = ToString((long double)_ed); \ - const auto _as = ToString((long double)_ad); \ - const auto _ds = ToString((long double)_dd); \ + UNIT_FAIL_IMPL("assertion failure", failMsg); \ + } \ + if (std::abs((_ed) - (_ad)) > (_dd)) { \ + const auto _es = ToString((long double)_ed); \ + const auto _as = ToString((long double)_ad); \ + const auto _ds = ToString((long double)_dd); \ auto&& failMsg = Sprintf("std::abs(%s - %s) > %s %s", _es.data(), _as.data(), _ds.data(), (::TStringBuilder() << C).data()); \ - UNIT_FAIL_IMPL("assertion failure", failMsg); \ - } \ - } while (false) - + UNIT_FAIL_IMPL("assertion failure", failMsg); \ + } \ + } while (false) + #define UNIT_ASSERT_DOUBLES_EQUAL(E, A, D) UNIT_ASSERT_DOUBLES_EQUAL_C(E, A, D, "") //strings diff --git a/library/cpp/testing/unittest/registar_ut.cpp b/library/cpp/testing/unittest/registar_ut.cpp index 1f36d53abb..5db231c49d 100644 --- a/library/cpp/testing/unittest/registar_ut.cpp +++ b/library/cpp/testing/unittest/registar_ut.cpp @@ -28,11 +28,11 @@ Y_UNIT_TEST_SUITE(TUnitTestMacroTest) { UNIT_ASSERT_DOUBLES_EQUAL(0.0, 0.01, 0.1); UNIT_ASSERT_DOUBLES_EQUAL(0.01, 0.0, 0.1); - - constexpr auto nan = std::numeric_limits<double>::quiet_NaN(); - UNIT_ASSERT_TEST_FAILS(doublesEqual(nan, 0.5, 0.1)); - UNIT_ASSERT_TEST_FAILS(doublesEqual(0.5, nan, 0.1)); - UNIT_ASSERT_DOUBLES_EQUAL(nan, nan, 0.1); + + constexpr auto nan = std::numeric_limits<double>::quiet_NaN(); + UNIT_ASSERT_TEST_FAILS(doublesEqual(nan, 0.5, 0.1)); + UNIT_ASSERT_TEST_FAILS(doublesEqual(0.5, nan, 0.1)); + UNIT_ASSERT_DOUBLES_EQUAL(nan, nan, 0.1); } Y_UNIT_TEST(StringsEqual) { diff --git a/library/cpp/timezone_conversion/README.md b/library/cpp/timezone_conversion/README.md index 828f1880bc..631579c60b 100644 --- a/library/cpp/timezone_conversion/README.md +++ b/library/cpp/timezone_conversion/README.md @@ -1,25 +1,25 @@ A library for translating between absolute times (i.e., `TInstant`) and civil times (i.e., `NDatetime::TSimpleTM`) using the rules defined by a time zone (i.e., `NDatetime::TTimeZone`). - + (the terms `absolute` and `civil` come from [cctz#fundamental-concepts][cctz-fundamental-concepts]) - + This is basically a wrapper around [CCTZ][cctz] with one important change: the time zone database is in Arcadia and is compiled with the library (which means your executable will end up ~2MB larger). - + See [contrib/libs/cctz/README][update] if you think zone database is outdated. -Quick start: -============ +Quick start: +============ ``` #include <library/cpp/timezone_conversion/convert.h> - -// NDatetime::{GetLocalTimeZone(),GetUtcTimeZone()} are also available. -NDatetime::TTimeZone msk = NDatetime::GetTimeZone("Europe/Moscow"); -TInstant now = TInstant::Now(); -NDatetime::TSimpleTM civil = NDatetime::ToCivilTime(now, msk); -Cout << "Local time in Moscow is " << civil.ToString() << Endl; -TInstant absolute = NDatetime::ToAbsoluteTime(civil, msk); -Cout << "The current UNIX time is " << absolute.Seconds() << Endl; + +// NDatetime::{GetLocalTimeZone(),GetUtcTimeZone()} are also available. +NDatetime::TTimeZone msk = NDatetime::GetTimeZone("Europe/Moscow"); +TInstant now = TInstant::Now(); +NDatetime::TSimpleTM civil = NDatetime::ToCivilTime(now, msk); +Cout << "Local time in Moscow is " << civil.ToString() << Endl; +TInstant absolute = NDatetime::ToAbsoluteTime(civil, msk); +Cout << "The current UNIX time is " << absolute.Seconds() << Endl; ``` [cctz-fundamental-concepts]: https://github.com/google/cctz#fundamental-concepts diff --git a/library/cpp/timezone_conversion/convert.cpp b/library/cpp/timezone_conversion/convert.cpp index 490bb4e270..5f489a2222 100644 --- a/library/cpp/timezone_conversion/convert.cpp +++ b/library/cpp/timezone_conversion/convert.cpp @@ -1,16 +1,16 @@ -#include "convert.h" - +#include "convert.h" + #include <contrib/libs/cctz/include/cctz/civil_time.h> -#include <util/generic/yexception.h> - -#include <chrono> - -namespace NDatetime { - static constexpr i64 TM_YEAR_OFFSET = 1900; - using TSystemClock = std::chrono::system_clock; +#include <util/generic/yexception.h> + +#include <chrono> + +namespace NDatetime { + static constexpr i64 TM_YEAR_OFFSET = 1900; + using TSystemClock = std::chrono::system_clock; using TTimePoint = std::chrono::time_point<TSystemClock>; - + static TSimpleTM CivilToTM(const cctz::civil_second& cs, const cctz::time_zone::absolute_lookup& al) { cctz::civil_day cd(cs); TSimpleTM tm; @@ -54,33 +54,33 @@ namespace NDatetime { /* TTimeZone GetTimeZone(const TString& name) { - TTimeZone result; + TTimeZone result; if (!cctz::load_time_zone(name, &result)) { ythrow yexception() << "Failed to load time zone " << name << ", " << result.name(); - } - return result; - } + } + return result; + } */ - - TTimeZone GetUtcTimeZone() { + + TTimeZone GetUtcTimeZone() { return cctz::utc_time_zone(); - } - - TTimeZone GetLocalTimeZone() { + } + + TTimeZone GetLocalTimeZone() { return cctz::local_time_zone(); - } - - TSimpleTM ToCivilTime(const TInstant& absoluteTime, const TTimeZone& tz) { + } + + TSimpleTM ToCivilTime(const TInstant& absoluteTime, const TTimeZone& tz) { TTimePoint tp = TSystemClock::from_time_t(absoluteTime.TimeT()); return CivilToTM(cctz::convert(tp, tz), tz.lookup(tp)); } - + TSimpleTM CreateCivilTime(const TTimeZone& tz, ui32 year, ui32 mon, ui32 day, ui32 h, ui32 m, ui32 s) { cctz::civil_second cs(year, mon, day, h, m, s); return CivilToTM(cs, tz.lookup(tz.lookup(cs).pre)); - } - - TInstant ToAbsoluteTime(const TSimpleTM& civilTime, const TTimeZone& tz) { + } + + TInstant ToAbsoluteTime(const TSimpleTM& civilTime, const TTimeZone& tz) { cctz::civil_second cs( civilTime.Year + TM_YEAR_OFFSET, civilTime.Mon + 1, @@ -89,5 +89,5 @@ namespace NDatetime { civilTime.Min, civilTime.Sec); return TInstant::Seconds(TSystemClock::to_time_t(tz.lookup(cs).pre)); - } -} + } +} diff --git a/library/cpp/timezone_conversion/convert.h b/library/cpp/timezone_conversion/convert.h index 768a9e110f..404650817c 100644 --- a/library/cpp/timezone_conversion/convert.h +++ b/library/cpp/timezone_conversion/convert.h @@ -1,36 +1,36 @@ -#pragma once - +#pragma once + #include "civil.h" #include <contrib/libs/cctz/include/cctz/time_zone.h> -#include <util/datetime/base.h> -#include <util/draft/datetime.h> - -namespace NDatetime { - /** - * @return The mother of all time zones. - * @see https://en.wikipedia.org/wiki/Coordinated_Universal_Time - */ - TTimeZone GetUtcTimeZone(); - - /** - * @return The time zone that is curently set on your machine. - */ - TTimeZone GetLocalTimeZone(); - - /** - * @param absoluteTime A TInstant representing a number of seconds elapsed - * since The Epoch (the microsecond part is ignored). - * @param tz The time zone to use for conversion. - * @return The civil time corresponding to absoluteTime. - * @note This conversion is always well-defined (i.e., there - * is exactly one civil time which corresponds to - * absoluteTime). - * @see https://en.wikipedia.org/wiki/Unix_time - */ - TSimpleTM ToCivilTime(const TInstant& absoluteTime, const TTimeZone& tz); - - /** +#include <util/datetime/base.h> +#include <util/draft/datetime.h> + +namespace NDatetime { + /** + * @return The mother of all time zones. + * @see https://en.wikipedia.org/wiki/Coordinated_Universal_Time + */ + TTimeZone GetUtcTimeZone(); + + /** + * @return The time zone that is curently set on your machine. + */ + TTimeZone GetLocalTimeZone(); + + /** + * @param absoluteTime A TInstant representing a number of seconds elapsed + * since The Epoch (the microsecond part is ignored). + * @param tz The time zone to use for conversion. + * @return The civil time corresponding to absoluteTime. + * @note This conversion is always well-defined (i.e., there + * is exactly one civil time which corresponds to + * absoluteTime). + * @see https://en.wikipedia.org/wiki/Unix_time + */ + TSimpleTM ToCivilTime(const TInstant& absoluteTime, const TTimeZone& tz); + + /** * Creates civil time in place with respect of given timezone. * @param[in] tz The time zone to use for creation. * @param[in] year The year of the creation time. @@ -44,17 +44,17 @@ namespace NDatetime { TSimpleTM CreateCivilTime(const TTimeZone& tz, ui32 year, ui32 mon, ui32 day, ui32 h = 0, ui32 m = 0, ui32 s = 0); /** - * @param civilTime A human-readable date and time (the following fields - * are used by this function: {Year,Mon,MDay,Hour,Min,Sec}). - * @param tz The time zone to use for conversion. - * @return Some absolute time corresponding to civilTime. - * @note If multiple absolute times match civilTime, the earliest - * if returned. - * If civilTime doesn't exist due to discontinuity in time - * (e.g., DST happened) we pretend the discontinuity isn't - * there (i.e., if we skipped from 1:59AM to 3:00AM then - * ToAbsoluteTime(2:30AM) == ToAbsoluteTime(3:30AM)). - * @see https://en.wikipedia.org/wiki/Daylight_saving_time - */ - TInstant ToAbsoluteTime(const TSimpleTM& civilTime, const TTimeZone& tz); -} + * @param civilTime A human-readable date and time (the following fields + * are used by this function: {Year,Mon,MDay,Hour,Min,Sec}). + * @param tz The time zone to use for conversion. + * @return Some absolute time corresponding to civilTime. + * @note If multiple absolute times match civilTime, the earliest + * if returned. + * If civilTime doesn't exist due to discontinuity in time + * (e.g., DST happened) we pretend the discontinuity isn't + * there (i.e., if we skipped from 1:59AM to 3:00AM then + * ToAbsoluteTime(2:30AM) == ToAbsoluteTime(3:30AM)). + * @see https://en.wikipedia.org/wiki/Daylight_saving_time + */ + TInstant ToAbsoluteTime(const TSimpleTM& civilTime, const TTimeZone& tz); +} diff --git a/library/cpp/timezone_conversion/ut/convert_ut.cpp b/library/cpp/timezone_conversion/ut/convert_ut.cpp index bbf9e9b826..91ad67673f 100644 --- a/library/cpp/timezone_conversion/ut/convert_ut.cpp +++ b/library/cpp/timezone_conversion/ut/convert_ut.cpp @@ -1,139 +1,139 @@ #include <library/cpp/timezone_conversion/convert.h> #include <library/cpp/testing/unittest/gtest.h> - -using namespace NDatetime; - -template <> + +using namespace NDatetime; + +template <> void Out<TSimpleTM>(IOutputStream& os, TTypeTraits<TSimpleTM>::TFuncParam value) { - os << value.ToString() << ", dst: " << int(value.IsDst); -} - -TSimpleTM ZonedTm(i32 utcHours, bool isDst, ui32 year, ui32 mon, ui32 day, ui32 h, ui32 m, ui32 s) { - TSimpleTM res(year, mon, day, h, m, s); - res.GMTOff = utcHours * 60 * 60; - res.IsDst = isDst; - return res; -} - -void CompareCivilTimes(const TSimpleTM& expected, const TSimpleTM& actual) { - EXPECT_EQ(expected.GMTOff, actual.GMTOff); - EXPECT_EQ(expected.Year, actual.Year); - EXPECT_EQ(expected.Mon, actual.Mon); - EXPECT_EQ(expected.MDay, actual.MDay); - EXPECT_EQ(expected.WDay, actual.WDay); - EXPECT_EQ(expected.Hour, actual.Hour); - EXPECT_EQ(expected.Min, actual.Min); - EXPECT_EQ(expected.Sec, actual.Sec); - EXPECT_EQ(expected.IsDst, actual.IsDst); - EXPECT_EQ(expected.IsLeap, actual.IsLeap); -} - -#define CHECK_ROUND_TRIP(tz, unixTime, civil) \ + os << value.ToString() << ", dst: " << int(value.IsDst); +} + +TSimpleTM ZonedTm(i32 utcHours, bool isDst, ui32 year, ui32 mon, ui32 day, ui32 h, ui32 m, ui32 s) { + TSimpleTM res(year, mon, day, h, m, s); + res.GMTOff = utcHours * 60 * 60; + res.IsDst = isDst; + return res; +} + +void CompareCivilTimes(const TSimpleTM& expected, const TSimpleTM& actual) { + EXPECT_EQ(expected.GMTOff, actual.GMTOff); + EXPECT_EQ(expected.Year, actual.Year); + EXPECT_EQ(expected.Mon, actual.Mon); + EXPECT_EQ(expected.MDay, actual.MDay); + EXPECT_EQ(expected.WDay, actual.WDay); + EXPECT_EQ(expected.Hour, actual.Hour); + EXPECT_EQ(expected.Min, actual.Min); + EXPECT_EQ(expected.Sec, actual.Sec); + EXPECT_EQ(expected.IsDst, actual.IsDst); + EXPECT_EQ(expected.IsLeap, actual.IsLeap); +} + +#define CHECK_ROUND_TRIP(tz, unixTime, civil) \ EXPECT_EQ( \ TInstant::Seconds(unixTime), \ ToAbsoluteTime(civil, tz)); \ - CompareCivilTimes( \ + CompareCivilTimes( \ civil, \ - ToCivilTime(TInstant::Seconds(unixTime), tz)); - -// Tests only unambiguous civil times (i.e., those that occurred exactly once). -TEST(TimeZoneConversion, Simple) { - TTimeZone msk = GetTimeZone("Europe/Moscow"); - // Before and after the temporary switch to UTC+3 in 2010. - CHECK_ROUND_TRIP( + ToCivilTime(TInstant::Seconds(unixTime), tz)); + +// Tests only unambiguous civil times (i.e., those that occurred exactly once). +TEST(TimeZoneConversion, Simple) { + TTimeZone msk = GetTimeZone("Europe/Moscow"); + // Before and after the temporary switch to UTC+3 in 2010. + CHECK_ROUND_TRIP( msk, 1288475999, ZonedTm(+4, true, 2010, 10, 31, 1, 59, 59)); - CHECK_ROUND_TRIP( + CHECK_ROUND_TRIP( msk, 1288475999 + 3 * 60 * 60, ZonedTm(+3, false, 2010, 10, 31, 3, 59, 59)); - - // Before and after the permanent switch to UTC+4 in 2011. - CHECK_ROUND_TRIP( + + // Before and after the permanent switch to UTC+4 in 2011. + CHECK_ROUND_TRIP( msk, 1301180399, ZonedTm(+3, false, 2011, 3, 27, 1, 59, 59)); - CHECK_ROUND_TRIP( + CHECK_ROUND_TRIP( msk, 1301180399 + 60 * 60, ZonedTm(+4, false, 2011, 3, 27, 3, 59, 59)); - - // Some random moment between 2011 and 2014 when UTC+4 (no DST) was in place. - CHECK_ROUND_TRIP( + + // Some random moment between 2011 and 2014 when UTC+4 (no DST) was in place. + CHECK_ROUND_TRIP( msk, 1378901234, ZonedTm(+4, false, 2013, 9, 11, 16, 7, 14)); - - // As of right now (i.e., as I'm writing this) Moscow is in UTC+3 (no DST). - CHECK_ROUND_TRIP( + + // As of right now (i.e., as I'm writing this) Moscow is in UTC+3 (no DST). + CHECK_ROUND_TRIP( msk, 1458513396, ZonedTm(+3, false, 2016, 3, 21, 1, 36, 36)); - - // Please add a new test if the current president moves Moscow back to UTC+4 - // or introduces DST again. -} - -TEST(TimeZoneConversion, TestRepeatedDate) { - TTimeZone ekb = GetTimeZone("Asia/Yekaterinburg"); - - CompareCivilTimes( - ZonedTm(+6, true, 2010, 10, 31, 2, 30, 0), - ToCivilTime(TInstant::Seconds(1288470600), ekb)); - - CompareCivilTimes( - ZonedTm(+5, false, 2010, 10, 31, 2, 30, 0), - ToCivilTime(TInstant::Seconds(1288474200), ekb)); - - CompareCivilTimes( + + // Please add a new test if the current president moves Moscow back to UTC+4 + // or introduces DST again. +} + +TEST(TimeZoneConversion, TestRepeatedDate) { + TTimeZone ekb = GetTimeZone("Asia/Yekaterinburg"); + + CompareCivilTimes( + ZonedTm(+6, true, 2010, 10, 31, 2, 30, 0), + ToCivilTime(TInstant::Seconds(1288470600), ekb)); + + CompareCivilTimes( + ZonedTm(+5, false, 2010, 10, 31, 2, 30, 0), + ToCivilTime(TInstant::Seconds(1288474200), ekb)); + + CompareCivilTimes( ZonedTm(+5, false, 2016, 5, 10, 9, 8, 7), CreateCivilTime(ekb, 2016, 5, 10, 9, 8, 7)); - CompareCivilTimes( + CompareCivilTimes( ZonedTm(+6, true, 2010, 10, 31, 2, 30, 0), CreateCivilTime(ekb, 2010, 10, 31, 2, 30, 0)); - // The earlier timestamp should be chosen. - EXPECT_EQ( - TInstant::Seconds(1288470600), - ToAbsoluteTime(TSimpleTM(2010, 10, 31, 2, 30, 0), ekb)); -} - -TEST(TimeZoneConversion, TestSkippedDate) { - TTimeZone nsk = GetTimeZone("Asia/Novosibirsk"); - - CompareCivilTimes( - ZonedTm(+6, false, 2011, 3, 27, 1, 30, 0), - ToCivilTime(TInstant::Seconds(1301167800), nsk)); - - CompareCivilTimes( - ZonedTm(+7, false, 2011, 3, 27, 3, 30, 0), - ToCivilTime(TInstant::Seconds(1301171400), nsk)); - - EXPECT_EQ( - TInstant::Seconds(1301171400), - ToAbsoluteTime(TSimpleTM(2011, 3, 27, 2, 30, 0), nsk)); - - EXPECT_EQ( - TInstant::Seconds(1301171400), - ToAbsoluteTime(TSimpleTM(2011, 3, 27, 3, 30, 0), nsk)); -} - -TEST(TimeZoneConversion, Utc) { - CHECK_ROUND_TRIP( + // The earlier timestamp should be chosen. + EXPECT_EQ( + TInstant::Seconds(1288470600), + ToAbsoluteTime(TSimpleTM(2010, 10, 31, 2, 30, 0), ekb)); +} + +TEST(TimeZoneConversion, TestSkippedDate) { + TTimeZone nsk = GetTimeZone("Asia/Novosibirsk"); + + CompareCivilTimes( + ZonedTm(+6, false, 2011, 3, 27, 1, 30, 0), + ToCivilTime(TInstant::Seconds(1301167800), nsk)); + + CompareCivilTimes( + ZonedTm(+7, false, 2011, 3, 27, 3, 30, 0), + ToCivilTime(TInstant::Seconds(1301171400), nsk)); + + EXPECT_EQ( + TInstant::Seconds(1301171400), + ToAbsoluteTime(TSimpleTM(2011, 3, 27, 2, 30, 0), nsk)); + + EXPECT_EQ( + TInstant::Seconds(1301171400), + ToAbsoluteTime(TSimpleTM(2011, 3, 27, 3, 30, 0), nsk)); +} + +TEST(TimeZoneConversion, Utc) { + CHECK_ROUND_TRIP( GetUtcTimeZone(), 1451703845, ZonedTm(0, false, 2016, 1, 2, 3, 4, 5)); -} - -TEST(TimeZoneConversion, Local) { - TTimeZone local = GetLocalTimeZone(); - auto nowAbsolute = TInstant::Now(); - auto nowCivilLocal = ToCivilTime(nowAbsolute, local); - EXPECT_EQ(nowAbsolute.Seconds(), ToAbsoluteTime(nowCivilLocal, local).Seconds()); -} - +} + +TEST(TimeZoneConversion, Local) { + TTimeZone local = GetLocalTimeZone(); + auto nowAbsolute = TInstant::Now(); + auto nowCivilLocal = ToCivilTime(nowAbsolute, local); + EXPECT_EQ(nowAbsolute.Seconds(), ToAbsoluteTime(nowCivilLocal, local).Seconds()); +} + TEST(TimeZoneConversion, BeforeEpoch) { { //NOTE: This test will not work because NDatetime::Convert() with TInstant does not work properly for dates before 1/1/1970 @@ -150,42 +150,42 @@ TEST(TimeZoneConversion, BeforeEpoch) { } -TEST(TimeZoneConversion, InvalidTimeZone) { - EXPECT_THROW(GetTimeZone("Europe/Mscow"), yexception); - EXPECT_THROW(GetTimeZone(""), yexception); -} - -TEST(TimeZoneConversion, TestSaratov) { - TTimeZone saratov = GetTimeZone("Europe/Saratov"); - - CompareCivilTimes( - ZonedTm(+4, false, 2016, 12, 5, 1, 55, 35), - ToCivilTime(TInstant::Seconds(1480888535), saratov)); - - CompareCivilTimes( - ZonedTm(+3, false, 2016, 12, 1, 0, 55, 35), - ToCivilTime(TInstant::Seconds(1480542935), saratov)); -} - -TEST(TimeZoneConversion, TestFutureDstChanges) { - TTimeZone london = GetTimeZone("Europe/London"); - - // This test assumes the British won't cancel DST before 2025. - // I don't think they will, but then again, nobody really expected Brexit. - - // DST is still in effect in early October 2025, meaning we are in UTC+1. - CHECK_ROUND_TRIP( - london, - 1760124660, - ZonedTm(+1, true, 2025, 10, 10, 20, 31, 0)); - - // 31 days later we're back to UTC+0 again. - CHECK_ROUND_TRIP( - london, +TEST(TimeZoneConversion, InvalidTimeZone) { + EXPECT_THROW(GetTimeZone("Europe/Mscow"), yexception); + EXPECT_THROW(GetTimeZone(""), yexception); +} + +TEST(TimeZoneConversion, TestSaratov) { + TTimeZone saratov = GetTimeZone("Europe/Saratov"); + + CompareCivilTimes( + ZonedTm(+4, false, 2016, 12, 5, 1, 55, 35), + ToCivilTime(TInstant::Seconds(1480888535), saratov)); + + CompareCivilTimes( + ZonedTm(+3, false, 2016, 12, 1, 0, 55, 35), + ToCivilTime(TInstant::Seconds(1480542935), saratov)); +} + +TEST(TimeZoneConversion, TestFutureDstChanges) { + TTimeZone london = GetTimeZone("Europe/London"); + + // This test assumes the British won't cancel DST before 2025. + // I don't think they will, but then again, nobody really expected Brexit. + + // DST is still in effect in early October 2025, meaning we are in UTC+1. + CHECK_ROUND_TRIP( + london, + 1760124660, + ZonedTm(+1, true, 2025, 10, 10, 20, 31, 0)); + + // 31 days later we're back to UTC+0 again. + CHECK_ROUND_TRIP( + london, 1760124660 + 31 * 24 * 60 * 60, - ZonedTm(+0, false, 2025, 11, 10, 19, 31, 0)); -} - + ZonedTm(+0, false, 2025, 11, 10, 19, 31, 0)); +} + TEST(TimeZoneConversion, TWDay) { TTimeZone nsk = GetTimeZone("Asia/Novosibirsk"); @@ -193,12 +193,12 @@ TEST(TimeZoneConversion, TWDay) { EXPECT_EQ(dow, ToCivilTime(TInstant::Seconds(e), nsk).WDay); } } - -TEST(TimeZoneConversion, TestBaikonur) { - // Yes, the Baikonur spaceport is located in Kyzylorda Region. - const auto baikonur = GetTimeZone("Asia/Qyzylorda"); - - CompareCivilTimes( - ZonedTm(+5, false, 2019, 1, 11, 23, 55, 23), - ToCivilTime(TInstant::Seconds(1547232923), baikonur)); -} + +TEST(TimeZoneConversion, TestBaikonur) { + // Yes, the Baikonur spaceport is located in Kyzylorda Region. + const auto baikonur = GetTimeZone("Asia/Qyzylorda"); + + CompareCivilTimes( + ZonedTm(+5, false, 2019, 1, 11, 23, 55, 23), + ToCivilTime(TInstant::Seconds(1547232923), baikonur)); +} diff --git a/library/cpp/timezone_conversion/ut/ya.make b/library/cpp/timezone_conversion/ut/ya.make index 781a57da9f..02862ae62b 100644 --- a/library/cpp/timezone_conversion/ut/ya.make +++ b/library/cpp/timezone_conversion/ut/ya.make @@ -1,15 +1,15 @@ -UNITTEST() - -OWNER(dfyz) - -PEERDIR( +UNITTEST() + +OWNER(dfyz) + +PEERDIR( library/cpp/testing/unittest library/cpp/timezone_conversion -) - -SRCS( - convert_ut.cpp +) + +SRCS( + convert_ut.cpp civil_ut.cpp -) - -END() +) + +END() diff --git a/library/cpp/timezone_conversion/ya.make b/library/cpp/timezone_conversion/ya.make index f99ebe73ee..c40e45d044 100644 --- a/library/cpp/timezone_conversion/ya.make +++ b/library/cpp/timezone_conversion/ya.make @@ -1,22 +1,22 @@ -LIBRARY() - +LIBRARY() + OWNER( dfyz petrk ) - -PEERDIR( - contrib/libs/cctz/tzdata - util/draft -) - -SRCS( - convert.cpp + +PEERDIR( + contrib/libs/cctz/tzdata + util/draft +) + +SRCS( + convert.cpp civil.cpp -) - +) + GENERATE_ENUM_SERIALIZATION(civil.h) -END() +END() RECURSE_FOR_TESTS(ut) diff --git a/library/cpp/uri/uri_ut.cpp b/library/cpp/uri/uri_ut.cpp index 2ebd83fc93..8e0c682a4f 100644 --- a/library/cpp/uri/uri_ut.cpp +++ b/library/cpp/uri/uri_ut.cpp @@ -127,7 +127,7 @@ namespace NUri { {"http://president.rf/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8", "http://president.rf/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8/1024", "http://president.rf/%D0%BD%D0%BE%D0%B2%D0%BE%D1%81%D1%82%D0%B8/1024", TUri::LinkIsLocal}, {nullptr, nullptr, nullptr, TUri::LinkIsBad}, }; - + Y_UNIT_TEST(test_httpURLNormalize) { TUri normalizedLink; diff --git a/util/datetime/base.cpp b/util/datetime/base.cpp index 38ecc3ab96..8144dcc1a2 100644 --- a/util/datetime/base.cpp +++ b/util/datetime/base.cpp @@ -67,80 +67,80 @@ namespace { return o << p.I; } - + inline IOutputStream& operator<<(IOutputStream& o, const TPad<6>& p) { - if (p.I < 100000) { - if (p.I >= 0) { - if (p.I < 10) { - o << '0' << '0' << '0' << '0' << '0'; - } else if (p.I < 100) { - o << '0' << '0' << '0' << '0'; - } else if (p.I < 1000) { - o << '0' << '0' << '0'; - } else if (p.I < 10000) { - o << '0' << '0'; - } else { - o << '0'; - } - } - } - - return o << p.I; - } - + if (p.I < 100000) { + if (p.I >= 0) { + if (p.I < 10) { + o << '0' << '0' << '0' << '0' << '0'; + } else if (p.I < 100) { + o << '0' << '0' << '0' << '0'; + } else if (p.I < 1000) { + o << '0' << '0' << '0'; + } else if (p.I < 10000) { + o << '0' << '0'; + } else { + o << '0'; + } + } + } + + return o << p.I; + } + void WriteMicroSecondsToStream(IOutputStream& os, ui32 microSeconds) { - os << '.' << Pad<6>(microSeconds); - } - + os << '.' << Pad<6>(microSeconds); + } + void WriteTmToStream(IOutputStream& os, const struct tm& theTm) { - os << Pad<4>(theTm.tm_year + 1900) << '-' << Pad<2>(theTm.tm_mon + 1) << '-' << Pad<2>(theTm.tm_mday) << 'T' + os << Pad<4>(theTm.tm_year + 1900) << '-' << Pad<2>(theTm.tm_mon + 1) << '-' << Pad<2>(theTm.tm_mday) << 'T' << Pad<2>(theTm.tm_hour) << ':' << Pad<2>(theTm.tm_min) << ':' << Pad<2>(theTm.tm_sec); - } - + } + template <bool PrintUpToSeconds, bool iso> void WritePrintableLocalTimeToStream(IOutputStream& os, const ::NPrivate::TPrintableLocalTime<PrintUpToSeconds, iso>& timeToPrint) { const TInstant& momentToPrint = timeToPrint.MomentToPrint; - struct tm localTime; - momentToPrint.LocalTime(&localTime); - WriteTmToStream(os, localTime); - if (!PrintUpToSeconds) { - WriteMicroSecondsToStream(os, momentToPrint.MicroSecondsOfSecond()); - } -#ifndef _win_ - i64 utcOffsetInMinutes = localTime.tm_gmtoff / 60; -#else - TIME_ZONE_INFORMATION tz; - if (GetTimeZoneInformation(&tz) == TIME_ZONE_ID_INVALID) { - ythrow TSystemError() << "Failed to get the system time zone"; - } - i64 utcOffsetInMinutes = -tz.Bias; -#endif - if (utcOffsetInMinutes == 0) { - os << 'Z'; - } else { - if (utcOffsetInMinutes < 0) { - os << '-'; - utcOffsetInMinutes = -utcOffsetInMinutes; - } else { - os << '+'; - } + struct tm localTime; + momentToPrint.LocalTime(&localTime); + WriteTmToStream(os, localTime); + if (!PrintUpToSeconds) { + WriteMicroSecondsToStream(os, momentToPrint.MicroSecondsOfSecond()); + } +#ifndef _win_ + i64 utcOffsetInMinutes = localTime.tm_gmtoff / 60; +#else + TIME_ZONE_INFORMATION tz; + if (GetTimeZoneInformation(&tz) == TIME_ZONE_ID_INVALID) { + ythrow TSystemError() << "Failed to get the system time zone"; + } + i64 utcOffsetInMinutes = -tz.Bias; +#endif + if (utcOffsetInMinutes == 0) { + os << 'Z'; + } else { + if (utcOffsetInMinutes < 0) { + os << '-'; + utcOffsetInMinutes = -utcOffsetInMinutes; + } else { + os << '+'; + } os << Pad<2>(utcOffsetInMinutes / 60); if (iso) { os << ':'; } os << Pad<2>(utcOffsetInMinutes % 60); - } - } + } + } } -template <> +template <> void Out<TDuration>(IOutputStream& os, TTypeTraits<TDuration>::TFuncParam duration) { - os << duration.Seconds(); - WriteMicroSecondsToStream(os, duration.MicroSecondsOfSecond()); - os << 's'; -} - -template <> + os << duration.Seconds(); + WriteMicroSecondsToStream(os, duration.MicroSecondsOfSecond()); + os << 's'; +} + +template <> void Out<TInstant>(IOutputStream& os, TTypeTraits<TInstant>::TFuncParam instant) { char buf[64]; auto len = FormatDate8601(buf, sizeof(buf), instant.TimeT()); @@ -149,20 +149,20 @@ void Out<TInstant>(IOutputStream& os, TTypeTraits<TInstant>::TFuncParam instant) Y_ENSURE(len, TStringBuf("Out<TInstant>: year does not fit into an integer")); os.Write(buf, len - 1 /* 'Z' */); - WriteMicroSecondsToStream(os, instant.MicroSecondsOfSecond()); - os << 'Z'; -} - -template <> + WriteMicroSecondsToStream(os, instant.MicroSecondsOfSecond()); + os << 'Z'; +} + +template <> void Out<::NPrivate::TPrintableLocalTime<false, false>>(IOutputStream& os, TTypeTraits<::NPrivate::TPrintableLocalTime<false, false>>::TFuncParam localTime) { - WritePrintableLocalTimeToStream(os, localTime); -} - -template <> + WritePrintableLocalTimeToStream(os, localTime); +} + +template <> void Out<::NPrivate::TPrintableLocalTime<false, true>>(IOutputStream& os, TTypeTraits<::NPrivate::TPrintableLocalTime<false, true>>::TFuncParam localTime) { - WritePrintableLocalTimeToStream(os, localTime); -} - + WritePrintableLocalTimeToStream(os, localTime); +} + template <> void Out<::NPrivate::TPrintableLocalTime<true, false>>(IOutputStream& os, TTypeTraits<::NPrivate::TPrintableLocalTime<true, false>>::TFuncParam localTime) { WritePrintableLocalTimeToStream(os, localTime); @@ -174,13 +174,13 @@ void Out<::NPrivate::TPrintableLocalTime<true, true>>(IOutputStream& os, TTypeTr } TString TDuration::ToString() const { - return ::ToString(*this); -} - + return ::ToString(*this); +} + TString TInstant::ToString() const { - return ::ToString(*this); -} - + return ::ToString(*this); +} + TString TInstant::ToRfc822String() const { return FormatGmTime("%a, %d %b %Y %H:%M:%S GMT"); } @@ -189,19 +189,19 @@ TString TInstant::ToStringUpToSeconds() const { char buf[64]; auto len = FormatDate8601(buf, sizeof(buf), TimeT()); if (!len) { - ythrow yexception() << "TInstant::ToStringUpToSeconds: year does not fit into an integer"; + ythrow yexception() << "TInstant::ToStringUpToSeconds: year does not fit into an integer"; } return TString(buf, len); -} - +} + TString TInstant::ToIsoStringLocal() const { return ::ToString(FormatIsoLocal(*this)); } TString TInstant::ToStringLocal() const { - return ::ToString(FormatLocal(*this)); -} - + return ::ToString(FormatLocal(*this)); +} + TString TInstant::ToRfc822StringLocal() const { return FormatLocalTime("%a, %d %b %Y %H:%M:%S %Z"); } @@ -211,9 +211,9 @@ TString TInstant::ToIsoStringLocalUpToSeconds() const { } TString TInstant::ToStringLocalUpToSeconds() const { - return ::ToString(FormatLocalUpToSeconds(*this)); -} - + return ::ToString(FormatLocalUpToSeconds(*this)); +} + TString TInstant::FormatLocalTime(const char* format) const noexcept { struct tm theTm; LocalTime(&theTm); @@ -228,12 +228,12 @@ TString TInstant::FormatGmTime(const char* format) const noexcept { ::NPrivate::TPrintableLocalTime<false, true> FormatIsoLocal(TInstant instant) { return ::NPrivate::TPrintableLocalTime<false, true>(instant); -} - +} + ::NPrivate::TPrintableLocalTime<false, false> FormatLocal(TInstant instant) { return ::NPrivate::TPrintableLocalTime<false, false>(instant); -} - +} + ::NPrivate::TPrintableLocalTime<true, true> FormatIsoLocalUpToSeconds(TInstant instant) { return ::NPrivate::TPrintableLocalTime<true, true>(instant); } @@ -242,10 +242,10 @@ TString TInstant::FormatGmTime(const char* format) const noexcept { return ::NPrivate::TPrintableLocalTime<true, false>(instant); } -void Sleep(TDuration duration) { - NanoSleep(duration.NanoSeconds()); -} - +void Sleep(TDuration duration) { + NanoSleep(duration.NanoSeconds()); +} + void sprint_gm_date(char* buf, time_t when, long* sec) { struct tm theTm; ::Zero(theTm); @@ -317,8 +317,8 @@ size_t FormatDate8601(char* buf, size_t len, time_t when) { if (ret) { TMemoryOutput out(buf, len); - WriteTmToStream(out, theTm); - out << 'Z'; + WriteTmToStream(out, theTm); + out << 'Z'; return out.Buf() - buf; } diff --git a/util/datetime/base.h b/util/datetime/base.h index 5e902b8f63..5088a7b929 100644 --- a/util/datetime/base.h +++ b/util/datetime/base.h @@ -443,15 +443,15 @@ public: return GmTimeR(&clock, tm); } - /** - * Formats the instant using the UTC time zone, with microsecond precision. - * - * @returns An ISO 8601 formatted string, e.g. '2015-11-21T23:30:27.991669Z'. + /** + * Formats the instant using the UTC time zone, with microsecond precision. + * + * @returns An ISO 8601 formatted string, e.g. '2015-11-21T23:30:27.991669Z'. * @note Global Out method is defined to TInstant, so it can be written as text to IOutputStream. - */ + */ TString ToString() const; - - /** + + /** * Formats the instant using the UTC time zone. * * @returns An RFC822 formatted string, e.g. 'Sun, 06 Nov 1994 08:49:37 GMT'. @@ -459,18 +459,18 @@ public: TString ToRfc822String() const; /** - * Formats the instant using the UTC time zone, with second precision. - * - * @returns An ISO 8601 formatted string, e.g. '2015-11-21T23:30:27Z'. - */ + * Formats the instant using the UTC time zone, with second precision. + * + * @returns An ISO 8601 formatted string, e.g. '2015-11-21T23:30:27Z'. + */ TString ToStringUpToSeconds() const; - /** - * Formats the instant using the system time zone, with microsecond precision. - * + /** + * Formats the instant using the system time zone, with microsecond precision. + * * @returns An ISO 8601 / RFC 3339 formatted string, * e.g. '2015-11-22T04:30:27.991669+05:00'. - */ + */ TString ToIsoStringLocal() const; /** @@ -480,8 +480,8 @@ public: * e.g. '2015-11-22T04:30:27.991669+0500'. */ TString ToStringLocal() const; - - /** + + /** * Formats the instant using the system time zone. * * @returns An RFC822 formatted string, e.g. 'Sun, 06 Nov 1994 08:49:37 MSK'. @@ -489,11 +489,11 @@ public: TString ToRfc822StringLocal() const; /** - * Formats the instant using the system time zone, with second precision. - * + * Formats the instant using the system time zone, with second precision. + * * @returns An ISO 8601 / RFC 3339 formatted string, * e.g. '2015-11-22T04:30:27+05:00'. - */ + */ TString ToIsoStringLocalUpToSeconds() const; /** @@ -503,7 +503,7 @@ public: * e.g. '2015-11-22T04:30:27+0500'. */ TString ToStringLocalUpToSeconds() const; - + TString FormatLocalTime(const char* format) const noexcept; TString FormatGmTime(const char* format) const noexcept; @@ -566,41 +566,41 @@ struct THash<TInstant> { } }; -namespace NPrivate { +namespace NPrivate { template <bool PrintUpToSeconds, bool iso> - struct TPrintableLocalTime { - TInstant MomentToPrint; - + struct TPrintableLocalTime { + TInstant MomentToPrint; + constexpr explicit TPrintableLocalTime(TInstant momentToPrint) - : MomentToPrint(momentToPrint) - { - } - }; -} - + : MomentToPrint(momentToPrint) + { + } + }; +} + /** @name Helpers for printing local times to `IOutputStream`s. - * The FormatLocal* functions create an opaque object that, when written to + * The FormatLocal* functions create an opaque object that, when written to * a `IOutputStream`, outputs this instant as an ISO 8601 formatted string - * using the system time zone. - * - * @note The only reason behind this set of functions is to avoid excessive - * allocations when you directly print the local time to a stream. - * - * If you need something beyond just printing the value or your code - * is not performance-critical, feel free to use the corresponding - * TInstant::ToString*() functions. - */ -///@{ + * using the system time zone. + * + * @note The only reason behind this set of functions is to avoid excessive + * allocations when you directly print the local time to a stream. + * + * If you need something beyond just printing the value or your code + * is not performance-critical, feel free to use the corresponding + * TInstant::ToString*() functions. + */ +///@{ /// @see TInstant::ToIsoStringLocal() ::NPrivate::TPrintableLocalTime<false, true> FormatIsoLocal(TInstant instant); -/// @see TInstant::ToStringLocal() +/// @see TInstant::ToStringLocal() ::NPrivate::TPrintableLocalTime<false, false> FormatLocal(TInstant instant); /// @see TInstant::ToIsoStringLocalUpToSeconds() ::NPrivate::TPrintableLocalTime<true, true> FormatIsoLocalUpToSeconds(TInstant instant); -/// @see TInstant::ToStringLocalUpToSeconds() +/// @see TInstant::ToStringLocalUpToSeconds() ::NPrivate::TPrintableLocalTime<true, false> FormatLocalUpToSeconds(TInstant instant); -///@} - +///@} + template <class S> static constexpr bool operator<(const TTimeBase<S>& l, const TTimeBase<S>& r) noexcept { return l.GetValue() < r.GetValue(); diff --git a/util/stream/output.cpp b/util/stream/output.cpp index db81b81b70..d43eb527a2 100644 --- a/util/stream/output.cpp +++ b/util/stream/output.cpp @@ -272,21 +272,21 @@ namespace { private: virtual void DoWrite(const void* buf, size_t len) override { with_lock (BufferMutex) { - Buffer.Write(buf, len); - } + Buffer.Write(buf, len); + } } virtual void DoFlush() override { with_lock (BufferMutex) { - LogFuncPtr(ANDROID_LOG_DEBUG, GetTag(), Buffer.Data()); - Buffer.Clear(); - } + LogFuncPtr(ANDROID_LOG_DEBUG, GetTag(), Buffer.Data()); + Buffer.Clear(); + } } virtual const char* GetTag() const = 0; private: - TMutex BufferMutex; + TMutex BufferMutex; TStringStream Buffer; TLogFuncPtr LogFuncPtr; }; diff --git a/util/system/context.h b/util/system/context.h index d2a349bfc5..e02b6a13ca 100644 --- a/util/system/context.h +++ b/util/system/context.h @@ -20,7 +20,7 @@ /* * switch method */ -#if defined(_bionic_) || defined(__IOS__) +#if defined(_bionic_) || defined(__IOS__) #define USE_GENERIC_CONT #elif defined(_cygwin_) #define USE_UCONTEXT_CONT diff --git a/util/system/datetime.cpp b/util/system/datetime.cpp index b07b50679a..60c4150298 100644 --- a/util/system/datetime.cpp +++ b/util/system/datetime.cpp @@ -94,7 +94,7 @@ void NanoSleep(ui64 ns) noexcept { #endif } -#if defined(_x86_) +#if defined(_x86_) extern const bool HaveRdtscp = NX86::HaveRDTSCP(); #endif diff --git a/util/system/datetime.h b/util/system/datetime.h index aa009974e0..e7fedbbfed 100644 --- a/util/system/datetime.h +++ b/util/system/datetime.h @@ -68,20 +68,20 @@ Y_FORCE_INLINE ui64 GetCycleCount() noexcept { return ((unsigned long long)lo) | (((unsigned long long)hi) << 32); #elif defined(_i386_) - extern const bool HaveRdtscp; - + extern const bool HaveRdtscp; + ui64 x; - if (HaveRdtscp) { - __asm__ volatile("rdtscp\n\t" - : "=A"(x)::"%ecx"); - } else { - __asm__ volatile("rdtsc\n\t" - : "=A"(x)); - } + if (HaveRdtscp) { + __asm__ volatile("rdtscp\n\t" + : "=A"(x)::"%ecx"); + } else { + __asm__ volatile("rdtsc\n\t" + : "=A"(x)); + } return x; #elif defined(_darwin_) return mach_absolute_time(); -#elif defined(__clang__) && !defined(_arm_) +#elif defined(__clang__) && !defined(_arm_) return __builtin_readcyclecounter(); #elif defined(_arm32_) return MicroSeconds(); diff --git a/util/system/direct_io.cpp b/util/system/direct_io.cpp index f59c54b0cb..58a72e0f48 100644 --- a/util/system/direct_io.cpp +++ b/util/system/direct_io.cpp @@ -2,7 +2,7 @@ #include <util/generic/singleton.h> #include <util/generic/yexception.h> -#include <util/system/info.h> +#include <util/system/info.h> #include "align.h" #ifdef _linux_ @@ -32,7 +32,7 @@ namespace { if (linuxVersionCode < KERNEL_VERSION(2, 4, 10)) { Alignment = 0; } else if (linuxVersionCode < KERNEL_VERSION(2, 6, 0)) { - Alignment = NSystemInfo::GetPageSize(); + Alignment = NSystemInfo::GetPageSize(); } else { // Default alignment used to be 512, but most modern devices rely on 4k physical blocks. // 4k alignment works well for both 512 and 4k blocks and doesn't require 512e support in the kernel. diff --git a/util/system/info.cpp b/util/system/info.cpp index cf6681e89a..88cd24afb2 100644 --- a/util/system/info.cpp +++ b/util/system/info.cpp @@ -183,7 +183,7 @@ size_t NSystemInfo::GetPageSize() noexcept { return sysInfo.dwPageSize; #else - return sysconf(_SC_PAGESIZE); + return sysconf(_SC_PAGESIZE); #endif } |