Exemplo n.º 1
0
 /**
  * Obtains the current instant from the system clock.
  * <p>
  * This will query the {@link Clock#systemUTC() system UTC clock} to
  * obtain the current instant.
  * <p>
  * Using this method will prevent the ability to use an alternate time-source for
  * testing because the clock is effectively hard-coded.
  *
  * @return Instant the current instant using the system clock, not null
  */
 public static function now()
 {
     return Clock::systemUTC()->instant();
 }
Exemplo n.º 2
0
 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);
 }
Exemplo n.º 3
0
 public function test_now()
 {
     $expected = Instant::nowOf(Clock::systemUTC());
     $test = Instant::now();
     $diff = Math::abs($test->toEpochMilli() - $expected->toEpochMilli());
     $this->assertTrue($diff < 100);
     // less than 0.1 secs
 }