21302 Posts in 5736 Topics by 2603 members
| Go to End | Next > | |
| Author | Topic: | 3639 Views |
-
DateTimeField, Invalid time format

20 April 2010 at 9:26am
Hi All,
I have been having a lot of issues with the datetimefield in 2.4. Basically, the popup calendar seems to enter the date in the wrong format (IE: DD/MM/YYYY, rather than MM/DD/YYY).
Is there a way of configuring the format that silverstripe expects for this field? Or is this a Bug?
Cheers,
Mo
-
Re: DateTimeField, Invalid time format

20 April 2010 at 10:30am
This isn't that well documented, it's true..
Here's an example of how to do it for NZDT, you'll want to adjust the format and locale for you own needs:$datefield = new DatetimeField('When', 'Date and time of event');
$datefield->getDateField()->setConfig('showcalendar', true);
$datefield->getTimeField()->setConfig('showdropdown', true);
$datefield->getDateField()->setConfig('dateformat', 'dd/MM/YYYY');also, in mysite/_config.php, it's good to set your locale.
i18n::set_locale('en_NZ');
Cheers,
- Luke -
Re: DateTimeField, Invalid time format

20 April 2010 at 11:41am
Cool, that seems to work. Thanks Luke!
Quick question, do you know if its possible to set $dateField->getDateField()->setConfig('dateformat', 'dd/MM/YYYY'); as the default for all versions of DateTimeField?
Maybe overriding a static in the class?
Cheers,
Mo
-
Re: DateTimeField, Invalid time format

21 April 2010 at 11:51am
At the moment, I don't believe there's a direct way to do this, short of modifying the DateField code.
The dateformat should be chosen by selecting the default for your locale. (from: i18n::get_locale()).You could always subclass DatetimeField and put in a setConfig call in your constructor.
Cheers,
- Luke -
Re: DateTimeField, Invalid time format

22 April 2010 at 10:41am
Is it possible to do something like this with CalendarDateField? I'm digging through the sapphire folder to see what methods are available for DateField, but can't find anything like setConfig().
Thanks!
-
Re: DateTimeField, Invalid time format

11 May 2010 at 12:18pm
The CalendarDateField is now marked as obsolete in SilverStripe core. You can still use it by including the legacydatetimefields module, but the new core Date/Time fields all have this extra setConfig method.
I believe that the legacy CalendarDateField will always use 'dd/MM/YYYY', and can't easily be configured, but I'm not sure that's correct, please reply here if you find more information on this.
Cheers,
- Luke -
Re: DateTimeField, Invalid time format

11 May 2010 at 9:01pm
I've opened a ticket for this here: http://open.silverstripe.org/ticket/5397
Basically, we need to configure the javascript calendar library according to the date format settings in PHP.
Unfortunately Zend_Date doesnt allow a more "forgiving" validation for date strings, so we have to ensure the js passes in the right format. I agree that "5 May 2010" is a bit of a weird default, thats the Unicode "date medium" setting for en_US...The date/time format confusion will also be less common once we implement this guy here: http://open.silverstripe.org/ticket/5352
Suggestions welcome, its a tricky problem...
-
Re: DateTimeField, Invalid time format

13 May 2010 at 6:11am
I ended up using DatePickerField from dataobjectmanager and modified a line of code to change that datepicker to US -style dates.
| 3639 Views | ||
| Go to Top | Next > |





