Closed (works as designed)
Project:
Date
Version:
6.x-2.x-dev
Component:
Date CCK Field
Priority:
Normal
Category:
Feature request
Assigned:
Unassigned
Reporter:
Created:
23 Jun 2009 at 10:58 UTC
Updated:
6 Jun 2011 at 15:35 UTC
Jump to comment: Most recent file
Comments
Comment #1
danielb commentedYes it is possible to do something like this with PHP. I've done it on this site (click links in the table - notice how the date display on the page differs for one-day events vs. events over several days). I don't have a backup of the code I wrote for the site, and I don't have access to the site's FTP anymore.
My algorithm basically compared the two dates at each level of granularity (year, year+month, year+month+day) and that would decide whether to print out a particular section of the first date (print it if it differs). If any parts of the first date were to be printed, then the hyphen was appended to the first date as well. You could do the same with the comma between month and year.
Then you have to consider how to do times of day as well, and perhaps writing out a few examples of what it should look like would help.
Comment #2
joachim commentedGiven that dates at some point end up as strings of the form YYYMMDDTHHMMSS, I wonder if we could just run the two date strings through substr_compare(), with successive offsets, until they fail to match.
Then it's just a matter of changing the granularity on the first date as we format it: the more they matched, the more granularity we remove.
Comment #3
karens commentedThis is very very complicated because it has to work in any language and for any date format. The folding currently being done is hard enough and there were lots of issues getting it working, I'm not anxious to push it any further.
The way to do things like this is to override the theme and do it yourself. You don't have to make it work in every possible situation, only your own, so that's easier.
Comment #4
joachim commentedOk thanks Karen.
Maybe we can start a page in this module's handbook for snippets for this.
Comment #5
matt.nz commentedI'm looking for a better way to override date folding.
At the moment I'm editing the date.theme file to override the date range display function with strtotime. This is less than ideal as the input dates don't contain a year. If I include a year, I need to include it in the single dates as well. But if I then override the display for single dates, it changes every single date on the site. It all feels very hack-ish, and there must be a better way to do it.
Any suggestions appreciated!
Comment #6
danepowell commentedI'm surprised this hasn't been replied to in two years, especially now that D7 has come out with such a focus on improved UX. Having to use date range formats like "March 12, 2012 - March 14, 2012" vs "March 12-14, 2012" is a huge detractor from usability. Is there any chance that this could be reconsidered for implementation in Date core? If not, does anyone have solid examples of how to accomplish this in the theme layer? I'm using Date 7.x-2.x
Comment #7
joachim commentedI actually wrote this up as a module for D6, but didn't release it given Karen's comments about problems making something like this generic enough to work with different formats and translations.
Here's the code.
Comment #8
danepowell commentedAwesome, I will have to try that out- thanks for posting!