Hi,

I've got a custom content type with a date field using the popup widget. I've added a custom format (d F Y h:ia) under admin/config/regional/date-time/formats but when I go to the field, under the drop down "CHOOSE HOW USERS ENTER DATES" that format isn't available. I noticed the system module provides this functionality to add the custom formats but I assume that I should be able to use them in input formats? I'm using the lastest dev version as of today.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

arlinsandbulte’s picture

Status: Active » Postponed (maintainer needs more info)

Sounds like you added a custom format at /admin/config/regional/date-time/formats
BUT
Did you also add a date type at /admin/config/regional/date-time??

You must first create a custom format, then use that format in a new date type.

acbramley’s picture

Yup, in fact I've got 2 custom date types, one using that format and another using just d F Y but still no luck. I've cleared all caches etc as well.

arlinsandbulte’s picture

Category: bug » feature
Status: Postponed (maintainer needs more info) » Active

Ah, OK. I follow now.
Hmmm... I don't think input formats CAN be customized... I was not aware of this limitation... was this different in older versions of date?
I just tried in D6 version too and this issue is there too. Only 14 different (hard coded?) input formats are allowed, even though there are 35 available default formats that can be selected when creating a new type. It looks like only output/display formats can be customized.

But I could be wrong,
@KarenS: can you confirm that this is a feature request?

acbramley’s picture

Hmmmm, I was sure you could do it in D6 but maybe I'm wrong. It would be a great feature!

David_Rothstein’s picture

For input formats, you can't reuse the ones defined at admin/config/regional/date-time/formats, but you can add a custom format by choosing the "Custom input format" option in the "Choose how users enter dates" dropdown and then typing your own in there.

Or at least, you can do that for select widgets and textfield widgets. For popup widgets, the code in _date_field_widget_settings_form() specifically hides the ability to use a custom format, so I think that's why it's not showing up in the above example.

I'm not sure what the exact rationale for that is, but my guess would be that since the popup code separates date and time into two separate input fields, it needs to be able to take whatever format you give it and parse it to figure out how to split apart the date and time. Maybe the idea is that it's not possible to guarantee that splitting will work correctly for an arbitrary format string.

acbramley’s picture

Yeah that makes sense. It would be nice if there was a few more available options like full month names etc.

KarenS’s picture

The reason for hiding custom formats with the popup date picker is because it won't handle anything you might come up with. See http://jqueryui.com/demos/datepicker/#date-formats, the examples are pretty limited. I haven't figured out exactly which would work and which wouldn't, but you definitely can't use everything that you can use everywhere else.

I suppose we could enable the custom format for the popup with some sort of warning text that not all formats will work.

KarenS’s picture

Also it does not use the same formats that the PHP date format uses, see http://docs.jquery.com/UI/Datepicker/formatDate. So you have to pick a format it supports and then massage it into the values that the datepicker wants.

So the current code has options that are known to work and no custom format. Any attempt to change it would require figuring out how to manipulate custom code into something that the datepicker likes.

KarenS’s picture

Title: Created a custom date format and it's not showing in input format options. » Add more custom formats for Date Popup

Re-naming this issue. This is just about the Date Popup widget, right?

KarenS’s picture

Hmm, just took care of #1241254: "Date format is invalid" error when using Popup calendar widget which illustrates that you can still get non-functional formats into the popup. Just add whatever you want as your 'short', 'medium', or 'long' format and it will be available, but that doesn't guarantee that it will work.

The old code had a specific list of formats that would work right for the popup field. Not sure if that got 'fixed' in the lastest round of changes.

Since there is in fact a way to try to use this with any format you might dream up, we might as well re-enable the 'custom' option with the warning that not all formats will work right in the popup.

acbramley’s picture

Agree with KarenS.

yingtho’s picture

Version: 7.x-2.x-dev » 7.x-2.6
Status: Active » Needs review
FileSize
453 bytes

Here is a patch to include custom dateformat against version 2.6.

Status: Needs review » Needs work

The last submitted patch, date_popup-add-custom-dateformat.patch, failed testing.

yingtho’s picture

This time it a proper git diff patch.

yingtho’s picture

This is testede and working patch. Done via clone of date module.

yingtho’s picture

Status: Needs work » Needs review

Change status so it will be testede again.

Status: Needs review » Needs work

The last submitted patch, date_popup-add-custom-formats.patch, failed testing.

yingtho’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, date_popup-add-custom-formats.patch, failed testing.

yingtho’s picture

Remove warning messages.

yingtho’s picture

Status: Needs work » Needs review

Retest.

Status: Needs review » Needs work

The last submitted patch, date_popup-add-custom-formats.patch, failed testing.

yingtho’s picture

Status: Needs work » Needs review
FileSize
636 bytes

We try again.

yingtho’s picture

Wrong file. We try again.

yingtho’s picture

Or this one.

Status: Needs review » Needs work

The last submitted patch, date_popup-add-custom-formats.patch, failed testing.

yingtho’s picture

The test failed due to "Class 'Migration' not found" but i haven't made any changes to this so it seems the normal test will also fail.

sisko’s picture

Suggestion:

Save your date as a timestamp. You can still use the Date-popup but when you output the date via Views or example, you can output in the desired format.

zwerg’s picture

Issue summary: View changes

Is there any solution?

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 25: date_popup-add-custom-formats.patch, failed testing.

andreyks’s picture

Assigned: Unassigned » andreyks
sanchiz’s picture

andreyks’s picture

FileSize
808 bytes

Update #25

sanchiz’s picture

Status: Needs work » Needs review

bot trigger

podarok’s picture

Status: Needs review » Fixed

#34 commited.
Thanks!

  • podarok committed 37fb74c on authored by andreyks
    Issue #1246940 by yingtho, andreyks | acbramley: Added more custom...

Status: Fixed » Closed (fixed)

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

GrantI’s picture

#34 worked perfectly for me!

NOTE OF CAUTION

If you are collecting a time along with your date make sure that your custom format also includes php time values for each unit (hour, minute and second) or you will break your input, as the time option won't display.

I went for the following format;

Tue 7 Jul - 07:29:53pm

PHP;

D j M - h:i:sa

Hope this helps.