As a partial solution to some problems with how repeating events report their date, I wrote some code for use in a CCK Computed Field that will calculate and display the next upcoming date-time. The thread is here. I'm posting this separately to generate a more understandable Title for people searching for this sort of thing. Also, I'm just learning PHP, so any review of the code would be appreciated.
Using Computed Field, the node view's section for fields can display something like:
Next upcoming date and time:
Jan 27 2009 8:30pm
Location:
Amina 's home
Contact:
Amina
Date of first event in series, then repeats (See "Repeats" above):
Oct 28 2008 8:30pm America/Toronto
Repeats every month fourth Tuesday until Tue Oct 25 2011 except Tue Dec 23 2008, Tue Dec 22 2009
Note that I retained the standard repeated events datetime field at the end for now, because I can't hide it without also losing the "Repeats" tab. The funky Label for that field is a vain attempt at trying to explain why what follows is not the date of the event, but rather a past date of the first iteration of the repeating event.
Anyway, there are still problems associated with the fact that the "next upcoming date" doesn't update unless the node is edited and saved again, but that's a not uncommon problem with Computed Field if you want to use it in Views. More work has to be done to deal with that...
Comments
Comment #1
ericm commentedTidied the issue title.
Comment #2
ericm commentedHere is the final code I came up with for displaying a Computed Field showing the next upcoming event date in the node display, as shown in the example at the top. I'll try to get around to writing this up for the Computed Field Code Snippets page. Note that this code has been tested against Drupal 6.8 and Date 6.x-2.0-rc6. Your mileage may vary.
COMPUTED CODE:
DISPLAY FORMAT:
OTHER RELEVANT COMPUTED FIELD SETTINGS:
Comment #3
ericm commentedIgnore the note about "Anyway, there are still problems associated with the fact that the "next upcoming date" doesn't update..." in the top item. That was solved elsewhere (more fully described here).
Comment #4
ericm commentedThere seem to be some problems with the Computed Field code I gave earlier. A minor one is that it doesn't take into account the event's time properly, so on the day of the event but before the time of the event it reports the Next Event to be the one after that day, as if that day's event is already past. I know how to fix that (I haven't set the actual event time before the calculation, so it is probably using midnight).
The more confusing problem is with repeating events that are annual. When the event is set to repeat every 1 year, the Computed Field code is returning a day several days after the correct one. The Date module's "Repeats" tab is showing the correct repeating days, so it must be something in my code. I'll post a fix if (and when) I find one. Any ideas or suggestions would be welcome.
Comment #5
karens commentedI just committed a new feature to -dev that should take care of this and more. The formatters now have settings so you can do choose to show or not show the repeat rule, display all repeats or the first repeat or the next repeat from today or whatever. You can also choose if you want to display both the from and to dates, or just the 'From' date or just the 'To' date.
If you use Advanced Help you'll see some popup help for this. The formatter settings are on the Display fields page and when you add Date fields to views.
I'm sure it will still need some tweaking to produce the right results everywhere, but so far in my testing it works to make this all very customizable.
If there are no immediate bugs, I'm planning to roll a new release with this in it.
Comment #6
ericm commentedThat sounds terrific! A much better solution than mine, for sure.
Comment #8
nrasmus commentedSorry for re-opening, but I'm hoping to get this to work on a 5.x install. I'm assuming that since views1 does not have a "Display fields" page, that the committed changes referenced in #5 is a 6.x only resolution to this--if I'm mistaken, I apologize (and hope someone will point me in the right direction).
@ #2, One thing to note, I believe you must also redefine the "field_datetime_repeating" field to your field name on line 41
That aside, it's not working correctly. When I do make that change, the next time appears correctly, but the date is displayed as +1 day from now for all events with no repeats (instead of the "No upcoming repeats"), and all events with repeat dates are +7 days. I'm assuming there are changes to some function(s) from 5.x to 6.x, but that's about as far as my personal expertise will carry me. Any ideas?
Comment #9
nrasmus commentedComment #10
arlinsandbulte commentedNo features being added to 5.x-2.x...
Comment #11
webengr commentedAnyone have suggestions for solution #2 that was for drupal 6
to work with Drupal 7.x and DATE 7.x-2.10
the above did not work for that because of function changes going from drupal 6 to 7,
??? date_default_timezone_name(); is now date_default_timezone();
??? date_make_date() was replaced with new DateObject()
???