Skip to content

Conversation

@kenjis
Copy link
Member

@kenjis kenjis commented Feb 14, 2024

Description
From https://github.com/codeigniter4/shield/pull/1027/files#r1488969384

Time::createFromTimestamp() returns Time with the timezone UTC.
This behavior is misleading.

--- a/app/Config/App.php
+++ b/app/Config/App.php
@@ -109,7 +109,7 @@ class App extends BaseConfig
      * @see https://www.php.net/manual/en/timezones.php for list of timezones
      *      supported by PHP.
      */
-    public string $appTimezone = 'UTC';
+    public string $appTimezone = 'Asia/Tokyo';
 
     /**
      * --------------------------------------------------------------------------
        //        UTC 1999-12-31 15:00:00
        // Asia/Tokyo 2000-01-01 00:00:00
        $timestamp = 946652400;

        $time = DatetimeCast::get($timestamp);

        return $time->format('Y-m-d H:i:s'); // 1999-12-31 15:00:00

Carbon sets the current timezone.

You can create instances from unix timestamps. createFromTimestamp() create a Carbon instance equal to the given timestamp and will set the timezone as well or default it to the current timezone.
https://carbon.nesbot.com/docs/#api-instantiation

Checklist:

  • Securely signed commits
  • Component(s) with PHPDoc blocks, only if necessary or adds value
  • Unit testing, with >80% coverage
  • User guide updated
  • Conforms to style guide

@kenjis kenjis added bug Verified issues on the current code behavior or pull requests that will fix them breaking change Pull requests that may break existing functionalities labels Feb 14, 2024
@kenjis kenjis force-pushed the fix-Time-createFromTimestamp branch from bd2635c to b1418a1 Compare February 14, 2024 08:17
Copy link
Contributor

@datamweb datamweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM🥳.
Thank you!🥀

@kenjis
Copy link
Member Author

kenjis commented Feb 14, 2024

Added docs.

@kenjis kenjis merged commit fcd8597 into codeigniter4:develop Feb 21, 2024
@kenjis kenjis deleted the fix-Time-createFromTimestamp branch February 21, 2024 01:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

breaking change Pull requests that may break existing functionalities bug Verified issues on the current code behavior or pull requests that will fix them

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants