-
-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Labels
bugSomething isn't workingSomething isn't working
Description
Daylight savings can cause problems in the time interval stepping:
void main() {
final start = DateTime(2025, 10, 20);
// Bad code, misses an hour
print(start.add(Duration(days: 7)));
// Better code
print(start.copyWith(day: start.day + 7));
}Output:
2025-10-26 23:00:00.000
2025-10-27 00:00:00.000
We do this here
blood-pressure-monitor-fl/app/lib/model/storage/interval_store.dart
Lines 89 to 117 in 821567b
| start: oldStart.add(Duration(days: directionalStep)), | |
| end: oldEnd.add(Duration(days: directionalStep)), | |
| ), | |
| TimeStep.week || TimeStep.last7Days => DateRange( | |
| start: oldStart.add(Duration(days: directionalStep * 7)), | |
| end: oldEnd.add(Duration(days: directionalStep * 7)), | |
| ), | |
| TimeStep.month => DateRange( | |
| // No fitting Duration: wraps correctly according to doc | |
| start: oldStart.copyWith(month: oldStart.month + directionalStep), | |
| end: oldEnd.copyWith(month: oldEnd.month + directionalStep), | |
| ), | |
| TimeStep.year => DateRange( | |
| // No fitting Duration: wraps correctly according to doc | |
| start: oldStart.copyWith(year: oldStart.year + directionalStep), | |
| end: oldEnd.copyWith(year: oldEnd.year + directionalStep), | |
| ), | |
| TimeStep.lifetime => DateRange( | |
| start: DateTime.fromMillisecondsSinceEpoch(1), | |
| end: DateTime.now().copyWith(hour: 23, minute: 59, second: 59), | |
| ), | |
| TimeStep.last30Days => DateRange( | |
| start: oldStart.add(Duration(days: directionalStep * 30)), | |
| end: oldEnd.add(Duration(days: directionalStep * 30)), | |
| ), | |
| TimeStep.custom => DateRange( | |
| start: oldStart.add(oldEnd.difference(oldStart) * directionalStep), | |
| end: oldEnd.add(oldEnd.difference(oldStart) * directionalStep), | |
| ), |
This could be the cause behind some of the impossible to reproduce bugs we had about missing measurements.
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working