Skip to content

Add shiftTimezone() method to Chronos#507

Open
dereuromark wants to merge 1 commit into3.nextfrom
add-shift-timezone-method
Open

Add shiftTimezone() method to Chronos#507
dereuromark wants to merge 1 commit into3.nextfrom
add-shift-timezone-method

Conversation

@dereuromark
Copy link
Member

Summary

Adds a shiftTimezone() method that changes the timezone while keeping the local time. This is different from setTimezone() which converts the time to the new timezone.

Difference from setTimezone()

Method Behavior
setTimezone() Converts to new timezone (same moment in time, different wall clock)
shiftTimezone() Keeps wall clock time (different moment in time, same wall clock)

Example

$dt = Chronos::create(2024, 6, 15, 10, 0, 0, 0, 'America/New_York');

// setTimezone converts - same moment, different wall clock
$converted = $dt->setTimezone('America/Chicago');
$converted->hour; // 9 (Chicago is 1 hour behind NY)

// shiftTimezone keeps wall clock - different moment
$shifted = $dt->shiftTimezone('America/Chicago');
$shifted->hour; // 10 (same wall clock time)

Adds a shiftTimezone() method that changes the timezone while keeping
the local time. This is different from setTimezone() which converts
the time to the new timezone.

For example, 10:00 AM in New York shifted to Chicago gives 10:00 AM
in Chicago, while setTimezone would give 9:00 AM in Chicago.
@dereuromark dereuromark added this to the 3.next milestone Mar 14, 2026
@dereuromark dereuromark marked this pull request as ready for review March 14, 2026 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant