-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bug: Time::createFromTimestamp() uses default timezone, not UTC for timestamp #3951
Comments
The Time::createFromTimestamp() method does not convert the timestamp to the new time zone. To convert use DateTime::setTimezone()
|
The Time::createFromTimestamp() method has a timezone argument. Going
should be the same as
(turns out However, they give different results (the latter does give a correct result by converting the result back to UTC from the default timezone, but the former just sets the timezone property to supplied value without converting the actual value). |
After some research I agree that this is a problem. We need to support int timestamps at any timezone but since this method accepts a "UNIX timestamp" it must assume the incoming int is UTC (https://en.m.wikipedia.org/wiki/Unix_time). I believe the original assessment is correct, that conversion using Passing this a timezone is a separate issue. The provided timezone (same with |
How about using |
Yes that is probably the most straightforward. |
Describe the bug
UNIX timestamps are all based on the UTC timezone. However, Time::createFromTimestamp() uses the default timezone. This means that created dates can be off by several hours
CodeIgniter 4 version
4.0.4
Affected module(s)
I18n\Time
Expected behavior, and steps to reproduce if appropriate
The timestamp should assume it is UTC, then create the date using the supplied timezone. Instead the time is offset. For example, the following code should output "2020-12-01 12:00:00". Instead it outputs "2020-12-01 06:00:00" (due to the -6 offset for Chicago).
I suspect the problem is that the timestamp is being converted to a date format by just using
date()
Context
The text was updated successfully, but these errors were encountered: