diff --git a/lib/src/extensions.dart b/lib/src/extensions.dart index 09720d0..a69c46d 100644 --- a/lib/src/extensions.dart +++ b/lib/src/extensions.dart @@ -34,7 +34,7 @@ extension DateTimeTimeExtension on DateTime { DateTime operator -(Duration duration) => subtract(duration); /// Returns only year, month and day - DateTime get date => DateTime(year, month, day); + DateTime get date => isUtc ? DateTime.utc(year, month, day) : DateTime(year, month, day); /// Returns only the time Duration get timeOfDay => hour.hours + minute.minutes + second.seconds; diff --git a/test/time_test.dart b/test/time_test.dart index c93c1a1..9b67e5a 100644 --- a/test/time_test.dart +++ b/test/time_test.dart @@ -89,12 +89,20 @@ void main() { ); }); - test('can get only year, month and day', () { - expect( - /// Returns only year, month and day - DateTime(2020, 4, 10, 15, 27, 30).date, - DateTime(2020, 4, 10, 0, 0, 0), - ); + group('can get only year, month and day', () { + test('when is not utc', () { + expect( + DateTime(2020, 4, 10, 15, 27, 30).date, + DateTime(2020, 4, 10, 0, 0, 0), + ); + }); + + test('when is utc', () { + expect( + DateTime.utc(2020, 4, 10, 15, 27, 30).date, + DateTime.utc(2020, 4, 10, 0, 0, 0), + ); + }); }); test('can get only the time', () {