Valid.fromTaf constructor

Valid.fromTaf(
  1. String? code,
  2. RegExpMatch? match,
  3. DateTime time
)

Named constructor of the Valid class using a TAF like group of valid period of time.

Args: code (String?): the code of the group. match (RegExpMatch?): the match of the regular expression. time (DateTime): the initial valid time of the forecast.

Implementation

Valid.fromTaf(super.code, RegExpMatch? match, DateTime time) {
  time = DateTime(
    time.year,
    time.month,
    time.day,
    time.hour,
    0,
    time.second,
    time.millisecond,
    time.microsecond,
  );

  if (match == null) {
    time = time.add(const Duration(hours: 1));

    _from = Time(time: time);
    _until = Time(time: time.add(const Duration(hours: 24)));
  } else {
    final fmday = int.parse(match.namedGroup('fmday')!);
    final fmhour = int.parse(match.namedGroup('fmhour')!);
    final tlday = int.parse(match.namedGroup('tlday')!);
    var tlhour = int.parse(match.namedGroup('tlhour')!);

    late DateTime from;
    late DateTime until;
    if (fmday == time.day) {
      from = time;
    } else {
      from = time.add(const Duration(days: 1));
    }

    if (tlday == time.day) {
      until = time;
    } else {
      until = time.add(const Duration(days: 1));
    }

    if (tlhour == 24) {
      until = until.add(const Duration(days: 1));
      tlhour = 0;
    }

    _from = Time(
        time: DateTime(
      from.year,
      from.month,
      from.day,
      fmhour,
      from.minute,
      from.second,
      from.millisecond,
      from.microsecond,
    ));

    _until = Time(
        time: DateTime(
      until.year,
      until.month,
      until.day,
      tlhour,
      until.minute,
      until.second,
      until.millisecond,
      until.microsecond,
    ));
  }
}