private function monthsUntil(LocalDate $end) { $packed1 = $this->getProlepticMonth() * 32 + $this->getDayOfMonth(); // no overflow $packed2 = $end->getProlepticMonth() * 32 + $end->getDayOfMonth(); // no overflow return Math::div($packed2 - $packed1, 32); }
private function previous(LocalDate $date) { $newDayOfMonth = $date->getDayOfMonth() - 1; if ($newDayOfMonth > 0) { return $date->withDayOfMonth($newDayOfMonth); } $date = $date->adjust($date->getMonth()->minus(1)); if ($date->getMonth() == Month::DECEMBER()) { $date = $date->withYear($date->getYear() - 1); } return $date->withDayOfMonth($date->getMonth()->length(Year::isLeapYear($date->getYear()))); }
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())); } }
public function serialize() { return $this->date->getYear() . ':' . $this->date->getMonthValue() . ':' . $this->date->getDayOfMonth() . ':' . $this->time->getHour() . ':' . $this->time->getMinute() . ':' . $this->time->getSecond() . ':' . $this->time->getNano(); }
/** * @dataProvider data_date */ public function test_date_parse(LocalDate $date, FormatStyle $dateStyle, $dateStyleOld, Locale $locale) { $old = \IntlDateFormatter::create($locale->getLocale(), $dateStyleOld, \IntlDateFormatter::NONE, new \DateTimeZone('UTC')); $oldDate = new \DateTime($date->getYear() . '-' . $date->getMonthValue() . '-' . $date->getDayOfMonth(), new \DateTimeZone('UTC')); $text = $old->format($oldDate); $f = $this->builder->appendLocalized($dateStyle, null)->toFormatter2($locale); $parsed = $f->parsePos($text, $this->pos); $this->assertEquals($this->pos->getIndex(), strlen($text)); $this->assertEquals($this->pos->getErrorIndex(), -1); $this->assertEquals(LocalDate::from($parsed), $date); }