package TestCase::Lib::SPVM::Time::Format {
  use SPVM::Time::Format;
  use SPVM::Time::Moment;

  sub test_parse : int () {
    my $format = SPVM::Time::Format->new("%Y-%m-%d %H:%M:%S %Z");
    my $m = $format->parse("2019-03-25 12:51:37 GMT");
    unless ($m->epoch == 1553518297) {
      return 0;
    }
    unless ($m->year == 2019) {
      return 0;
    }
    unless ($m->month == 3) {
      return 0;
    }
    unless ($m->day == 25) {
      return 0;
    }
    unless ($m->day_of_week == SPVM::Time::Moment->MONDAY) {
      return 0;
    }
    unless ($m->day_of_year == 84) {
      return 0;
    }
    unless ($m->hour == 12) {
      return 0;
    }
    unless ($m->minute == 51) {
      return 0;
    }
    unless ($m->second == 37) {
      return 0;
    }
    return 1;
  }

  sub test_RFC1123 : int () {
    my $format = SPVM::Time::Format->RFC1123;
    unless ($format->parse("Wed, 02 Jan 2030 03:04:56 GMT")->epoch == 1893553496) { # TODO: Allow UTC
      return 0;
    }
    unless ($format->time_to_str(SPVM::Time::Moment->from_epoch(1893553496)) eq "Wed, 02 Jan 2030 03:04:56 UTC") {
      warn ($format->time_to_str(SPVM::Time::Moment->from_epoch(1893553496)));
      return 0;
    }
    return 1;
  }

  sub test_time_to_str : int () {
    my $format = SPVM::Time::Format->new("%Y-%m-%d %H:%M:%S %Z");
    my $output = $format->time_to_str(SPVM::Time::Moment->from_epoch(1553518297));
    return $output eq "2019-03-25 12:51:37 UTC";
  }

  sub test_timezone_JST : int () {
    my $format = SPVM::Time::Format->new("%Y-%m-%d %H:%M:%S %Z");
    my $m = $format->parse("2019-03-25 12:51:37 JST");
    return $m->epoch == 1553485897;
  }
}
