Problem/Motivation
Sometimes a date range spans an entire month, from the first day to the last. "1 - 31 October 2021" is one such example. This can be shortened to "October 2021".
The same applies to ranges spanning multiple complete months, and even complete years, e.g.:
"1 January 2021 - 31 January 2021" -> "January 2021"
"1 January 2021 - 31 March 2021" -> "January - March 2021"
"1 January 2021 - 31 December 2021" -> "2021"
"1 January 2021 - 31 December 2022" -> "2021 - 2022"
Currently it's only possible to do this by omitting the day/day+month from the format patterns altogether, losing precision.
This issue proposes a way to do this only when a range spans complete months and/or years. So the same format entity that would normally show "1 - 15 October 2021" would also be able to show "October 2021" where appropriate.
Proposed resolution
There is a patch in this issue that adds this functionality.
Remaining tasks
Review the approach and patch.
User interface changes
TBC.
API changes
TBC.
Data model changes
TBC.
| Comment | File | Size | Author |
|---|---|---|---|
| #31 | 2919426-31-with-tests.patch | 14.27 KB | matsbla |
| #30 | 2919426-tests-only.patch | 1.4 KB | matsbla |
| #27 | 2919426-27.patch | 12.86 KB | matsbla |
Comments
Comment #2
matsbla commentedWould be great to get a feedback about this issue. I can also help provide a patch for it.
Comment #3
matsbla commentedComment #4
sergei_semipiadniy commentedHi,
For now there are options All month and All year in config form.
Please, test the patch.
Comment #5
sergei_semipiadniy commentedComment #6
sergei_semipiadniy commentedAlso reduced unnecessary string translations.
Comment #7
sergei_semipiadniy commentedRe-arranged month and year fields.
Added extra description.
Comment #8
matsbla commentedThe patch looks great for me, however after I apply it I get some undefined indexes:
Notice: Undefined index: whole_month_pattern i Drupal\daterange_compact\Form\DateRangeFormatForm->form() (linje 150 av /srv/bindings/46aba7e3706b42c893272ab8cdfe17af/code/modules/contrib/daterange_compact/src/Form/DateRangeFormatForm.php) #0 /srv/bindings/46aba7e3706b42c893272ab8cdfe17af/code/core/includes/bootstrap.inc(584): _drupal_error_handler_real(8, 'Undefined index...', '/srv/bindings/4...', 150, Array) #1 /srv/bindings/46aba7e3706b42c893272ab8cdfe17af/code/modules/contrib/daterange_compact/src/Form/DateRangeFormatForm.php(150):
Notice: Undefined index: whole_year_pattern i Drupal\daterange_compact\Form\DateRangeFormatForm->form() (linje 160 av /srv/bindings/46aba7e3706b42c893272ab8cdfe17af/code/modules/contrib/daterange_compact/src/Form/DateRangeFormatForm.php) #0 /srv/bindings/46aba7e3706b42c893272ab8cdfe17af/code/core/includes/bootstrap.inc(584): _drupal_error_handler_real(8, 'Undefined index...', '/srv/bindings/4...', 160, Array) #1 /srv/bindings/46aba7e3706b42c893272ab8cdfe17af/code/modules/contrib/daterange_compact/src/Form/DateRangeFormatForm.php(160)
Comment #9
sergei_semipiadniy commented@matsbla Have you run drush updb command to perform DB update?
Comment #10
ajay_reddyError while applying the patch:
Followed below steps:
Comment #11
sergei_semipiadniy commentedHi,
@ajay_reddy Please try alternative command to apply patch:
patch -p1 < daterange_compact-provide_opion_to_remove_redundant_date-2919426-6-D8.patch
Because patch contains file (daterange_compact.install) that is not presented in git index.
Regards!
Comment #12
sergei_semipiadniy commentedAdd checkbox to Enable/Disable short month(s)/year(s) patterns.
Comment #13
matsbla commented#12 looks good to me!
Comment #14
sergei_semipiadniy commentedFix error: daterange_compact.install: No such file or directory during patch applying.
Comment #15
sergei_semipiadniy commentedComment #16
sergei_semipiadniy commentedMats, I added small improvements and #15 is the best for now.
Comment #17
matsbla commentedUpdated patch
Comment #18
matsbla commentedComment #19
matsbla commentedComment #20
matsbla commentedComment #21
erik.erskine commentedThank you @sergei_semipiadniy and @matsbla for your contributions and helping move this forward.
I'm trying to clarify the use case and see what is and isn't available already.
I tried to recreate the first example described in the issue summary:
Yand no special same day/month/year handling.The output is "2021", which is what I expected.
Then I tried to recreate the second example:
F YFF YF YThe output is "December 2021", which is also what I expected.
That mimics the test coverage that exists for those two use cases.
Have I understood the issue summary correctly? Or is there something else I've missed that the patch provides? In which case, let's clarify that so we can add a test for it.
Comment #22
matsbla commentedThat is correct!
In patch from #15 there is a config option enable_whole_year_month but I think it is redundant, I think if you leave pattern empty it should just fallback to default option.
I think the year pattern is appended to the month pattern, so you just need to write F.
+ $extra_description = $this->t('The year pattern will be appended to the month pattern.');However I think it makes more sense to just write out the fulle pattern 'F Y'
Comment #23
matsbla commentedComment #24
u_tiwari commentedUpdated patch to make values persistent
Comment #25
matsbla commented@u_tiwari
Thank you!
I worked a little more on this patch, I made separate sections for whole month and whole year pattern. They now also have start pattern and end pattern just like the other formats. However for whole month I think we need two different start pattern depending on if it is the same year or different years, e.g:
01.01.2000-31.2.2000 = Jan - Feb 2000
01.10.2000-31.01.2001 = Oct 2000 - Jan 2001
Comment #26
matsbla commentedJust a small typo with the whole_year_separator
Comment #27
matsbla commentedComment #28
erik.erskine commentedYou can already do that much without the patch, using the patterns in #21. So I've misunderstood something.
Let's clarify the requirements a bit more and get some concrete examples. Then we can turn those into tests.
A quick look through the patch suggests you want to use a different pattern when the range spans a whole month (or a whole year). In other words, one format that can do the following:
This would consider "1 - 31" redundant (in the context of January 2021) and remove it, but leave in "1 - 15".
Have I understood this correctly?
Comment #29
matsbla commentedYes!
Any date that has start date first day of the month and end date last day of the month, should use "whole month(s)" pattern.
Any date that has start date first day of the year an d end date last day of the year, should use "whole year(s)" pattern.
"1 January 2021 - 31 January 2021" -> "January 2021"
"1 January 2021 - 31 March 2021" -> "January - March 2021"
"1 January 2021 - 31 December 2021" -> "2021"
"1 January 2021 - 31 December 2022" -> "2021 - 2022"
Comment #30
matsbla commentedComment #31
matsbla commentedComment #32
erik.erskine commentedGot it! I've updated the issue summary with this clarification.
Thanks for adding the tests too, that's a big help.