sessionStartDay function Architecture

DateTime sessionStartDay(
  1. DateTime startedAt, {
  2. required bool startedAtIsUtc,
})

The calendar day a learning_sessions row started on, as local midnight, from its stored started_at and started_at_is_utc (migration 090).

A row marked UTC is an instant, bucketed on the device's day (localDay). A legacy row was written before the app sent UTC: its local wall-clock time went out with no offset and was stored as UTC, so its UTC fields are the writer's local date and time (a 23:30 session in Paris is 23:30Z). Its day is the date of those fields, the day the learner saw when they studied. Reading it with localDay would move it by the writer's UTC offset: to the next day for that Paris session, to the day before for a 01:00 session in New York.

Implementation

DateTime sessionStartDay(DateTime startedAt, {required bool startedAtIsUtc}) {
  if (startedAtIsUtc) return localDay(startedAt);
  final utc = startedAt.toUtc();
  return DateTime(utc.year, utc.month, utc.day);
}