public function test_of()
 {
     //used for standard offset
     $stdOffset1 = ZoneOffset::UTC();
     $stdOffset2 = ZoneOffset::ofHours(1);
     $time_of_stdOffsetTransition1 = LocalDateTime::of(2013, 1, 5, 1, 0);
     $stdOffsetTransition1 = ZoneOffsetTransition::of($time_of_stdOffsetTransition1, $stdOffset1, $stdOffset2);
     $stdOffsetTransition_list = [];
     $stdOffsetTransition_list[] = $stdOffsetTransition1;
     //used for wall offset
     $wallOffset1 = ZoneOffset::ofHours(2);
     $wallOffset2 = ZoneOffset::ofHours(4);
     $wallOffset3 = ZoneOffset::ofHours(7);
     $time_of_wallOffsetTransition1 = LocalDateTime::of(2013, 2, 5, 1, 0);
     $time_of_wallOffsetTransition2 = LocalDateTime::of(2013, 3, 5, 1, 0);
     $time_of_wallOffsetTransition3 = LocalDateTime::of(2013, 10, 5, 1, 0);
     $wallOffsetTransition1 = ZoneOffsetTransition::of($time_of_wallOffsetTransition1, $wallOffset1, $wallOffset2);
     $wallOffsetTransition2 = ZoneOffsetTransition::of($time_of_wallOffsetTransition2, $wallOffset2, $wallOffset3);
     $wallOffsetTransition3 = ZoneOffsetTransition::of($time_of_wallOffsetTransition3, $wallOffset3, $wallOffset1);
     $wallOffsetTransition_list = [];
     $wallOffsetTransition_list[] = $wallOffsetTransition1;
     $wallOffsetTransition_list[] = $wallOffsetTransition2;
     $wallOffsetTransition_list[] = $wallOffsetTransition3;
     //used for ZoneOffsetTransitionRule
     $ruleOffset = ZoneOffset::ofHours(3);
     $timeDefinition = TimeDefinition::WALL();
     $rule1 = ZoneOffsetTransitionRule::of(Month::FEBRUARY(), 2, DayOfWeek::MONDAY(), LocalTime::of(1, 0), false, $timeDefinition, ZoneOffset::UTC(), ZoneOffset::UTC(), $ruleOffset);
     $rule_list = [];
     $rule_list[] = $rule1;
     //Begin verification
     $zoneRule = ZoneRules::of($stdOffset1, $wallOffset1, $stdOffsetTransition_list, $wallOffsetTransition_list, $rule_list);
     $before_time_of_stdOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_stdOffsetTransition1, $stdOffset1)->minusSeconds(1);
     $after_time_of_stdOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_stdOffsetTransition1, $stdOffset1)->plusSeconds(1);
     $this->assertEquals($zoneRule->getStandardOffset($before_time_of_stdOffsetTransition1->toInstant()), $stdOffset1);
     $this->assertEquals($zoneRule->getStandardOffset($after_time_of_stdOffsetTransition1->toInstant()), $stdOffset2);
     $before_time_of_wallOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition1, $wallOffset1)->minusSeconds(1);
     $after_time_of_wallOffsetTransition1 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition1, $wallOffset1)->plusSeconds(1);
     $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition1->toInstant()), $wallOffsetTransition1);
     $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition1->toInstant()), $wallOffsetTransition2);
     $before_time_of_wallOffsetTransition2 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition2, $wallOffset2)->minusSeconds(1);
     $after_time_of_wallOffsetTransition2 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition2, $wallOffset2)->plusSeconds(1);
     $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition2->toInstant()), $wallOffsetTransition2);
     $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition2->toInstant()), $wallOffsetTransition3);
     $before_time_of_wallOffsetTransition3 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition3, $wallOffset3)->minusSeconds(1);
     $after_time_of_wallOffsetTransition3 = OffsetDateTime::ofDateTime($time_of_wallOffsetTransition3, $wallOffset3)->plusSeconds(1);
     $this->assertEquals($zoneRule->nextTransition($before_time_of_wallOffsetTransition3->toInstant()), $wallOffsetTransition3);
     $this->assertEquals($zoneRule->nextTransition($after_time_of_wallOffsetTransition3->toInstant()), $rule1->createTransition(2014));
 }
 public function test_getDayOfWeek()
 {
     $dow = DayOfWeek::MONDAY();
     foreach (Month::values() as $month) {
         $length = $month->length(false);
         for ($i = 1; $i <= $length; $i++) {
             $d = LocalDateTime::ofDateAndTime(LocalDate::ofMonth(2007, $month, $i), self::TEST_200707_15_12_30_40_987654321()->toLocalTime());
             $this->assertSame($d->getDayOfWeek(), $dow);
             $dow = $dow->plus(1);
         }
     }
 }
 function data_format_withZone_withChronology()
 {
     $ym = YearMonth::of(2008, 6);
     $ld = LocalDate::of(2008, 6, 30);
     $lt = LocalTime::of(11, 30);
     $ldt = LocalDateTime::of(2008, 6, 30, 11, 30);
     $ot = OffsetTime::ofLocalTime(LocalTime::of(11, 30), self::OFFSET_PONE());
     $odt = OffsetDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 11, 30), self::OFFSET_PONE());
     $zdt = ZonedDateTime::ofDateTime(LocalDateTime::of(2008, 6, 30, 11, 30), self::ZONE_PARIS());
     $thaiZdt = ThaiBuddhistChronology::INSTANCE()->zonedDateTimeFrom($zdt);
     $instant = Instant::ofEpochSecond(3600);
     return [[null, null, DayOfWeek::MONDAY(), "::::"], [null, null, $ym, "2008::::ISO"], [null, null, $ld, "2008::::ISO"], [null, null, $lt, ":11:::"], [null, null, $ldt, "2008:11:::ISO"], [null, null, $ot, ":11:+01:00::"], [null, null, $odt, "2008:11:+01:00::ISO"], [null, null, $zdt, "2008:11:+02:00:Europe/Paris:ISO"], [null, null, $instant, "::::"], [IsoChronology::INSTANCE(), null, DayOfWeek::MONDAY(), "::::ISO"], [IsoChronology::INSTANCE(), null, $ym, "2008::::ISO"], [IsoChronology::INSTANCE(), null, $ld, "2008::::ISO"], [IsoChronology::INSTANCE(), null, $lt, ":11:::ISO"], [IsoChronology::INSTANCE(), null, $ldt, "2008:11:::ISO"], [IsoChronology::INSTANCE(), null, $ot, ":11:+01:00::ISO"], [IsoChronology::INSTANCE(), null, $odt, "2008:11:+01:00::ISO"], [IsoChronology::INSTANCE(), null, $zdt, "2008:11:+02:00:Europe/Paris:ISO"], [IsoChronology::INSTANCE(), null, $instant, "::::ISO"], [null, self::ZONE_PARIS(), DayOfWeek::MONDAY(), ":::Europe/Paris:"], [null, self::ZONE_PARIS(), $ym, "2008:::Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $ld, "2008:::Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $lt, ":11::Europe/Paris:"], [null, self::ZONE_PARIS(), $ldt, "2008:11::Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $ot, ":11:+01:00:Europe/Paris:"], [null, self::ZONE_PARIS(), $odt, "2008:12:+02:00:Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $zdt, "2008:11:+02:00:Europe/Paris:ISO"], [null, self::ZONE_PARIS(), $instant, "1970:02:+01:00:Europe/Paris:ISO"], [null, self::OFFSET_PTHREE(), DayOfWeek::MONDAY(), ":::+03:00:"], [null, self::OFFSET_PTHREE(), $ym, "2008:::+03:00:ISO"], [null, self::OFFSET_PTHREE(), $ld, "2008:::+03:00:ISO"], [null, self::OFFSET_PTHREE(), $lt, ":11::+03:00:"], [null, self::OFFSET_PTHREE(), $ldt, "2008:11::+03:00:ISO"], [null, self::OFFSET_PTHREE(), $ot, null], [null, self::OFFSET_PTHREE(), $odt, "2008:13:+03:00:+03:00:ISO"], [null, self::OFFSET_PTHREE(), $zdt, "2008:12:+03:00:+03:00:ISO"], [null, self::OFFSET_PTHREE(), $instant, "1970:04:+03:00:+03:00:ISO"], [ThaiBuddhistChronology::INSTANCE(), null, DayOfWeek::MONDAY(), null], [ThaiBuddhistChronology::INSTANCE(), null, $ym, null], [ThaiBuddhistChronology::INSTANCE(), null, $ld, "2551::::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $lt, ":11:::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $ldt, "2551:11:::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $ot, ":11:+01:00::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $odt, "2551:11:+01:00::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, $instant, "::::ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), null, DayOfWeek::MONDAY(), null], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ym, null], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ld, "2551:::Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $lt, ":11::Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ldt, "2551:11::Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $ot, ":11:+01:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $odt, "2551:12:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $zdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $instant, "2513:02:+01:00:Europe/Paris:ThaiBuddhist"], [null, self::ZONE_PARIS(), $thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [ThaiBuddhistChronology::INSTANCE(), self::ZONE_PARIS(), $thaiZdt, "2551:11:+02:00:Europe/Paris:ThaiBuddhist"], [IsoChronology::INSTANCE(), self::ZONE_PARIS(), $thaiZdt, "2008:11:+02:00:Europe/Paris:ISO"]];
 }
 /**
  * @group long
  */
 public function test_loop()
 {
     // loop round at least one 400 $year cycle, including before 1970
     $date = LocalDate::of(1960, 1, 5);
     // Tuseday of $week 1 1960
     $year = 1960;
     $wby = 1960;
     $weekLen = 52;
     $week = 1;
     while ($date->getYear() < 2400) {
         $loopDow = $date->getDayOfWeek();
         if ($date->getYear() != $year) {
             $year = $date->getYear();
         }
         if ($loopDow == DayOfWeek::MONDAY()) {
             $week++;
             if ($week == 53 && $weekLen == 52 || $week == 54) {
                 $week = 1;
                 $firstDayOfWeekBasedYear = $date->plusDays(14)->withDayOfYear(1);
                 $firstDay = $firstDayOfWeekBasedYear->getDayOfWeek();
                 $weekLen = $firstDay == DayOfWeek::THURSDAY() || $firstDay == DayOfWeek::WEDNESDAY() && $firstDayOfWeekBasedYear->isLeapYear() ? 53 : 52;
                 $wby++;
             }
         }
         $this->assertEquals(IsoFields::WEEK_OF_WEEK_BASED_YEAR()->rangeRefinedBy($date), ValueRange::of(1, $weekLen), "Failed on " . $date . " " . $date->getDayOfWeek());
         $this->assertEquals(IsoFields::WEEK_OF_WEEK_BASED_YEAR()->getFrom($date), $week, "Failed on " . $date . " " . $date->getDayOfWeek());
         $this->assertEquals($date->get(IsoFields::WEEK_OF_WEEK_BASED_YEAR()), $week, "Failed on " . $date . " " . $date->getDayOfWeek());
         $this->assertEquals(IsoFields::WEEK_BASED_YEAR()->getFrom($date), $wby, "Failed on " . $date . " " . $date->getDayOfWeek());
         $this->assertEquals($date->get(IsoFields::WEEK_BASED_YEAR()), $wby, "Failed on " . $date . " " . $date->getDayOfWeek());
         $date = $date->plusDays(1);
     }
 }
 public function test_getDayOfWeek()
 {
     $dow = DayOfWeek::MONDAY();
     foreach (Month::values() as $month) {
         $length = $month->length(false);
         for ($i = 1; $i <= $length; $i++) {
             $d = LocalDate::ofMonth(2007, $month, $i);
             $this->assertSame($d->getDayOfWeek(), $dow);
             $dow = $dow->plus(1);
         }
     }
 }
 public function test_enum()
 {
     $this->assertEquals(DayOfWeek::valueOf("MONDAY"), DayOfWeek::MONDAY());
     $this->assertEquals(DayOfWeek::values()[0], DayOfWeek::MONDAY());
 }
 function providerDayOfWeekData()
 {
     return [[Locale::US(), "e", "1", DayOfWeek::SUNDAY()], [Locale::US(), "ee", "01", DayOfWeek::SUNDAY()], [Locale::US(), "c", "1", DayOfWeek::SUNDAY()], [Locale::UK(), "e", "1", DayOfWeek::MONDAY()], [Locale::UK(), "ee", "01", DayOfWeek::MONDAY()], [Locale::UK(), "c", "1", DayOfWeek::MONDAY()]];
 }
 public function test_equals()
 {
     $weekDef_iso = WeekFields::ISO();
     $weekDef_sundayStart = WeekFields::SUNDAY_START();
     $this->assertTrue($weekDef_iso->equals(WeekFields::of(DayOfWeek::MONDAY(), 4)));
     $this->assertTrue($weekDef_sundayStart->equals(WeekFields::of(DayOfWeek::SUNDAY(), 1)));
     //$this->assertEquals($weekDef_iso->hashCode(), WeekFields::of(DayOfWeek::MONDAY(), 4)->hashCode());
     // $this->assertEquals($weekDef_sundayStart->hashCode(), WeekFields::of(DayOfWeek::SUNDAY(), 1)->hashCode());
     $this->assertFalse($weekDef_iso->equals($weekDef_sundayStart));
     //$this->assertNotEquals($weekDef_iso->hashCode(), $weekDef_sundayStart->hashCode());
 }
Beispiel #9
0
 /**
  * The ISO-8601 definition, where a week starts on Monday and the first week
  * has a minimum of 4 days.
  * <p>
  * The ISO-8601 standard defines a calendar system based on weeks.
  * It uses the week-based-year and week-of-week-based-year concepts to split
  * up the passage of days instead of the standard year/month/day.
  * <p>
  * Note that the first week may start in the previous calendar year.
  * Note also that the first few days of a calendar year may be in the
  * week-based-year corresponding to the previous calendar year.
  * @return WeekFields
  */
 public static function ISO()
 {
     if (self::$ISO === null) {
         self::$ISO = new WeekFields(DayOfWeek::MONDAY(), 4);
     }
     return self::$ISO;
 }
 public function test_factory_previousOrCurrent()
 {
     $this->assertNotNull(TemporalAdjusters::previousOrSame(DayOfWeek::MONDAY()));
 }