Exemplo n.º 1
0
 public function instant()
 {
     if ($this->tickNanos % 1000000 == 0) {
         $millis = $this->baseClock->millis();
         return Instant::ofEpochMilli($millis - Math::floorMod($millis, $this->tickNanos / 1000000));
     }
     $instant = $this->baseClock->instant();
     $nanos = $instant->getNano();
     $adjust = Math::floorMod($nanos, $this->tickNanos);
     return $instant->minusNanos($adjust);
 }
Exemplo n.º 2
0
 /**
  * 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));
 }
Exemplo n.º 3
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());
 }
Exemplo n.º 4
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);
 }
Exemplo n.º 5
0
 /**
  * Obtains the current instant from the specified clock.
  * <p>
  * This will query the specified clock to obtain the current time.
  * <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 Instant the current instant, not null
  */
 public static function nowOf(Clock $clock)
 {
     return $clock->instant();
 }
Exemplo n.º 6
0
 public function instant()
 {
     return $this->baseClock->instant()->plusAmount($this->offset);
 }
Exemplo n.º 7
0
 /**
  * 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);
 }