/**
  * @setUp
  */
 public function setUp()
 {
     $this->builder = new DateTimeFormatterBuilder();
     $this->dta = ZonedDateTime::ofDateTime(LocalDateTime::of(2011, 6, 30, 12, 30, 40, 0), ZoneId::of("Europe/Paris"));
     $this->locale = Locale::of("en");
     $this->decimalStyle = DecimalStyle::STANDARD();
 }
Ejemplo n.º 2
0
 function data_durationBetweenLocalDateTime()
 {
     return [[LocalDateTime::of(2013, 3, 24, 0, 44, 31, 565000000), LocalDateTime::of(2013, 3, 24, 0, 44, 30, 65000000), -2, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 565000000), LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), -1, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 565000000), LocalDateTime::of(2013, 3, 24, 0, 44, 32, 65000000), 0, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 565000000), LocalDateTime::of(2013, 3, 24, 0, 44, 33, 65000000), 1, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 565000000), LocalDateTime::of(2013, 3, 24, 0, 44, 34, 65000000), 2, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 30, 565000000), -1, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 31, 565000000), 0, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 32, 565000000), 1, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 33, 565000000), 2, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 34, 565000000), 3, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 30, 65000000), -1, 0], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), 0, 0], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 32, 65000000), 1, 0], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 33, 65000000), 2, 0], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2013, 3, 24, 0, 44, 34, 65000000), 3, 0], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2813, 3, 24, 0, 44, 30, 565000000), 2 * self::CYCLE_SECS - 1, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2813, 3, 24, 0, 44, 31, 565000000), 2 * self::CYCLE_SECS + 0, 500000000], [LocalDateTime::of(2013, 3, 24, 0, 44, 31, 65000000), LocalDateTime::of(2813, 3, 24, 0, 44, 32, 565000000), 2 * self::CYCLE_SECS + 1, 500000000]];
 }
 public function test_appendTextMapIncomplete()
 {
     $map = [1, "JNY"];
     $this->builder->appendText3(ChronoField::MONTH_OF_YEAR(), $map);
     $f = $this->builder->toFormatter();
     $dt = LocalDateTime::of(2010, 2, 1, 0, 0);
     $this->assertEquals($f->format($dt), "2");
 }
 function data_adjustInto()
 {
     return [[OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), OffsetDateTime::of(2012, 3, 4, 1, 1, 1, 100, ZoneOffset::UTC()), OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), null], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), OffsetDateTime::MAX(), OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), null], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), OffsetDateTime::MIN(), OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), null], [OffsetDateTime::MAX(), OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), OffsetDateTime::ofDateTime(OffsetDateTime::MAX()->toLocalDateTime(), ZoneOffset::ofHours(-18)), null], [OffsetDateTime::MIN(), OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), OffsetDateTime::ofDateTime(OffsetDateTime::MIN()->toLocalDateTime(), ZoneOffset::ofHours(18)), null], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), ZonedDateTime::of(2012, 3, 4, 1, 1, 1, 100, self::ZONE_GAZA()), ZonedDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::ZONE_GAZA()), null], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), LocalDateTime::of(2012, 3, 4, 1, 1, 1, 100), null, DateTimeException::class], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), LocalDate::of(2210, 2, 2), null, DateTimeException::class], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), LocalTime::of(22, 3, 0), null, DateTimeException::class], [OffsetDateTime::of(2012, 3, 4, 23, 5, 0, 0, self::OFFSET_PONE()), OffsetTime::of(22, 3, 0, 0, ZoneOffset::UTC()), null, DateTimeException::class]];
 }
 public function test_toString_overlap()
 {
     $ldt = LocalDateTime::of(2010, 10, 31, 1, 0);
     $test = ZoneOffsetTransition::of($ldt, self::OFFSET_0300(), self::OFFSET_0200());
     $this->assertEquals("Transition[Overlap at 2010-10-31T01:00+03:00 to +02:00]", $test->__toString());
 }
Ejemplo n.º 6
0
 /**
  * Completes the build converting the builder to a set of time-zone rules.
  * <p>
  * Calling this method alters the state of the builder.
  * Further rules should not be added to this builder once this method is called.
  *
  * @param string $zoneId the time-zone ID, not null
  * @param array $deduplicateMap a map for deduplicating the values, not null
  * @return ZoneRules the zone rules, not null
  * @throws \LogicException if no windows have been added
  * @throws \LogicException if there is only one rule defined as being forever for any given window
  */
 public function _toRules($zoneId, &$deduplicateMap)
 {
     $this->deduplicateMap = $deduplicateMap;
     if (empty($this->windowList)) {
         throw new \LogicException("No windows have been added to the builder");
     }
     /** @var ZoneOffsetTransition[] $standardTransitionList */
     $standardTransitionList = [];
     /** @var ZoneOffsetTransition[] */
     $transitionList = [];
     /** @var ZoneOffsetTransitionRule[] */
     $lastTransitionRuleList = [];
     // initialize the standard offset calculation
     $firstWindow = $this->windowList[0];
     $loopStandardOffset = $firstWindow->standardOffset;
     $loopSavings = 0;
     if ($firstWindow->fixedSavingAmountSecs !== null) {
         $loopSavings = $firstWindow->fixedSavingAmountSecs;
     }
     /** @var ZoneOffset $firstWallOffset */
     $firstWallOffset = $this->deduplicate(ZoneOffset::ofTotalSeconds($loopStandardOffset->getTotalSeconds() + $loopSavings));
     /** @var LocalDateTime $loopWindowStart */
     $loopWindowStart = $this->deduplicate(LocalDateTime::of(Year::MIN_VALUE, 1, 1, 0, 0));
     $loopWindowOffset = $firstWallOffset;
     // build the windows and rules to interesting data
     foreach ($this->windowList as $window) {
         // tidy the state
         $window->tidy($loopWindowStart->getYear());
         // calculate effective savings at the start of the window
         $effectiveSavings = $window->fixedSavingAmountSecs;
         if ($effectiveSavings === null) {
             // apply rules from this window together with the standard offset and
             // savings from the last window to find the savings amount applicable
             // at start of this window
             $effectiveSavings = 0;
             foreach ($window->ruleList as $rule) {
                 $trans = $rule->toTransition($loopStandardOffset, $loopSavings);
                 if ($trans->toEpochSecond() > $loopWindowStart->toEpochSecond($loopWindowOffset)) {
                     // previous savings amount found, which could be the savings amount at
                     // the instant that the window starts (hence isAfter)
                     break;
                 }
                 $effectiveSavings = $rule->savingAmountSecs;
             }
         }
         // check if standard offset changed, and update it
         if ($loopStandardOffset->equals($window->standardOffset) === false) {
             $standardTransitionList[] = $this->deduplicate(ZoneOffsetTransition::of(LocalDateTime::ofEpochSecond($loopWindowStart->toEpochSecond($loopWindowOffset), 0, $loopStandardOffset), $loopStandardOffset, $window->standardOffset));
             $loopStandardOffset = $this->deduplicate($window->standardOffset);
         }
         // check if the start of the window represents a transition
         $effectiveWallOffset = $this->deduplicate(ZoneOffset::ofTotalSeconds($loopStandardOffset->getTotalSeconds() + $effectiveSavings));
         if ($loopWindowOffset->equals($effectiveWallOffset) === false) {
             $trans = $this->deduplicate(ZoneOffsetTransition::of($loopWindowStart, $loopWindowOffset, $effectiveWallOffset));
             $transitionList[] = $trans;
         }
         $loopSavings = $effectiveSavings;
         // apply rules within the window
         foreach ($window->ruleList as $rule) {
             /** @var ZoneOffsetTransition $trans */
             $trans = $this->deduplicate($rule->toTransition($loopStandardOffset, $loopSavings));
             if ($trans !== null && $trans->toEpochSecond() < $loopWindowStart->toEpochSecond($loopWindowOffset) === false && $trans->toEpochSecond() < $window->createDateTimeEpochSecond($loopSavings) && $trans->getOffsetBefore()->equals($trans->getOffsetAfter()) === false) {
                 $transitionList[] = $trans;
                 $loopSavings = $rule->savingAmountSecs;
             }
         }
         // calculate last rules
         foreach ($window->lastRuleList as $lastRule) {
             $transitionRule = $this->deduplicate($lastRule->toTransitionRule($loopStandardOffset, $loopSavings));
             $lastTransitionRuleList[] = $transitionRule;
             $loopSavings = $lastRule->savingAmountSecs;
         }
         // finally we can calculate the true end of the window, passing it to the next window
         $loopWindowOffset = $this->deduplicate($window->createWallOffset($loopSavings));
         $loopWindowStart = $this->deduplicate(LocalDateTime::ofEpochSecond($window->createDateTimeEpochSecond($loopSavings), 0, $loopWindowOffset));
     }
     return ZoneRules::of($firstWindow->standardOffset, $firstWallOffset, $standardTransitionList, $transitionList, $lastTransitionRuleList);
 }
Ejemplo n.º 7
0
 private function createLDT($year, $month, $day)
 {
     return LocalDateTime::of($year, $month, $day, 0, 0);
 }
Ejemplo n.º 8
0
 private static function dateTimeZoned($year, $month, $dayOfMonth, $hour, $minute, $second, $nanoOfSecond, ZoneOffset $offset, ZoneId $zoneId)
 {
     return ZonedDateTime::ofStrict(LocalDateTime::of($year, $month, $dayOfMonth, $hour, $minute, $second, $nanoOfSecond), $offset, $zoneId);
 }
 private static function DT_2012_06_30_12_30_40()
 {
     return LocalDateTime::of(2012, 6, 30, 12, 30, 40);
 }
 public function test_fieldResolvesToChronoLocalDateTime_noOverrideChrono_matches()
 {
     $ldt = LocalDateTime::of(2010, 6, 30, 12, 30);
     $f = (new DateTimeFormatterBuilder())->appendValue(new ResolvingField($ldt))->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());
 }
Ejemplo n.º 11
0
 public function parse(DateTimeParseContext $context, $text, $position)
 {
     // TODO cache formatter
     // new context to avoid overwriting fields like year/month/day
     $minDigits = $this->fractionalDigits < 0 ? 0 : $this->fractionalDigits;
     $maxDigits = $this->fractionalDigits < 0 ? 9 : $this->fractionalDigits;
     $parser = (new DateTimeFormatterBuilder())->append(DateTimeFormatter::ISO_LOCAL_DATE())->appendLiteral('T')->appendValue2(ChronoField::HOUR_OF_DAY(), 2)->appendLiteral(':')->appendValue2(ChronoField::MINUTE_OF_HOUR(), 2)->appendLiteral(':')->appendValue2(ChronoField::SECOND_OF_MINUTE(), 2)->appendFraction(ChronoField::NANO_OF_SECOND(), $minDigits, $maxDigits, true)->appendLiteral('Z')->toFormatter()->toPrinterParser(false);
     $newContext = $context->copy();
     $pos = $parser->parse($newContext, $text, $position);
     if ($pos < 0) {
         return $pos;
     }
     // parser restricts most fields to 2 digits, so definitely int
     // correctly parsed nano is also guaranteed to be valid
     $yearParsed = $newContext->getParsed(ChronoField::YEAR());
     $month = $newContext->getParsed(ChronoField::MONTH_OF_YEAR());
     $day = $newContext->getParsed(ChronoField::DAY_OF_MONTH());
     $hour = $newContext->getParsed(ChronoField::HOUR_OF_DAY());
     $min = $newContext->getParsed(ChronoField::MINUTE_OF_HOUR());
     $secVal = $newContext->getParsed(ChronoField::SECOND_OF_MINUTE());
     $nanoVal = $newContext->getParsed(ChronoField::NANO_OF_SECOND());
     $sec = $secVal !== null ? $secVal : 0;
     $nano = $nanoVal !== null ? $nanoVal : 0;
     $days = 0;
     if ($hour === 24 && $min === 0 && $sec === 0 && $nano === 0) {
         $hour = 0;
         $days = 1;
     } else {
         if ($hour === 23 && $min === 59 && $sec === 60) {
             $context->setParsedLeapSecond();
             $sec = 59;
         }
     }
     $year = $yearParsed % 10000;
     try {
         $ldt = LocalDateTime::of($year, $month, $day, $hour, $min, $sec, 0)->plusDays($days);
         $instantSecs = $ldt->toEpochSecond(ZoneOffset::UTC());
         $instantSecs += Math::multiplyExact(Math::div($yearParsed, 10000), self::SECONDS_PER_10000_YEARS);
     } catch (RuntimeException $ex) {
         // TODO What do we actually catch here and why
         return ~$position;
     }
     $successPos = $pos;
     $successPos = $context->setParsedField(ChronoField::INSTANT_SECONDS(), $instantSecs, $position, $successPos);
     return $context->setParsedField(ChronoField::NANO_OF_SECOND(), $nano, $position, $successPos);
 }
Ejemplo n.º 12
0
 /**
  * Obtains an instance of {@code ZonedDateTime} from a year, month, day,
  * hour, minute, second, nanosecond and time-zone.
  * <p>
  * This creates a zoned date-time matching the local date-time of the seven
  * specified fields as closely as possible.
  * 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 be adjusted.
  * <p>
  * The local date-time is resolved to a single instant on the time-line.
  * This is achieved by finding a valid offset from UTC/Greenwich for the local
  * date-time as defined by the {@link ZoneRules rules} of the zone ID.
  *<p>
  * In most cases, there is only one valid offset for a local date-time.
  * In the case of an overlap, when clocks are set back, there are two valid offsets.
  * This method uses the earlier offset typically corresponding to "summer".
  * <p>
  * In the case of a gap, when clocks jump forward, there is no valid offset.
  * Instead, the local date-time is adjusted to be later by the length of the gap.
  * For a typical one hour daylight savings change, the local date-time will be
  * moved one hour later into the offset typically corresponding to "summer".
  * <p>
  * This method exists primarily for writing test cases.
  * Non test-code will typically use other methods to create an offset time.
  * {@code LocalDateTime} has five 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 $year the year to represent, from MIN_YEAR to MAX_YEAR
  * @param int $month the month-of-year to represent, from 1 (January) to 12 (December)
  * @param int $dayOfMonth the day-of-month to represent, from 1 to 31
  * @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 ZoneId $zone the time-zone, not null
  * @return ZonedDateTime the offset date-time, not null
  * @throws DateTimeException if the value of any field is out of range, or
  *  if the day-of-month is invalid for the month-year
  */
 public static function of($year, $month, $dayOfMonth, $hour, $minute, $second, $nanoOfSecond, ZoneId $zone)
 {
     $dt = LocalDateTime::of($year, $month, $dayOfMonth, $hour, $minute, $second, $nanoOfSecond);
     return self::ofLocal($dt, $zone, null);
 }
Ejemplo n.º 13
0
 public function test_atDate()
 {
     $t = LocalTime::of(11, 30);
     $this->assertEquals($t->atDate(LocalDate::of(2012, 6, 30)), LocalDateTime::of(2012, 6, 30, 11, 30));
 }
 function data_rfc()
 {
     return [[LocalDateTime::of(2008, 6, 3, 11, 5, 30), "Z", "Tue, 3 Jun 2008 11:05:30 GMT"], [LocalDateTime::of(2008, 6, 30, 11, 5, 30), "Z", "Mon, 30 Jun 2008 11:05:30 GMT"], [LocalDateTime::of(2008, 6, 3, 11, 5, 30), "+02:00", "Tue, 3 Jun 2008 11:05:30 +0200"], [LocalDateTime::of(2008, 6, 30, 11, 5, 30), "-03:00", "Mon, 30 Jun 2008 11:05:30 -0300"]];
 }
Ejemplo n.º 15
0
 public function test_now_Clock()
 {
     $instant = LocalDateTime::of(2010, 12, 31, 0, 0)->toInstant(ZoneOffset::UTC());
     $clock = Clock::fixed($instant, ZoneOffset::UTC());
     $test = YearMonth::nowOf($clock);
     $this->assertEquals($test->getYear(), 2010);
     $this->assertEquals($test->getMonth(), Month::DECEMBER());
 }
Ejemplo n.º 16
0
 function data_quartersBetween()
 {
     return [[LocalDate::of(2000, 1, 1), LocalDate::of(2000, 1, 1), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 1, 2), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 2, 1), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 3, 1), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 3, 31), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 4, 1), 1], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 4, 2), 1], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 6, 30), 1], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 7, 1), 2], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 10, 1), 3], [LocalDate::of(2000, 1, 1), LocalDate::of(2000, 12, 31), 3], [LocalDate::of(2000, 1, 1), LocalDate::of(2001, 1, 1), 4], [LocalDate::of(2000, 1, 1), LocalDate::of(2002, 1, 1), 8], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 12, 31), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 10, 2), 0], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 10, 1), -1], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 7, 2), -1], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 7, 1), -2], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 4, 2), -2], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 4, 1), -3], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 1, 2), -3], [LocalDate::of(2000, 1, 1), LocalDate::of(1999, 1, 1), -4], [LocalDate::of(2000, 1, 1), LocalDate::of(1998, 12, 31), -4], [LocalDate::of(2000, 1, 1), LocalDate::of(1998, 10, 2), -4], [LocalDate::of(2000, 1, 1), LocalDate::of(1998, 10, 1), -5], [LocalDate::of(2000, 1, 1), LocalDateTime::of(2001, 4, 5, 0, 0), 5]];
 }
Ejemplo n.º 17
0
 private function dt($year, $month, $day, $hour, $min, $sec, $nano)
 {
     return LocalDateTime::of($year, $month, $day, $hour, $min, $sec, $nano);
 }
Ejemplo n.º 18
0
 public function data_formatStyle()
 {
     return [[ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::ZONEID_PARIS()), FormatStyle::FULL(), "Tuesday, October 2, 2001 1:02:03 AM CEST Europe/Paris"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::ZONEID_PARIS()), FormatStyle::LONG(), "October 2, 2001 1:02:03 AM CEST Europe/Paris"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::ZONEID_PARIS()), FormatStyle::MEDIUM(), "Oct 2, 2001, 1:02:03 AM Europe/Paris"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::ZONEID_PARIS()), FormatStyle::SHORT(), "10/2/01, 1:02 AM Europe/Paris"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::OFFSET_PTWO()), FormatStyle::FULL(), "Tuesday, October 2, 2001 at 1:02:03 AM +02:00 +02:00"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::OFFSET_PTWO()), FormatStyle::LONG(), "October 2, 2001 at 1:02:03 AM +02:00 +02:00"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::OFFSET_PTWO()), FormatStyle::MEDIUM(), "Oct 2, 2001, 1:02:03 AM +02:00"], [ZonedDateTime::ofDateTime(LocalDateTime::of(2001, 10, 2, 1, 2, 3), self::OFFSET_PTWO()), FormatStyle::SHORT(), "10/2/01, 1:02 AM +02:00"]];
 }
 public function test_parseBest_firstOption()
 {
     $test = DateTimeFormatter::ofPattern("yyyy-MM-dd HH:mm[XXX]");
     $result = $test->parseBest("2011-06-30 12:30+03:00", TemporalQueries::fromCallable([ZonedDateTime::class, "from"]), TemporalQueries::fromCallable([LocalDateTime::class, "from"]));
     $ldt = LocalDateTime::of(2011, 6, 30, 12, 30);
     $this->assertEquals($result, ZonedDateTime::ofDateTime($ldt, ZoneOffset::ofHours(3)));
 }
Ejemplo n.º 20
0
 function data_atStartOfDayZoneId()
 {
     return [[LocalDate::of(2008, 6, 30), self::ZONE_PARIS(), ZonedDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 0, 0), self::ZONE_PARIS())], [LocalDate::of(2008, 6, 30), self::OFFSET_PONE(), ZonedDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 0, 0), self::OFFSET_PONE())], [LocalDate::of(2007, 4, 1), self::ZONE_GAZA(), ZonedDateTime::ofDateTime(LocalDateTime::of(2007, 4, 1, 1, 0), self::ZONE_GAZA())]];
 }
Ejemplo n.º 21
0
 private static function ZDT()
 {
     return LocalDateTime::of(2008, 6, 30, 11, 30, 10, 500)->atZone(ZoneOffset::ofHours(2));
 }
Ejemplo n.º 22
0
 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]];
 }
Ejemplo n.º 23
0
 /**
  * Obtains an instance of {@code OffsetDateTime} from a year, month, day,
  * hour, minute, second, nanosecond and offset.
  * <p>
  * This creates an offset date-time with the seven 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 LocalDateTime} has five 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 $year the year to represent, from MIN_YEAR to MAX_YEAR
  * @param int $month the month-of-year to represent, from 1 (January) to 12 (December)
  * @param int $dayOfMonth the day-of-month to represent, from 1 to 31
  * @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 OffsetDateTime the offset date-time, not null
  * @throws DateTimeException if the value of any field is out of range, or
  *  if the day-of-month is invalid for the month-year
  */
 public static function of($year, $month, $dayOfMonth, $hour, $minute, $second, $nanoOfSecond, ZoneOffset $offset)
 {
     $dt = LocalDateTime::of($year, $month, $dayOfMonth, $hour, $minute, $second, $nanoOfSecond);
     return new OffsetDateTime($dt, $offset);
 }
Ejemplo n.º 24
0
 function data_toString()
 {
     return [[Instant::ofEpochSecond(65, 567), "1970-01-01T00:01:05.000000567Z"], [Instant::ofEpochSecond(65, 560), "1970-01-01T00:01:05.000000560Z"], [Instant::ofEpochSecond(65, 560000), "1970-01-01T00:01:05.000560Z"], [Instant::ofEpochSecond(65, 560000000), "1970-01-01T00:01:05.560Z"], [Instant::ofEpochSecond(1, 0), "1970-01-01T00:00:01Z"], [Instant::ofEpochSecond(60, 0), "1970-01-01T00:01:00Z"], [Instant::ofEpochSecond(3600, 0), "1970-01-01T01:00:00Z"], [Instant::ofEpochSecond(-1, 0), "1969-12-31T23:59:59Z"], [LocalDateTime::of(0, 1, 2, 0, 0)->toInstant(ZoneOffset::UTC()), "0000-01-02T00:00:00Z"], [LocalDateTime::of(0, 1, 1, 12, 30)->toInstant(ZoneOffset::UTC()), "0000-01-01T12:30:00Z"], [LocalDateTime::of(0, 1, 1, 0, 0, 0, 1)->toInstant(ZoneOffset::UTC()), "0000-01-01T00:00:00.000000001Z"], [LocalDateTime::of(0, 1, 1, 0, 0)->toInstant(ZoneOffset::UTC()), "0000-01-01T00:00:00Z"], [LocalDateTime::of(-1, 12, 31, 23, 59, 59, 999999999)->toInstant(ZoneOffset::UTC()), "-0001-12-31T23:59:59.999999999Z"], [LocalDateTime::of(-1, 12, 31, 12, 30)->toInstant(ZoneOffset::UTC()), "-0001-12-31T12:30:00Z"], [LocalDateTime::of(-1, 12, 30, 12, 30)->toInstant(ZoneOffset::UTC()), "-0001-12-30T12:30:00Z"], [LocalDateTime::of(-9999, 1, 2, 12, 30)->toInstant(ZoneOffset::UTC()), "-9999-01-02T12:30:00Z"], [LocalDateTime::of(-9999, 1, 1, 12, 30)->toInstant(ZoneOffset::UTC()), "-9999-01-01T12:30:00Z"], [LocalDateTime::of(-9999, 1, 1, 0, 0)->toInstant(ZoneOffset::UTC()), "-9999-01-01T00:00:00Z"], [LocalDateTime::of(-10000, 12, 31, 23, 59, 59, 999999999)->toInstant(ZoneOffset::UTC()), "-10000-12-31T23:59:59.999999999Z"], [LocalDateTime::of(-10000, 12, 31, 12, 30)->toInstant(ZoneOffset::UTC()), "-10000-12-31T12:30:00Z"], [LocalDateTime::of(-10000, 12, 30, 12, 30)->toInstant(ZoneOffset::UTC()), "-10000-12-30T12:30:00Z"], [LocalDateTime::of(-15000, 12, 31, 12, 30)->toInstant(ZoneOffset::UTC()), "-15000-12-31T12:30:00Z"], [LocalDateTime::of(-19999, 1, 2, 12, 30)->toInstant(ZoneOffset::UTC()), "-19999-01-02T12:30:00Z"], [LocalDateTime::of(-19999, 1, 1, 12, 30)->toInstant(ZoneOffset::UTC()), "-19999-01-01T12:30:00Z"], [LocalDateTime::of(-19999, 1, 1, 0, 0)->toInstant(ZoneOffset::UTC()), "-19999-01-01T00:00:00Z"], [LocalDateTime::of(-20000, 12, 31, 23, 59, 59, 999999999)->toInstant(ZoneOffset::UTC()), "-20000-12-31T23:59:59.999999999Z"], [LocalDateTime::of(-20000, 12, 31, 12, 30)->toInstant(ZoneOffset::UTC()), "-20000-12-31T12:30:00Z"], [LocalDateTime::of(-20000, 12, 30, 12, 30)->toInstant(ZoneOffset::UTC()), "-20000-12-30T12:30:00Z"], [LocalDateTime::of(-25000, 12, 31, 12, 30)->toInstant(ZoneOffset::UTC()), "-25000-12-31T12:30:00Z"], [LocalDateTime::of(9999, 12, 30, 12, 30)->toInstant(ZoneOffset::UTC()), "9999-12-30T12:30:00Z"], [LocalDateTime::of(9999, 12, 31, 12, 30)->toInstant(ZoneOffset::UTC()), "9999-12-31T12:30:00Z"], [LocalDateTime::of(9999, 12, 31, 23, 59, 59, 999999999)->toInstant(ZoneOffset::UTC()), "9999-12-31T23:59:59.999999999Z"], [LocalDateTime::of(10000, 1, 1, 0, 0)->toInstant(ZoneOffset::UTC()), "+10000-01-01T00:00:00Z"], [LocalDateTime::of(10000, 1, 1, 12, 30)->toInstant(ZoneOffset::UTC()), "+10000-01-01T12:30:00Z"], [LocalDateTime::of(10000, 1, 2, 12, 30)->toInstant(ZoneOffset::UTC()), "+10000-01-02T12:30:00Z"], [LocalDateTime::of(15000, 12, 31, 12, 30)->toInstant(ZoneOffset::UTC()), "+15000-12-31T12:30:00Z"], [LocalDateTime::of(19999, 12, 30, 12, 30)->toInstant(ZoneOffset::UTC()), "+19999-12-30T12:30:00Z"], [LocalDateTime::of(19999, 12, 31, 12, 30)->toInstant(ZoneOffset::UTC()), "+19999-12-31T12:30:00Z"], [LocalDateTime::of(19999, 12, 31, 23, 59, 59, 999999999)->toInstant(ZoneOffset::UTC()), "+19999-12-31T23:59:59.999999999Z"], [LocalDateTime::of(20000, 1, 1, 0, 0)->toInstant(ZoneOffset::UTC()), "+20000-01-01T00:00:00Z"], [LocalDateTime::of(20000, 1, 1, 12, 30)->toInstant(ZoneOffset::UTC()), "+20000-01-01T12:30:00Z"], [LocalDateTime::of(20000, 1, 2, 12, 30)->toInstant(ZoneOffset::UTC()), "+20000-01-02T12:30:00Z"], [LocalDateTime::of(25000, 12, 31, 12, 30)->toInstant(ZoneOffset::UTC()), "+25000-12-31T12:30:00Z"], [LocalDateTime::of(-999999999, 1, 1, 12, 30)->toInstant(ZoneOffset::UTC())->minus(1, CU::DAYS()), "-1000000000-12-31T12:30:00Z"], [LocalDateTime::of(999999999, 12, 31, 12, 30)->toInstant(ZoneOffset::UTC())->plus(1, CU::DAYS()), "+1000000000-01-01T12:30:00Z"], [Instant::MIN(), "-1000000000-01-01T00:00:00Z"], [Instant::MAX(), "+1000000000-12-31T23:59:59.999999999Z"]];
 }