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