Problem/Motivation
In OfficeHoursListItemFormatter->formatLabel(), "normal days" and "exception days" both use $settings['day_format'].
This is clearly unintended, since $settings['exceptions']['date_format'] exists.
Using $settings['day_format'] also produces chaotic effects. For instance, "3-letter weekday abbreviation" maps to the default date/time format "short" so it "works." However values like "two-letter" or "number" will either:
- work by coincidence if there's a text format by that name, like for
"short" - produce "some unreadable string" as seen in #3567869: Fix Exception day formatting when day format is 'number'
Steps to reproduce
- Set an Office Hours field's "Date format for exception day" to any value other than
"short". - Set the field's "Day notation" to "3-letter weekday abbreviation".
- On an entity with that field, add an exception that will show (per the display settings).
- Render the entity, and see that it ignores the chosen the date/time format.
- Set the field's "Day notation" to "number".
- Render the entity, and see that it uses the hardcoded "Y-m-d" format.
- Set the field's "Day notation" to "2-letter weekday abbreviation".
- Render the entity, and see that it produces a mess.
Proposed resolution
Honor the value, and remove code written to mitigate problems caused by the oversight.
Remaining tasks
- Use the "Date format for exception day" when appropriate.
- Remove the hack added in #3567869: Fix Exception day formatting when day format is 'number'
Issue fork office_hours-3576462
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
mw4ll4c3 commentedThis is a tested and working solution, as clean as it's going to get without reworking things. The test failures are inherited from the 8.x-1.x branch.
Comment #4
johnvWow, you are active.
I am working on this issue.
Comment #6
johnvPlease check the new code.
I managed to remove the static code and use $item->label().
Comment #8
mw4ll4c3 commentedI'm seeing the selected format on the latest 8.x-1.x -- thank you very much!
I can't vouch the Seasons stuff that's in there because I'm not using it (have to keep moving for now) but the little other little spot fixes are obviously fine.
And yes, I've tried to be active. Noticed it a while back, had no time, changed the underlying date/time format, came back later, found the root issue after #3567869: Fix Exception day formatting when day format is 'number', did a quick fix, and got that PHP error the day after (because I didn't clean up after myself).
My "fixes" had to be pretty shallow, but getting issues posted / bounced up was prudent, to air things and get them searchable... and offer "working-ish" stuff for whoever needs a small fix before the next stable release.
I'll keep doing that when I can, while you're cleaning stuff up in there.
Comment #9
johnvSetting the satus back to Active, since an error is introduced:
- Formatter is incorrect when 'all day' checkmark is set.
- When adding (the first) exception, the date is set to '03-03-1973'.
- A second, third exception cannot be added
Comment #10
mw4ll4c3 commentedComment #12
johnvI also tested how the Date formatter responds in formValidation in validateOfficeHoursSlot(). The errors did not show at all. Above commit fixes that.
Comment #14
johnvAbove commits fixes the following findings from #9:
- Formatter is incorrect when 'all day' checkmark is set.
Still to do:
- When adding (the first) exception, the date is set to '03-03-1973'.
- A second, third exception cannot be added
Comment #16
johnvThe reversal of setting NULL in first commit fixes the above regression problems.
Comment #18
johnvThere is a problem. The current/next css indicator is not set in some cases.
Comment #20
johnv