Beispiel #1
0
 /**
  * Gets the month-of-year field using the {@code Month} enum.
  * <p>
  * This method returns the enum {@link Month} for the month.
  * This avoids confusion as to what {@code int} values mean.
  * If you need access to the primitive {@code int} value then the enum
  * provides the {@link Month#getValue() int value}.
  *
  * @return Month the month-of-year, not null
  * @see #getMonthValue()
  */
 public function getMonth()
 {
     return Month::of($this->month);
 }
 /**
  * @dataProvider provider_sampleDates
  */
 public function test_get($y, $m)
 {
     $a = YearMonth::of($y, $m);
     $this->assertEquals($a->getYear(), $y);
     $this->assertEquals($a->getMonth(), Month::of($m));
     $this->assertEquals($a->getMonthValue(), $m);
 }
 /**
  * @dataProvider provider_sampleDates
  */
 public function test_getDOY($y, $m, $d)
 {
     $a = LocalDateTime::of($y, $m, $d, 12, 30);
     $total = 0;
     for ($i = 1; $i < $m; $i++) {
         $total += Month::of($i)->length(Year::isLeapYear($y));
     }
     $doy = $total + $d;
     $this->assertEquals($a->getDayOfYear(), $doy);
 }
 /**
  * @dataProvider provider_sampleDates
  */
 public function test_get($m, $d)
 {
     $a = MonthDay::of($m, $d);
     $this->assertEquals($a->getMonth(), Month::of($m));
     $this->assertEquals($a->getMonthValue(), $m);
     $this->assertEquals($a->getDayOfMonth(), $d);
 }
 private function parseMonth(\CachingIterator $s)
 {
     $s->next();
     $month = $s->current();
     if ($m = preg_match(self::$MONTH, $month, $mr)) {
         for ($moy = 1; $moy < 13 && $moy < count($mr); $moy++) {
             if ($mr[$moy] !== '') {
                 return Month::of($moy);
             }
         }
     }
     throw new IllegalArgumentException("Unknown month: " . $month);
 }
Beispiel #6
0
 /**
  * Returns a copy of this {@code MonthDay} with the month-of-year altered.
  * <p>
  * This returns a month-day with the specified month.
  * If the day-of-month is invalid for the specified month, the day will
  * be adjusted to the last valid day-of-month.
  * <p>
  * This instance is immutable and unaffected by this method call.
  *
  * @param int $month the month-of-year to set in the returned month-day, from 1 (January) to 12 (December)
  * @return MonthDay a {@code MonthDay} based on this month-day with the requested month, not null
  * @throws DateTimeException if the month-of-year value is invalid
  */
 public function withMonth($month)
 {
     return self::with(Month::of($month));
 }
Beispiel #7
0
 /**
  * @dataProvider data_minus
  */
 public function test_minus_long($base, $amount, $expected)
 {
     $this->assertEquals(Month::of($base)->minus($amount), Month::of($expected));
 }
 /**
  * @dataProvider data_dayOfWeekInMonth_negative
  */
 public function test_lastInMonth($year, $month, DayOfWeek $dow, LocalDate $expected)
 {
     for ($day = 1; $day <= Month::of($month)->length(false); $day++) {
         $date = LocalDate::of($year, $month, $day);
         $test = TemporalAdjusters::lastInMonth($dow)->adjustInto($date);
         $this->assertEquals($test, $expected, "day-of-month=" . $day);
     }
 }