The all day events module works fine when you are using 24 hour format without jscalendar, storing the dates as YYYY-MM-DD 00:00:00 to YYYY-MM-DD 23:59:00.

With 12 hour format and no jscalendar, the time boxes do not show up (which is correct) but it stores YYYY-MM-DD 12:00:00 to YYYY-MM-DD 13:59:00 instead of YYYY-MM-DD 00:00:00 to YYYY-MM-DD 23:59:00, which loses the all day-ness.

With jscalendar (regardless of 12/24 hour setting), the pop up box defaults to the current time and it saves whatever time is in there to the database, esentially ignoring the checkbox for all day.

A possible solution would be to have another db field for "all day". If this is set, it ignores any times that might be with the dates when displaying. The only issue I can see with this is that the textbox on the entry form when using jscalendar would still show times, which may be confusing. Otherwise this could make things a lot simpler since we wouldn't be relying on the times being 00:00 to 23:59 to signify all day.

Michelle

CommentFileSizeAuthor
#15 fix12hr_event.patch362 bytesmichelle
#14 fix12hr.patch1.83 KBmichelle

Comments

snufkin’s picture

and it would also allow different theming for all-day events. im not sure i have time to do this right now because SoC is starting, but i will try to follow this issue.

michelle’s picture

Partially fixed. Thanks to Gurpartap giving me the syntax that hours of searching didn't yield, I changed this function in event_all_day.js and it now works with 12 hour clocks. This didn't fix the jscalendar issue, but I'm holding off on that because there's a question of what jscalendar is going to be used.

function EventAllDayYes() {
  if ($('input[@name=end_ampm]').size()) {
    $("#edit-end-hour").val(11);
    $("#edit-end-minute").val(59);
    $("#edit-start-hour").val(0);
    $("#edit-start-minute").val(0);
    $('input[@name=start_ampm][@value=am]').attr('checked', 'checked');
    $('input[@name=end_ampm][@value=pm]').attr('checked', 'checked');
  } else {  
    $("#edit-end-hour").val(23);
    $("#edit-end-minute").val(59);
    $("#edit-start-hour").val(0);
    $("#edit-start-minute").val(0);
  }
  $("div.time").attr("style", "display: none;");
}

Michelle

nancydru’s picture

Fabulous! It doesn't fix the "Determine" function either, but that's very minor.

michelle’s picture

Hmm... Actually, not so minor. I went to fix the determine function and discovered another problem. When you enter an event and set it all day it converts it to 00:00 - 23:59 on save to the database, which is fine, so that all the other functions can tell that it's all day. But when you go to edit it, the conversion back to the 12 hour clock makes it 12:00-11:59 instead of 00:00-11:59 which is a problem when you go to save it again and also a problem for determining that it's an all day event. Looking into this more now.

Michelle

michelle’s picture

Ok, I should have waited a few minutes before posting. I figured it out right after.

Here's the event_all_day.js change:

function eventAllDayDetermine() {
  if ($('input[@name=end_ampm]').size()) {
    if (  
      ($("#edit-end-hour").val() == "11") &&
      ($("#edit-end-minute").val() == "59") &&
      ($("#edit-start-hour").val() == "0") &&
      ($("#edit-start-minute").val() == "0")) {
        EventAllDayYes();
        $("#edit-start-minute-all-day").attr("checked","true");
    }
  } else {
    if (  
      ($("#edit-end-hour").val() == "23") &&
      ($("#edit-end-minute").val() == "59") &&
      ($("#edit-start-hour").val() == "0") &&
      ($("#edit-start-minute").val() == "0")) {
        EventAllDayYes();
        $("#edit-start-minute-all-day").attr("checked","true");
    }
  }  
}

I'm sure that could be compacted more since it duplicates most of the check but this was it's easy to see that we're doing things one way for 12 hour and another for 24 hour. For this to work, a change is needed in event.module:

function event_form_date($date, $prefix = 'start') {
[...snip...]
    $date['hour'] = $date['hour'] % 12;
//    if ($date['hour'] == 0) {
//      $date['hour'] = 12;
//    }

I don't know why that was in there so I don't know what harm commenting it out may cause. So far, I don't see a problem. We need it to leave the start hour at 0 in order for all day to work properly. If there is a side effect of commenting this out, then hopefully it can be solved by an if test.

Michelle

michelle’s picture

Don't use this latest code, yet... It causes problems with 12pm. Unfortunately my son woke up crabby from his nap so I have to get off the computer. I'll work in it more later.

Michelle

michelle’s picture

Actually, I don't think it's my code. I put the event module back to stock and it still chokes on 12 noon. So I guess I found another bug. AFAIK, my code is safe. If anyone discovers otherwise, please comment.

Michelle

nancydru’s picture

Hmm, I don't have that code in event.module.

michelle’s picture

Status: Active » Needs review

Setting this one as a "patch", too, even though it's not technically a patch. I don't want to mark them as fixed until the actual module code gets it.

Nancy: Are you using the latest dev snapshot? I don't know when the code got added.

Michelle

nancydru’s picture

I'm using the May 2 code.

There is an error in your JS code. In 12 hr format, the start hour is 12, not 0.

function eventAllDayDetermine() {
  if ($('input[@name=end_ampm]').size()) {
    if ( 
      ($("#edit-end-hour").val() == "11") &&
      ($("#edit-end-minute").val() == "59") &&
      ($("#edit-start-hour").val() == "12") &&
      ($("#edit-start-minute").val() == "0")) {
        EventAllDayYes();
        $("#edit-start-minute-all-day").attr("checked","true");
    }
  } else {
    if ( 
      ($("#edit-end-hour").val() == "23") &&
      ($("#edit-end-minute").val() == "59") &&
      ($("#edit-start-hour").val() == "0") &&
      ($("#edit-start-minute").val() == "0")) {
        EventAllDayYes();
        $("#edit-start-minute-all-day").attr("checked","true");
    }
  } 
}

function EventAllDayYes() {
  if ($('input[@name=end_ampm]').size()) {
    $("#edit-end-hour").val(11);
    $("#edit-end-minute").val(59);
    $("#edit-start-hour").val(12);
    $("#edit-start-minute").val(0);
    $('input[@name=start_ampm][@value=am]').attr('checked', 'checked');
    $('input[@name=end_ampm][@value=pm]').attr('checked', 'checked');
  } else {  
    $("#edit-end-hour").val(23);
    $("#edit-end-minute").val(59);
    $("#edit-start-hour").val(0);
    $("#edit-start-minute").val(0);
  }
  $("div.time").attr("style", "display: none;");
}
michelle’s picture

That wasn't an error. The 0 instead of 12 is intentional and is the reason the event.module code that forces 0 to become 12 needs to be commented out. If you set it to 12:00am - 11:59 pm, the module does not recognize it as being an all day event. It needs to be 00:00am - 11:59pm which gets converted properly in the database to 00:00 - 23:59, which is what it needs to be in order to be considered an all day event.

By the way, May 2 code is pretty old. The latest dev snapshot, which is the code I'm testing against, was a couple days ago. I can't guarantee these changes will work against old code as I don't know what's all changed in V2 in the last month.

Michelle

nancydru’s picture

Hmm, it didn't work at all for me until I put the 12 in there. Now it works fine.

I'm using 5.x-1.x-dev, and the Update_status module says May 2 is the recommended version.

michelle’s picture

Nancy: Ah, that's the problem then. This issue is for 5.x-2.x as that's what I'm actively working on. 5.x-1.x uses an entirely different method of storing times. A method which doesn't work well, which is why it was re-written. Good that you found a solution that works for that version as I'm pushing to get V2 ready for release and just don't have the time to test backports to V1 as well.

Michelle

michelle’s picture

StatusFileSize
new1.83 KB

Ok, I tried my hand at making a patch. Hopefully I did it right.

Michelle

michelle’s picture

StatusFileSize
new362 bytes

Also need the bit to comment out the auto changing of 0 to 12 in the event module.

Michelle

michelle’s picture

Status: Needs review » Fixed

We now have a "has_time" field so the times being stored are now irrelevant. Marking this fixed.

Michelle

Anonymous’s picture

Status: Fixed » Closed (fixed)