Beispiel #1
0
 public function withZone(ZoneId $zone)
 {
     if ($zone->equals($this->baseClock->getZone())) {
         // intentional NPE
         return $this;
     }
     return new TickClock($this->baseClock->withZone($zone), $this->tickNanos);
 }
Beispiel #2
0
 public function withZone(ZoneId $zone)
 {
     if ($zone->equals($this->baseClock->getZone())) {
         // intentional NPE
         return $this;
     }
     return new OffsetClock($this->baseClock->withZone($zone), $this->offset);
 }
 /**
  * Obtains the current date-time from the specified clock.
  * <p>
  * This will query the specified clock to obtain the current date-time.
  * The offset will be calculated from the time-zone in the clock.
  * <p>
  * Using this method allows the use of an alternate clock for testing.
  * The alternate clock may be introduced using {@link Clock dependency injection}.
  *
  * @param Clock $clock the clock to use, not null
  * @return OffsetDateTime the current date-time, not null
  */
 public static function nowOf(Clock $clock)
 {
     $now = $clock->instant();
     // called once
     return self::ofInstant($now, $clock->getZone()->getRules()->getOffset($now));
 }
Beispiel #4
0
 /**
  * Obtains the current time from the specified clock.
  * <p>
  * This will query the specified clock to obtain the current time.
  * Using this method allows the use of an alternate clock for testing.
  * The alternate clock may be introduced using {@link Clock dependency injection}.
  *
  * @param Clock $clock the clock to use, not null
  * @return LocalTime the current time, not null
  */
 public static function nowOf(Clock $clock)
 {
     // inline OffsetTime factory to avoid creating object and InstantProvider checks
     $now = $clock->instant();
     // called once
     $offset = $clock->getZone()->getRules()->getOffset($now);
     $localSecond = $now->getEpochSecond() + $offset->getTotalSeconds();
     // overflow caught later
     $secsOfDay = (int) Math::floorMod($localSecond, self::SECONDS_PER_DAY);
     return self::ofNanoOfDay($secsOfDay * self::NANOS_PER_SECOND + $now->getNano());
 }
Beispiel #5
0
 /**
  * Obtains the current date from the specified clock.
  * <p>
  * This will query the specified clock to obtain the current date - today.
  * Using this method allows the use of an alternate clock for testing.
  * The alternate clock may be introduced using {@link Clock dependency injection}.
  *
  * @param Clock $clock the clock to use, not null
  * @return LocalDate the current date, not null
  */
 public static function nowOf(Clock $clock)
 {
     // inline to avoid creating object and Instant checks
     $now = $clock->instant();
     // called once
     $offset = $clock->getZone()->getRules()->getOffset($now);
     $epochSec = $now->getEpochSecond() + $offset->getTotalSeconds();
     // overflow caught later
     $epochDay = Math::floorDiv($epochSec, LocalTime::SECONDS_PER_DAY);
     return LocalDate::ofEpochDay($epochDay);
 }
 /**
  * Obtains the current date-time from the specified clock.
  * <p>
  * This will query the specified clock to obtain the current date-time.
  * Using this method allows the use of an alternate clock for testing.
  * The alternate clock may be introduced using {@link Clock dependency injection}.
  *
  * @param Clock $clock the clock to use, not null
  * @return LocalDateTime the current date-time, not null
  */
 public static function nowOf(Clock $clock)
 {
     $now = $clock->instant();
     // called once
     $offset = $clock->getZone()->getRules()->getOffset($now);
     return self::ofEpochSecond($now->getEpochSecond(), $now->getNano(), $offset);
 }