package TestCase::Lib::SPVM::Time {
  use SPVM::Time;
  
  sub test_time : long () {
    my $time = SPVM::Time->time;
    
    return $time;
  }

  sub test_localtime : SPVM::Time::Info ($time : long) {
    my $time_info = SPVM::Time->localtime($time);
    
    return $time_info;
  }

  sub test_gmtime : SPVM::Time::Info ($time : long) {
    my $time_info = SPVM::Time->gmtime($time);
    
    return $time_info;
  }

  sub test_strptime : int () {
    # strptime
    {
      my $time_info = SPVM::Time->strptime("2019-03-25 12:51:37 GMT", "%Y-%m-%d %H:%M:%S GMT");
      
      unless ($time_info->sec == 37) {
        return 0;
      }
      unless ($time_info->min == 51) {
        return 0;
      }
      unless ($time_info->hour == 12) {
        return 0;
      }
      unless ($time_info->mday == 25) {
        return 0;
      }
      # 3 - 1
      unless ($time_info->mon == 2) {
        return 0;
      }
      # 2019 - 1900
      unless ($time_info->year == 119) {
        return 0;
      }
    }
    
    return 1;
  }

  sub test_strftime : int () {
    # strftime
    {
      my $time_info = SPVM::Time->strptime("2019-03-25 12:51:37 GMT", "%Y-%m-%d %H:%M:%S GMT");
      
      my $str = SPVM::Time->strftime("%Y-%m-%d %H:%M:%S GMT", $time_info);
      
      unless ($str eq "2019-03-25 12:51:37 GMT") {
        return 0;
      }
    }
    
    return 1;
  }

  sub test_mktime : int () {
    {
      my $time = SPVM::Time->time();
      
      my $time_info = SPVM::Time->localtime($time);
      
      my $time_ret = SPVM::Time->mktime($time_info);
      
      unless ($time_ret isa long) {
        return 0;
      }
      unless ($time == $time_ret) {
        return 0;
      }
    }
    
    return 1;
  }

  sub test_timegm : int () {
    {
      my $time = SPVM::Time->time();
      
      my $time_info = SPVM::Time->gmtime($time);
      
      my $time_ret = SPVM::Time->timegm($time_info);

      unless ($time_ret isa long) {
        return 0;
      }
      unless ($time == $time_ret) {
        return 0;
      }
    }
    
    return 1;
  }

}
