Exemplo n.º 1
0
 private function ym($year, $month)
 {
     return YearMonth::of($year, $month);
 }
 function data_format_withZone_withChronology()
 {
     $ym = YearMonth::of(2008, 6);
     $ld = LocalDate::of(2008, 6, 30);
     $lt = LocalTime::of(11, 30);
     $ldt = LocalDateTime::of(2008, 6, 30, 11, 30);
     $ot = OffsetTime::ofLocalTime(LocalTime::of(11, 30), self::OFFSET_PONE());
     $odt = OffsetDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 11, 30), self::OFFSET_PONE());
     $zdt = ZonedDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 11, 30), self::ZONE_PARIS());
     $thaiZdt = ThaiBuddhistChronology::INSTANCE()->zonedDateTimeFrom($zdt);
     $instant = Instant::ofEpochSecond(3600);
     return [[null, null, DayOfWeek::MONDAY(), "::::"], [null, null, $ym, "2008::::ISO"], [null, null, $ld, "2008::::ISO"], [null, null, $lt, ":11:::"], [null, null, $ldt, "2008:11:::ISO"], [null, null, $ot, ":11:+01:00::"], [null, null, $odt, "2008:11:+01:00::ISO"], [null, null, $zdt, "2008:11:+02:00:Europe/Paris:ISO"], [null, null, $instant, "::::"], [IsoChronology::INSTANCE(), null, DayOfWeek::MONDAY(), "::::ISO"], [IsoChronology::INSTANCE(), null, $ym, "2008::::ISO"], [IsoChronology::INSTANCE(), null, $ld, "2008::::ISO"], [IsoChronology::INSTANCE(), null, $lt, ":11:::ISO"], [IsoChronology::INSTANCE(), null, $ldt, "2008:11:::ISO"], [IsoChronology::INSTANCE(), null, $ot, ":11:+01:00::ISO"], [IsoChronology::INSTANCE(), null, $odt, "2008:11:+01:00::ISO"], [IsoChronology::INSTANCE(), null, $zdt, "2008:11:+02:00:Europe/Paris:ISO"], [IsoChronology::INSTANCE(), null, $instant, "::::ISO"], [null, self::ZONE_PARIS(), DayOfWeek::MONDAY(), ":::Europe/Paris:"], [null, self::ZONE_PARIS(), $ym, "2008:::Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $ld, "2008:::Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $lt, ":11::Europe/Paris:"], [null, self::ZONE_PARIS(), $ldt, "2008:11::Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $ot, ":11:+01:00:Europe/Paris:"], [null, self::ZONE_PARIS(), $odt, "2008:12:+02:00:Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $zdt, "2008:11:+02:00:Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $instant, "1970:02:+01:00:Europe/Paris:ISO"], [null, self::OFFSET_PTHREE(), DayOfWeek::MONDAY(), ":::+03:00:"], [null, self::OFFSET_PTHREE(), $ym, "2008:::+03:00:ISO"], [null, self::OFFSET_PTHREE(), $ld, "2008:::+03:00:ISO"], [null, self::OFFSET_PTHREE(), $lt, ":11::+03:00:"], [null, self::OFFSET_PTHREE(), $ldt, "2008:11::+03:00:ISO"], [null, self::OFFSET_PTHREE(), $ot, null], [null, self::OFFSET_PTHREE(), $odt, "2008:13:+03:00:+03:00:ISO"], [null, self::OFFSET_PTHREE(), $zdt, "2008:12:+03:00:+03:00:ISO"], [null, self::OFFSET_PTHREE(), $instant, "1970:04:+03:00:+03:00:ISO"], [ThaiBuddhistChronology::INSTANCE(), null, DayOfWeek::MONDAY(), null], [ThaiBuddhistChronology::INSTANCE(), null, $ym, null], [ThaiBuddhistChronology::INSTANCE(), null, $ld, "2551::::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $lt, ":11:::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $ldt, "2551:11:::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $ot, ":11:+01:00::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $odt, "2551:11:+01:00::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $instant, "::::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, DayOfWeek::MONDAY(), null], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ym, null], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ld, "2551:::Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $lt, ":11::Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ldt, "2551:11::Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ot, ":11:+01:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $odt, "2551:12:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $instant, "2513:02:+01:00:Europe/Paris:ThaiBuddhist"], [null, self::ZONE_PARIS(), $thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [IsoChronology::INSTANCE(), self::ZONE_PARIS(), $thaiZdt, "2008:11:+02:00:Europe/Paris:ISO"]];
 }
Exemplo n.º 3
0
 /**
  * Combines this year with a month to create a {@code YearMonth}.
  * <p>
  * This returns a {@code YearMonth} formed from this year and the specified month.
  * All possible combinations of year and month are valid.
  * <p>
  * This method can be used as part of a chain to produce a date:
  * <pre>
  *  LocalDate date = year.atMonth(month).atDay(day);
  * </pre>
  *
  * @param int $month the month-of-year to use, from 1 (January) to 12 (December)
  * @return YearMonth Year the year-month formed from this year and the specified month, not null
  * @throws DateTimeException if the month is invalid
  */
 public function atMonthNumerical($month)
 {
     return YearMonth::of($this->year, $month);
 }
Exemplo n.º 4
0
 /**
  * Calculates the amount of time until another year-month in terms of the specified unit.
  * <p>
  * This calculates the amount of time between two {@code YearMonth}
  * objects in terms of a single {@code TemporalUnit}.
  * The start and end points are {@code this} and the specified year-month.
  * The result will be negative if the end is before the start.
  * The {@code Temporal} passed to this method is converted to a
  * {@code YearMonth} using {@link #from(TemporalAccessor)}.
  * For example, the amount in years between two year-months can be calculated
  * using {@code startYearMonth.until(endYearMonth, YEARS)}.
  * <p>
  * The calculation returns a whole number, representing the number of
  * complete units between the two year-months.
  * For example, the amount in decades between 2012-06 and 2032-05
  * will only be one decade as it is one month short of two decades.
  * <p>
  * There are two equivalent ways of using this method.
  * The first is to invoke this method.
  * The second is to use {@link TemporalUnit#between(Temporal, Temporal)}:
  * <pre>
  *   // these two lines are equivalent
  *   amount = start.until(end, MONTHS);
  *   amount = MONTHS.between(start, end);
  * </pre>
  * The choice should be made based on which makes the code more readable.
  * <p>
  * The calculation is implemented in this method for {@link ChronoUnit}.
  * The units {@code MONTHS}, {@code YEARS}, {@code DECADES},
  * {@code CENTURIES}, {@code MILLENNIA} and {@code ERAS} are supported.
  * Other {@code ChronoUnit} values will throw an exception.
  * <p>
  * If the unit is not a {@code ChronoUnit}, then the result of this method
  * is obtained by invoking {@code TemporalUnit.between(Temporal, Temporal)}
  * passing {@code this} as the first argument and the converted input temporal
  * as the second argument.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param Temporal $endExclusive the end date, exclusive, which is converted to a {@code YearMonth}, not null
  * @param TemporalUnit $unit the unit to measure the amount in, not null
  * @return int the amount of time between this year-month and the end year-month
  * @throws DateTimeException if the amount cannot be calculated, or the end
  *  temporal cannot be converted to a {@code YearMonth}
  * @throws UnsupportedTemporalTypeException if the unit is not supported
  * @throws ArithmeticException if numeric overflow occurs
  */
 public function until(Temporal $endExclusive, TemporalUnit $unit)
 {
     $end = YearMonth::from($endExclusive);
     if ($unit instanceof ChronoUnit) {
         $monthsUntil = $end->getProlepticMonth() - $this->getProlepticMonth();
         // no overflow
         switch ($unit) {
             case ChronoUnit::MONTHS():
                 return $monthsUntil;
             case ChronoUnit::YEARS():
                 return Math::div($monthsUntil, 12);
             case ChronoUnit::DECADES():
                 return Math::div($monthsUntil, 120);
             case ChronoUnit::CENTURIES():
                 return Math::div($monthsUntil, 1200);
             case ChronoUnit::MILLENNIA():
                 return Math::div($monthsUntil, 12000);
             case ChronoUnit::ERAS():
                 return $end->getLong(ChronoField::ERA()) - $this->getLong(ChronoField::ERA());
         }
         throw new UnsupportedTemporalTypeException("Unsupported unit: " . $unit);
     }
     return $unit->between($this, $end);
 }
 public function test_padOptional()
 {
     $this->builder->appendValue(ChronoField::MONTH_OF_YEAR())->appendLiteral(':')->padNext(5)->optionalStart()->appendValue(ChronoField::DAY_OF_MONTH())->optionalEnd()->appendLiteral(':')->appendValue(ChronoField::YEAR());
     $this->assertEquals($this->builder->toFormatter()->format(LocalDate::of(2013, 2, 1)), "2:    1:2013");
     $this->assertEquals($this->builder->toFormatter()->format(YearMonth::of(2013, 2)), "2:     :2013");
 }
Exemplo n.º 6
0
 public function test_atMonth_int()
 {
     $test = Year::of(2008);
     $this->assertEquals($test->atMonthNumerical(6), YearMonth::of(2008, 6));
 }
 /**
  * @expectedException \Celest\DateTimeException
  */
 public function test_print_rfc1123_missingField()
 {
     $test = YearMonth::of(2008, 6);
     DateTimeFormatter::RFC_1123_DATE_TIME()->format($test);
 }