private function time($hour, $min, $sec, $nano)
 {
     return LocalTime::of($hour, $min, $sec, $nano);
 }
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_print_TemporalAppendable_noSuchField()
 {
     $test = $this->fmt->withLocale(Locale::ENGLISH())->withDecimalStyle(DecimalStyle::STANDARD());
     $test->formatTo(LocalTime::of(11, 30), $buf);
 }
 /**
  * Adds a multi-year transition rule to the current window.
  * <p>
  * This adds a rule such that the offset, expressed as a daylight savings amount,
  * changes at the specified date-time for each year in the range.
  *
  * @param int $startYear the start year of the rule, from MIN_VALUE to MAX_VALUE
  * @param int $endYear the end year of the rule, from MIN_VALUE to MAX_VALUE
  * @param Month $month the month of the transition, not null
  * @param int $dayOfMonthIndicator the day-of-month of the transition, adjusted by dayOfWeek,
  *   from 1 to 31 adjusted later, or -1 to -28 adjusted earlier from the last day of the month
  * @param DayOfWeek|null $dayOfWeek the day-of-week to adjust to, null if day-of-month should not be adjusted
  * @param LocalTime $time the time that the transition occurs as defined by timeDefintion, not null
  * @param bool $timeEndOfDay whether midnight is at the end of day
  * @param TimeDefinition $timeDefinition the definition of how to convert local to actual time, not null
  * @param int $savingAmountSecs the amount of saving from the standard offset after the transition in seconds
  * @return ZoneRulesBuilder $this, for chaining
  * @throws DateTimeException if a date-time field is out of range
  * @throws IllegalArgumentException if the day of month indicator is invalid
  * @throws IllegalArgumentException if the end of day midnight flag does not match the time
  * @throws \LogicException if no window has yet been added
  * @throws \LogicException if the window already has fixed savings
  * @throws \LogicException if the window has reached the maximum capacity of 2000 rules
  */
 public function addRuleToWindow9($startYear, $endYear, Month $month, $dayOfMonthIndicator, $dayOfWeek, LocalTime $time, $timeEndOfDay, TimeDefinition $timeDefinition, $savingAmountSecs)
 {
     ChronoField::YEAR()->checkValidValue($startYear);
     ChronoField::YEAR()->checkValidValue($endYear);
     if ($dayOfMonthIndicator < -28 || $dayOfMonthIndicator > 31 || $dayOfMonthIndicator === 0) {
         throw new IllegalArgumentException("Day of month indicator must be between -28 and 31 inclusive excluding zero");
     }
     if ($timeEndOfDay && $time->equals(LocalTime::MIDNIGHT()) == false) {
         throw new IllegalArgumentException("Time must be midnight when end of day flag is true");
     }
     if (empty($this->windowList)) {
         throw new \LogicException("Must add a window before adding a rule");
     }
     $window = $this->windowList[count($this->windowList) - 1];
     $window->addRule($startYear, $endYear, $month, $dayOfMonthIndicator, $dayOfWeek, $time, $timeEndOfDay, $timeDefinition, $savingAmountSecs);
     return $this;
 }
示例#4
0
 /**
  * A query for {@code LocalTime} returning null if not found.
  * @param TemporalAccessor $temporal
  * @return null|LocalTime
  */
 public static function _localTime(TemporalAccessor $temporal)
 {
     if ($temporal->isSupported(ChronoField::NANO_OF_DAY())) {
         return LocalTime::ofNanoOfDay($temporal->getLong(ChronoField::NANO_OF_DAY()));
     }
     return null;
 }
示例#5
0
 /**
  * Returns a zoned date-time from this date at the earliest valid time according
  * to the rules in the time-zone.
  * <p>
  * Time-zone rules, such as daylight savings, mean that not every local date-time
  * is valid for the specified zone, thus the local date-time may not be midnight.
  * <p>
  * In most cases, there is only one valid offset for a local date-time.
  * In the case of an overlap, there are two valid offsets, and the earlier one is used,
  * corresponding to the first occurrence of midnight on the date.
  * In the case of a gap, the zoned date-time will represent the instant just after the gap.
  * <p>
  * If the zone ID is a {@link ZoneOffset}, then the result always has a time of midnight.
  * <p>
  * To convert to a specific time in a given time-zone call {@link #atTime(LocalTime)}
  * followed by {@link LocalDateTime#atZone(ZoneId)}.
  *
  * @param ZoneId $zone the zone ID to use, not null
  * @return ZonedDateTime the zoned date-time formed from this date and the earliest valid time for the zone, not null
  */
 public function atStartOfDayWithZone(ZoneId $zone)
 {
     // need to handle case where there is a gap from 11:30 to 00:30
     // standard ZDT factory would result in 01:00 rather than 00:30
     $ldt = $this->atTime(LocalTime::MIDNIGHT());
     if ($zone instanceof ZoneOffset === false) {
         $rules = $zone->getRules();
         $trans = $rules->getTransition($ldt);
         if ($trans != null && $trans->isGap()) {
             $ldt = $trans->getDateTimeAfter();
         }
     }
     return ZonedDateTime::ofDateTime($ldt, $zone);
 }
 public function __construct()
 {
     $this->month = Month::JANUARY();
     $this->time = LocalTime::MIDNIGHT();
     $this->timeDefinition = TimeDefinition::WALL();
 }
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_until_invalidType()
 {
     $start = YearMonth::of(2010, 6);
     $start->until(LocalTime::of(11, 30), CU::MONTHS());
 }
示例#8
0
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_factory_from_TemporalAccessor_invalid_noDerive()
 {
     ZoneId::from(LocalTime::of(12, 30));
 }
示例#9
0
 private function updateCheckConflict(LocalTime $timeToSet, Period $periodToSet)
 {
     if ($this->time != null) {
         if ($this->time->equals($timeToSet) == false) {
             throw new DateTimeException("Conflict found: Fields resolved to different times: " . $this->time . " " . $timeToSet);
         }
         if ($this->excessDays->isZero() == false && $periodToSet->isZero() == false && $this->excessDays->equals($periodToSet) == false) {
             throw new DateTimeException("Conflict found: Fields resolved to different excess periods: " . $this->excessDays . " " . $periodToSet);
         } else {
             $this->excessDays = $periodToSet;
         }
     } else {
         $this->time = $timeToSet;
         $this->excessDays = $periodToSet;
     }
 }
 /**
  * @expectedException \Celest\DateTimeParseException
  */
 public function test_fieldResolvesToChronoZonedDateTime_overrideChrono_wrongChrono()
 {
     $cldt = ThaiBuddhistChronology::INSTANCE()->dateNow()->atTime(LocalTime::NOON())->atZone(self::EUROPE_PARIS());
     $f = (new DateTimeFormatterBuilder())->appendValue(new ResolvingField($cldt))->toFormatter();
     $f = $f->withChronology(MinguoChronology::INSTANCE());
     $f->parse("1234567890");
 }
示例#11
0
 public function unserialize($serialized)
 {
     $v = explode(':', $serialized);
     $this->date = LocalDate::of($v[0], $v[1], $v[2]);
     $this->time = LocalTime::of($v[3], $v[4], $v[5]);
 }
示例#12
0
 /**
  * @expectedException     \Celest\DateTimeException
  */
 public function test_until_invalidType()
 {
     $start = Year::of(2010);
     $start->until(LocalTime::of(11, 30), ChronoUnit::YEARS());
 }
 public function until(Temporal $endExclusive, TemporalUnit $unit)
 {
     $end = $this->getChronology()->localDateTime($endExclusive);
     if ($unit instanceof ChronoUnit) {
         if ($unit->isTimeBased()) {
             $amount = $end->getLong(ChronoField::EPOCH_DAY()) - $this->date->getLong(ChronoField::EPOCH_DAY());
             switch ($unit) {
                 case ChronoUnit::NANOS():
                     $amount = Math::multiplyExact($amount, self::NANOS_PER_DAY);
                     break;
                 case ChronoUnit::MICROS():
                     $amount = Math::multiplyExact($amount, self::MICROS_PER_DAY);
                     break;
                 case ChronoUnit::MILLIS():
                     $amount = Math::multiplyExact($amount, self::MILLIS_PER_DAY);
                     break;
                 case ChronoUnit::SECONDS():
                     $amount = Math::multiplyExact($amount, self::SECONDS_PER_DAY);
                     break;
                 case ChronoUnit::MINUTES():
                     $amount = Math::multiplyExact($amount, self::MINUTES_PER_DAY);
                     break;
                 case ChronoUnit::HOURS():
                     $amount = Math::multiplyExact($amount, self::HOURS_PER_DAY);
                     break;
                 case ChronoUnit::HALF_DAYS():
                     $amount = Math::multiplyExact($amount, 2);
                     break;
             }
             return Math::addExact($amount, $this->time->until($end->toLocalTime(), $unit));
         }
         $endDate = $end->toLocalDate();
         if ($end->toLocalTime()->isBefore($this->time)) {
             $endDate = $endDate->minus(1, ChronoUnit::DAYS());
         }
         return $this->date->until($endDate, $unit);
     }
     return $unit->between($this, $end);
 }
示例#14
0
 /**
  * Obtains an instance of {@code ZonedDateTime} from a temporal object.
  * <p>
  * This obtains a zoned date-time based on the specified temporal.
  * A {@code TemporalAccessor} represents an arbitrary set of date and time information,
  * which this factory converts to an instance of {@code ZonedDateTime}.
  * <p>
  * The conversion will first obtain a {@code ZoneId} from the temporal object,
  * falling back to a {@code ZoneOffset} if necessary. It will then try to obtain
  * an {@code Instant}, falling back to a {@code LocalDateTime} if necessary.
  * The result will be either the combination of {@code ZoneId} or {@code ZoneOffset}
  * with {@code Instant} or {@code LocalDateTime}.
  * Implementations are permitted to perform optimizations such as accessing
  * those fields that are equivalent to the relevant objects.
  * <p>
  * This method matches the signature of the functional interface {@link TemporalQuery}
  * allowing it to be used as a query via method reference, {@code ZonedDateTime::from}.
  *
  * @param TemporalAccessor $temporal the temporal object to convert, not null
  * @return ZonedDateTime the zoned date-time, not null
  * @throws DateTimeException if unable to convert to an {@code ZonedDateTime}
  */
 public static function from(TemporalAccessor $temporal)
 {
     if ($temporal instanceof ZonedDateTime) {
         return $temporal;
     }
     try {
         $zone = ZoneId::from($temporal);
         if ($temporal->isSupported(ChronoField::INSTANT_SECONDS())) {
             $epochSecond = $temporal->getLong(ChronoField::INSTANT_SECONDS());
             $nanoOfSecond = $temporal->get(ChronoField::NANO_OF_SECOND());
             return self::create($epochSecond, $nanoOfSecond, $zone);
         } else {
             $date = LocalDate::from($temporal);
             $time = LocalTime::from($temporal);
             return self::ofDateAndTime($date, $time, $zone);
         }
     } catch (DateTimeException $ex) {
         throw new DateTimeException("Unable to obtain ZonedDateTime from TemporalAccessor: " . $temporal . " of type " . get_class($temporal), $ex);
     }
 }
 function data_fieldAndAccessor()
 {
     return [[CF::YEAR(), LocalDate::of(2000, 2, 29), true, 2000], [CF::YEAR(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 2000], [CF::MONTH_OF_YEAR(), LocalDate::of(2000, 2, 29), true, 2], [CF::MONTH_OF_YEAR(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 2], [CF::DAY_OF_MONTH(), LocalDate::of(2000, 2, 29), true, 29], [CF::DAY_OF_MONTH(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 29], [CF::DAY_OF_YEAR(), LocalDate::of(2000, 2, 29), true, 60], [CF::DAY_OF_YEAR(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 60], [CF::HOUR_OF_DAY(), LocalTime::of(5, 4, 3, 200), true, 5], [CF::HOUR_OF_DAY(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 5], [CF::MINUTE_OF_DAY(), LocalTime::of(5, 4, 3, 200), true, 5 * 60 + 4], [CF::MINUTE_OF_DAY(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 5 * 60 + 4], [CF::MINUTE_OF_HOUR(), LocalTime::of(5, 4, 3, 200), true, 4], [CF::MINUTE_OF_HOUR(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 4], [CF::SECOND_OF_DAY(), LocalTime::of(5, 4, 3, 200), true, 5 * 3600 + 4 * 60 + 3], [CF::SECOND_OF_DAY(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 5 * 3600 + 4 * 60 + 3], [CF::SECOND_OF_MINUTE(), LocalTime::of(5, 4, 3, 200), true, 3], [CF::SECOND_OF_MINUTE(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 3], [CF::NANO_OF_SECOND(), LocalTime::of(5, 4, 3, 200), true, 200], [CF::NANO_OF_SECOND(), LocalDateTime::of(2000, 2, 29, 5, 4, 3, 200), true, 200], [CF::YEAR(), LocalTime::of(5, 4, 3, 200), false, -1], [CF::MONTH_OF_YEAR(), LocalTime::of(5, 4, 3, 200), false, -1], [CF::DAY_OF_MONTH(), LocalTime::of(5, 4, 3, 200), false, -1], [CF::DAY_OF_YEAR(), LocalTime::of(5, 4, 3, 200), false, -1], [CF::HOUR_OF_DAY(), LocalDate::of(2000, 2, 29), false, -1], [CF::MINUTE_OF_DAY(), LocalDate::of(2000, 2, 29), false, -1], [CF::MINUTE_OF_HOUR(), LocalDate::of(2000, 2, 29), false, -1], [CF::SECOND_OF_DAY(), LocalDate::of(2000, 2, 29), false, -1], [CF::SECOND_OF_MINUTE(), LocalDate::of(2000, 2, 29), false, -1], [CF::NANO_OF_SECOND(), LocalDate::of(2000, 2, 29), false, -1]];
 }
 /**
  * Parses a Rule line.
  *
  * @param $s \CachingIterator the line scanner, not null
  * @param TZDBMonthDayTime $mdt the object to parse into, not null
  */
 private function parseMonthDayTime(\CachingIterator $s, TZDBMonthDayTime $mdt)
 {
     $mdt->month = $this->parseMonth($s);
     if ($s->hasNext()) {
         $s->next();
         $dayRule = $s->current();
         if (strpos($dayRule, "last") === 0) {
             $mdt->dayOfMonth = -1;
             $mdt->dayOfWeek = $this->parseDayOfWeek(substr($dayRule, 4));
             $mdt->adjustForwards = false;
         } else {
             $index = strpos($dayRule, ">=");
             if ($index > 0) {
                 $mdt->dayOfWeek = $this->parseDayOfWeek(substr($dayRule, 0, $index));
                 $dayRule = substr($dayRule, $index + 2);
             } else {
                 $index = strpos($dayRule, "<=");
                 if ($index > 0) {
                     $mdt->dayOfWeek = $this->parseDayOfWeek(substr($dayRule, 0, $index));
                     $mdt->adjustForwards = false;
                     $dayRule = substr($dayRule, $index + 2);
                 }
             }
             $mdt->dayOfMonth = \intval($dayRule);
         }
         if ($s->hasNext()) {
             $s->next();
             $timeStr = $s->current();
             $secsOfDay = $this->parseSecs($timeStr);
             if ($secsOfDay === 86400) {
                 $mdt->endOfDay = true;
                 $secsOfDay = 0;
             }
             $mdt->time = LocalTime::ofSecondOfDay($secsOfDay);
             $mdt->timeDefinition = $this->parseTimeDefinition($timeStr[strlen($timeStr) - 1]);
         }
     }
 }
 public function test_truncatedTo_normal()
 {
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->truncatedTo(CU::NANOS()), self::TEST_2008_6_30_11_30_59_000000500());
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->truncatedTo(CU::SECONDS()), self::TEST_2008_6_30_11_30_59_000000500()->withNano(0));
     $this->assertEquals(self::TEST_2008_6_30_11_30_59_000000500()->truncatedTo(CU::DAYS()), self::TEST_2008_6_30_11_30_59_000000500()->adjust(LocalTime::MIDNIGHT()));
 }
 public function test_toString_floatingWeek_overlap_endOfDay()
 {
     $test = ZoneOffsetTransitionRule::of(Month::OCTOBER(), 20, DayOfWeek::SUNDAY(), LocalTime::MIDNIGHT(), true, TimeDefinition::WALL(), self::OFFSET_0200(), self::OFFSET_0300(), self::OFFSET_0200());
     $this->assertEquals($test->__toString(), "TransitionRule[Overlap +03:00 to +02:00, SUNDAY on or after OCTOBER 20 at 24:00 WALL, standard offset +02:00]");
 }
示例#19
0
 function data_durationBetweenLocalTime()
 {
     return [[LocalTime::of(11, 0, 30), LocalTime::of(11, 0, 45), 15, 0], [LocalTime::of(11, 0, 30), LocalTime::of(11, 0, 25), -5, 0]];
 }
 /**
  * Checks if this object equals another.
  * <p>
  * The entire state of the object is compared.
  *
  * @param mixed $otherRule the other object to compare to, null returns false
  * @return bool true if equal
  */
 public function equals($otherRule)
 {
     if ($otherRule === $this) {
         return true;
     }
     if ($otherRule instanceof ZoneOffsetTransitionRule) {
         $other = $otherRule;
         return $this->month == $other->month && $this->dom == $other->dom && $this->dow == $other->dow && $this->timeDefinition == $other->timeDefinition && $this->time->equals($other->time) && $this->timeEndOfDay == $other->timeEndOfDay && $this->standardOffset->equals($other->standardOffset) && $this->offsetBefore->equals($other->offsetBefore) && $this->offsetAfter->equals($other->offsetAfter);
     }
     return false;
 }
 function comparisons_LocalDateTime(array $localDates)
 {
     $this->comparisons_LocalDateTime2($localDates, [LocalTime::MIDNIGHT(), LocalTime::of(0, 0, 0, 999999999), LocalTime::of(0, 0, 59, 0), LocalTime::of(0, 0, 59, 999999999), LocalTime::of(0, 59, 0, 0), LocalTime::of(0, 59, 59, 999999999), LocalTime::NOON(), LocalTime::of(12, 0, 0, 999999999), LocalTime::of(12, 0, 59, 0), LocalTime::of(12, 0, 59, 999999999), LocalTime::of(12, 59, 0, 0), LocalTime::of(12, 59, 59, 999999999), LocalTime::of(23, 0, 0, 0), LocalTime::of(23, 0, 0, 999999999), LocalTime::of(23, 0, 59, 0), LocalTime::of(23, 0, 59, 999999999), LocalTime::of(23, 59, 0, 0), LocalTime::of(23, 59, 59, 999999999)]);
 }
示例#22
0
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_factory_CalendricalObject_invalid_noDerive()
 {
     MonthDay::from(LocalTime::of(12, 30));
 }
 public function test_truncatedTo_normal()
 {
     $this->assertEquals($this->TEST_DATE_TIME->truncatedTo(CU::NANOS()), $this->TEST_DATE_TIME);
     $this->assertEquals($this->TEST_DATE_TIME->truncatedTo(CU::SECONDS()), $this->TEST_DATE_TIME->withNano(0));
     $this->assertEquals($this->TEST_DATE_TIME->truncatedTo(CU::DAYS()), $this->TEST_DATE_TIME->adjust(LocalTime::MIDNIGHT()));
 }
 public function localDateTime(TemporalAccessor $temporal)
 {
     try {
         return $this->dateFrom($temporal)->atTime(LocalTime::from($temporal));
     } catch (DateTimeException $ex) {
         throw new DateTimeException("Unable to obtain ChronoLocalDateTime from TemporalAccessor: " . get_class($temporal), $ex);
     }
 }
示例#25
0
     *
     * @return string a string representation of this time, not null
     */
    public function __toString()
    {
        $buf = "";
        $hourValue = $this->hour;
        $minuteValue = $this->minute;
        $secondValue = $this->second;
        $nanoValue = $this->nano;
        $buf .= ($hourValue < 10 ? "0" : "") . $hourValue . ($minuteValue < 10 ? ":0" : ":") . $minuteValue;
        if ($secondValue > 0 || $nanoValue > 0) {
            $buf .= ($secondValue < 10 ? ":0" : ":") . $secondValue;
            if ($nanoValue > 0) {
                $buf .= '.';
                if ($nanoValue % 1000000 == 0) {
                    $buf .= substr(Math::div($nanoValue, 1000000) + 1000, 1);
                } else {
                    if ($nanoValue % 1000 == 0) {
                        $buf .= substr(Math::div($nanoValue, 1000) + 1000000, 1);
                    } else {
                        $buf .= substr($nanoValue + 1000000000, 1);
                    }
                }
            }
        }
        return $buf;
    }
}
LocalTime::init();
 public function test_print_append()
 {
     $buf = "EXISTING";
     $this->getFormatterFraction(ChronoField::NANO_OF_SECOND(), 0, 9, true)->formatTo(LocalTime::of(12, 30, 40, 3), $buf);
     $this->assertEquals("EXISTING.000000003", $buf);
 }
示例#27
0
 public function test_of()
 {
     //used for standard offset
     $stdOffset1 = ZoneOffset::UTC();
     $stdOffset2 = ZoneOffset::ofHours(1);
     $time_of_stdOffsetTransition1 = LocalDateTime::of(2013, 1, 5, 1, 0);
     $stdOffsetTransition1 = ZoneOffsetTransition::of($time_of_stdOffsetTransition1, $stdOffset1, $stdOffset2);
     $stdOffsetTransition_list = [];
     $stdOffsetTransition_list[] = $stdOffsetTransition1;
     //used for wall offset
     $wallOffset1 = ZoneOffset::ofHours(2);
     $wallOffset2 = ZoneOffset::ofHours(4);
     $wallOffset3 = ZoneOffset::ofHours(7);
     $time_of_wallOffsetTransition1 = LocalDateTime::of(2013, 2, 5, 1, 0);
     $time_of_wallOffsetTransition2 = LocalDateTime::of(2013, 3, 5, 1, 0);
     $time_of_wallOffsetTransition3 = LocalDateTime::of(2013, 10, 5, 1, 0);
     $wallOffsetTransition1 = ZoneOffsetTransition::of($time_of_wallOffsetTransition1, $wallOffset1, $wallOffset2);
     $wallOffsetTransition2 = ZoneOffsetTransition::of($time_of_wallOffsetTransition2, $wallOffset2, $wallOffset3);
     $wallOffsetTransition3 = ZoneOffsetTransition::of($time_of_wallOffsetTransition3, $wallOffset3, $wallOffset1);
     $wallOffsetTransition_list = [];
     $wallOffsetTransition_list[] = $wallOffsetTransition1;
     $wallOffsetTransition_list[] = $wallOffsetTransition2;
     $wallOffsetTransition_list[] = $wallOffsetTransition3;
     //used for ZoneOffsetTransitionRule
     $ruleOffset = ZoneOffset::ofHours(3);
     $timeDefinition = TimeDefinition::WALL();
     $rule1 = ZoneOffsetTransitionRule::of(Month::FEBRUARY(), 2, DayOfWeek::MONDAY(), LocalTime::of(1, 0), false, $timeDefinition, ZoneOffset::UTC(), ZoneOffset::UTC(), $ruleOffset);
     $rule_list = [];
     $rule_list[] = $rule1;
     //Begin verification
     $zoneRule = ZoneRules::of($stdOffset1, $wallOffset1, $stdOffsetTransition_list, $wallOffsetTransition_list, $rule_list);
     $before_time_of_stdOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_stdOffsetTransition1, $stdOffset1)->minusSeconds(1);
     $after_time_of_stdOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_stdOffsetTransition1, $stdOffset1)->plusSeconds(1);
     $this->assertEquals($zoneRule->getStandardOffset($before_time_of_stdOffsetTransition1->toInstant()), $stdOffset1);
     $this->assertEquals($zoneRule->getStandardOffset($after_time_of_stdOffsetTransition1->toInstant()), $stdOffset2);
     $before_time_of_wallOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition1, $wallOffset1)->minusSeconds(1);
     $after_time_of_wallOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition1, $wallOffset1)->plusSeconds(1);
     $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition1->toInstant()), $wallOffsetTransition1);
     $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition1->toInstant()), $wallOffsetTransition2);
     $before_time_of_wallOffsetTransition2 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition2, $wallOffset2)->minusSeconds(1);
     $after_time_of_wallOffsetTransition2 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition2, $wallOffset2)->plusSeconds(1);
     $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition2->toInstant()), $wallOffsetTransition2);
     $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition2->toInstant()), $wallOffsetTransition3);
     $before_time_of_wallOffsetTransition3 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition3, $wallOffset3)->minusSeconds(1);
     $after_time_of_wallOffsetTransition3 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition3, $wallOffset3)->plusSeconds(1);
     $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition3->toInstant()), $wallOffsetTransition3);
     $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition3->toInstant()), $rule1->createTransition(2014));
 }
示例#28
0
 public function test_atTime_LocalTime()
 {
     $t = LocalDate::of(2008, 6, 30);
     $this->assertEquals($t->atTime(LocalTime::of(11, 30)), LocalDateTime::of(2008, 6, 30, 11, 30));
 }
示例#29
0
 public function test_adjustInto_OffsetDateTime()
 {
     $base = ZoneOffset::ofHoursMinutesSeconds(1, 1, 1);
     for ($i = -18; $i <= 18; $i++) {
         $offsetDateTime_target = OffsetDateTime::ofDateAndTime(LocalDate::of(1909, 2, 2), LocalTime::of(10, 10, 10), ZoneOffset::ofHours($i));
         $offsetDateTime_result = $base->adjustInto($offsetDateTime_target);
         $this->assertEquals($base, $offsetDateTime_result->getOffset());
         //Do not change $offset of ZonedDateTime after adjustInto()
         $zonedDateTime_target = $offsetDateTime_target->toZonedDateTime();
         $zonedDateTime_result = $base->adjustInto($zonedDateTime_target);
         $this->assertEquals($zonedDateTime_target->getOffset(), $zonedDateTime_result->getOffset());
     }
 }
示例#30
0
 /**
  * Outputs this time as a {@code String}, such as {@code 10:15:30+01:00}.
  * <p>
  * The output will be one of the following ISO-8601 formats:
  * <ul>
  * <li>{@code HH:mmXXXXX}</li>
  * <li>{@code HH:mm:ssXXXXX}</li>
  * <li>{@code HH:mm:ss.SSSXXXXX}</li>
  * <li>{@code HH:mm:ss.SSSSSSXXXXX}</li>
  * <li>{@code HH:mm:ss.SSSSSSSSSXXXXX}</li>
  * </ul>
  * The format used will be the shortest that outputs the full value of
  * the time where the omitted parts are implied to be zero.
  *
  * @return string a string representation of this time, not null
  */
 public function __toString()
 {
     return $this->time->__toString() . $this->offset->__toString();
 }