package TestCase::Lib::SPVM::Time::Moment {
  use SPVM::Time::Moment;
  use SPVM::Time (time);

  sub test_basic : int () {
    # UTC: 2019/3/25 Monday 12:51:37
    my $m = SPVM::Time::Moment->from_epoch(1553518297);
    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 && SPVM::Time::Moment->MONDAY == 1) {
      return 0;
    }
    # perl -MDateTime -le 'my $dt = DateTime->from_epoch(epoch => 1553518297); print $dt->day_of_year'
    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_leap_year : int () {
    my $m = SPVM::Time::Moment->from_epoch(1582934400);
    unless ($m->epoch == 1582934400) {
      return 0;
    }
    unless ($m->year == 2020) {
      return 0;
    }
    unless ($m->month == 2) {
      return 0;
    }
    unless ($m->day == 29) {
      return 0;
    }
    unless ($m->day_of_week == SPVM::Time::Moment->SATURDAY) {
      return 0;
    }
    unless ($m->hour == 0) {
      return 0;
    }
    unless ($m->minute == 0) {
      return 0;
    }
    unless ($m->second == 0) {
      return 0;
    }
    return 1;
  }

  sub test_now : int () {
    my $eps = 10;
    my $epoch_now = time();
    my $now = SPVM::Time::Moment->now;
    return $epoch_now - $eps <= $now->epoch && $now->epoch + $epoch_now + $eps;
  }
}
