Allow `Timestamp.toDateTime()` to return a `DateTime` in local timezone (#653)
Port of cl/426100118
diff --git a/protobuf/lib/src/protobuf/mixins/well_known.dart b/protobuf/lib/src/protobuf/mixins/well_known.dart
index f644284..66854c9 100644
--- a/protobuf/lib/src/protobuf/mixins/well_known.dart
+++ b/protobuf/lib/src/protobuf/mixins/well_known.dart
@@ -151,9 +151,12 @@
///
/// The result is in UTC time zone and has microsecond precision, as
/// [DateTime] does not support nanosecond precision.
- DateTime toDateTime() => DateTime.fromMicrosecondsSinceEpoch(
- seconds.toInt() * Duration.microsecondsPerSecond + nanos ~/ 1000,
- isUtc: true);
+ ///
+ /// Use [toLocal] to convert to local time zone, instead of the default UTC.
+ DateTime toDateTime({bool toLocal = false}) =>
+ DateTime.fromMicrosecondsSinceEpoch(
+ seconds.toInt() * Duration.microsecondsPerSecond + nanos ~/ 1000,
+ isUtc: !toLocal);
/// Updates [target] to be the time at [dateTime].
///