Review main Merged

81915[BUGFIX] Use correct timezones with timestamp based \DateTime

Andreas Wolf CR +2 V +2 Normal +84 −70 updated 04/07/24, 09:49

Commit message

As documented by PHP, `\DateTime` or `\DateTimeImmutable`
objects created with a timestamp only ('@12345678') as the
first constructor argument will use UTC as TimeZone.

Creating an object instance without any constructor arguments
will use the `date_default_timezone_get()` timezone for the
object - and setting the timestamp using `setTimestamp()` will
not change the object's timezone.

That means, that formatting the value will be done using
the object Timezone and **NOT** the default PHP Timezone
(`date_default_timezone_get()`).

Consequently, this may lead to wrong interpretation of
the displayed formatted value in the context of another
timezone - if no timezone information (+0000/-0100) is
included.

This change streamlines this for a couple of places were
it is expected to format date, datetime or time values
for the current context timezone by ensuring objects get
the current timezone set instead of `UTC`.

Note: Changing the date default timezone on the fly after
an object has been created will show a similar effect like
using constructor values, even if the object has been
created by using the `setTimestamp()` method.

[1] https://3v4l.org/sGEe2

Review

  • Code review CR +2 Done
    • Stefan Bürk +2
    • Oliver Klee +1
    • Garvin Hicking +1
    • Andreas Wolf +1
  • Verified V +2 Done
    • Stefan Bürk +2
    • Oliver Klee +1
    • Garvin Hicking +1
    • core-ci +1 CI

Issues 2

Files 20

Review log 4257

Show 2232 earlier messages
  1. Andreas Wolf uploaded patch set 1 11/23/23, 12:06

  2. Mathias Brodala commented on patch set 1 11/23/23, 12:11

    Application.php:75

    You can directly pass the timezone as 2nd constructor argument.
  3. core-ci voted on patch set 1 V +1 11/23/23, 12:25 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/49660

  4. Andreas Wolf commented on patch set 1 11/23/23, 19:41

    Application.php:75 Reply

    I thought so too, but that does not work when specifying a timestamp.
  5. Garvin Hicking commented on patch set 1 11/29/23, 14:32

    DateTimeAspectTest.php:67

    Wouldn't this test also need a counterpart for actual timezones, so that a -x / +y offset return can be checked, by changing the current timezone and creating a new datetime object based off it? (I assume the testing framework just uses a 0-offset timezone by default?)
  6. Anja Leichsenring uploaded patch set 2 V +1 02/02/24, 10:00

  7. Anja Leichsenring commented on patch set 2 CR +1 V +1 02/02/24, 10:01

    DateTimeAspectTest.php:67 Reply

    like this?
  8. Anja Leichsenring updated the commit message in patch set 3 CR +1 V +1 02/02/24, 10:05

  9. Anja Leichsenring voted on patch set 3 CR +1 V +1 02/02/24, 10:05

  10. core-ci voted on patch set 2 V -1 02/02/24, 10:10 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/52625

  11. core-ci voted on patch set 3 V -1 02/02/24, 10:11 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/52628

  12. Garvin Hicking commented on patch set 3 02/02/24, 11:06

    DateTimeAspectTest.php:67 Reply

    Probably, don't know the exact formatting here and what the TF uses by default. But also we should create tests with actual different offsets than 0 to verify behavior.
  13. Garvin Hicking commented on patch set 3 02/02/24, 11:07

    DateTimeAspectTest.php:67 Reply

    Ah sorry, didn't see the "+5" there already. Should do, but CI reports a "05" vs "5" issue.
  14. Anja Leichsenring commented on patch set 4 CR +1 V +1 03/08/24, 08:59

    Published edit on patch set 3.
  15. core-ci voted on patch set 4 V -1 03/08/24, 09:04 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/54211

  16. Markus Klein commented on patch set 4 CR -1 03/29/24, 12:17

    On it. There are quite a few more places to fix. moreover it seems cleaner to ``` (new DateTimeImmutable())->setTimestamp($ts) ``` because that uses the default timezone per definition
  17. Markus Klein uploaded patch set 5 CR -1 V -1 03/29/24, 12:41

  18. Markus Klein uploaded patch set 6 03/29/24, 12:43

  19. core-ci voted on patch set 5 V -1 03/29/24, 12:49 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55062

  20. core-ci voted on patch set 6 V -1 03/29/24, 12:50 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55063

  21. Markus Klein uploaded patch set 7 V -1 03/29/24, 12:58

  22. core-ci voted on patch set 7 V -1 03/29/24, 13:05 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55064

  23. Markus Klein uploaded patch set 8 V -1 03/29/24, 13:08

  24. Markus Klein commented on patch set 8 03/29/24, 13:10

    DateTimeAspectTest.php:67 Reply

    Done
  25. core-ci voted on patch set 8 V +1 03/29/24, 13:14 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55065

  26. Oliver Klee commented on patch set 8 03/30/24, 10:22

    PreviewModule.php:244

    This code now does not look like it could throw an exception anymore. Maybe we can drop the try/catch and make the return type non-nullable.
  27. Markus Klein commented on patch set 8 04/01/24, 15:53

    PreviewModule.php:244 Reply

    Done
  28. Markus Klein commented on patch set 9 V +1 04/01/24, 15:53

    Published edit on patch set 8.
  29. Markus Klein commented on patch set 10 04/01/24, 15:53

    Published edit on patch set 9.
  30. core-ci voted on patch set 10 V +1 04/01/24, 15:59 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55117

  31. core-ci voted on patch set 9 V -1 04/01/24, 16:00 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55116

  32. Jan Delius voted on patch set 10 CR +1 V +1 04/03/24, 13:47

  1. Oliver Klee voted on patch set 10 CR +1 V +1 04/03/24, 16:42

  2. Stefan Bürk commented on patch set 10 CR -1 04/03/24, 19:43

    tmp -1
  3. Stefan Bürk commented on patch set 10 04/04/24, 13:06

    TYPO3 v11 is in priority and security bugfix mode, and albeit this change is mostly cosmetic this may introduce a drastically change in output for a patch-level release (if one will happen again - there is no schedule for it). Not sure if that may raise some shitstorm - beside the fact it would be a legit bugfix. That means, that I would remove 11.5 from the releases list. Responsible project maintainers can still backport this bugfix manually and use composer patches to apply it on a TYPO3 v11 then. Literally, the same counts for TYPO3 v12, but as this is still in normal maintenance mode I'd would take it as bugfix for that version. Most places are context bound and pure display related, which is fine so far. In general I postulate, that we need kind of a concept on how to deal with date/time information in the future throughout the core: * storage/passing (ex. UTC only) vs context/timezone bound etc. * Formatting (context bound BE/FE - default php timezone / explicit timezone formatting * Formatting locale aware (IntlDateFormatter) and think about more configurable context (BE user timezone setting, FE user timezone setting) etc. A special remark, which should not be related to the touched places in this change, goes to dealing with persisting/reading datetime values to and from the database not using the unix-timestamp (integer value). If no timezone is provdided, `2012-01-02 19:00:12`, the database connection AND/OR datbase server default timezone also comes into play. The concecpt should also deal with the question about microtime (which make sense for logging and having MORE granual timings). In general, this change should be good for main and 12.4. Fine to limit it to these version ? See other comment, found a unrelated place which would make sense to tackle with this change also. NOTE: Mention the concept should not be taken as blocker for this change !!! I added it to emphasize that dealing with time/date/dateime formatings is a tricky topic and the reason it took quite some time to fully understand the impact of this change.

    MailMessage.php:94

    Not sure about that one ....

    SchedulerModuleController.php:750

    Unrelated - but `is_numeric()` is bogus here. That would allow to use exponent like strings. We should better use the `MathUtility::canBeInterpretatedAsInt()` method. What do you think ? Change it along the way ?
  4. Stefan Bürk voted on patch set 10 CR 0 04/04/24, 13:15

  5. Markus Klein commented on patch set 10 04/04/24, 15:14

    Reply

    v11: I know that officially we are in that phase, but practice is that still a lot of projects have this as the current upgrade target, or no option to upgrade further due to missing v12 compatibility of extensions. We have to face reality here. I see no harm in showing the right time in Install Tool. I consider it a must-have to have a correct time in the Context. It is simply wrong to have diverging EXEC_TIME and Context-Time. > storage/passing (ex. UTC only) Is perfect for some cases, as catastrophe in others. But not to be discussed here. I fully agree that date/time is a nightmare in any kind. (I did a lot of fixing and streamlining in v7/v8 back then.)

    MailMessage.php:94 Reply

    Also mails should not be from the future, if your current timezone is something < 0000.

    SchedulerModuleController.php:750 Reply

    Yes, will adjust that too.
  6. Markus Klein commented on patch set 11 CR +1 V +1 04/04/24, 15:16

    Published edit on patch set 10.
  7. core-ci voted on patch set 11 V -1 04/04/24, 15:22 Core CI is not happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55339

  8. Markus Klein commented on patch set 12 V -1 04/04/24, 19:02

    Published edit on patch set 11.
  9. core-ci voted on patch set 12 V +1 04/04/24, 19:07 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55343

  10. Stefan Bürk commented on patch set 12 04/05/24, 11:21

    MailMessage.php:94 Reply

    This may hit only code adding it and directly reading&displaying it without proper transforming it from the DateTime timezone to the "to display Timezone" which is a consumer issue. But that's a concept thing again, not to be discussed here and now. For sending mails and symfony handling code this is safe to change. Let's do it.

    SchedulerModuleController.php:750 Reply

    Done
  11. Stefan Bürk updated the commit message in patch set 13 V +1 04/05/24, 11:40

  12. core-ci voted on patch set 13 V +1 04/05/24, 11:45 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55381

  13. Oliver Klee voted on patch set 13 CR +1 V +1 04/05/24, 11:55

  14. Markus Klein updated the commit message in patch set 14 CR +1 V +1 04/05/24, 12:30

  15. core-ci voted on patch set 14 V +1 04/05/24, 12:36 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55382

  16. Stefan Bürk voted on patch set 14 CR +1 V +1 04/05/24, 15:08

  17. Garvin Hicking commented on patch set 14 CR +1 V +1 04/05/24, 21:22

    This gets my head spinning, but it's looking good. Probably better wait for the next 12.x release a few days before a 11.x release with this is made, just as extra precaution for side effects?
  18. Andreas Wolf commented on patch set 15 CR +1 V +1 04/06/24, 09:13

    Published edit on patch set 14.
  19. Andreas Wolf commented on patch set 15 CR +1 04/06/24, 09:15

    I created the initial patchset, but there were so many additional changes that it's enough to justify me voting on it.
  20. core-ci voted on patch set 15 V +1 04/06/24, 09:19 Core CI is happy: https://git.typo3.org/typo3/CI/cms/-/pipelines/55433

  21. Garvin Hicking voted on patch set 15 CR +1 V +1 04/06/24, 10:23

  22. Stefan Bürk commented on patch set 15 04/06/24, 11:09

    Going to merge this when I'm back at home ... enjoying the sun today ;)
  23. Oliver Klee voted on patch set 15 CR +1 V +1 04/07/24, 08:03

  24. Stefan Bürk voted on patch set 15 CR +2 V +2 04/07/24, 08:15

  25. Stefan Bürk merged patch set 16 04/07/24, 09:49