public function test_withNanoOfSecond_normal()
 {
     $base = OffsetDateTime::ofDateAndTime(LocalDate::of(2008, 6, 30), LocalTime::of(11, 30, 59, 1), self::OFFSET_PONE());
     $test = $base->withNano(15);
     $this->assertEquals($test, OffsetDateTime::ofDateAndTime(LocalDate::of(2008, 6, 30), LocalTime::of(11, 30, 59, 15), self::OFFSET_PONE()));
 }
 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));
 }
 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]];
 }
 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));
 }
示例#5
0
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_until_invalidType()
 {
     $start = Instant::ofEpochSecond(12, 3000);
     $start->until(LocalTime::of(11, 30), CU::SECONDS());
 }
 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)]);
 }
示例#7
0
 /**
  * Combines this date with a time to create a {@code LocalDateTime}.
  * <p>
  * This returns a {@code LocalDateTime} formed from this date at the
  * specified hour, minute, second and nanosecond.
  * The individual time fields must be within their valid range.
  * All possible combinations of date and time are valid.
  *
  * @param int $hour the hour-of-day to use, from 0 to 23
  * @param int $minute the minute-of-hour to use, from 0 to 59
  * @param int $second the second-of-minute to represent, from 0 to 59
  * @param int $nanoOfSecond the nano-of-second to represent, from 0 to 999,999,999
  * @return LocalDateTime the local date-time formed from this date and the specified time, not null
  * @throws DateTimeException if the value of any field is out of range
  */
 public function atTimeNumerical($hour, $minute, $second = 0, $nanoOfSecond = 0)
 {
     return $this->atTime(LocalTime::of($hour, $minute, $second, $nanoOfSecond));
 }
示例#8
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]);
 }
示例#9
0
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_factory_from_TemporalAccessor_invalid_noDerive()
 {
     ZoneId::from(LocalTime::of(12, 30));
 }
示例#10
0
 /**
  * @expectedException     \Celest\DateTimeException
  */
 public function test_until_invalidType()
 {
     $start = Year::of(2010);
     $start->until(LocalTime::of(11, 30), ChronoUnit::YEARS());
 }
 public function test_fieldResolvesToChronoZonedDateTime_noOverrideChrono_matches()
 {
     $zdt = ZonedDateTime::of(2010, 6, 30, 12, 30, 0, 0, self::EUROPE_PARIS());
     $f = (new DateTimeFormatterBuilder())->appendValue(new ResolvingField($zdt))->toFormatter();
     $accessor = $f->parse("1234567890");
     $this->assertEquals($accessor->query(TemporalQueries::localDate()), LocalDate::of(2010, 6, 30));
     $this->assertEquals($accessor->query(TemporalQueries::localTime()), LocalTime::of(12, 30));
     $this->assertEquals($accessor->query(TemporalQueries::chronology()), IsoChronology::INSTANCE());
     $this->assertEquals($accessor->query(TemporalQueries::zoneId()), self::EUROPE_PARIS());
 }
示例#12
0
 private function time($hour, $min, $sec, $nano)
 {
     return LocalTime::of($hour, $min, $sec, $nano);
 }
示例#13
0
 public function test_with_adjustment_LocalTime()
 {
     $test = self::TEST_11_30_59_500_PONE()->adjust(LocalTime::of(13, 30));
     $this->assertEquals($test, OffsetTime::of(13, 30, 0, 0, self::OFFSET_PONE()));
 }
示例#14
0
 /**
  * Obtains an instance of {@code OffsetTime} from an hour, minute, second and nanosecond.
  * <p>
  * This creates an offset time with the four specified fields.
  * <p>
  * This method exists primarily for writing test cases.
  * Non test-code will typically use other methods to create an offset time.
  * {@code LocalTime} has two additional convenience variants of the
  * equivalent factory method taking fewer arguments.
  * They are not provided here to reduce the footprint of the API.
  *
  * @param int $hour the hour-of-day to represent, from 0 to 23
  * @param int $minute the minute-of-hour to represent, from 0 to 59
  * @param int $second the second-of-minute to represent, from 0 to 59
  * @param int $nanoOfSecond the nano-of-second to represent, from 0 to 999,999,999
  * @param ZoneOffset $offset the zone offset, not null
  * @return OffsetTime the offset time, not null
  * @throws DateTimeException if the value of any field is out of range
  */
 public static function of($hour, $minute, $second, $nanoOfSecond, ZoneOffset $offset)
 {
     return new OffsetTime(LocalTime::of($hour, $minute, $second, $nanoOfSecond), $offset);
 }
示例#15
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]];
 }
示例#16
0
 private function resolveTime($hod, $moh, $som, $nos)
 {
     if ($this->resolverStyle == ResolverStyle::LENIENT()) {
         $totalNanos = Math::multiplyExact($hod, 3600000000000);
         $totalNanos = Math::addExact($totalNanos, Math::multiplyExact($moh, 60000000000));
         $totalNanos = Math::addExact($totalNanos, Math::multiplyExact($som, 1000000000));
         $totalNanos = Math::addExact($totalNanos, $nos);
         $excessDays = (int) Math::floorDiv($totalNanos, 86400000000000);
         // safe int cast
         $nod = Math::floorMod($totalNanos, 86400000000000);
         $this->updateCheckConflict(LocalTime::ofNanoOfDay($nod), Period::ofDays($excessDays));
     } else {
         // STRICT or SMART
         $mohVal = CF::MINUTE_OF_HOUR()->checkValidIntValue($moh);
         $nosVal = CF::NANO_OF_SECOND()->checkValidIntValue($nos);
         // handle 24:00 end of day
         if ($this->resolverStyle == ResolverStyle::SMART() && $hod == 24 && $mohVal == 0 && $som == 0 && $nosVal == 0) {
             $this->updateCheckConflict(LocalTime::MIDNIGHT(), Period::ofDays(1));
         } else {
             $hodVal = CF::HOUR_OF_DAY()->checkValidIntValue($hod);
             $somVal = CF::SECOND_OF_MINUTE()->checkValidIntValue($som);
             $this->updateCheckConflict(LocalTime::of($hodVal, $mohVal, $somVal, $nosVal), Period::ZERO());
         }
     }
 }
示例#17
0
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_until_invalidType()
 {
     $start = YearMonth::of(2010, 6);
     $start->until(LocalTime::of(11, 30), CU::MONTHS());
 }
 private static function TIME_0100()
 {
     return LocalTime::of(1, 0);
 }
 public function test_with_adjuster_LocalTime()
 {
     $base = ZonedDateTime::ofDateTime(self::TEST_PARIS_OVERLAP_2008_10_26_02_30(), self::ZONE_PARIS());
     $test = $base->adjust(LocalTime::of(2, 29));
     $this->check($test, 2008, 10, 26, 2, 29, 0, 0, self::OFFSET_0200(), self::ZONE_PARIS());
 }
示例#20
0
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_factory_CalendricalObject_invalid_noDerive()
 {
     MonthDay::from(LocalTime::of(12, 30));
 }
 /**
  * @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);
 }
 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);
 }
示例#23
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());
     }
 }
 function data_time()
 {
     return [[LocalTime::of(11, 30), FormatStyle::SHORT(), \IntlDateFormatter::SHORT, Locale::UK()], [LocalTime::of(11, 30), FormatStyle::SHORT(), \IntlDateFormatter::SHORT, Locale::US()], [LocalTime::of(11, 30), FormatStyle::SHORT(), \IntlDateFormatter::SHORT, Locale::FRANCE()], [LocalTime::of(11, 30), FormatStyle::SHORT(), \IntlDateFormatter::SHORT, Locale::JAPAN()], [LocalTime::of(11, 30), FormatStyle::MEDIUM(), \IntlDateFormatter::MEDIUM, Locale::UK()], [LocalTime::of(11, 30), FormatStyle::MEDIUM(), \IntlDateFormatter::MEDIUM, Locale::US()], [LocalTime::of(11, 30), FormatStyle::MEDIUM(), \IntlDateFormatter::MEDIUM, Locale::FRANCE()], [LocalTime::of(11, 30), FormatStyle::MEDIUM(), \IntlDateFormatter::MEDIUM, Locale::JAPAN()]];
 }