fromDateTime static method

Tm fromDateTime(
  1. DateTime dt
)

Creates a Tm from a Dart DateTime.

Implementation

static Tm fromDateTime(DateTime dt) {
  // calculate day of year
  final startOfYear = DateTime(dt.year, 1, 1);
  final daysSinceJan1 = dt.difference(startOfYear).inDays;
  return Tm(
    tm_sec: dt.second,
    tm_min: dt.minute,
    tm_hour: dt.hour,
    tm_mday: dt.day,
    tm_mon: dt.month - 1,
    tm_year: dt.year - 1900,
    tm_wday: dt.weekday == 7 ? 0 : dt.weekday,
    tm_yday: daysSinceJan1,
    tm_isdst: -1,
  );
}