Problem/Motivation
The plain and custom datetime formatters aren't ignoring the time portion on date-only fields. This is appearing in Pacific/Auckland again. The default formatter appears to work as intended.
Proposed resolution
Fix it.
Add test coverage to make sure this doesn't happen again.
Remaining tasks
User interface changes
API changes
Data model changes
Original Report
Hi,
I have two date only fields on a node. Both are displayed with a custom php date format. They are both showing the date on day after what the field is actually set to. So a date that is set to April 4 is displaying April 5.
The sites timezone is set to pacific/auckland. Users may not set their own timezones. I have set the custom field display widgets to also use the pacific/auckland time zone. (bugs also manifests when no time zone is selected, because I assume it still defaults to pacific/auckland)
I added a printout for the hour in 24hour format to see what was happening and I see the time is set to 00 hours the next day.
According to this: https://www.drupal.org/node/2859021#comment-11978151
when date only fields are loaded into timestamps for display they are assigned a time of 1200 hours, but I think since my site is set to Pacific/Auckland time which is +12 hours, that becomes 0000hours the next day.
I believe this could be a consequence of "Remove any timezone conversion and time handling from date-only fields." related to the bug in this ticket
https://www.drupal.org/node/2739290
As I workaround I am setting the custom display widgets time zone to UTC(+0), which will get the dates to display correctly.
| Comment | File | Size | Author |
|---|---|---|---|
| #16 | 2861986-16.patch | 4.81 KB | savkaviktor16@gmail.com |
| #11 | 2861986-11.patch | 5.07 KB | jofitz |
Comments
Comment #2
mpdonadioConfirmed :(
Not sure what we botched in #2739290: UTC+12 is broken on date only fields, but it looks like the custom and plain formatters aren't honoring the logic to ignore the time-portion for date-only formats. Also not sure why the timezone loop in those tests isn't catching this.
Downgrading this, as I don't think this qualifies as a Major.
As a workaround, I think the best action is to create a custom date format under admin/config/regional/date-time, use the Default formatter, and then pick the custom format you just made. That seems to work for me.
Comment #3
mpdonadioDateTimeFieldTest::testDateField() tests all the formatters in the zone loop. UTC+12 and UTC+13 are in there. I have no clue what is up. And, the attached passes locally.
Comment #4
mpdonadioThis works with manual testing. I am really confused about what is going on with the test coverage and how this slipped through.
Still still needs test adjustments.
Comment #7
mpdonadioThis should come up green, but I can't figure out a way to make the plain formatters fail w/o the fix.
@Pharitz, can you test this to see if it fixes your problem?
Comment #10
jhedstromTests have been converted to phpunit.
Is it an issue with the plain formatter?
Comment #11
jofitzRe-rolled.
Comment #14
berdir> I can't figure out a way to make the plain formatters fail w/o the fix.
Me and @kim.pepper did! :)
See #3009377-68: Replace drupal_get_user_timezone with a date_default_timezone_get() and an event listener for the explanation why it didn't fail in HEAD. Came up with the same fix as this did over there after a lot of painful debugging.
I guess we can close this as a duplicate.
Comment #15
andypostComment #16
savkaviktor16@gmail.com commentedRe-rolled
Comment #17
joachim commentedWe've now got two ternary operators for the $timezone in two different places, which makes it hard to read.
Is the existing ternary still needed -- can $timezone still be '' with the new code?
If so, the logic should all be combined into one part of code (though avoid nesting ternaries for readability please...).
If not, it should be removed.
Comment #18
mpdonadioTentatively closing this as a dup, since the same code is essentially also in #3009377: Replace drupal_get_user_timezone with a date_default_timezone_get() and an event listener, which is currently RTBC.
I do agree with the comment in #17, though, but I think we can make that a novice followup task once ^^ lands.