Skip to content

Commit 436f863

Browse files
authored
Handle UTC during date #60
2 parents 6b0358a + ef78ed7 commit 436f863

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

lib/src/extensions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ extension DateTimeTimeExtension on DateTime {
3434
DateTime operator -(Duration duration) => subtract(duration);
3535

3636
/// Returns only year, month and day
37-
DateTime get date => DateTime(year, month, day);
37+
DateTime get date => isUtc ? DateTime.utc(year, month, day) : DateTime(year, month, day);
3838

3939
/// Returns only the time
4040
Duration get timeOfDay => hour.hours + minute.minutes + second.seconds;

test/time_test.dart

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,20 @@ void main() {
8989
);
9090
});
9191

92-
test('can get only year, month and day', () {
93-
expect(
94-
/// Returns only year, month and day
95-
DateTime(2020, 4, 10, 15, 27, 30).date,
96-
DateTime(2020, 4, 10, 0, 0, 0),
97-
);
92+
group('can get only year, month and day', () {
93+
test('when is not utc', () {
94+
expect(
95+
DateTime(2020, 4, 10, 15, 27, 30).date,
96+
DateTime(2020, 4, 10, 0, 0, 0),
97+
);
98+
});
99+
100+
test('when is utc', () {
101+
expect(
102+
DateTime.utc(2020, 4, 10, 15, 27, 30).date,
103+
DateTime.utc(2020, 4, 10, 0, 0, 0),
104+
);
105+
});
98106
});
99107

100108
test('can get only the time', () {

0 commit comments

Comments
 (0)