diff --git a/date.html b/date.html index a50b68d..11a9a40 100644 --- a/date.html +++ b/date.html @@ -26,7 +26,7 @@

Howard E. Hinnant
-2018-03-03
+2018-06-02

date

@@ -162,9 +162,9 @@ in order to cut down on the verbosity.

-constexpr auto x1 = 2015_y/mar/22;
-constexpr auto x2 = mar/22/2015;
-constexpr auto x3 = 22_d/mar/2015;
+constexpr auto x1 = 2015_y/March/22;
+constexpr auto x2 = March/22/2015;
+constexpr auto x3 = 22_d/March/2015;
 

@@ -223,9 +223,9 @@ to indicate the last day of the month for that year:

-constexpr auto x1 = 2015_y/feb/last;
-constexpr auto x2 = feb/last/2015;
-constexpr auto x3 = last/feb/2015;
+constexpr auto x1 = 2015_y/February/last;
+constexpr auto x2 = February/last/2015;
+constexpr auto x3 = last/February/2015;
 

@@ -248,9 +248,9 @@ Anywhere you can specify a day you can instead specify an indexe

-constexpr auto x1 = 2015_y/mar/sun[4];
-constexpr auto x2 = mar/sun[4]/2015;
-constexpr auto x3 = sun[4]/mar/2015;
+constexpr auto x1 = 2015_y/March/Sunday[4];
+constexpr auto x2 = March/Sunday[4]/2015;
+constexpr auto x3 = Sunday[4]/March/2015;
 

@@ -271,9 +271,9 @@ constexpr auto x4 = year_month_day{x3};

-constexpr auto x1 = 2015_y/mar/sun[last];
-constexpr auto x2 = mar/sun[last]/2015;
-constexpr auto x3 = sun[last]/mar/2015;
+constexpr auto x1 = 2015_y/March/Sunday[last];
+constexpr auto x2 = March/Sunday[last]/2015;
+constexpr auto x3 = Sunday[last]/March/2015;
 constexpr auto x4 = year_month_day{x3};
 cout << x3 << '\n';
 cout << x4 << '\n';
@@ -299,7 +299,7 @@ API.
 

-constexpr auto x1 = 2015_y/mar/sun[last];
+constexpr auto x1 = 2015_y/March/Sunday[last];
 constexpr auto x2 = year_month_weekday_last{year{2015}, month{3u}, weekday_last{weekday{0u}}};
 static_assert(x1 == x2,                                   "No matter the API, x1 and x2 have the same value ...");
 static_assert(is_same<decltype(x1), decltype(x2)>::value, "... and are the same type");
@@ -436,7 +436,7 @@ int
 main()
 {
     using namespace date;
-    std::cout << weekday{jul/4/2001} << '\n';
+    std::cout << weekday{July/4/2001} << '\n';
 }
 
@@ -459,7 +459,7 @@ int main() { using namespace date; - static_assert(weekday{2001_y/jul/4} == wed, ""); + static_assert(weekday{2001_y/July/4} == Wednesday, ""); }
@@ -489,7 +489,7 @@ main() using namespace date; for (auto m = 1; m <= 12; ++m) { - auto meet = year_month_day{m/fri[1]/2015}; + auto meet = year_month_day{m/Friday[1]/2015}; cout << meet << '\n'; meet = meet.year()/meet.month()/(meet.day()+weeks{2}); cout << meet << '\n'; @@ -808,7 +808,7 @@ involves shifting the epoch to Jan. 1, 1970.
- + @@ -898,7 +898,7 @@ seconds between these two epochs ... who knew?

clang generates identical assembly for these two functions at -O2 and higher. That -is, the sub-expression (sys_days(jan/1/2000) - sys_days(jan/1/1970)) is +is, the sub-expression (sys_days(January/1/2000) - sys_days(January/1/1970)) is reduced down to a number of days (10,957) at compile time, and then this sub-expression, which has type days is added to a time_point with a resolution of seconds, which causes the compiler to convert @@ -1042,8 +1042,8 @@ utc_offset_Eastern_US(std::chrono::system_clock::time_point tp) constexpr auto EST = -5h; constexpr auto EDT = -4h; const auto y = year_month_day{floor<days>(tp)}.year(); - const auto begin = sys_days{sun[2]/mar/y} + 2h - EST; // EDT begins at this UTC time - const auto end = sys_days{sun[1]/nov/y} + 2h - EDT; // EST begins at this UTC time + const auto begin = sys_days{Sunday[2]/March/y} + 2h - EST; // EDT begins at this UTC time + const auto end = sys_days{Sunday[1]/November/y} + 2h - EDT; // EST begins at this UTC time if (tp < begin || end <= tp) return EST; return EDT; @@ -1078,7 +1078,7 @@ std::cout << ymd << ' ' << time << '\n';

The hub of this library is sys_days. This is a serial-based time -point which simply counts the days since (or before) jan/1/1970. And +point which simply counts the days since (or before) January/1/1970. And ironically this all important hub is nothing but a type alias to a std-defined type. That is, the central theme this library is built around is nothing more than this:

@@ -1122,7 +1122,7 @@ public: constexpr operator date::sys_days() const noexcept { using namespace date; - return iso_week_start(y_) + w_ - weeks{1} + (wd_ - mon); + return iso_week_start(y_) + w_ - weeks{1} + (wd_ - Monday); } friend std::ostream& operator<<(std::ostream& os, const iso_week& x) @@ -1137,7 +1137,7 @@ private: iso_week_start(date::year y) noexcept { using namespace date; - return sys_days{thu[1]/jan/y} - (thu-mon); + return sys_days{Thursday[1]/January/y} - (Thursday-Monday); } static @@ -1199,16 +1199,16 @@ to rule 2, this can be elegantly coded as:

-return sys_days{thu[1]/jan/y} - (thu-mon);
+return sys_days{Thursday[1]/January/y} - (Thursday-Monday);
 

That is, first find the first Thursday in January for year y, and then subtract the number of days required to find the Monday before this day. This could have been done -with days{3}. But I chose to code this as (thu-mon). +with days{3}. But I chose to code this as (Thursday-Monday). Computationally and performance wise, these two choices are identical: they both subtract the literal 3. I chose the latter because I believe it to be more readable. -"3" is just a magic constant. But "(thu-mon)" is the number of +"3" is just a magic constant. But "(Thursday-Monday)" is the number of days Thursday is past Monday.

@@ -1217,7 +1217,7 @@ The constructor iso_week(date::sys_days dp) has to first discover w ISO week-based year the sys_days dp falls into. Most often this is the same as the civil (year_month_day) year number associated dp. But because the week-based year may start a few days earlier or later than -jan/1, the week-based year number may be one less or one greater than the +January/1, the week-based year number may be one less or one greater than the civil year number associated dp. Once the proper start of the week-based year is nailed down (in start), the translation to the field-based iso_week is trivial: @@ -1232,7 +1232,7 @@ The conversion from iso_week to sys_days is even easie

-return iso_week_start(y_) + w_ - weeks{1} + (wd_ - mon);
+return iso_week_start(y_) + w_ - weeks{1} + (wd_ - Monday);
 

@@ -1332,7 +1332,7 @@ limit(const std::string& msg) using namespace std; using namespace std::chrono; using dsecs = sys_time<duration<double>>; - constexpr auto ymin = sys_days{year::min()}/jan/1}; + constexpr auto ymin = sys_days{year::min()}/January/1}; constexpr auto ymax = sys_days{year::max()}/12/last}; constexpr auto dmin = sys_time<D>::min(); constexpr auto dmax = sys_time<D>::max(); @@ -1611,7 +1611,7 @@ operator<<(std::basic_ostream<CharT, Traits>& os, const local_ti

Everything here is contained in the namespace date. The literal operators, -and the constexpr field literals (e.g. sun, jan, etc.) are +and the constexpr field literals (e.g. Sunday, January, etc.) are in namespace date::literals and imported into namespace date.

@@ -1898,9 +1898,9 @@ referring to UTC.

For example, we can say that the upcoming 2017 New Years will be commonly -celebrated at local_time<days>{2017_y/jan/1} + 0s. For those +celebrated at local_time<days>{2017_y/January/1} + 0s. For those in a time zone with a zero offset from UTC, it will be celebrated at the -concrete time of sys_days{2017_y/jan/1} + 0s. These two timestamps +concrete time of sys_days{2017_y/January/1} + 0s. These two timestamps have different types, though both have the exact same representation (a count of seconds), because they mean two subtly different things, and are both quite useful. @@ -1920,7 +1920,7 @@ template <class Duration>

local_days is a convient way to write local_time<days>. The upcoming 2017 New Years will be commonly celebrated at -local_days{2017_y/jan/1} + 0s. +local_days{2017_y/January/1} + 0s.

@@ -2433,18 +2433,18 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, m
             std::chrono::minutes* offset = nullptr);
 
 inline namespace literals {
-constexpr month jan{1};
-constexpr month feb{2};
-constexpr month mar{3};
-constexpr month apr{4};
-constexpr month may{5};
-constexpr month jun{6};
-constexpr month jul{7};
-constexpr month aug{8};
-constexpr month sep{9};
-constexpr month oct{10};
-constexpr month nov{11};
-constexpr month dec{12};
+constexpr month January{1};
+constexpr month February{2};
+constexpr month March{3};
+constexpr month April{4};
+constexpr month May{5};
+constexpr month June{6};
+constexpr month July{7};
+constexpr month August{8};
+constexpr month September{9};
+constexpr month October{10};
+constexpr month November{11};
+constexpr month December{12};
 }
 
@@ -2662,7 +2662,7 @@ and month{13} becomes month{1}. — end note

-Example: feb + months{11} == jan. +Example: February + months{11} == January.

@@ -2702,7 +2702,7 @@ the returned value m shall satisfy the equality: y + m == x.

-Example: jan - feb == months{11} . +Example: January - February == months{11} .

@@ -3249,15 +3249,13 @@ from_stream(std::basic_istream<CharT, Traits>& is, const CharT* fmt, w std::basic_string<CharT, Traits, Alloc>* abbrev = nullptr, std::chrono::minutes* offset = nullptr); -inline namespace literals { -constexpr weekday sun{0}; -constexpr weekday mon{1}; -constexpr weekday tue{2}; -constexpr weekday wed{3}; -constexpr weekday thu{4}; -constexpr weekday fri{5}; -constexpr weekday sat{6}; -} +constexpr weekday Sunday{0}; +constexpr weekday Monday{1}; +constexpr weekday Tuesday{2}; +constexpr weekday Wednesday{3}; +constexpr weekday Thursday{4}; +constexpr weekday Friday{5}; +constexpr weekday Saturday{6};

Overview

@@ -3501,7 +3499,7 @@ arithmetic. [Note: For example weekday{7} becomes increments or decrements is not a valid implementation.

-Example: mon + days{6} == sun. +Example: Monday + days{6} == Sunday.

@@ -3541,7 +3539,7 @@ the returned value d shall satisfy the equality: y + d == x.

-Example: sun - mon == days{6}. +Example: Sunday - Monday == days{6}.

@@ -3651,8 +3649,8 @@ weekday of a month. It is most easily constructed by indexing a weekday
-constexpr auto wdi = sun[2];  // wdi is the second Sunday of an as yet unspecified month
-static_assert(wdi.weekday() == sun);
+constexpr auto wdi = Sunday[2];  // wdi is the second Sunday of an as yet unspecified month
+static_assert(wdi.weekday() == Sunday);
 static_assert(wdi.index() == 2);
 
@@ -3786,8 +3784,8 @@ It is most easily constructed by indexing a weekday with last

-constexpr auto wdl = sun[last];  // wdl is the last Sunday of an as yet unspecified month
-static_assert(wdl.weekday() == sun);
+constexpr auto wdl = Sunday[last];  // wdl is the last Sunday of an as yet unspecified month
+static_assert(wdl.weekday() == Sunday);
 

@@ -3971,7 +3969,7 @@ constexpr bool month_day::ok() const noexcept;

Returns: true if m_.ok() is true, and if 1_d <= d_, and if d_ <= the number of days in month -m_. For m_ == feb the number of days is considered to be 29. +m_. For m_ == February the number of days is considered to be 29. Otherwise returns false.

@@ -4146,8 +4144,8 @@ It is most easily constructed using the expression m/last or

-constexpr auto mdl = feb/last;  // mdl is the last day of February of an as yet unspecified year
-static_assert(mdl.month() == feb);
+constexpr auto mdl = February/last;  // mdl is the last day of February of an as yet unspecified year
+static_assert(mdl.month() == February);
 

@@ -5140,9 +5138,9 @@ back to a sys_days. [Example:

-static_assert(year_month_day{sys_days{2017y/jan/0}}  == 2016y/dec/31);
-static_assert(year_month_day{sys_days{2017y/jan/31}} == 2017y/jan/31);
-static_assert(year_month_day{sys_days{2017y/jan/32}} == 2017y/feb/1);
+static_assert(year_month_day{sys_days{2017y/January/0}}  == 2016y/December/31);
+static_assert(year_month_day{sys_days{2017y/January/31}} == 2017y/January/31);
+static_assert(year_month_day{sys_days{2017y/January/32}} == 2017y/February/1);
 

end example] @@ -5283,7 +5281,7 @@ constexpr year_month_day operator+(const year_month_day& ymd, const years&am Returns: (ymd.year() + dy) / ymd.month() / ymd.day().

-Remarks: If ymd.month() is feb and ymd.day() +Remarks: If ymd.month() is February and ymd.day() is not in the range [1_d, 28_d], the resultant year_month_day is not guaranteed to return true from ok().

@@ -6435,9 +6433,9 @@ example:

-year_month ym = 2015_y/apr;
-month_day md1 = apr/4;
-month_day md2 = 4_d/apr;
+year_month ym = 2015_y/April;
+month_day md1 = April/4;
+month_day md2 = 4_d/April;
 

@@ -6449,8 +6447,8 @@ has type int.

 auto a = 2015/4/4;       // a == int(125)
 auto b = 2015_y/4/4;     // b == year_month_day{year(2015), month(4), day(4)}
-auto c = 2015_y/4_d/apr; // error: invalid operands to binary expression ('date::year' and 'date::day')
-auto d = 2015/apr/4;     // error: invalid operands to binary expression ('int' and 'const date::month')
+auto c = 2015_y/4_d/April; // error: invalid operands to binary expression ('date::year' and 'date::day')
+auto d = 2015/April/4;     // error: invalid operands to binary expression ('int' and 'const date::month')
 

diff --git a/tz.html b/tz.html index b1e4f31..da51358 100644 --- a/tz.html +++ b/tz.html @@ -26,7 +26,7 @@

Howard E. Hinnant
-2018-03-22
+2018-06-02


Time Zone Database Parser

@@ -330,7 +330,7 @@ main() { using namespace date::literals; using namespace std::chrono_literals; - auto meet_nyc = make_zoned("America/New_York", date::local_days{mon[1]/may/2016} + 9h); + auto meet_nyc = make_zoned("America/New_York", date::local_days{Monday[1]/May/2016} + 9h); auto meet_lon = make_zoned("Europe/London", meet_nyc); auto meet_syd = make_zoned("Australia/Sydney", meet_nyc); std::cout << "The New York meeting is " << meet_nyc << '\n'; @@ -352,7 +352,7 @@ The Sydney meeting is 2016-05-02 23:00:00 AEST

The first time, meet_nyc is a pairing of a time zone ("America/New_York") -with a local time (mon[1]/may/2016 at 09:00). Note that this +with a local time (Monday[1]/May/2016 at 09:00). Note that this input is exactly reflected in the output:

@@ -393,7 +393,7 @@ local times. This is called a local_time.

-auto new_years = local_time<days>{2017_y/jan/1} + 0h + 0m + 0s;
+auto new_years = local_time<days>{2017_y/January/1} + 0h + 0m + 0s;
 

@@ -431,7 +431,7 @@ In summary: When is 1min after New Years 2017?

-auto t = local_days{jan/1/2017} + 1min;
+auto t = local_days{January/1/2017} + 1min;
 cout << t << '\n';  // 2017-01-01 00:01
 
@@ -440,7 +440,7 @@ When is 1min after New Years 2017 UTC?

-auto t = sys_days{jan/1/2017} + 1min;
+auto t = sys_days{January/1/2017} + 1min;
 cout << t << '\n';  // 2017-01-01 00:01
 
@@ -457,7 +457,7 @@ When is 1min after New Years 2017 in New York?

-zoned_seconds t{"America/New_York", local_days{jan/1/2017} + 1min};
+zoned_seconds t{"America/New_York", local_days{January/1/2017} + 1min};
 cout << t << '\n';  // 2017-01-01 00:01:00 EST
 
@@ -466,7 +466,7 @@ What time will it be in New York when it is 1min after New Years 2017 UTC?

-zoned_seconds t{"America/New_York", sys_days{jan/1/2017} + 1min};
+zoned_seconds t{"America/New_York", sys_days{January/1/2017} + 1min};
 cout << t << '\n';  // 2016-12-31 19:01:00 EST
 
@@ -578,7 +578,7 @@ main() using namespace std::chrono_literals; using namespace date; - auto departure = make_zoned("America/New_York", local_days{dec/30/1978} + 12h + 1min); + auto departure = make_zoned("America/New_York", local_days{December/30/1978} + 12h + 1min); auto flight_length = 14h + 44min; auto arrival = make_zoned("Asia/Tehran", departure.get_sys_time() + flight_length); @@ -620,7 +620,7 @@ line to look at the same flight 24 hours later:

-auto departure = make_zoned("America/New_York", local_days{dec/31/1978} + 12h + 1min);
+auto departure = make_zoned("America/New_York", local_days{December/31/1978} + 12h + 1min);
 

@@ -652,7 +652,7 @@ main() using namespace std::chrono; using namespace date; - auto departure = make_zoned("America/New_York", local_days{dec/31/1978} + 12h + 1min); + auto departure = make_zoned("America/New_York", local_days{December/31/1978} + 12h + 1min); auto departure_utc = clock_cast<utc_clock>(departure.get_sys_time()); auto flight_length = 14h + 44min; auto arrival = make_zoned("Asia/Tehran", clock_cast<system_clock>(departure_utc + flight_length)); @@ -1553,7 +1553,7 @@ main() using namespace std::chrono_literals; try { - auto zt = make_zoned("America/New_York", local_days{sun[2]/mar/2016} + 2h + 30min); + auto zt = make_zoned("America/New_York", local_days{Sunday[2]/March/2016} + 2h + 30min); } catch (const nonexistent_local_time& e) { @@ -1633,7 +1633,7 @@ main() using namespace std::chrono_literals; try { - auto zt = make_zoned("America/New_York", local_days{sun[1]/nov/2016} + 1h + 30min); + auto zt = make_zoned("America/New_York", local_days{Sunday[1]/November/2016} + 1h + 30min); } catch (const ambiguous_local_time& e) { @@ -2939,7 +2939,7 @@ to_utc(const std::chrono::time_point<tai_clock, Duration>& t) noexcept Returns: utc_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 378691210s

-Note: 378691210s == sys_days{1970y/jan/1} - sys_days{1958y/jan/1} + 10s +Note: 378691210s == sys_days{1970y/January/1} - sys_days{1958y/January/1} + 10s

@@ -2954,7 +2954,7 @@ tai_clock::from_utc(const utc_time<Duration>& t) noexcept; Returns: tai_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 378691210s

-Note: 378691210s == sys_days{1970y/jan/1} - sys_days{1958y/jan/1} + 10s +Note: 378691210s == sys_days{1970y/January/1} - sys_days{1958y/January/1} + 10s

@@ -3083,7 +3083,7 @@ gps_clock::to_utc(const gps_time<Duration>& t) noexcept; Returns: gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} + 315964809s

-Note: 315964809s == sys_days{1980y/jan/sun[1]} - sys_days{1970y/jan/1} + 9s +Note: 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s

@@ -3098,7 +3098,7 @@ gps_clock::from_utc(const utc_time<Duration>& t) noexcept; Returns: gps_time<common_type_t<Duration, seconds>>{t.time_since_epoch()} - 315964809s

-Note: 315964809s == sys_days{1980y/jan/sun[1]} - sys_days{1970y/jan/1} + 9s +Note: 315964809s == sys_days{1980y/January/Sunday[1]} - sys_days{1970y/January/1} + 9s

@@ -3180,7 +3180,7 @@ main() { using namespace date; using namespace std::chrono; - auto start = clock_cast<utc_clock>(sys_days{2015_y/jul/1} - 500ms); + auto start = clock_cast<utc_clock>(sys_days{2015_y/July/1} - 500ms); auto end = start + 2s; for (auto utc = start; utc < end; utc += 100ms) {
Shift epoch from jan/1/2000 to jan/1/1970Shift epoch from January/1/2000 to January/1/1970
@@ -820,7 +820,7 @@ time_point shift_epoch(time_point t) { using namespace date; - return t + (sys_days(jan/1/2000) - sys_days(jan/1/1970)); + return t + (sys_days(January/1/2000) - sys_days(January/1/1970)); }