Jump to:

23369 Posts in 18145 Topics by 2863 members

General Questions

SilverStripe Forums » General Questions » DateTimeField, Invalid time format

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

Page: 1 2
Go to End
Author Topic: 4455 Views
  • Mo
    Avatar
    Community Member
    505 Posts

    DateTimeField, Invalid time format Link to this post

    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

  • Mo
    Avatar
    Community Member
    505 Posts

    Re: DateTimeField, Invalid time format Link to this post

    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

  • Dynamic
    Avatar
    Community Member
    16 Posts

    Re: DateTimeField, Invalid time format Link to this post

    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!

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: DateTimeField, Invalid time format Link to this post

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

  • ttyl
    Avatar
    Community Member
    114 Posts

    Re: DateTimeField, Invalid time format Link to this post

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

  • Mo
    Avatar
    Community Member
    505 Posts

    Re: DateTimeField, Invalid time format Link to this post

    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

  • Ingo
    Avatar
    Forum Moderator
    801 Posts

    Re: DateTimeField, Invalid time format Link to this post

    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

  • Antti
    Avatar
    Community Member
    6 Posts

    Re: DateTimeField, Invalid time format Link to this post

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

    4455 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.