/** * @group long */ public function test_now_Clock_allSecsInDay_beforeEpoch() { $expected = LocalTime::MIDNIGHT()->plusNanos(123456789); for ($i = -1; $i >= -(24 * 60 * 60); $i--) { $instant = Instant::ofEpochSecond($i)->plusNanos(123456789); $clock = Clock::fixed($instant, ZoneOffset::UTC()); $test = ZonedDateTime::nowOf($clock); $this->assertEquals($test->getYear(), 1969); $this->assertEquals($test->getMonth(), Month::DECEMBER()); $this->assertEquals($test->getDayOfMonth(), 31); $expected = $expected->minusSeconds(1); $this->assertEquals($test->toLocalTime(), $expected); $this->assertEquals($test->getOffset(), ZoneOffset::UTC()); $this->assertEquals($test->getZone(), ZoneOffset::UTC()); } }
public function test_now_Clock() { $instant = LocalDateTime::of(2010, 12, 31, 0, 0)->toInstant(ZoneOffset::UTC()); $clock = Clock::fixed($instant, ZoneOffset::UTC()); $test = YearMonth::nowOf($clock); $this->assertEquals($test->getYear(), 2010); $this->assertEquals($test->getMonth(), Month::DECEMBER()); }
public function test_with_adjustment_Month() { $test = self::TEST_2008_6_30_11_30_59_000000500()->adjust(Month::DECEMBER()); $this->assertEquals($test, OffsetDateTime::ofDateAndTime(LocalDate::of(2008, 12, 30), LocalTime::of(11, 30, 59, 500), self::OFFSET_PONE())); }
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 test_toString() { $this->assertEquals(Month::JANUARY()->__toString(), "JANUARY"); $this->assertEquals(Month::FEBRUARY()->__toString(), "FEBRUARY"); $this->assertEquals(Month::MARCH()->__toString(), "MARCH"); $this->assertEquals(Month::APRIL()->__toString(), "APRIL"); $this->assertEquals(Month::MAY()->__toString(), "MAY"); $this->assertEquals(Month::JUNE()->__toString(), "JUNE"); $this->assertEquals(Month::JULY()->__toString(), "JULY"); $this->assertEquals(Month::AUGUST()->__toString(), "AUGUST"); $this->assertEquals(Month::SEPTEMBER()->__toString(), "SEPTEMBER"); $this->assertEquals(Month::OCTOBER()->__toString(), "OCTOBER"); $this->assertEquals(Month::NOVEMBER()->__toString(), "NOVEMBER"); $this->assertEquals(Month::DECEMBER()->__toString(), "DECEMBER"); }
public function test_previousOrCurrent() { foreach (Month::values() as $month) { for ($i = 1; $i <= $month->length(false); $i++) { $date = self::date(2007, $month, $i); foreach (DayOfWeek::values() as $dow) { $test = TemporalAdjusters::previousOrSame($dow)->adjustInto($date); $this->assertSame($test->getDayOfWeek(), $dow); if ($test->getYear() == 2007) { $dayDiff = $test->getDayOfYear() - $date->getDayOfYear(); $this->assertTrue($dayDiff <= 0 && $dayDiff > -7); $this->assertEquals($date->equals($test), $date->getDayOfWeek() == $dow); } else { $this->assertFalse($date->getDayOfWeek() == $dow); $this->assertSame($month, Month::JANUARY()); $this->assertTrue($date->getDayOfMonth() < 7); $this->assertEquals($test->getYear(), 2006); $this->assertSame($test->getMonth(), Month::DECEMBER()); $this->assertTrue($test->getDayOfMonth() > 25); } } } } }