This happened when I used the 'Y-m-d h:i a' format.

I can see a working time field, and I can adjust the hours, minutes, and AM/PM without any issues, but when I submit the form, the dates comes out with the time truncated. Specifically, I inserted a drupal_set_message function in the submit op of the nodeapi hook, and that indicated that the date outputted by the form had the time truncated already.

CommentFileSizeAuthor
#3 date_popup_ampm_bug.tar.gz598 bytesMike Wacker
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

debrajn’s picture

Assigned: Unassigned » debrajn

you can print like following

format_date($node->created, 'custom', 'D, d M Y h a')

KarenS’s picture

Status: Active » Postponed (maintainer needs more info)

I have no idea what this report is saying, either the original report or the reply. Read through the debugging tips on the project page and if you still have problems after that I need an example that I can reproduce, which means telling me exactly how the field is configured, what value you are putting into it, etc.

Mike Wacker’s picture

Version: 5.x-2.5 » 6.x-2.1
Assigned: debrajn » Unassigned
Status: Postponed (maintainer needs more info) » Active
FileSize
598 bytes

Attached is a 20-line module that demonstrates the bug (which I tested this time against version 6.x-2.1). Its pretty easy to read the code and see what it does, but here's the description.

It creates a popup date form item on the node edit form under "Authoring information", and then echoes back the value of that form item when you submit the form. Enter a date and time, and you'll see that the value comes back with the time set to 00:00:00, no matter what you put in as the time.

KarenS’s picture

Status: Active » Fixed

You left several really really important pieces of information out of this report.

1) You are not using CCK to create a Date popup in the normal manner, you are trying to implement a custom element using the API.
2) You are trying to intervene in the node published date field to use the date popup there.

I originally tried to alter the node published date automatically but found that lots of other modules interfere with that field so that there is no reliable way to add the Date Popup to it and have it work right. And in this case the reason 12 hour time won't work is that Drupal Core is making assumptions about what value is in that field and doing it's own manipulation of the value. If you change your format to use 24 hour time (which is what core expects to be in there) it works fine.

This is not a bug, this is something that may or may not be possible to do with the way that core works now.

Mike Wacker’s picture

Status: Fixed » Active

The inference on 2) was incorrect. I'm not trying to override the node published date field; I was adding another date field under the "Authoring information" fieldset when I originally encountered this bug. I can replicate this bug in any form, not just the node edit form. Here's a modified date_popup_ampm_bug.module which demonstrates this:

function date_popup_ampm_bug_menu() {
  return array(
    'date_popup_ampm_bug' => array(
      'title' => 'Date Popup AM/PM Bug',
      'page callback' => 'drupal_get_form',
      'page arguments' => array('date_popup_ampm_bug_form'),
      'access callback' => TRUE,
    ),
  );
}

function date_popup_ampm_bug_form() {
  $form['date_ampm'] = array(
    '#type' => 'date_popup',
    '#title' => '12-Hour Date',
    '#date_format' => 'Y-m-d h:i a',
  );
  $form['submit'] = array(
    '#type' => 'submit',
    '#value' => 'Submit',
  );
  return $form;
}

function date_popup_ampm_bug_form_submit($form, &$form_state) {
  drupal_set_message($form_state['values']['date_ampm']);
}
KarenS’s picture

OK, I can see what you're talking about now. Wow, no one ever gave me a module to do my debugging before. Kind of nice!

I'll see what I can figure out...

KarenS’s picture

Status: Active » Fixed

OK, the problem in your case is you are using a time format that the timepicker widget doesn't support. So you tell the API to expect a date as H:i a but the timepicker is sending a date that looks like H:iA. Since the time is not in the expected format, it can't be interpreted.

This is a limitation of the timepicker and using the API. In the UI I don't let you select a format the timepicker can't use, but I can't keep you from doing that in your custom code.

Someone should add this to the documentation. It is documented in the module code itself, and I guess I assumed anyone writing code might look there. If you have time, you can write a patch to add this to the advanced help documentation.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Umayal’s picture

Title: AM/PM time format doesn't work » how to save AM/PM time format
Version: 6.x-2.1 » 7.x-2.5
Component: Date Popup » Date Field

how to save manually AM/PM time format to content.
I already saved manually year,month,day,hour,minute.
(I created the node pro-grammatically)