From 9ec105344e7ef35cdc243983a96558a65e5e21b1 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Tue, 22 May 2018 15:25:20 -0400 Subject: [PATCH] Updated Examples and Recipes (markdown) --- Examples-and-Recipes.md | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/Examples-and-Recipes.md b/Examples-and-Recipes.md index 4cef036..4b23b46 100644 --- a/Examples-and-Recipes.md +++ b/Examples-and-Recipes.md @@ -257,10 +257,10 @@ to_tm(date::zoned_seconds tp) t.tm_sec = tod.seconds().count(); t.tm_min = tod.minutes().count(); t.tm_hour = tod.hours().count(); - t.tm_mday = unsigned{ymd.day()}; - t.tm_mon = unsigned{ymd.month()} - 1; - t.tm_year = int{ymd.year()} - 1900; - t.tm_wday = unsigned{weekday{ld}}; + t.tm_mday = (ymd.day() - 0_d).count(); + t.tm_mon = (ymd.month() - January).count(); + t.tm_year = (ymd.year() - 1900_y).count(); + t.tm_wday = (weekday{ld} - Sunday).count(); t.tm_yday = (ld - local_days{ymd.year()/jan/1}).count(); t.tm_isdst = tp.get_info().save != minutes{0}; return t; @@ -275,8 +275,6 @@ The time of day is just the difference between the seconds-precision `time_point Now we just start filling out the `tm`, being careful to bias the month and year correctly. It is also good practice to first zero the entire `tm` so as to zero-out any platform-specific fields of the `tm`. -The `weekday` encoding of this library is the same encoding used in C, and so that conversion is straight forward, going from `local_days`, to `weekday`, to `unsigned`, and finally to `int`. - The computation for days-since-Jan 1 is found by simply subtracting the expression for New Years day for the current year from the already stored `local_days` value. Finally we can set `tm_isdst` to 1 if the `save` member of `sys_info` is not `0min`, and to 0 otherwise. The `sys_info` can be obtained from the `zoned_seconds`, and contains all kinds of useful information (including the UTC offset should you want to install that into your platform-specific `tm`). @@ -705,10 +703,10 @@ std::tm to_calendar_time(std::chrono::time_point tp) result.tm_sec = tod.seconds().count(); result.tm_min = tod.minutes().count(); result.tm_hour = tod.hours().count(); - result.tm_mday = unsigned(ymd.day()); - result.tm_mon = unsigned(ymd.month()) - 1u; // Zero-based! - result.tm_year = int(ymd.year()) - 1900; - result.tm_wday = unsigned(weekday); + result.tm_mday = (ymd.day() - 0_d).count(); + result.tm_mon = (ymd.month() - January).count(); + result.tm_year = (ymd.year() - 1900_y).count(); + result.tm_wday = (weekday - Sunday).count(); result.tm_yday = daysSinceJan1.count(); result.tm_isdst = -1; // Information not available return result;