/** * 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() { $dow0 = Math::floorMod($this->toEpochDay() + 3, 7); return DayOfWeek::of($dow0 + 1); }
/** * @dataProvider data_minus */ public function test_minus_long($base, $amount, $expected) { $this->assertEquals(DayOfWeek::of($base)->minus($amount), DayOfWeek::of($expected)); }
protected function resolveAligned(ChronoLocalDate $base, $months, $weeks, $dow) { $date = $base->plus($months, ChronoUnit::MONTHS())->plus($weeks, ChronoUnit::WEEKS()); if ($dow > 7) { $date = $date->plus(($dow - 1) / 7, ChronoUnit::WEEKS()); $dow = ($dow - 1) % 7 + 1; } else { if ($dow < 1) { $date = $date->plus(Math::subtractExact($dow, 7) / 7, ChronoUnit::WEEKS()); $dow = ($dow + 6) % 7 + 1; } } return $date->adjust(TemporalAdjusters::nextOrSame(DayOfWeek::of((int) $dow))); }
/** * @param string $str * @return DayOfWeek * @throws IllegalArgumentException */ private function parseDayOfWeek($str) { if (preg_match(self::$DOW, $str, $mr)) { for ($dow = 1; $dow < 8 && $dow < count($mr); $dow++) { if ($mr[$dow] !== '') { return DayOfWeek::of($dow); } } } throw new IllegalArgumentException("Unknown day-of-week: " . $str); }