fix: Correct DateTime to Timestamp conversions for timezone accuracy and ensure startTimestamp uses the full order.startDate.
This commit is contained in:
@@ -171,16 +171,23 @@ class DataConnectService with DataErrorHandler, SessionHandlerMixin {
|
||||
}
|
||||
}
|
||||
|
||||
/// Converts a Data Connect [Timestamp] to a Dart [DateTime].
|
||||
/// Converts a Data Connect [Timestamp] to a Dart [DateTime] in local time.
|
||||
///
|
||||
/// Firebase Data Connect always stores and returns timestamps in UTC.
|
||||
/// Calling [toLocal] ensures the result reflects the device's timezone so
|
||||
/// that shift dates, start/end times, and formatted strings are correct for
|
||||
/// the end user.
|
||||
DateTime? toDateTime(dynamic timestamp) {
|
||||
if (timestamp == null) return null;
|
||||
if (timestamp is fdc.Timestamp) {
|
||||
return timestamp.toDateTime();
|
||||
return timestamp.toDateTime().toLocal();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/// Converts a Dart [DateTime] to a Data Connect [Timestamp].
|
||||
///
|
||||
/// Converts the [DateTime] to UTC before creating the [Timestamp].
|
||||
fdc.Timestamp toTimestamp(DateTime dateTime) {
|
||||
final DateTime utc = dateTime.toUtc();
|
||||
final int millis = utc.millisecondsSinceEpoch;
|
||||
|
||||
Reference in New Issue
Block a user