Fixed DST handling by moving to timeofday#2503
Merged
Hydrocharged merged 1 commit intomainfrom Mar 28, 2026
Merged
Conversation
timeofday
Contributor
|
Contributor
|
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.
time.Timeserialization and deserialization can cause information to be irreversibly lost due to daylight savings time changes. The location isn't directly serialized due to it being tied to the runtime system information (different operating systems may have different time zone information), and is therefore reconstructed on deserialization.This is fine for
timestamptz, as we internally process everything as UTC and use the client's timezone when returning values to the client. Fortimetz, however, the timezone information is embedded in the value itself and is independent of the client, and this was causing information loss during serialization. This PR changes serialization to use thetimetz.TimeTZtype, which is already used at most steps (by castingtime.Timetotimetz.TimeTZand vice-versa), and therefore the change propagates to all functions that take atimetzvalue.In line with this, the
timetype was updated to usetimeofday.TimeOfDay, which is also already used internally in most functions. Although serialization is fine, this was changed to be more inline withtimetz(astimetz.TimeTZdirectly usestimeofday.TimeOfDay) and also due totime.Timecarrying implicit information that can cause direct value comparisons to be incorrect. For example,'01:00:00'::timeshould sort before'02:00:00'::time, however adding 24 hours to the first value will still result in the correct hour mark for display, but internally thetime.Timevalue would be on the next day, and would cause the comparison to actually show'02:00:00'::timeappearing first (assuming they started on the same day to begin with).All of these issues are fixed by using the correct types that are already in Doltgres, and already used by the internal functions. I'm not sure why we decided to use
time.Timeinstead of those anyway (asintervaluses the internal type rather than casting totime.Duration), but this fixes it. This does mean that the serialization is incompatible with existing databases, however since serialization was incorrect in the first place, it's a necessary change.