-
Notifications
You must be signed in to change notification settings - Fork 40
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
Date fields can show timezone twice in custom formats - hardcoded in theme #3575
Comments
Interesting... I am also inclined to say that we should not be appending timezone to date "blindly" or based on assumptions. Having said that though, I would like to see if there is a "smart" way to regex timezone out of the provided text format string. Unfortunately, I most likely won't have time to work on this till next weekend (unless anyone else beats me to it by then). Thanks for taking the time to report this @indigoxela 👍 |
An interesting question is: why is the timezone added anyway? Git blame of that file doesn't give me a clue. Is this something, that has been requested, or is there a technical need for it? |
It's funny, this kind of behavior (timezone added to date) is around for a very long time, since Drupal 6 So there probably really is a need for it. But it's easy to prevent double timezones.
Above code prevents double timezones in single dates, date combos possibly need some attention too. @klonos next weekend sounds like a good plan, no need to stress yourself out. |
I'm trying to figure out the logic behind that timezone handling. A possible reason, why it was initially added could be, that date fields can have a timezone set (user/date/site), but there's no conversion when showing them (like core dates have). So the idea behind that automatic adding was possibly to clarify the timezone (hence offset). Not sure... Double timezone (or offset) info can never be useful and is probably just a side effect. So my suggestion from my previous comment could be a valid solution, if removing the timezone completely is not possible. |
Actually this issue here is a follow up of an older issue (#1097). A more generic solution, which works for me:
Is this the proper approach? Worth a pull request? |
Thanks @indigoxela 👍 ...that approach seems good to me, but seems that it could get false positives. And yes, I would try a PR. By the way, shouldn't
|
...did some googling around, and I came across this, which might be worth taking a look at if we want to avoid using a regex: https://stackoverflow.com/questions/21485281/find-out-if-a-date-time-string-contains-a-timezone
The solution seems to work for php 5.4 up to 7, but fails in 5.3 (due to short array format used). |
...this also seems helpful: https://blog.serverdensity.com/handling-timezone-conversion-with-php-datetime |
Seems that whatever solution we figure would be best would need some testing with random/multilingual strings use in custom dates, to see if it works in those cases. So, not as easy a task as it seems ...but not impossible either 😄 |
@klonos many thanks for your feedback. Thinking about your remarks and searching through the module code - it seems to me, we tried to fix the problem at the wrong place. function date_formatter_process() and function _get_custom_date_format() in file date.module seem promising. We have more info about the field settings there, than we have in the theme function. I was wondering, why some formats already had empty timezone info. When playing around with custom formats, it wasn't always predictable, what one gets. And yes, I agree, we need some testing for that, as soon as we fully understand the logic. ;) |
Yep, indeed. That's why Date is one of those "beastly" modules 😅 |
I have to correct myself in two points:
For theme_date_display_single() I still favor my approach with $tz_offset_chars (slightly revised). I didn't have much luck with your example. Btw. we already have the timezone_type available in BackdropDateTime, but it's not helpful. For theme_date_display_combination() I need a little more time - it really has some bugs and is hard to understand. |
Thanks @indigoxela for your time and effort on this 👍 ...I am currently focused on other tasks (namely #495), but this one is one of my favorite head-scratchers, so will definitely come back to it. If in the meantime you have time to draft a PR, I'd be more than happy to review. |
Spent some more time on the date module... We're probably lucky, this never worked:
I suppose, it was meant to strip timezones (didn't work because of the space added two lines above). Update regarding timezone (I removed parts of my comment): the timezone granularity exists and works correctly. I was fooled by something unrelated to date module (see: #3598) |
Before I even start a PR - it needs more changes than I thought: Yes, I really removed the "$timezone" from date_display_single(). I kept $timezone adding/moving for ranges, but for less cases because:
Feedback is welcome. |
@klonos you're maybe pretty busy, but just in case you missed my previous comment Did you find the time yet to inspect the changes that I consider necessary? |
I took a quick look at the code @indigoxela. It is more involved but might end up being ok. I recommend making a PR and noting that it might still need more work. And let the automated tests run. There's a date timezone test so that might catch any problems. |
@herbdool many thanks for taking a look. The pull request already exists: backdrop/backdrop#2555 Yes, it might need more work. Any hint is welcome. |
@indigoxela I don't have specific changes at this time. Just looked again and see you've added a test which is great and it's passing. |
@klonos do you feel like testing this one? |
It seems, no one is eager to test/review my pull request. ;) Maybe some explanation will help: While trying to understand the date format handling I had trouble with, it turned out that the code was actually written for Drupal 6. Hence it doesn't make much sense with Drupal 7, even less with Backdrop. Additionally I figured out, that it doesn't work as intended because of a faulty str_replace (see comment #3575 (comment)). So I really don't think, my changes will break anything. |
I will try to test this in the next few days. Thanks @indigoxela |
I've checked the code and the automated test. The test looks thorough and passes. Thanks @indigoxela! It's complex stuff so I might be missing something but looks like you've covered the bases. RTBC from me. |
Looks good to me too. Merged backdrop/backdrop#2555 into 1.x and 1.12.x. And a big WELCOME to @indigoxela!! This looks like it was your first issue for Backdrop, and what a doozy! Thanks so much! |
Description of the bug
When using a custom format for a date (core module) field, which includes a timezone name, the resulting format gets pretty weird.
Steps To Reproduce
To reproduce the behavior:
e:Ymd\THis
Actual behavior
The date for my example shows as: Europe/Vienna:20190328T000000 Europe/Vienna
(Note the timezone added twice)
Expected behavior
I'd expect my custom date format to be respected as-is: Europe/Vienna:20190328T000000
Additional information
The actual problem happens in date.theme.inc.
Path: core/modules/date/date.theme.inc
and later on...
It is assumed, that only the exact format 'Y-m-d\TH:iO' can contain a timezone (line 321).
Then the timezone is added, regardless of a custom format (line 327).
Suggestions for a solution:
PR backdrop/backdrop#2555
The text was updated successfully, but these errors were encountered: