示例#1
0
 /**
  * @internal
  * @param LocalDate $date
  * @return int
  */
 public static function getWeekBasedYear(LocalDate $date)
 {
     $year = $date->getYear();
     $doy = $date->getDayOfYear();
     if ($doy <= 3) {
         $dow = $date->getDayOfWeek()->getValue() - 1;
         if ($doy - $dow < -2) {
             $year--;
         }
     } else {
         if ($doy >= 363) {
             $dow = $date->getDayOfWeek()->getValue() - 1;
             $doy = $doy - 363 - ($date->isLeapYear() ? 1 : 0);
             if ($doy - $dow >= 0) {
                 $year++;
             }
         }
     }
     return $year;
 }
示例#2
0
 /**
  * Gets the day-of-week field, which is an enum {@code DayOfWeek}.
  * <p>
  * This method returns the enum {@link DayOfWeek} for the day-of-week.
  * 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 DayOfWeek#getValue() int value}.
  * <p>
  * Additional information can be obtained from the {@code DayOfWeek}.
  * This includes textual names of the values.
  *
  * @return DayOfWeek the day-of-week, not null
  */
 public function getDayOfWeek()
 {
     return $this->date->getDayOfWeek();
 }
 /**
  * @dataProvider data_week
  */
 public function test_WBY(LocalDate $date, DayOfWeek $dow, $week, $wby)
 {
     $this->assertEquals($date->getDayOfWeek(), $dow);
     $this->assertEquals(IsoFields::WEEK_BASED_YEAR()->getFrom($date), $wby);
     $this->assertEquals($date->get(IsoFields::WEEK_BASED_YEAR()), $wby);
 }
 public function setFields(LocalDate $dt)
 {
     if ($dt !== null) {
         $this->fields->put(ChronoField::YEAR(), $dt->getYear());
         $this->fields->put(ChronoField::MONTH_OF_YEAR(), $dt->getMonthValue());
         $this->fields->put(ChronoField::DAY_OF_MONTH(), $dt->getDayOfMonth());
         $this->fields->put(ChronoField::DAY_OF_YEAR(), $dt->getDayOfYear());
         $this->fields->put(ChronoField::DAY_OF_WEEK(), $dt->getDayOfWeek()->getValue());
         $this->fields->put(IsoFields::WEEK_BASED_YEAR(), $dt->getLong(IsoFields::WEEK_BASED_YEAR()));
         $this->fields->put(IsoFields::WEEK_OF_WEEK_BASED_YEAR(), $dt->getLong(IsoFields::WEEK_OF_WEEK_BASED_YEAR()));
     }
 }