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.
When editing the "Date format" in the configuration currently there are only two time formats 'H:i:s' and 'h:i:sA' which are allowed for use with date popup and timepicker. But we should allow more variations than these. Lower case 'a' for am/pm is acceptable, as are all the variations without seconds. Patch to follow.
Jonathan
Comments
Comment #1
jonathan1055 CreditAttribution: jonathan1055 commentedIn scheduler_admin_validate() the $acceptable array can therefore be defined as:
Then in _scheduler_strtotime() instead of using the fixed constant SCHEDULER_DATE_FORMAT, we can use the following to derive the format in which date_popup will return the string:
Patch against 1.1+35
Jonathan
Comment #2
jonathan1055 CreditAttribution: jonathan1055 commentedFollowing from a bug discovered in #1069668: Default time with user override comment #68 when using date_popup with no time entry, we need one extra line in this patch. In addition to deriving $date_format as described above, we need to do the same for $date_only_format
Patch rolled against 1.1+38
Comment #3
jonathan1055 CreditAttribution: jonathan1055 commentedHere's the interdiff to show what has actually been changed.
Comment #4
jonathan1055 CreditAttribution: jonathan1055 commentedUpping the priority, because this now fixes a bug in the committed code for #1069668: Default time with user override. If this patch gets done, we get two greens for the price of one.
Read https://drupal.org/node/1069668#comment-8170819 comments #68 and #69 (ignore #70 to #75 as that was someone hijacking the issue to report a different problem)
Comment #5
jonathan1055 CreditAttribution: jonathan1055 commented2: 2123103_2.more_popup_formats.patch queued for re-testing.
Comment #6
pfrenssenNice addition, especially seeing as every country has its own preferred way of working with times. The description alongside the "Date format" field needs to be updated. It still mentions that the options "a" and "A" are not allowed with the date picker. The sentence "If you are using Date Popup..." still uses the original list of supported time formats, but maybe it can be removed? The validation message is very complete, and the description seems a bit long.
I looked into allowing periods as separator as this is also popular in some countries, but this is not supported by the Date Popup module.
This also needs tests, for the new functionality, but especially for the bugfix to avoid possible regressions. I will take care of those.
Comment #7
jonathan1055 CreditAttribution: jonathan1055 commentedThanks for the review.
We think along very similar lines, and I have already coded each of these changes in #2123223: Improve the configuration page text and add links
With this enhancement they are now! The beauty of it is that we parse the text string returned from date_popup in exactly the way that date_popup wants, then internally Scheduler redisplays the date with our format. Dots are fine:
and you get
Thank you for taking care of the tests. I've learned a lot from your test work, so should try writing my own next time. Are you going to use the new format with the the separate .test file? That works well because the tests are split up.
Comment #8
jonathan1055 CreditAttribution: jonathan1055 commentedDid you mean dots in the time format? They are not supported by date_popup if you use the jQuery timepicker. But they are ok if using popup for the date but plain text entry for the time. We could allow these in the validation but convert . to : behind the scenes at the point of entry if using the timepicker.
Comment #9
pfrenssenYeah I meant in the time format. Some countries use times like "10.25" or "10h25", but it is no big deal to not support these.
I'll have a look at #2123223: Improve the configuration page text and add links before I start on tests. The tests will probably still be in the same file, as this seems like a very simple test to write.
Comment #10
jonathan1055 CreditAttribution: jonathan1055 commentedI will look at allowing . and also - in the time part. If it is a trivial fix then it would be good to add, but if it is compex I agree it is not a blocker and we can cope without it.
As for 'h' that would be complex to do, because that letter is used as the standard php replacement token for hours.
Comment #11
pfrenssenIt's probably not worth the trouble to spend too much time on this. The double colon as separator between hours and minutes is universally understood.
Comment #12
jonathan1055 CreditAttribution: jonathan1055 commentedI looked at it but it is a bit messy to code right now. Yes I agree, lets leave the actual changes as they are in the patch (way back in #2). If/when #1855810: Define #return_value_format for date_popup to set the form value gets committed then a change to allow . and - will be trivial. For the record, this is what it would need in scheduler_admin_validate()
So we are both happy with the changes to .module. What kind of tests were you thinking about?
Jonathan
Comment #13
pfrenssenI want to cover a number of different date and time formats in a new testDateFormats() test, and will extend the testDefaultTime() test to make sure the configuration that triggers the bug in #1069668: Default time with user override is covered.
To achieve this I am thinking of reworking the assertDefaultTime() method. It is currently doing multiple things: it is testing both the cases of "date only" functionality being enabled or disabled. and to achieve this it creates new nodes and toggles the "allow date only" configuration half way through the method. As it does multiple things it difficult to reuse this code, and this is also a Code Smell™. It depends though on how much work is needed, if it is too much trouble I will leave it as is.
Comment #14
pfrenssenI started working on tests, but am discovering some small problems with default time. I'm going to move the test + fixes to #1069668: Default time with user override.
Comment #15
jonathan1055 CreditAttribution: jonathan1055 commentedOK. If all the tests are going to be done in other issues, is this one ready for committing? I presume it would be good to get this in, then the tests can be developed more easily. I can then help with the tests.
Comment #16
pfrenssenHere is the test for this issue.
Comment #18
pfrenssenComment #19
jonathan1055 CreditAttribution: jonathan1055 commentedAll looks good, and the tests are a great addition. One minor point, there are six time formats in the new $allowed array, but you have only tested five of them. For completeness, would it be good to add 'h:iA' in the group labelled 'Test a number of supported date formats'?
When you've done, it will be RTBC, as you have reviewed my .module changes in #6.
Jonathan
Comment #20
pfrenssenOk I will address this on Wednesday. I'm now at a D8 code sprint in Vienna until tomorrow.
Comment #21
pfrenssenAdded Jonathan's suggestion from comment #19 and committed to branch 7.x-1.x: commit 35739c5. Thanks!
Comment #23
vitalius2009 CreditAttribution: vitalius2009 as a volunteer commentedOne more important addition. I think it would be more relevant to have an ability for using spaces before Ante meridiem or Post meridiem.
Comment #24
vitalius2009 CreditAttribution: vitalius2009 as a volunteer commentedI uploaded correct version of patch according patch contributing guide.
Comment #25
jonathan1055 CreditAttribution: jonathan1055 as a volunteer commentedHi vitalius2009,
This issue was closed nearly three years ago. Your idea is reasonable but it should be on a new issue.
After uploading the patch on the new issue, remember to set the status to 'needs review' so that automated testing will be triggered.
Jonathan
Edit: The new issue is #2825987: Additional datetime popup formats with space before a.m/p.m