Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

General Questions

General questions about getting started with SilverStripe that don't fit in any of the categories above.

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

DateTimeField, Invalid time format


Go to End
Reply

10 Posts   4562 Views

Avatar
Mo

20 April 2010 at 9:26am Community Member, 509 Posts

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

Avatar
Mo

20 April 2010 at 11:41am Community Member, 509 Posts

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

Avatar
Dynamic

22 April 2010 at 10:41am Community Member, 16 Posts

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!

Avatar
Ingo

11 May 2010 at 9:01pm Forum Moderator, 801 Posts

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...

Avatar
ttyl

13 May 2010 at 6:11am Community Member, 114 Posts

I ended up using DatePickerField from dataobjectmanager and modified a line of code to change that datepicker to US -style dates.

Avatar
Mo

3 June 2010 at 10:23pm Community Member, 509 Posts

Could you add a "TimeZone" dropdown next to the field. By default it would be filled in with one (say, us/uk etc), but then it could be changed?

Alternatively, you could maybe have a static in the DatetimeField class, something like:

DatetimeField::$timezone = "dd/mm/yyyy";

Just some thoughts?

Mo

Avatar
Ingo

4 June 2010 at 9:00am Forum Moderator, 801 Posts

Timezone support would be great, although we'd have to investigate how its storage works across databases.
Tom has done some timezone extensions to the CMS, incl. a TZDateTimeField: http://open.silverstripe.org/browser/modules/timezoneawareness/trunk - its pre 2.4 stable, not sure how useful it still is.

Do you guys still see this as part of the DateField codebase? I want to avoid ending up with a huge bloated class (think HasManyComplexTableField), any suggestions on how to apply this cleanly in terms of design patterns?

Zend_Date already has good timezone conversion support, so making this a presentational setting (and storing the date without timezone) might be a lot simpler.

By the way, I've added a patch to the datepicker ticket mentioned before - it works with jQuery UI now, wohoo :) Still looking for feedback and code review: http://open.silverstripe.org/ticket/5397

Avatar
Antti

1 September 2010 at 10:52pm Community Member, 6 Posts

Do you get this working if you empty browser cache completely?
My calendar dosnt popup when i go to date field in cms. If i refresh browser then its ok, and after that it load ok.

Same thing happens with Dataobjectmanager module. First load dosnt seem to load correctly like something were missing, but after refreshing all ok.

My code looks like this.
class MyPage extends Page {
   static $db = array (
'MyPageName'    => 'Text',
      'From'         => 'Date',
      'To'         => 'Date'
}

public function getCMSFields() {
$f = parent::getCMSFields();

      // add fields
      $datefieldFrom    = new DateField('From','From');
      $datefieldTo     = new DateField('To','To');
      $datefieldFrom->setConfig('showcalendar', true);
      $datefieldTo->setConfig('showcalendar', true);

      $f->addFieldToTab("Root.Content.Main", $datefieldFrom);
      $f->addFieldToTab("Root.Content.Main", $datefieldTo);

return $f;
}
}

I been banging my head against wall with this one pretty long....

Go to Top