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) {
|
DateTime? toDateTime(dynamic timestamp) {
|
||||||
if (timestamp == null) return null;
|
if (timestamp == null) return null;
|
||||||
if (timestamp is fdc.Timestamp) {
|
if (timestamp is fdc.Timestamp) {
|
||||||
return timestamp.toDateTime();
|
return timestamp.toDateTime().toLocal();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Converts a Dart [DateTime] to a Data Connect [Timestamp].
|
/// Converts a Dart [DateTime] to a Data Connect [Timestamp].
|
||||||
|
///
|
||||||
|
/// Converts the [DateTime] to UTC before creating the [Timestamp].
|
||||||
fdc.Timestamp toTimestamp(DateTime dateTime) {
|
fdc.Timestamp toTimestamp(DateTime dateTime) {
|
||||||
final DateTime utc = dateTime.toUtc();
|
final DateTime utc = dateTime.toUtc();
|
||||||
final int millis = utc.millisecondsSinceEpoch;
|
final int millis = utc.millisecondsSinceEpoch;
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ class ClientCreateOrderRepositoryImpl
|
|||||||
order.startDate.day,
|
order.startDate.day,
|
||||||
);
|
);
|
||||||
final Timestamp orderTimestamp = _service.toTimestamp(orderDateOnly);
|
final Timestamp orderTimestamp = _service.toTimestamp(orderDateOnly);
|
||||||
final Timestamp startTimestamp = orderTimestamp;
|
final Timestamp startTimestamp = _service.toTimestamp(order.startDate);
|
||||||
final Timestamp endTimestamp = _service.toTimestamp(order.endDate);
|
final Timestamp endTimestamp = _service.toTimestamp(order.endDate);
|
||||||
|
|
||||||
final OperationResult<dc.CreateOrderData, dc.CreateOrderVariables>
|
final OperationResult<dc.CreateOrderData, dc.CreateOrderVariables>
|
||||||
@@ -259,7 +259,7 @@ class ClientCreateOrderRepositoryImpl
|
|||||||
order.startDate.day,
|
order.startDate.day,
|
||||||
);
|
);
|
||||||
final Timestamp orderTimestamp = _service.toTimestamp(orderDateOnly);
|
final Timestamp orderTimestamp = _service.toTimestamp(orderDateOnly);
|
||||||
final Timestamp startTimestamp = orderTimestamp;
|
final Timestamp startTimestamp = _service.toTimestamp(order.startDate);
|
||||||
|
|
||||||
final OperationResult<dc.CreateOrderData, dc.CreateOrderVariables>
|
final OperationResult<dc.CreateOrderData, dc.CreateOrderVariables>
|
||||||
orderResult = await _service.connector
|
orderResult = await _service.connector
|
||||||
|
|||||||
Reference in New Issue
Block a user