Fixes DateTime to handle extreme time zones#334
Merged
muditchaudhary merged 3 commits intocedar-policy:mainfrom Oct 23, 2025
Merged
Fixes DateTime to handle extreme time zones#334muditchaudhary merged 3 commits intocedar-policy:mainfrom
muditchaudhary merged 3 commits intocedar-policy:mainfrom
Conversation
Signed-off-by: Mudit Chaudhary <chmudit@amazon.com>
Signed-off-by: Mudit Chaudhary <chmudit@amazon.com>
shaobo-he-aws
approved these changes
Oct 2, 2025
mark-creamer-amazon
approved these changes
Oct 23, 2025
|
|
||
| long epochMillis = localDateTime.get().toInstant(ZoneOffset.UTC).toEpochMilli(); | ||
| long offsetMillis = convertOffsetToMilliseconds(sign, offsetHours, offsetMinutes); | ||
| long adjustedEpochMillis = epochMillis - offsetMillis; |
Contributor
There was a problem hiding this comment.
Had a double take as to why we're subtracting an offset here instead of adding
Contributor
Author
There was a problem hiding this comment.
Ah yeah. this does look confusing.
For example, let's take this timestamp 10/23/2025-19:00::00 UTC. This is equivalent to 1,761,246,000,000 epochMillis.
For UTC-4:00 the equivalent timestamp for the above timestamp is 10/23/2025-15:00::00 UTC-4:00. So, their epochMillis should be equal. Now, let's say we want to convert 10/23/2025-15:00::00 UTC-4:00 to epochMillis.
This is how the code will do it:
- Extract non-timezone part of the timestamp
10/23/2025-15:00::00, treat it as UTC and get its epochMillis i.e.,1,761,231,600,000.1,761,231,600,000 (10/23/2025-15:00::00)<1,761,246,000,000 (10/23/2025-19:00::00 UTC). So, this extracted epochMillis is behind the actual target value. - Calculate the millisecond offset of the timezone with sign i.e.,
-4:00=-14,400,000. - Subtract the offset millisecond from epochMillis in Step 1 i.e.,
1,761,231,600,000 - (-14,400,000) = 1761246000000 = 10/23/2025-19:00::00 UTC
So, eventually the offset is added when it is a negative offset (UTC is ahead) and subtracted when it is a positive (UTC is behind)
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.
Overview
Fixes DateTime (#328) to support extreme time zones. Java DateTIme cannot handle extreme timezones (E.g., +2359, -2359). However, these are valid in Cedar. It now support all valid Cedar Datetime values
0000-01-01T00:00:00+2359to9999-12-31T23:59:59-2359.Changes