コード例 #1
0
 public function test_parse_leapSecond()
 {
     $expected = OffsetDateTime::of(1970, 2, 3, 23, 59, 59, 123456789, ZoneOffset::UTC())->toInstant();
     $f = (new DateTimeFormatterBuilder())->appendInstant4(-1)->toFormatter();
     foreach (ResolverStyle::values() as $style) {
         $pared = $f->withResolverStyle($style)->parse("1970-02-03T23:59:60.123456789Z");
         $this->assertEquals($pared->query(Instant::fromQuery()), $expected);
         $this->assertEquals($pared->query(DateTimeFormatter::parsedExcessDays()), Period::ZERO());
         $this->assertEquals($pared->query(DateTimeFormatter::parsedLeapSecond()), true);
     }
 }
コード例 #2
0
 /**
  * A query that provides access to the excess days that were parsed.
  * <p>
  * This returns a singleton {@linkplain TemporalQuery query} that provides
  * access to additional information from the parse. The query always returns
  * a non-null period, with a zero period returned instead of null.
  * <p>
  * There are two situations where this query may return a non-zero period.
  * <ul>
  * <li>If the {@code ResolverStyle} is {@code LENIENT} and a time is parsed
  *  without a date, then the complete result of the parse consists of a
  *  {@code LocalTime} and an excess {@code Period} in days.
  *
  * <li>If the {@code ResolverStyle} is {@code SMART} and a time is parsed
  *  without a date where the time is 24:00:00, then the complete result of
  *  the parse consists of a {@code LocalTime} of 00:00:00 and an excess
  *  {@code Period} of one day.
  * </ul>
  * <p>
  * In both cases, if a complete {@code ChronoLocalDateTime} or {@code Instant}
  * is parsed, then the excess days are added to the date part.
  * As a result, this query will return a zero period.
  * <p>
  * The {@code SMART} behaviour handles the common "end of day" 24:00 value.
  * Processing in {@code LENIENT} mode also produces the same result:
  * <pre>
  *  Text to parse        Parsed object                         Excess days
  *  "2012-12-03T00:00"   LocalDateTime.of(2012, 12, 3, 0, 0)   ZERO
  *  "2012-12-03T24:00"   LocalDateTime.of(2012, 12, 4, 0, 0)   ZERO
  *  "00:00"              LocalTime.of(0, 0)                    ZERO
  *  "24:00"              LocalTime.of(0, 0)                    Period.ofDays(1)
  * </pre>
  * The query can be used as follows:
  * <pre>
  *  TemporalAccessor parsed = formatter.parse(str);
  *  LocalTime time = parsed.query(LocalTime::from);
  *  Period extraDays = parsed.query(DateTimeFormatter.parsedExcessDays());
  * </pre>
  * @return TemporalQuery a query that provides access to the excess days that were parsed
  */
 public static function parsedExcessDays()
 {
     return self::$PARSED_EXCESS_DAYS = new FuncTemporalQuery(function (TemporalAccessor $t) {
         if ($t instanceof Parsed) {
             return $t->excessDays;
         } else {
             return Period::ZERO();
         }
     });
 }
コード例 #3
0
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_factory_from_TemporalAmount_Period()
 {
     Duration::from(Period::ZERO());
 }
コード例 #4
0
ファイル: Parsed.php プロジェクト: celest-time/prototype
 private function resolvePeriod()
 {
     // add whole days if we have both date and time
     if ($this->date != null && $this->time != null && $this->excessDays->isZero() == false) {
         $this->date = $this->date->plusAmount($this->excessDays);
         $this->excessDays = Period::ZERO();
     }
 }
コード例 #5
0
 function data_toString()
 {
     return [[Period::ZERO(), "P0D"], [Period::ofDays(0), "P0D"], [Period::ofYears(1), "P1Y"], [Period::ofMonths(1), "P1M"], [Period::ofDays(1), "P1D"], [Period::of(1, 2, 0), "P1Y2M"], [Period::of(0, 2, 3), "P2M3D"], [Period::of(1, 2, 3), "P1Y2M3D"]];
 }
コード例 #6
0
 /**
  * @dataProvider data_resolveFourToTime
  */
 public function test_resolveFourToDateTime($style, $hour, $min, $sec, $nano, $expectedTime, $excessPeriod)
 {
     $f = (new DateTimeFormatterBuilder())->parseDefaulting(ChronoField::YEAR(), 2012)->parseDefaulting(ChronoField::MONTH_OF_YEAR(), 6)->parseDefaulting(ChronoField::DAY_OF_MONTH(), 30)->parseDefaulting(ChronoField::HOUR_OF_DAY(), $hour)->parseDefaulting(ChronoField::MINUTE_OF_HOUR(), $min)->parseDefaulting(ChronoField::SECOND_OF_MINUTE(), $sec)->parseDefaulting(ChronoField::NANO_OF_SECOND(), $nano)->toFormatter();
     $styles = $style !== null ? [$style] : ResolverStyle::values();
     if ($expectedTime !== null && $excessPeriod !== null) {
         $expectedDate = LocalDate::of(2012, 6, 30)->plusAmount($excessPeriod);
         foreach ($styles as $s) {
             $accessor = $f->withResolverStyle($s)->parse("");
             $this->assertEquals($accessor->query(TemporalQueries::localDate()), $expectedDate, "ResolverStyle: " . $s);
             $this->assertEquals($accessor->query(TemporalQueries::localTime()), $expectedTime, "ResolverStyle: " . $s);
             $this->assertEquals($accessor->query(DateTimeFormatter::parsedExcessDays()), Period::ZERO(), "ResolverStyle: " . $s);
         }
     }
 }
コード例 #7
0
 public function test_minus_TemporalAmount_zero()
 {
     $period = Period::ZERO();
     $t = self::TEST_123040987654321()->minusAmount($period);
     $this->assertEquals($t, self::TEST_123040987654321());
 }
コード例 #8
0
 public function test_minus_MinusAdjuster_zero()
 {
     $t = self::TEST_11_30_59_500_PONE()->minusAmount(Period::ZERO());
     $this->assertEquals($t, self::TEST_11_30_59_500_PONE());
 }