I might be missing something obvious here...
I have a Date range field of "Date & time" subtype.
I want to achieve the exact same results as shown on the module description page:
Examples:
24–25 January 2017 (range is within a single month)
29 January–3 February 2017 (range is within a single year)
9:00am–4:30pm, 1 April 2017 (range is within a single day)
I.e., drop the time and possibly compact the month and year if the range is not within a single day, keep the time and don't repeat the date if it's a one day event. It actually works exactly this way for me with the Nice format kindly provided by eliasbrat (https://www.drupal.org/node/2834016) but with some i18n-related quirks which is why I decided to try this perceivably more robust module.
But I just cannot set it up this way. As my field is "Date&time", the upper "Date only formats" section does not seem to apply to me and the lower "Date & time formats" section does not have any provision for "Same month"/"Same year". So what I seem to be able to do is drop the time if the range is outside one day but no year/month contraction happens, here's what I'm getting: "29 June 2017 - 30 June 2017".
I might be willing to try making a patch (add Same month/Same year sections to Date&Time formats) but I would like to make sure first I am indeed not missing something obvious. Actually if I had it my way I would probably get rid of separate "Date only" and "Date & time" sections altogether - they only add complexity and confusion IMO.
Would appreciate any clarification.
Comments
Comment #2
erik.erskine commented@ndlarge thanks for reporting this. I'm trying to understand your use case a bit better. You say the field type allows for dates and times, but for some events you don't want to display the times. So when you create a multi-day event, what time values are you storing?
Would this problem go away if you were able to use the same field to store a mix of both date only and date+time values, optionally leaving the time blank?
Comment #3
marassa commentedCorrect. I use the date range field for an Event content type. If it's a one-day seminar or an excursion then start time is relevant. If it's an exhibition running for 11 months then the time when it starts on the first day is irrelevant. Since I need times for at least some of my events, I had to declare the field as "Date and time".
Any arbitrary values as they are not displayed anyway.
I guess it would, and it would be more logical that way but it works fine for me as it is.
By the way, I have already modified the module and it seems to work the way I want on my site: http://art.nouveau.world
If you think it's worth making a patch I can try to do it (I guess it's time I learned how to do that ;)
And by the way thank you for a great module!
Comment #4
dwwMaybe it's better to discuss this here, instead of at #2834016-21: Add 'Compact' datetime range formatter and beyond...
Overall, I find ndlarge's perspective compelling. It seems like a *lot* of additional complication in this code and in various parts of the UI, to provide date-only vs. date-time sections within the same format. There will always be a separate formatter instance for different field types, so you can easily select different range formats for these two uses. Trying to reuse the exact same format for totally different date field types seems like the problem. And that's true of core, too, not just these compact date ranges.
What's the point in all the overhead of making separate format entities if we then try to make them so complex that you only ever configure one for your whole site? ;) At that point, it should have been a bunch of config knobs. ;) But no, you did the right thing by making flexible formats. Now we just have to finish the job and simplify them (but make them actually work for all the cases).
I'd propose:
- Massively simplify these config entities (and supporting code) by removing date-only vs. datetime distinction.
- Provide 4 options within each format:
-- default
-- same day
-- same month
-- same year
- Encourage sites to create multiple formats if they have a mix of date-only and date-time fields to deal with.
Yes, it's true that "same day" doesn't exactly make sense for a daterange of date-only fields. That'd be a daterange that starts and stops on the same day. In that case, you'd want no separator and no end date displayed at all (like the core widget does). If we fix #2959070: More flexible separators while we're at it, then we can completely cover this case, since the expected configuration for this would be something like:
start: 'Y-m-d'
separator: ''
end: ''
Am I missing something here? Is there a reason that life is better if you can reuse the same format for many different date field types? If I'm configuring a view, either I'm telling it to render entities (in which case I get the nice per-instance view mode stuff as configured / intended) or I'm rendering specific fields (in which case I know what field type I'm dealing with and can pick the right format accordingly).
Can anyone come up with a counter-example where re-using the same format across different field types is a win?
I'd like to clean this all up before this code moves into datetime_extras. Hoping to get agreement on how we want it to work going forward.
Thanks!
-Derek
Comment #5
dwwRFC: I just posted a fleshed out proposal in an issue summary update to #2834016: Add 'Compact' datetime range formatter
If we're all happy with that, we can mark this issue fixed once that's done.
Thanks,
-Derek
Comment #6
dwwIf we had something like #3021557: Make date_all_day a set of widgets and formatters for core's datetime_range field type we could update the formatter to have 2 format settings: all-day vs. date-time.
Maybe we should do that anyway?
Comment #7
erik.erskine commentedMy reasoning for this was to try to avoid the following scenario which happens with the core date fields:
1. you create a date only field somewhere
2. you use the default "medium" format as provided by core
3. when you come to view content, it shows the date plus a time of 12:00
Ideally I'd have wanted to be able to restrict a particular format to either date-only or date+time fields, but that isn't possible. So this seemed like the next best thing - ensure the formatter does something sensible with whatever it's given, namely show the time when there is one, and not when the field is date only.
I also toyed with the idea of trying to parse the pattern and omit the time elements, but that quickly got too complicated and error prone.
But I appreciate that's not how core works and it makes the structure more complicated, so open to better suggestions :)
Comment #8
erik.erskine commentedAgreed, but the difficulty comes with not being able to say "this is a format for date/times" and "this is a date only format".
Perhaps the module should ship with two default config entities to encourage this. "Medium" by itself doesn't help.
Comment #9
dwwWe certainly *could* add a selector on the format entities that ties them to date vs. datetime field types, then force the right thing when configuring the formatter.
But I don't think that's necessary, or even a good move. Given #3021557: Make date_all_day a set of widgets and formatters for core's datetime_range field type and use-cases like @ndlarge there are obviously cases where you want a "Date-only" format to apply to a datetime field.
Frankly, I don't think we can or should go too out of our way to attempt to force site builders to configure this as we expect. If they re-use a format with times in it on a date-only field, they'll see it, and can fix it.
As it is, having separate patterns in the same format for date-only and date+time is both insufficiently powerful (since many of us need "same month" or "same year" patterns, even if there are times) and additional complication in the UI, config storage schema, and more.
If #7 is the only reason we can come up with for leaving it the way it is, I think we should move forward with my counter-proposal @ #2834016: Add 'Compact' datetime range formatter which is both simpler and more powerful.
Any further thoughts?
Thanks!
-Derek
Comment #10
marassa commentedI have been following the discussion with interest but I really have nothing to add to what I have already written and I'm glad that someone finally found my "perspective compelling" ;)
I do understand Erik's desire to create something perfect and completely "foolproof" but unfortunately the solution proposed becomes a problem in itself in my particular use case, not to speak of excessively complicated configuration and code. I am all for throwing out the bath water, but keep the baby please ;)
Finally, I believe now all parties agree that "that's not how core works" and that if the perceived "problem" indeed needs solving (I personally believe it doesn't) then it needs to be addressed in the core date/time field where it belongs, not in the range field formatter.
I am currently running an altered version of Erik's module (I never created the patch because Erik did not seem to be interested) but of course I would rather run a properly released version of any module that would actually do what I want it to do, so I support what Derek is proposing, in whatever module he deems fit.
Comment #11
erik.erskine commentedThe 2.0 release takes the approach described in #4, so I think we can consider this issue fixed.
Thanks everyone for the input.
Comment #13
marassa commentedThanks a lot Erik - works fine for me! One less patch to carry around ;)
Had to manually re-create my compact format in the new structure and re-apply it to all relevant fields for the site to stop crashing. Probably should be mentioned somewhere in the README or release notes.