Skip to content

Bug: Difference in behaviour of native DateTime::setTimezone() and CI's Time:setTimezone() #2989

Closed
@kloukas

Description

@kloukas

Describe the bug
The native php DateTime::setTimezone() functions converts the time of object to the specified timezone, CI's Time Class which extends DateTime simply changes the Timezone without doing any conversion.

CodeIgniter 4 version
Current develop branch

Expected behavior, and steps to reproduce if appropriate
Consider the following code

$time = new \DateTime('13 May 2020 10:00 GMT');
$time->setTimeZone(new \DateTimeZone('GMT+1'));

This creates a new DateTime object with time 2020-05-13T10:00:00+00:00 and after conversion it becomes 2020-05-13T11:00:00+01:00, the timezone changes and the time is converted to the new timezone.

Doing the same using CI's Time class

$time = new Time('13 May 2020 10:00 GMT');
$time = $time->setTimezone(new \DateTimeZone('GMT+1'));

Initially, this creates an object with time 2020-05-13T10:00:00+00:00 as well, after conversion however the object has time 2020-05-13T10:00:00+01:00, the timezone changes but there is not conversion done. The time is 10:00AM in both instances

If this is the intended behaviour and not a bug should the docs be changed to reflect that? They currently say "Converts the time from it’s current timezone into the new one" which does not exactly describe what the function is doing.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions