File tree Expand file tree Collapse file tree 3 files changed +17
-5
lines changed
user_guide_src/source/libraries Expand file tree Collapse file tree 3 files changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -773,14 +773,15 @@ protected function setValue(string $name, $value)
773773 /**
774774 * Returns a new instance with the revised timezone.
775775 *
776- * @param \DateTimeZone $timezone
776+ * @param string| \DateTimeZone $timezone
777777 *
778778 * @return \CodeIgniter\I18n\Time
779779 * @throws \Exception
780780 */
781781 public function setTimezone ($ timezone )
782782 {
783- return Time::parse ($ this ->toDateTimeString (), $ timezone , $ this ->locale );
783+ $ timezone = $ timezone instanceof DateTimeZone ? $ timezone : new DateTimeZone ($ timezone );
784+ return Time::instance ($ this ->toDateTime ()->setTimezone ($ timezone ), $ this ->locale );
784785 }
785786
786787 /**
Original file line number Diff line number Diff line change @@ -974,6 +974,14 @@ public function testHumanizeNow()
974974 $ this ->assertEquals ('Just now ' , $ time ->humanize ());
975975 }
976976
977+ public function testSetTimezoneDate ()
978+ {
979+ $ time = Time::parse ('13 May 2020 10:00 ' , 'GMT ' );
980+ $ time2 = $ time ->setTimezone ('GMT+8 ' );
981+ $ this ->assertEquals ('2020-05-13 10:00:00 ' , $ time ->toDateTimeString ());
982+ $ this ->assertEquals ('2020-05-13 18:00:00 ' , $ time2 ->toDateTimeString ());
983+ }
984+
977985 //--------------------------------------------------------------------
978986 // Missing tests
979987
Original file line number Diff line number Diff line change @@ -347,12 +347,15 @@ setTimezone()
347347
348348Converts the time from it's current timezone into the new one::
349349
350- $time = Time::parse('May 10, 2017 ', 'America/Chicago');
350+ $time = Time::parse('13 May 2020 10:00 ', 'America/Chicago');
351351 $time2 = $time->setTimezone('Europe/London'); // Returns new instance converted to new timezone
352352
353- echo $time->timezoneName ; // American/Chicago
354- echo $time2->timezoneName ; // Europe/London
353+ echo $time->getTimezoneName() ; // American/Chicago
354+ echo $time2->getTimezoneName() ; // Europe/London
355355
356+ echo $time->toDateTimeString(); // 2020-05-13 10:00:00
357+ echo $time2->toDateTimeString(); // 2020-05-13 18:00:00
358+
356359setTimestamp()
357360--------------
358361
You can’t perform that action at this time.
0 commit comments