/** * @param \DateTimeZone $dateTimeZone * * @return TimeZone */ public static function fromDateTimeZone(\DateTimeZone $dateTimeZone) { return TimeZone::parse($dateTimeZone->getName()); }
/** * @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))); }
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()); }
/** * @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); }
/** * @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))); }
/** * @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))); }
/** * @dataProvider providerParseInvalidStringThrowsException * @expectedException \Brick\DateTime\Parser\DateTimeParseException * * @param string $text */ public function testParseInvalidStringThrowsException($text) { TimeZone::parse($text); }
/** * @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); }
/** * @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); }