Skip to content
Open
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
7 changes: 6 additions & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ jobs:
- name: Analyze
run: dart analyze lib

- name: Run Bucharest timezone regression
env:
TZ: Europe/Bucharest
run: dart test --tags bucharest_tz

- name: Run tests
run: dart test --coverage coverage
run: dart test --exclude-tags bucharest_tz --coverage coverage

- name: Coverage
run: dart run coverage:format_coverage -l -i ./coverage/test/time_test.dart.vm.json -o ./coverage/lcov.info
Expand Down
2 changes: 2 additions & 0 deletions dart_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
tags:
bucharest_tz:
4 changes: 2 additions & 2 deletions lib/src/extensions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,8 +139,8 @@ extension DateTimeTimeExtension on DateTime {
bool isAtSameMicrosecondAs(DateTime other) => isAtSameMillisecondAs(other) && microsecond == other.microsecond;

static int _calculateDifference(DateTime date) {
final now = clock.now();
return DateTime(date.year, date.month, date.day).difference(DateTime(now.year, now.month, now.day)).inDays;
final now = date.isUtc ? clock.now().toUtc() : clock.now();
return date.date.difference(now.date).inDays;
}

/// Returns a range of dates to [to], exclusive start, inclusive end
Expand Down
1 change: 1 addition & 0 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ dev_dependencies:
lints: ^6.0.0
test: ^1.28.0
coverage: ^1.15.0
timezone: ^0.11.0
40 changes: 40 additions & 0 deletions test/time_test.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'package:clock/clock.dart';
import 'package:test/test.dart';
import 'package:time/time.dart';
import 'package:timezone/timezone.dart' as tz;
import 'package:timezone/data/latest.dart' as tz;
Comment on lines +4 to +5

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

L5 can be removed, no?


void main() {
final date = DateTime(2000, 1, 1);
tz.initializeTimeZones();

group('TimeExtension', () {
group('Integers', () {
Expand Down Expand Up @@ -126,6 +129,43 @@ void main() {
expect(reconstructed, equals(original));
});

test(
'handles utc isToday correctly across DST switch',
() {
final location = tz.getLocation('Europe/Bucharest');
tz.setLocalLocation(location);
final now = tz.TZDateTime.local(2026, 3, 29, 16);

withClock(Clock.fixed(now), () {
final todayUtc = DateTime.utc(2026, 3, 29);
final tomorrowUtc = DateTime.utc(2026, 3, 30);

// Older implementation of _calculateDifference from time: 2.1.6.
int oldCalculateDifference(DateTime date) {
final now = clock.now();
return DateTime(date.year, date.month, date.day).difference(
DateTime(now.year, now.month, now.day),
).inDays;
}

expect(
oldCalculateDifference(todayUtc),
0,
reason: 'Old implementation will mark UTC today as today.',
);
expect(
oldCalculateDifference(tomorrowUtc),
0,
reason: 'Old implementation will mark UTC tomorrow as today.',
);

expect(todayUtc.isToday, true, reason: 'New implementation handles UTC correctly.');
expect(tomorrowUtc.isToday, false, reason: 'New implementation handles UTC correctly.');
});
},
tags: ['bucharest_tz'],
);

test('can handle isToday', () {
final today = date;
withClock(Clock.fixed(today), () {
Expand Down
Loading