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.

Thoughts?

Thanks!
- Robert

Comments

handsofaten’s picture

I second this request... would be very helpful for me...

handsofaten’s picture

Here's an ugly hack to deal with this problem. Detailed explanation here: http://drupal.org/node/194123#comment-1661560

<?php
function 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
   
   
$start_time = explode(' ', $vars['node']->calendar_start);
   
   
$end_time = explode(' ', $vars['node']->calendar_end);
   
   
$diff = (strtotime($end_time[1]) - strtotime($start_time[1]))/3600;
   
    if(
$start_time[1] != '00:00:00' || $diff > 5){
       
template_preprocess_calendar_node($vars);
    }
}
?>
tandersonmd’s picture

hands,

Where does this code go? I tried it in my main template file to no avail.

Thanks.

Thomas

philw_’s picture

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.

pudge’s picture

Anyone has more info on this? I tried putting the code in #2 into my template.php and nothing changed in my calendar view. I am not sure if I need to change the name of the function to match my hook?

dnotes’s picture

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.

milkmiruku’s picture

I've tried adding the hack to template.php and clearing all caches but to no avail.

All modules are using the latest dev versions.

http://theforest.org.uk/events

mcpuddin’s picture

Status:Active» Needs review
StatusFileSize
new6.02 KB

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.

handsofaten’s picture

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.)

handsofaten’s picture

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.

illmatix’s picture

Right on! Thanks for the patch I'm testing it out now.

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).

vwX’s picture

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.

For example here is the flow for building a month:

template_preprocess_calendar_month
template_preprocess_calendar <- fields themed here
calendar_build_nodes
calendar_build_calendar
calendar_build_month
calendar_build_week
calendar_build_day

If the fields had knowledge of the date they were being placed it would be much easier to do advanced theming with this module and it would fix issues like this along with other similar issues.

mcpuddin’s picture

Version:6.x-2.1» 6.x-2.2

@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

PS Make sure you are using 6.x-2.2

progkiller’s picture

StatusFileSize
new14.32 KB
new12.96 KB

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

Dreher’s picture

Patch didn't work for me. Set the end day time at 3:00 and events ending at 1:00 am still show on next day. Following.

eclauset’s picture

Subscribe

philw_’s picture

This still isn't fixed? :( I wish I could help but my skills wouldn't be much use!

SoniaWilk’s picture

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.

Hope that little fix helps someone else!

Saiboth’s picture

#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.

Does anyone have an idea what to change in patch #8: Let users cancel their accounts to make it work again?

EDIT: With 6.19 I only had a caching problem (had to clean the views cache).

=> It works fine and is very helpful for me. I hope this gets accepted to the main code line!

Saiboth’s picture

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.

developer-x’s picture

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.

mcpuddin’s picture

This looks great and solves the issue from a theming perspective. I would absolutely recommend this approach if you are looking at a calendar that diverts from the traditional, out of the box theming.

mcpuddin’s picture

@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"?

Saiboth’s picture

@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.

Thanks for looking into this issue!

mcpuddin’s picture

StatusFileSize
new7.63 KB

Hi Saiboth,

Attached is a fix that works both for the Month and Week views but not the mini calendar. This solution still goes off of configuring the "Calendar Page" view display.

Please let me know if it work for you Saiboth and, again, thank you very much for testing and reporting back!
James

Saiboth’s picture

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

PS: Meanwhile, calendar 2.4 is out; the patch you added for theme/theme.inc touches the same file as a patch for #382852: [Calendar Views] Replacement patterns don't work if referencing a field excluded from display in 2.4.

davethedruper’s picture

The patch is great but is there a way to make it work for 2.4? This was the first patch I've applied so be easy on me.

loominade’s picture

subscribe

tanjerine’s picture

+1

druryjeff’s picture

Here's a brute-force JavaScript/jQuery solution that worked for me

// 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

var elem = $('div');
if(elem.hasClass('calendar-calendar')){
    $('[id]').each(function(){
        var ids = $('[id='+this.id+']');
        if(ids.length>1 && ids[0]==this){
            if(this.id != 'node-data-field-date-field-date-value' && this.id != 'node-title' && this.id != 'term-data-name'){
                ids.eq(1).hide();
            }
        }
    });
}

This is not a perfect solution as it relies on JavaScript, but it works.

Props to sunsean for the jquery duplicate div check – http://stackoverflow.com/questions/482763/jquery-to-check-for-duplicate-....

leovw’s picture

Version:6.x-2.2» 6.x-2.4

Any chance of updating the patch in #25 for 2.4 ? ?

Thanks

EDIT

I have tried patching and whilst I get the option in the view to change when a day ends it doesn't have an effect on the view

mssarath’s picture

function MYTHEMENAME_preprocess_calendar_month_node(&$vars) {
   
    $start_day = format_date(strtotime($vars['node']->raw->node_data_field_date_field_date_value),'custom','j' );
    $cur_day = format_date(strtotime($vars['calendar_start']),'custom','j' );
    if ( $start_day != $cur_day){
      unset($vars['node']);
    }
    template_preprocess_calendar_node($vars);
}

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.

** clear the caches!

Drupal web development company

Frando’s picture

See #2109255: Properly display dates that span over midnight in week view for a different solution (7.x): Events that span midnight are displayed on the pre-midnight day at the actual start date, and on the post-midnight day at 00:00.