Jump to:
| Project: | Event |
| Version: | 6.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | minor |
| Assigned: | Unassigned |
| Status: | active |
Issue Summary
When creating or editing an event, upon pressing preview, the preview time always says "am" unless the hour is set to 12. Example: a time of 2:01 PM (1401 hours) shows up in preview as "2:1 am". If I just hit submit, the correct time is saved to the database.
This may be related to my site's date and time settings. The site-wide date
and time formats are 24hr while the events module is set to use a 12-hour time notation. I'm setting the priority to minor since someone else would have opened a bug already if this wasn't a rare case.
This is happening with the latest 6.x. I recently upgraded event for the first time since September or thereabouts and I don't recall this happening before. I diffed the two versions and don't see a likely cause. I upgraded Drupal from 6.6 to 6.8 at the same time.
I tried copying the fix in case 'presave' of event_nodeapi to case 'view', but it did not work because the previewed date in case 'view' is not aware of $node->event['start_exploded']['ampm']. The value is null at this point. Copying code like that isn't an elegant solution anyways.
Attaching a list of event variables.
| Attachment | Size |
|---|---|
| eventvars.txt | 905 bytes |
Comments
#1
Found these lines in nodeapi case 'view' circa line 2330 wipe out the ampm information:
$node->event['start_exploded'] = event_explode_date($node->event['start']);
$node->event['end_exploded'] = event_explode_date($node->event['end']);
In my report I found the ampm information missing because I put my tests after these lines.
Root problem: the am/pm information does not exist in the ['start'] and ['end'] received by event_explode_date(). Values before and after those two lines, with test event from 9:14 am to 9:34 pm:
DEBUG: view subcase event start: '2008-12-27 9:14:00' ampm: 'am' end: '2008-12-27 9:34:00' ampm: 'pm'
DEBUG: event_explode_date received: '2008-12-27 9:14:00'
DEBUG: event_explode_date received: '2008-12-27 9:34:00'
DEBUG: view subcase event start: '2008-12-27 9:14:00' ampm: '' end: '2008-12-27 9:34:00' ampm: ''
#2
hey dturover,
I am experiencing the same problem. I am new to Drupal and not sure I understand: did you fix the issue in your module?
I am looking for a resolution to this as well and would love to know where/what to edit/change to egt Events to show PM times.
#3
I hate myself for writing code like this.
//print "DEBUG: start_exploded is first: "; print_r($node->event['start_exploded']);
//print "<br/>DEBUG: start is: " .$node->event['start'];
//print "<br/>DEBUG: end_exploded is first: "; print_r($node->event['end_exploded']);
//print "<br/>DEBUG: end is: " .$node->event['end'];
$HACK_start_ampm = $node->event['start_exploded']['ampm'];
$HACK_end_ampm = $node->event['end_exploded']['ampm'];
$node->event['start_exploded'] = event_explode_date($node->event['start']);
$node->event['end_exploded'] = event_explode_date($node->event['end']);
if($HACK_start_ampm == 'pm' && $node->event['start_exploded']['hour'] < 12){
$node->event['start_exploded']['hour'] += 12;}
if($HACK_end_ampm == 'pm' && $node->event['end_exploded']['hour'] < 12){
$node->event['end_exploded']['hour'] += 12;}
// print "<br/>DEBUG: start_exploded is now: "; print_r($node->event['start_exploded']);
One could also skip the exploding and hope for the best.
//$node->event['start_exploded'] = event_explode_date($node->event['start']);//$node->event['end_exploded'] = event_explode_date($node->event['end']);
if($node->event['start_exploded']['ampm'] == 'pm' && $node->event['start_exploded']['hour'] < 12){
$node->event['start_exploded']['hour'] += 12;}
if($node->event['end_exploded']['ampm'] == 'pm' && $node->event['end_exploded']['hour'] < 12){
$node->event['end_exploded']['hour'] += 12;}
Both should be considered as extremely experimental not-entirely-solutions. It would not surprise me if either or both of them break a few things.
There are a few of "the real problem" here. One is that event->['start'] and event->['end'] have no knowledge of the ampm information for 12hr format dates. The calls to explode that use them might not be necessary in the first place. Once all that is over, the module does not respect the ampm information and goes by the hour alone. I'm not sure what the cause of this is, but I think it's related to the format lines immediately after this part of the code.
What I chose to do is raise the hour by twelve if we are working with a "pm" hour below 12. This converts the 12-hour format to 24-hour so the module likes it.
Here is an extra snippet that will keep midnight to 12:59AM from displaying as pm in preview.
if($HACK_start_ampm == 'am' && $node->event['start_exploded']['hour'] == 12){$node->event['start_exploded']['hour'] = 0;}
if($HACK_end_ampm == 'am' && $node->event['end_exploded']['hour'] == 12){
$node->event['end_exploded']['hour'] = 0;}
#4
Subscribing, and must disagree with the priority setting of minor. This seems like a functionality that absolutely must work.
Having said that, I would also like to say a big "Thank You" to dturover - that code worked like a charm.