Example #1
0
 /**
  * @param \DateTimeZone $dateTimeZone
  *
  * @return TimeZone
  */
 public static function fromDateTimeZone(\DateTimeZone $dateTimeZone)
 {
     return TimeZone::parse($dateTimeZone->getName());
 }
Example #2
0
 /**
  * @dataProvider providerNow
  *
  * @param integer $epochSecond  The epoch second to set the clock time to.
  * @param string  $timeZone     The time-zone to get the current year in.
  * @param integer $expectedYear The expected year.
  */
 public function testNow($epochSecond, $timeZone, $expectedYear)
 {
     $this->setClockTime($epochSecond);
     $this->assertYearIs($expectedYear, Year::now(TimeZone::parse($timeZone)));
 }
Example #3
0
 public function testChangeTimeZone()
 {
     $timezone1 = TimeZone::parse('UTC');
     $timezone2 = TimeZone::parse('America/Los_Angeles');
     $datetime1 = ZonedDateTime::ofInstant(Instant::of(1000000000), $timezone1);
     $datetime2 = $datetime1->withTimeZoneSameInstant($timezone2);
     $this->assertSame($timezone1, $datetime1->getTimezone());
     $this->assertSame($timezone2, $datetime2->getTimezone());
     $this->assertSame('2001-09-08T18:46:40', (string) $datetime2->getDateTime());
     $datetime2 = $datetime1->withTimeZoneSameLocal($timezone2);
     $this->assertSame($timezone1, $datetime1->getTimezone());
     $this->assertSame($timezone2, $datetime2->getTimezone());
     $this->assertSame('2001-09-09T01:46:40', (string) $datetime2->getDateTime());
 }
Example #4
0
 /**
  * @dataProvider providerNow
  *
  * @param integer $epochSecond The epoch second.
  * @param string  $timeZone    The time-zone.
  * @param integer $year        The expected year.
  * @param integer $month       The expected month.
  */
 public function testNow($epochSecond, $timeZone, $year, $month)
 {
     $previousClock = Clock::setDefault(new FixedClock(Instant::of($epochSecond)));
     $this->assertYearMonthIs($year, $month, YearMonth::now(TimeZone::parse($timeZone)));
     Clock::setDefault($previousClock);
 }
Example #5
0
 /**
  * @dataProvider providerNow
  *
  * @param integer $epochSecond The epoch second to set the clock to.
  * @param string  $timeZone    The time-zone to get the date in.
  * @param integer $year        The expected year.
  * @param integer $month       The expected month.
  * @param integer $day         The expected day.
  */
 public function testNow($epochSecond, $timeZone, $year, $month, $day)
 {
     $this->setClockTime($epochSecond);
     $this->assertLocalDateIs($year, $month, $day, LocalDate::now(TimeZone::parse($timeZone)));
 }
Example #6
0
 /**
  * @dataProvider providerNow
  *
  * @param integer $epochSecond       The epoch second to set the clock time to.
  * @param string  $timeZone          The time-zone to get the current day-of-week in.
  * @param integer $expectedDayOfWeek The expected day-of-week, from 1 to 7.
  */
 public function testNow($epochSecond, $timeZone, $expectedDayOfWeek)
 {
     $this->setClockTime($epochSecond);
     $this->assertDayOfWeekIs($expectedDayOfWeek, DayOfWeek::now(TimeZone::parse($timeZone)));
 }
Example #7
0
 /**
  * @dataProvider providerParseInvalidStringThrowsException
  * @expectedException \Brick\DateTime\Parser\DateTimeParseException
  *
  * @param string $text
  */
 public function testParseInvalidStringThrowsException($text)
 {
     TimeZone::parse($text);
 }
Example #8
0
 /**
  * @dataProvider providerAtTimeZone
  *
  * @param string  $dateTime     The date-time.
  * @param string  $timeZone     The time-zone.
  * @param integer $epochSeconds  The expected epoch second of the resulting instant.
  * @param integer $nanos The expected nano-of-second of the resulting instant.
  */
 public function testAtTimeZone($dateTime, $timeZone, $epochSeconds, $nanos)
 {
     $zonedDateTime = LocalDateTime::parse($dateTime)->atTimeZone(TimeZone::parse($timeZone));
     $this->assertReadableInstantIs($epochSeconds, $nanos, $zonedDateTime);
 }
Example #9
0
 /**
  * @dataProvider providerNow
  *
  * @param integer $epochSecond The epoch second.
  * @param string  $timeZone    The time-zone.
  * @param integer $month       The expected month.
  * @param integer $day         The expected day.
  */
 public function testNow($epochSecond, $timeZone, $month, $day)
 {
     $previousClock = Clock::setDefault(new FixedClock(Instant::of($epochSecond)));
     $this->assertMonthDayIs($month, $day, MonthDay::now(TimeZone::parse($timeZone)));
     Clock::setDefault($previousClock);
 }