Jump to:

This was requested previously by another user for an earlier version... http://drupal.org/node/194123 but I think the message was that it would have to be re-submitted for v6.

Basis: There are many events that extend past midnight. If a party starts Saturday at 9:00 PM and goes to 1:00AM in the morning, you would rarely even consider Sunday.

So, I wonder if it is possible for an event that spans midnight to only appear in one date block in the calendar view. i.e. seeing the bloack span through sunday is slightly misleading to my users. Especially when an event runs from 8PM - 12:00... we create an entire entry based on 1 minute of time.

<?phpfunction phptemplate_preprocess_calendar_month_node(&$vars) {//if start time = midnight & lasts 5 hours or less, don't show the event //this is a hackish way of not double-listing an event that goes past midnight

I'd love some more explanation too - I really need to not show events like the ones described above - my drupal site will be listing a lot of concerts and clubbing events that will finish between midnight and 3/4am.

Just because it's a mistake I've made a million times, I'll mention that you'll need to clear the cache after adding the new function to your template.php. There could be other reasons why the code might not work but that would be my first thought.

I approached the original problem of displaying events as one day when they span into the night a different way. Basically I modified the calendar module to take in a new parameter for the "end of a day". Typically a day stops at midnight, however I allow an admin to set a parameter in the calendar view to be whatever they want (1am, 2am, 3am, 4am, etc).

My approach can support single day events or multiday events; whereas the preview approach mentioned in comment 2 limits it single day events. Something to note of my approach, the "end of a day" parameter is calendar wide -- so it will apply to all events displayed in the calendar.

I have attached the patch for review, please let me know what you think! This is my first large patch submission, so I would appreciate any feedback to help me with this process.

mcpuddin -- i like this approach. certainly more usable than my little template function (sorry for those of you who couldn't get it to work). i patched this in to calendar module (6.x-2.2), and it seemed to be successful, but i'm not seeing where you set the end of day time in the calendar view settings.

EDIT: i see it. apparently my calendar view was set up under an older version of calendar, so some of the style info wasn't showing up correctly. i've moved it over to the new style, and your patch seems to be working very well. thanks! (if anyone else is having trouble finding it, the setting is under the "Calendar page" display, in the "Calendar settings" box at the very bottom of the view settings column.)

i'm not terribly experienced with drupal, but in my testing (on calendar 6.x-2.2) this patch works very well and i think is an elegant solution to the problem. fwiw, i hope this is officially moved into the calendar module in the next version.

those of you looking for an immediate solution should apply the patch.

I found the option and set it to 4am. The event still displays on the next day. Also when i go in to the day view (agenda view i think its called) the event only displays on the next day not the actual day it should. (Friday instead of Thursday).

I think this problem is actually because the event fields are themed before the calendar is rendered. While this patch addresses the issue of an event that crosses midnight, it really doesn't address the problem of being able to vary the theme of the fields based on what date in the calendar they fall into.

@illmatix: Can you tell me how to reproduce this? Its working for me so far when I tried to do what you did.

@vwX: I'm not sure if I fully understand your recommendation in terms of the patch I submitted. In my patch, I modify the date if the calendar view specifies an "end day" in calendar_build_nodes. Can you provide an example use case of what you describe so I can address it in this patch and/or fix this patch for misplaced code. Thanks.

A thing to note, this fix will work on calendar views only that are attached to "Calendar Page" because that parameter is set in the "Calendar Page" view. So Year, Month, Day, and Week should work fine but Block and Upcoming will not. Since calendar does not come with any global admin settings, I found the "Calendar Page" view the most appropriate place to put this.

Please send me feedback and I'll adjust the patch to work for you guys,
James

Hi, I experience similar problem. I had a "3wholeday" event that starts at April 28 00:00 and end at April 30 00:00. With your patch, it should only appear on April 28 and 29 if I set the day_end to be mid-night. However, it still appeared on April 28, 29, 30. However, if I set the day_end to be some time other than mid-night, it would appear on April 27, 28, 29

I used this patch perfectly for a Calendar Style. Unfortunately, I need to use the Unformatted List style instead so it doesn't work any more. Anyone have any suggestions?

EDIT - I went and had a shower and I figured it out...something in the water, maybe? I just created a custom date format that was just the day, month, year, without the time. I then created a second custom date format that was just the time. In my View, under Fields I added Content: Date (From and To) twice. First one formatted with the day, month, year, showing only "From". Then for the second one I added my Time format, showing From and To. I then set them to be inline with each other, and presto! I got exactly what I wanted WITHOUT any funky programming I would need to deal with when upgrading.

#8 works for me with drupal 6.16, but not any more with 6.19 (same calendar version 6.x-2.2); in 6.19, the new variable is not visible in the views module. Furthermore, [#2] seems to not work in either of these two versions, and [#18] is not suitable for me.

I found a bug in patch #8: In the week view and the day view of the the calendar view, times are shifted by the amount by which the "end of day"-parameter differs from midnight. So if your "end of day" is set to 3 am, an event starting at 10pm is listed in the week view below a horizontal line indicating 7pm.

Another approach to this problem is not to "fix" this by truncating at an arbitrary hour or adjusting end-of-day, but to style these events as a "multi-day" style ala google. I've submitted a patch to do this at http://drupal.org/node/931392#comment-3611920.

This visually differentiates items the span days from individual items or repeating items.

@Saiboth, I see your the issue and am ready to send over a patch that fixes that issue. When making the original, I did not really take the day view, week view, or mini view into consideration. There is however a limitation in using the mini view in using the 'end day' because it does not inherit from the "Calendar Page" view display. Would you all mind if the "end day" be configured per each view in the "Calendar Settings" instead of just on the "Calendar Page"?

@mcpuddin #23: I am fine with configuring "end day" per view. Actually, in my specific setup, I don't use the mini view so far, so I would not care about ommiting this. However, your proposal is probably more consistent.

Hi James,
thanks for your patch! The time difference of the day-end parameter is now correctly added in the week and day views. However, something is not quite correct with the formating of the time, when using the 24h scheme in the date field. It seems that events with a start time larger than 12h are not sorted in correctly.
I attached 2 screenshots of week views, one where 21h is sorted before 10h, and one where events >12h don't get separate time slots.
Could you have a look at this?
Many thanks for your help!
Saiboth

// when dates span across midnight hour (i.e. 9pm - 1am), two date blocks are populated on the calendar// the second date has the same id as the first// look for duplicate ids (excepting the duplicate ids used by drupal to make the calendar)// use hide() method to remove second date (identified using ids.eq(1)) from view// only apply this operation to elements on pages with a "calendar-calendar" div

the function extract the 'day' part of 'FROM' field , and day part of 'current calendar date' , and if both are different it will unset that node , i took the raw data , as we have custom format on node data.

ie, if we have one event which span for 3 days
14 th , 15th and 16th july,

the FROM day is 14th , and current day is 14th while it generate node for that day
on 15th , the from day is still 14th and current day will change to 15 , so it will be removed from variables.
for 16th also , from day remain same 14 , and current day is 16 , so it will be unset from variables.

** Above function will not check month or year , as its enough for our need now, as the events are only for one day , if there is an event which start on 14th july , end on 14th august , this function will print that event on both 14th of july and august and if its year long event , it will get printed in every month 14th , so adjust the function, to check the month or year as necessary.