コード例 #1
0
ファイル: TCKYearTest.php プロジェクト: celest-time/prototype
 public function test_now_Clock()
 {
     $instant = OffsetDateTime::ofDateAndTime(LocalDate::of(2010, 12, 31), LocalTime::of(0, 0), ZoneOffset::UTC())->toInstant();
     $clock = Clock::fixed($instant, ZoneOffset::UTC());
     $test = Year::nowof($clock);
     $this->assertEquals($test->getValue(), 2010);
 }
コード例 #2
0
 /**
  * @group long
  */
 public function test_tick_ClockDuration_20nanos()
 {
     for ($i = 0; $i < 1000; $i++) {
         $test = Clock::tick(Clock::fixed(self::ZDT()->withNano($i)->toInstant(), self::PARIS()), Duration::ofNanos(20));
         $this->assertEquals($test->instant(), self::ZDT()->withNano(Math::div($i, 20) * 20)->toInstant());
         $this->assertEquals($test->getZone(), self::PARIS());
     }
 }
コード例 #3
0
 public function test_now_Clock_offsets()
 {
     $base = ZonedDateTime::ofDateTime(LocalDateTime::of(1970, 1, 1, 12, 0), ZoneOffset::UTC());
     for ($i = -9; $i < 15; $i++) {
         $offset = ZoneOffset::ofHours($i);
         $clock = Clock::fixed($base->toInstant(), $offset);
         $test = ZonedDateTime::nowOf($clock);
         $this->assertEquals($test->getHour(), (12 + $i) % 24);
         $this->assertEquals($test->getMinute(), 0);
         $this->assertEquals($test->getSecond(), 0);
         $this->assertEquals($test->getNano(), 0);
         $this->assertEquals($test->getOffset(), $offset);
         $this->assertEquals($test->getZone(), $offset);
     }
 }
コード例 #4
0
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_now_Clock_tooLow()
 {
     $clock = Clock::fixed($this->MIN_INSTANT->minusNanos(1), ZoneOffset::UTC());
     LocalDateTime::nowOf($clock);
 }
コード例 #5
0
 public function test_now_Clock()
 {
     $instant = LocalDateTime::of(2010, 12, 31, 0, 0)->toInstant(ZoneOffset::UTC());
     $clock = Clock::fixed($instant, ZoneOffset::UTC());
     $test = YearMonth::nowOf($clock);
     $this->assertEquals($test->getYear(), 2010);
     $this->assertEquals($test->getMonth(), Month::DECEMBER());
 }
コード例 #6
0
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_now_Clock_tooLow()
 {
     $clock = Clock::fixed(self::MIN_INSTANT()->minusNanos(1), ZoneOffset::UTC());
     LocalDate::nowOf($clock);
 }
コード例 #7
0
 public function test_now_Clock_min()
 {
     $clock = Clock::fixed(Instant::MIN(), ZoneOffset::UTC());
     $test = LocalTime::nowOf($clock);
     $this->assertEquals($test->getHour(), 0);
     $this->assertEquals($test->getMinute(), 0);
     $this->assertEquals($test->getSecond(), 0);
     $this->assertEquals($test->getNano(), 0);
 }
コード例 #8
0
 /**
  * @group long
  */
 public function test_now_Clock_allSecsInDay_beforeEpoch()
 {
     for ($i = -1; $i >= -(24 * 60 * 60); $i--) {
         $expected = Instant::ofEpochSecond($i)->plusNanos(123456789);
         $clock = Clock::fixed($expected, ZoneOffset::UTC());
         $test = Instant::nowOf($clock);
         $this->assertEquals($test, $expected);
     }
 }