Skip to content

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

Merged
merged 8 commits into from
Sep 5, 2024
Merged

Add a type supporting dates. #1804

merged 8 commits into from
Sep 5, 2024

Conversation

vsian
Copy link
Contributor

@vsian vsian commented Sep 4, 2024

What problem does this PR solve?

  1. Add a date type DateStdT which supports date functionalities using only std::chrono libraries.
  2. Add corresponding test cases.
  3. Remove C types from test for existing date type DateT.

Type of change

  • New Feature (non-breaking change which adds functionality)
  • Test cases

@vsian vsian added the ci PR can be test label Sep 4, 2024
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;
Copy link
Member

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));
}
Copy link
Member

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);
Copy link
Member

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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

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.

@yangzq50
Copy link
Member

yangzq50 commented Sep 5, 2024

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;

@JinHai-CN JinHai-CN merged commit cb0d0b3 into infiniflow:main Sep 5, 2024
3 checks passed
@JinHai-CN JinHai-CN mentioned this pull request Sep 11, 2024
79 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ci PR can be test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants