localDay function Architecture

DateTime localDay(
  1. DateTime instant
)

The calendar day instant falls on where the device is, as local midnight.

Timestamps come back from the server in UTC (...+00:00), and DateTime.parse keeps them in UTC. Taking .year, .month and .day of such a value buckets by the UTC date: a session at 21:00 in New York (01:00Z the next day) or at 01:00 in Paris (23:00Z the day before) lands on the wrong day, which broke streaks and the "studied today" check once the app started writing real UTC times. Every calendar-day bucket in the app goes through here, and test/core/utils/local_day_test.dart fails on a hand-rolled DateTime(x.year, x.month, x.day) anywhere else in lib/.

Implementation

DateTime localDay(DateTime instant) {
  final local = instant.toLocal();
  return DateTime(local.year, local.month, local.day);
}