-
Notifications
You must be signed in to change notification settings - Fork 382
Add a type supporting dates. #1804
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
src/common/stl.cppm
Outdated
using std::chrono::year_month_day; | ||
using std::chrono::sys_days; | ||
using std::chrono::system_clock; | ||
|
||
using std::chrono::ceil; | ||
using std::chrono::days; | ||
using std::tm; | ||
using std::time_t; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove unused tm, time_t, mktime
int32_t year{0}, month{0}, day{0}; | ||
if (!Date2YMD(value, year, month, day)) { | ||
ParserError(std::format("Invalid date: {}-{}-{}", year, month, day)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
try to use operator<< of year_month_day
year = static_cast<int>(ymd.year()); | ||
month = static_cast<unsigned>(ymd.month()); | ||
day = static_cast<unsigned>(ymd.day()); | ||
return IsDateValid(year, month, day); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return ymd.ok() ?
std::chrono::sys_days output_sd(std::chrono::days{input.value} + std::chrono::duration_cast<std::chrono::days>(std::chrono::years{interval.value})); | ||
output.value = output_sd.time_since_epoch().count(); | ||
return true; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for year and month, check https://en.cppreference.com/w/cpp/chrono/year_month_day/operator_arith
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to clarify, when using std::chrono::year_month_day, "2020-1-30" + 1 month will yield "2020-2-30", then it will be adjusted to "2020-03-01", is this behavior desired? It seems that the original pull request matches the functionalities of previously existing type DateT.
If the new type is ready for application, you can edit internal_types.h: // Date and Time
// Date and Time
using DateT_Old = DateType;
using DateT = DateTypeStd; |
What problem does this PR solve?
Type of change