Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hello,
I am liking the module so far and I would like to use it on a D8 site. Are there any plans to include the option to set the start and/or end time to midnight? I saw a similar issue was resolved for D7 but nothing for D8: https://www.drupal.org/node/1661512
Thanks!
Comment | File | Size | Author |
---|---|---|---|
#14 | interdiff-2764193-11-13.txt | 715 bytes | Shreya Shetty |
#14 | office_hours-2764193-13.patch | 3.91 KB | Shreya Shetty |
#11 | interdiff-2764193-5-11.txt | 1.08 KB | Shreya Shetty |
#11 | office_hours-2764193-11.patch | 3.81 KB | Shreya Shetty |
#5 | office_hours-2764193-5.patch | 3.8 KB | heikki |
Comments
Comment #2
heikki CreditAttribution: heikki at Avoltus Oy commentedI ran into this same issue myself.
I made a patch that fixed the issue for me.
The patch makes saving hour value with 0 to 24 (for example 0:30 (030 -> 2430)).
The patch isn't tested with all the possible setting combinations, but at least works fine with 24h -format and without the "Validate hours" option.
The proper way to fix would be to change the fields to varchar, to enable values with starting zeroes.
As the issue with saving midnight comes from values being '000' but the DB field being of 'INT' type (defined in 'office_hours/src/Plugin/Field/FieldType/OfficeHoursItem.php').
^^ This is also reported here: https://www.drupal.org/node/2768577
Comment #3
heikki CreditAttribution: heikki at Avoltus Oy commentedComment #4
tklepsch CreditAttribution: tklepsch at OpenConcept Consulting Inc. commentedThe patch seems to work as advertised and I am able to display it in either 12h or 24h formats within nodes and views. However, when saving the content, I am presented with the following warning:
This repeats about 28 times (which correlates to the number of values available). I'm not seeing any adverse affects as a result of the warning and the information is still saved to the database.
Comment #5
heikki CreditAttribution: heikki at Avoltus Oy commentedThanks for testing tklepsch!
I updated the patch to prevent these warnings.
Also improved returning of the 24xx values in format() helper (I wasn't able to alter those times in my custom field formatter before).
Comment #6
johnvYou can move $time = substr('0000' . $time, -4) into convertSafeTim(). Then strlen is always 4.
Comment #7
johnvConvertSafeTime takes a second parameter as Boolean, but the default value is 1, not TRUE. You can add the type in the variables declaration and documentation, too.
Comment #8
johnvBetter name parameter $to as $direction. The current name sounds like from-to , not like vice-versa.
Comment #9
johnvThanks for the patch. Sorry for the little nitbits. I do this on my smartphone on holidays.
Comment #10
johnvComment #11
Shreya Shetty CreditAttribution: Shreya Shetty as a volunteer and at Trigyn Technologies Ltd commentedThank you for the review . I have made some changes according to your suggestions
Comment #12
Shreya Shetty CreditAttribution: Shreya Shetty as a volunteer and at Trigyn Technologies Ltd commentedComment #13
heikki CreditAttribution: heikki at Avoltus Oy commentedI don't have any more time to use on this issue, so it would be much appreciated if someone could iron the minor kinks out.
Like johnv said, it would be good idea to include the $time = substr('0000' . $time, -4) in convertSafeTime().
Comment #14
Shreya Shetty CreditAttribution: Shreya Shetty as a volunteer and at Trigyn Technologies Ltd commentedComment #15
tklepsch CreditAttribution: tklepsch at OpenConcept Consulting Inc. commentedI can confirm that both patch #5 and patch #11 do not display the warning label and work as desired without issue. I can't really give much feedback regarding the code, as it's not my area of expertise.
In patch #13, However, when I save the content the values with 0:00 are reset to the default settings of Hour: Minutes and those values are no longer displayed in the published nodes or views. No warnings or errors are shown in the process.
Comment #16
johnvComment #17
johnvTodays commits from other issues already solve the problem if one of both hours is midnight.
I have the impression that the new function OfficeHoursDateHelper::convertSafeTime() duplicates OfficeHoursDateHelper::format()
I will first work on #2808909: Time Format: ampm with periods (a.m. and p.m.), where all hours will be formatted using 1 function OfficeHoursDateHelper::format().
Comment #18
johnvOK, #2808909 is done for now.
ITMT, #2860255: Feature: around the clock (D8) is raised.
Let's close this issue, since the OR case is resolved. And handle the AND case in #2860255: Feature: around the clock (D8)
Comment #19
johnv