Exemple #1
0
 private function toDateTime($year)
 {
     $this->adjustToFowards($year);
     if ($this->dayOfMonth === -1) {
         $dayOfMonth = $this->month->length(Year::isLeapYear($year));
         $date = LocalDate::ofMonth($year, $this->month, $dayOfMonth);
         if ($this->dayOfWeek !== null) {
             $date = $date->adjust(TemporalAdjusters::previousOrSame($this->dayOfWeek));
         }
     } else {
         $date = LocalDate::ofMonth($year, $this->month, $this->dayOfMonth);
         if ($this->dayOfWeek !== null) {
             $date = $date->adjust(TemporalAdjusters::nextOrSame($this->dayOfWeek));
         }
     }
     $ldt = LocalDateTime::ofDateAndTime($date, $this->time);
     if ($this->endOfDay) {
         $ldt = $ldt->plusDays(1);
     }
     return $ldt;
 }
 /**
  * @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);
 }
 function resolveYMD(FieldValues $fieldValues, ResolverStyle $resolverStyle)
 {
     $y = CF::YEAR()->checkValidIntValue($fieldValues->remove(CF::YEAR()));
     if ($resolverStyle == ResolverStyle::LENIENT()) {
         $months = Math::subtractExact($fieldValues->remove(CF::MONTH_OF_YEAR()), 1);
         $days = Math::subtractExact($fieldValues->remove(CF::DAY_OF_MONTH()), 1);
         return LocalDate::of($y, 1, 1)->plusMonths($months)->plusDays($days);
     }
     $moy = CF::MONTH_OF_YEAR()->checkValidIntValue($fieldValues->remove(CF::MONTH_OF_YEAR()));
     $dom = CF::DAY_OF_MONTH()->checkValidIntValue($fieldValues->remove(CF::DAY_OF_MONTH()));
     if ($resolverStyle == ResolverStyle::SMART()) {
         // previous valid
         if ($moy == 4 || $moy == 6 || $moy == 9 || $moy == 11) {
             $dom = Math::min($dom, 30);
         } else {
             if ($moy == 2) {
                 $dom = Math::min($dom, Month::FEBRUARY()->length(Year::isLeapYear($y)));
             }
         }
     }
     return LocalDate::of($y, $moy, $dom);
 }
Exemple #4
0
 /**
  * Checks if the year is a leap year, according to the ISO proleptic
  * calendar system rules.
  * <p>
  * This method applies the current rules for leap years across the whole time-line.
  * In general, a year is a leap year if it is divisible by four without
  * remainder. However, years divisible by 100, are not leap years, with
  * the exception of years divisible by 400 which are.
  * <p>
  * For example, 1904 is a leap year it is divisible by 4.
  * 1900 was not a leap year as it is divisible by 100, however 2000 was a
  * leap year as it is divisible by 400.
  * <p>
  * The calculation is proleptic - applying the same rules into the far future and far past.
  * This is historically inaccurate, but is correct for the ISO-8601 standard.
  *
  * @return bool true if the year is leap, false otherwise
  */
 public function isLeap()
 {
     return Year::isLeapYear($this->year);
 }
Exemple #5
0
 /**
  * Checks if the year is valid for this month-day.
  * <p>
  * This method checks whether this month and day and the input year form
  * a valid date. This can only return false for February 29th.
  *
  * @param int $year the year to validate
  * @return bool true if the year is valid for this month-day
  * @see Year#isValidMonthDay(MonthDay)
  */
 public function isValidYear($year)
 {
     return ($this->day == 29 && $this->month == 2 && Year::isLeapYear($year) == false) == false;
 }