Skip to content

Handle UTC during date #60

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 14 additions & 6 deletions test/time_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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', () {
Expand Down