Skip to content

Add a type supporting dates.#1804

Merged
JinHai-CN merged 8 commits intoinfiniflow:mainfrom
vsian:main
Sep 5, 2024
Merged

Add a type supporting dates.#1804
JinHai-CN merged 8 commits intoinfiniflow:mainfrom
vsian:main

Conversation

@vsian
Copy link
Copy Markdown
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
Comment thread src/common/stl.cppm Outdated
using std::chrono::ceil;
using std::chrono::days;
using std::tm;
using std::time_t;
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Copy link
Copy Markdown
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
Copy Markdown
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
@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