-
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
901c5c7
485351f
0b1e037
558f2ef
ab75ea7
f239799
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,8 @@ import 'dart:convert'; | |
import 'dart:typed_data'; | ||
|
||
import 'package:meta/meta.dart'; | ||
import 'package:postgres/src/timezone_settings.dart'; | ||
|
||
|
||
import '../buffer.dart'; | ||
import '../time_converters.dart'; | ||
|
@@ -69,6 +71,9 @@ class ParameterStatusMessage extends ServerMessage { | |
factory ParameterStatusMessage.parse(PgByteDataReader reader) { | ||
final name = reader.readNullTerminatedString(); | ||
final value = reader.readNullTerminatedString(); | ||
if (name.toLowerCase() == 'timezone') { | ||
reader.timeZone.value = value; | ||
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 not update the 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. I believe that in this case it should not be immutable because when you use the SQL command "set timezone TO 'GMT';" you are changing the connection configuration, and this has to be reflected in the connection instance, because if after the user executes the SQL command to change the timezone and he reads the timezone property he will want to see the current value, right? I don't know the driver code very well, especially version 3, so I don't know if the driver user can read the timezone of the current connection through some method or property, as I have been very busy I haven't had much time to look at this, I don't know exactly how this could be done in another way. |
||
} | ||
return ParameterStatusMessage._(name, value); | ||
} | ||
} | ||
|
@@ -366,8 +371,8 @@ class XLogDataMessage implements ReplicationMessage, ServerMessage { | |
/// If [XLogDataMessage.data] is a [LogicalReplicationMessage], then the method | ||
/// will return a [XLogDataLogicalMessage] with that message. Otherwise, it'll | ||
/// return [XLogDataMessage] with raw data. | ||
static XLogDataMessage parse(Uint8List bytes, Encoding encoding) { | ||
final reader = PgByteDataReader(encoding: encoding)..add(bytes); | ||
static XLogDataMessage parse(Uint8List bytes, Encoding encoding, TimeZoneSettings timeZone) { | ||
final reader = PgByteDataReader(encoding: encoding, timeZone: timeZone)..add(bytes); | ||
final walStart = LSN(reader.readUint64()); | ||
final walEnd = LSN(reader.readUint64()); | ||
final time = dateTimeFromMicrosecondsSinceY2k(reader.readUint64()); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/// A class to configure time zone settings for decoding timestamps and dates. | ||
class TimeZoneSettings { | ||
/// The default time zone value. | ||
/// | ||
/// The [value] represents the name of the time zone location. Default is 'UTC'. | ||
String value = 'UTC'; | ||
|
||
/// Creates a new instance of [TimeZoneSettings]. | ||
/// | ||
/// [value] is the name of the time zone location. | ||
/// | ||
/// The optional named parameters: | ||
/// - [forceDecodeTimestamptzAsUTC]: if true, decodes timestamps with timezone (timestamptz) as UTC. If false, decodes them using the timezone defined in the connection. | ||
/// - [forceDecodeTimestampAsUTC]: if true, decodes timestamps without timezone (timestamp) as UTC. If false, decodes them as local datetime. | ||
/// - [forceDecodeDateAsUTC]: if true, decodes dates as UTC. If false, decodes them as local datetime. | ||
TimeZoneSettings( | ||
this.value, { | ||
this.forceDecodeTimestamptzAsUTC = true, | ||
this.forceDecodeTimestampAsUTC = true, | ||
this.forceDecodeDateAsUTC = true, | ||
}); | ||
|
||
/// If true, decodes the timestamp with timezone (timestamptz) as UTC. | ||
/// If false, decodes the timestamp with timezone using the timezone defined in the connection. | ||
bool forceDecodeTimestamptzAsUTC = true; | ||
|
||
/// If true, decodes the timestamp without timezone (timestamp) as UTC. | ||
/// If false, decodes the timestamp without timezone as local datetime. | ||
bool forceDecodeTimestampAsUTC = true; | ||
|
||
/// If true, decodes the date as UTC. | ||
/// If false, decodes the date as local datetime. | ||
bool forceDecodeDateAsUTC = true; | ||
} |
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.
Is there a reason for changing this to a switch statement? If all else being equal, let's not change this (or if this is needed, let's do this in a different PR).
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.
At first I thought I needed to change this but then I saw that it wouldn't be necessary, it turns out that I forgot to revert this change.