Skip to content

Preserving millisecond precision in DateTime parser - #3934

Open
averyk22 wants to merge 3 commits into
mainfrom
datetime-millisecond-precision
Open

averyk22 wants to merge 3 commits into
mainfrom
datetime-millisecond-precision

Conversation

@averyk22

@averyk22 averyk22 commented Sep 21, 2026

Copy link
Copy Markdown
Collaborator

Issue #, if available:

Description of changes:
Added millisecond precision to ISO_8601, ISO_8601 Basic Date Parser, and the AutoDetect path.

Check all that applies:

  • Did a review by yourself.
  • Added proper tests to cover this PR. (If tests are not applicable, explain.)
  • Checked if this PR is a breaking (APIs have been changed) change.
  • Checked if this PR will not introduce cross-platform inconsistent behavior.
  • Checked if this PR would require a ReadMe/Wiki update.

Check which platforms you have built SDK on to verify the correctness of this PR.

  • Linux
  • Windows
  • Android
  • MacOS
  • IOS
  • Other Platforms

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@@ -1529,6 +1535,7 @@ void DateTime::ConvertTimestampStringToTimePoint(const char* timestamp, DateForm
if (IsSecondsSinceEpochRepresentable(tt))
{
m_time = std::chrono::system_clock::from_time_t(tt);
m_time += std::chrono::milliseconds(milliseconds);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit/minor: Time is assigned by comparing to how long it has been since 1970, an edgecase of date before 1970 would render a negative number. if m_time is negative, % 1000 on a negative number stays negative.

Fix: floor when splitting into seconds + ms so the fraction is always 0–999

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

not sure if this is a valid case, can you create a string such that a negative value for a millisecond exists? the state machine should take care of that.

@@ -405,6 +406,7 @@ class DateParser
bool m_utcAssumed;
// The size should be at least one byte greater than the maximum possible size so that we could use the last char to indicate the end of the string.
char m_tz[7];
int m_milliseconds;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: i know its inited to zero in the constructor however just make this int m_milliseconds{0}; to avoid issues in the the future. int x does NOT guarantee x will be 0. the constructor value make sure now, but if another constructor is added, this will be a easy miss.

{
DateTime gmtDate("2026-09-15T18:00:00.016Z", DateFormat::ISO_8601);
ASSERT_TRUE(gmtDate.WasParseSuccessful());
ASSERT_EQ(16, gmtDate.Millis() % 1000);

@sbiscigl sbiscigl Sep 22, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

shouldn't gmtDate.Millis() be 16? and not gmtDate.Millis() % 1000? 2026-09-15T18:00:00.016Z means that theres .016 seconds on the time meaning 16 miliseconds. shouldnt we not need the modulo operation on it? let me know if im mistaken Millis in this context is epoch millis not millis of datetime

@averyk22
averyk22 enabled auto-merge September 23, 2026 20:14
@averyk22
averyk22 disabled auto-merge September 23, 2026 20:14

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants