示例#1
0
 public function test_now()
 {
     $expected = Year::nowOf(Clock::systemDefaultZone());
     $test = Year::now();
     for ($i = 0; $i < 100; $i++) {
         if ($expected->equals($test)) {
             return;
         }
         $expected = Year::nowOf(Clock::systemDefaultZone());
         $test = Year::now();
     }
     $this->assertEquals($test, $expected);
 }
示例#2
0
 /**
  * Obtains the current date-time from the system clock in the default time-zone.
  * <p>
  * This will query the {@link Clock#systemDefaultZone() system clock} in the default
  * time-zone to obtain the current date-time.
  * The offset will be calculated from the time-zone in the clock.
  * <p>
  * Using this method will prevent the ability to use an alternate clock for testing
  * because the clock is hard-coded.
  *
  * @return OffsetDateTime the current date-time using the system clock, not null
  */
 public static function now()
 {
     return self::nowOf(Clock::systemDefaultZone());
 }
 public function dateNow()
 {
     return $this->dateNowOf(Clock::systemDefaultZone());
 }
 public function test_now()
 {
     $expected = ZonedDateTime::nowOf(Clock::systemDefaultZone());
     $test = ZonedDateTime::now();
     $diff = Math::abs($test->toLocalTime()->toNanoOfDay() - $expected->toLocalTime()->toNanoOfDay());
     if ($diff >= 100000000) {
         // may be date change
         $expected = ZonedDateTime::nowOf(Clock::systemDefaultZone());
         $test = ZonedDateTime::now();
         $diff = Math::abs($test->toLocalTime()->toNanoOfDay() - $expected->toLocalTime()->toNanoOfDay());
     }
     $this->assertTrue($diff < 100000000);
     // less than 0.1 secs
 }
 public function test_now()
 {
     $nowDT = ZonedDateTime::now();
     $expected = OffsetTime::nowOf(Clock::systemDefaultZone());
     $test = OffsetTime::now();
     $diff = Math::abs($test->toLocalTime()->toNanoOfDay() - $expected->toLocalTime()->toNanoOfDay());
     $this->assertTrue($diff < 100000000);
     // less than 0.1 secs
     $this->assertEquals($test->getOffset(), $nowDT->getOffset());
 }