mirror of
https://github.com/HowardHinnant/date.git
synced 2025-08-05 13:44:26 +02:00
Rename day_point to sys_days
@@ -110,7 +110,7 @@ look if ported to this library.
|
||||
auto d = year(y)/m/day;
|
||||
if (!d.ok())
|
||||
throw std::exception{};
|
||||
auto birthday = day_point(d);
|
||||
auto birthday = sys_days(d);
|
||||
auto today = floor<days>(current_zone()
|
||||
->to_local(system_clock::now()).first);
|
||||
auto days_alive = today - birthday;
|
||||
@@ -143,11 +143,11 @@ look if ported to this library.
|
||||
auto today = floor<days>(current_zone()->
|
||||
to_local(system_clock::now()).first);
|
||||
auto current_year = year_month_day{today}.year();
|
||||
auto days_since_year_start = today - day_point(current_year/jan/1);
|
||||
auto days_since_year_start = today - sys_days(current_year/jan/1);
|
||||
std::cout << "Days since Jan 1: "
|
||||
<< days_since_year_start.count() << '\n';
|
||||
auto days_until_year_start =
|
||||
day_point((current_year + years{1})/jan/1) - today;
|
||||
sys_days((current_year + years{1})/jan/1) - today;
|
||||
std::cout << "Days until next Jan 1: "
|
||||
<< days_until_year_start.count() << '\n';
|
||||
}
|
||||
@@ -262,11 +262,11 @@ look if ported to this library.
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
std::vector<date::day_point>
|
||||
std::vector<date:: sys_days>
|
||||
generate_holidays(date::year y)
|
||||
{
|
||||
using namespace date;
|
||||
std::vector<day_point> holidays;
|
||||
std::vector< sys_days> holidays;
|
||||
holidays.push_back(y/jan/1); // Western New Year
|
||||
holidays.push_back(y/jul/4); // US Independence Day
|
||||
holidays.push_back(y/dec/25); // Christmas day
|
||||
@@ -362,7 +362,7 @@ look if ported to this library.
|
||||
using namespace std::chrono;
|
||||
using namespace date;
|
||||
|
||||
auto d = day_point(2002_y/feb/1); // an arbitrary date;
|
||||
auto d = sys_days(2002_y/feb/1); // an arbitrary date;
|
||||
// construct a time by adding up some durations durations
|
||||
auto t1 = d + 5h + 4min + 2s + 1ms;
|
||||
// construct a new time by subtracting some times
|
||||
@@ -411,7 +411,7 @@ look if ported to this library.
|
||||
using namespace std::chrono;
|
||||
using namespace date;
|
||||
auto zone = current_zone();
|
||||
auto t10 = day_point(2002_y/jan/1) + 7h;
|
||||
auto t10 = sys_days(2002_y/jan/1) + 7h;
|
||||
auto t11 = zone->to_local(t10);
|
||||
std::cout << "UTC <--> Zone base on current setting\n";
|
||||
std::cout << t11.first << ' ' << t11.second << " is "
|
||||
@@ -422,7 +422,7 @@ look if ported to this library.
|
||||
// eastern timezone is utc-5
|
||||
zone = locate_zone("America/New_York");
|
||||
// 5 hours b/f midnight NY time
|
||||
auto t1 = day_point(2001_y/dec/31) + 19h + 0s;
|
||||
auto t1 = sys_days(2001_y/dec/31) + 19h + 0s;
|
||||
std::cout << "\nUTC <--> New York while DST is NOT active (5 hours)\n";
|
||||
auto t2 = zone->to_sys(t1);
|
||||
std::cout << t1 << " in New York is " << t2 << " UTC time\n";
|
||||
@@ -431,7 +431,7 @@ look if ported to this library.
|
||||
std::cout << t2 << " UTC is " << t3 << " New York time\n\n";
|
||||
|
||||
// 4 hours b/f midnight NY time
|
||||
auto t4 = day_point(2002_y/may/31) + 20h + 0s;
|
||||
auto t4 = sys_days(2002_y/may/31) + 20h + 0s;
|
||||
std::cout << "UTC <--> New York while DST is active (4 hours)\n";
|
||||
auto t5 = zone->to_sys(t4);
|
||||
std::cout << t4 << " in New York is " << t5 << " UTC time\n";
|
||||
@@ -441,7 +441,7 @@ look if ported to this library.
|
||||
|
||||
// Arizona timezone is utc-7 with no dst
|
||||
zone = locate_zone("America/Phoenix");
|
||||
auto t7 = day_point(2002_y/may/31) + 17h + 0s;
|
||||
auto t7 = sys_days(2002_y/may/31) + 17h + 0s;
|
||||
std::cout << "UTC <--> Arizona (7 hours)\n";
|
||||
auto t8 = zone->to_sys(t7);
|
||||
std::cout << t7 << " in Arizona is " << t8 << " UTC time\n";
|
||||
@@ -458,7 +458,7 @@ look if ported to this library.
|
||||
{
|
||||
using namespace std::chrono;
|
||||
using namespace date;
|
||||
auto d = day_point(2002_y/feb/1); // an arbitrary date
|
||||
auto d = sys_days(2002_y/feb/1); // an arbitrary date
|
||||
auto t = d + 3h + 5s; //an arbitray time on that day
|
||||
if (d <= t && t < d + days{1})
|
||||
std::cout << d << " contains " << t << '\n';
|
||||
@@ -514,7 +514,7 @@ an example using the IANA timezone database see the [Local to UTC Conversion](#L
|
||||
|
||||
// local departure time in phoenix is 11 pm on March 30 2005
|
||||
// (ny changes to dst on apr 3 at 2 am)
|
||||
auto phx_departure = day_point(2005_y/mar/30) + 23h + 0min;
|
||||
auto phx_departure = sys_days(2005_y/mar/30) + 23h + 0min;
|
||||
auto utc_departure = phx_tz->to_sys(phx_departure);
|
||||
|
||||
auto flight_length = 4h + 30min;
|
||||
@@ -557,9 +557,9 @@ an example using the IANA timezone database see the [Local to UTC Conversion](#L
|
||||
using namespace date;
|
||||
|
||||
auto nyc_tz = locate_zone("America/New_York");
|
||||
auto nyc_time = day_point(2004_y/oct/4) + 12h + 14min + 32s;
|
||||
auto nyc_time = sys_days(2004_y/oct/4) + 12h + 14min + 32s;
|
||||
std::cout << nyc_time << '\n';
|
||||
auto time_t_epoch = day_point(1970_y/1/1);
|
||||
auto time_t_epoch = sys_days(1970_y/1/1);
|
||||
std::cout << time_t_epoch << '\n';
|
||||
|
||||
// first convert nyc_time to utc via the utc_time()
|
||||
|
Reference in New Issue
Block a user