Add a type supporting dates.#1804
Merged
JinHai-CN merged 8 commits intoinfiniflow:mainfrom Sep 5, 2024
Merged
Conversation
yangzq50
suggested changes
Sep 5, 2024
| using std::chrono::ceil; | ||
| using std::chrono::days; | ||
| using std::tm; | ||
| using std::time_t; |
Member
There was a problem hiding this comment.
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)); | ||
| } |
Member
There was a problem hiding this comment.
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); |
| 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; | ||
| } |
Member
There was a problem hiding this comment.
for year and month, check https://en.cppreference.com/w/cpp/chrono/year_month_day/operator_arith
Contributor
Author
There was a problem hiding this comment.
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.
Member
|
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; |
yangzq50
approved these changes
Sep 5, 2024
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What problem does this PR solve?
Type of change