Skip to content
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

[OJS] Dates are not good (timezone mistake) in ReviewAssignmentEmailVariable (I think...) #10579

Open
forgive38 opened this issue Nov 5, 2024 · 2 comments

Comments

@forgive38
Copy link
Contributor

forgive38 commented Nov 5, 2024

Describe the bug
I use "Europe/Paris" as timezone in config.inc.php

When a reviewer receive a review remind, the dates due are one day before (exemple : 15.10.2024 for 16.10.2024 in the Web UI)

I think it's happening here:

protected function formatDate(string $date, string $locale, Context $context): ?string

in fact, Carbon converts a date string (without tz) and uses the application's timezone (positioned here:
(

date_default_timezone_set($timeZone ?: ini_get('date.timezone') ?: 'UTC');
)
) to convert the date into utc
So in my case, with 'Europe/Paris' if $dateDue = '2024-11-12 00:00:00' Carbon converts this string as '2024-11-11 22:00:00' with the timezone UTC (+0) which is correct.
BUT when translatedFormat('d.m.Y') is used, 11.11.2024 is displayed instead of 12.11.2024.
So you need to tell Carbon to manage the date with the application's timezone
this is done with Carbon->setTimezone(date_default_timezone_get())

PR is coming

It's probably related to: #10264

(maybe use of UTC everywhere in the application is better, and use timezone only for user interactions)

What application are you using?
OJS 3.4 / main

@asmecher
Copy link
Member

asmecher commented Nov 5, 2024

@forgive38, we should be consistent about where this is applied; I suspect everywhere else that Carbon::translatedFormat is called, this should also be added. Would you mind expanding the scope of this issue a little bit?

@forgive38
Copy link
Contributor Author

forgive38 commented Nov 8, 2024

oh I was wrong
the problem isn't exactly that.
Carbon does parse a date taking into account the application's timezone, but not if it's a timestamp since Carbon version 3.
From Carbon doc:
You can create instances from [unix timestamps](https://en.wikipedia.org/wiki/Unix_time). createFromTimestamp() create a Carbon instance equal to the given timestamp and will set the timezone to the given timezone as second parameter, or to UTC if non given (since Carbon 3) (in previous versions it defaulted to date_default_timezone_get())

and I looked at the code and didn't see the problem elsewhere
I'll rewrite the PR.
HTH

forgive38 added a commit to forgive38/pkp-lib that referenced this issue Nov 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants