-
Notifications
You must be signed in to change notification settings - Fork 38
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
decode timestamp without timezone as local DateTime and decode timestamp with timezone respecting the timezone defined in the connection #342
Open
insinfo
wants to merge
6
commits into
isoos:master
Choose a base branch
from
insinfo:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
901c5c7
decode timestamp without timezone as local DateTime and decode timest…
485351f
add more flexibility on how timestamp and timestaptz types are decode…
0b1e037
add more flexibility on how timestamp and timestaptz types are decode…
558f2ef
fix define location for TZDateTime.toLocal()
ab75ea7
fix decode timestamp without timezone as local DateTime, ignore past …
f239799
extract method to create a PostgreSQL Epoch Base DateTime using the c…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -796,7 +796,15 @@ class PostgresBinaryDecoder { | |
if (dinput.timeZone.forceDecodeDateAsUTC) { | ||
return DateTime.utc(2000).add(Duration(days: value)); | ||
} | ||
return DateTime(2000).add(Duration(days: value)); | ||
// https://github.com/dart-lang/sdk/issues/56312 | ||
// ignore past timestamp transitions and use only current timestamp in local datetime | ||
final nowDt = DateTime.now(); | ||
var baseDt = DateTime(2000); | ||
if (baseDt.timeZoneOffset != nowDt.timeZoneOffset) { | ||
final difference = baseDt.timeZoneOffset - nowDt.timeZoneOffset; | ||
baseDt = baseDt.add(difference); | ||
} | ||
return baseDt.add(Duration(days: value)); | ||
case TypeOid.timestampWithoutTimezone: | ||
final value = buffer.getInt64(0); | ||
//infinity || -infinity | ||
|
@@ -807,7 +815,15 @@ class PostgresBinaryDecoder { | |
if (dinput.timeZone.forceDecodeTimestampAsUTC) { | ||
return DateTime.utc(2000).add(Duration(microseconds: value)); | ||
} | ||
return DateTime(2000).add(Duration(microseconds: value)); | ||
// https://github.com/dart-lang/sdk/issues/56312 | ||
// ignore previous timestamp transitions and use only the current system timestamp in local date and time so that the behavior is correct on Windows and Linux | ||
final nowDt = DateTime.now(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's extract these two into a method that does the correction. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes definitely |
||
var baseDt = DateTime(2000); | ||
if (baseDt.timeZoneOffset != nowDt.timeZoneOffset) { | ||
final difference = baseDt.timeZoneOffset - nowDt.timeZoneOffset; | ||
baseDt = baseDt.add(difference); | ||
} | ||
return baseDt.add(Duration(microseconds: value)); | ||
|
||
case TypeOid.timestampWithTimezone: | ||
final value = buffer.getInt64(0); | ||
|
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering, without fully seeing the context, if this operation is always valid. E.g. can this be close to or larger than a full day? Or instead of substracting a half hour, are we adding 23.5 hours, just because of a strange combination?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe that there will not be this problem because the timezone transitions of the past are more related to the daylight saving time of countries that by law no longer have daylight saving time.