Beispiel #1
0
 public function test_now_ZoneId()
 {
     $zone = ZoneId::of("UTC+01:02:03");
     $expected = Year::nowOf(Clock::system($zone));
     $test = Year::nowIn($zone);
     for ($i = 0; $i < 100; $i++) {
         if ($expected->equals($test)) {
             return;
         }
         $expected = Year::nowOf(Clock::system($zone));
         $test = Year::nowIn($zone);
     }
     $this->assertEquals($test, $expected);
 }
 /**
  * Obtains the current date-time from the system clock in the specified time-zone.
  * <p>
  * This will query the {@link Clock#system(ZoneId) system clock} to obtain the current date-time.
  * Specifying the time-zone avoids dependence on the default time-zone.
  * The offset will be calculated from the specified time-zone.
  * <p>
  * Using this method will prevent the ability to use an alternate clock for testing
  * because the clock is hard-coded.
  *
  * @param ZoneId $zone the zone ID to use, not null
  * @return OffsetDateTime the current date-time using the system clock, not null
  */
 public static function nowIn(ZoneId $zone)
 {
     return self::nowOf(Clock::system($zone));
 }
 public function dateNowIn(ZoneId $zone)
 {
     return $this->dateNowOf(Clock::system($zone));
 }
 public function test__equals()
 {
     $a = Clock::tick(Clock::system(self::PARIS()), Duration::ofMillis(500));
     $b = Clock::tick(Clock::system(self::PARIS()), Duration::ofMillis(500));
     $this->assertEquals($a->equals($a), true);
     $this->assertEquals($a->equals($b), true);
     $this->assertEquals($b->equals($a), true);
     $this->assertEquals($b->equals($b), true);
     $c = Clock::tick(Clock::system(self::MOSCOW()), Duration::ofMillis(500));
     $this->assertEquals($a->equals($c), false);
     $d = Clock::tick(Clock::system(self::PARIS()), Duration::ofMillis(499));
     $this->assertEquals($a->equals($d), false);
     $this->assertEquals($a->equals(null), false);
     $this->assertEquals($a->equals("other type"), false);
     $this->assertEquals($a->equals(Clock::systemUTC()), false);
 }