HackerOne users: Testing against this community violates our program's Terms of Service and will result in your bounty being denied.

Date format problem: year isn't displayed if first

csakipcsakip New
edited August 2012 in Localization

Hi,
I tried to add a date input to the form with the order: year, month, day - national standard. The year doesn't get displayed. If the year is second or third then it displays fine.

No year:
echo $Sender->Form->Date('date', array('Fields' => array('year','month','day')));

Ok:
echo $Sender->Form->Date('date', array('Fields' => array('month','year','day')));

Comments

  • @csakip

    I think you may need to set in locale.php or definitions.php whichever you are using. try modifying Date.DefaultFormat to see if you get the results you want.

    e.g.

    $Definition['Date.DefaultFormat']=''%Y %e %B';

    the code - for Date in class.format.php

     public static function Date($Timestamp = '', $Format = '') { code - for Date
    ...
    ...
    
       if ($Format == '') {
             // If the timestamp was during the current day
             if (date('Y m d', $Timestamp) == date('Y m d', $Now)) {
                // Use the time format
                $Format = T('Date.DefaultTimeFormat', '%l:%M%p');
             } else if (date('Y', $Timestamp) == date('Y', $Now)) {
                // If the timestamp is the same year, show the month and date
                $Format = T('Date.DefaultDayFormat', '%B %e');
             } else if (date('Y', $Timestamp) != date('Y', $Now)) {
                // If the timestamp is not the same year, just show the year
                $Format = T('Date.DefaultYearFormat', '%B %Y');
             } else {
                // Otherwise, use the date format
                $Format = T('Date.DefaultFormat', '%B %e, %Y');
             }
          }
    

    http://www.php.net/manual/en/function.date.php

    or make your own routine if that doesn't work.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • Thanks, but it's not about the displaying date as text but the date inputs on forms. (btw: nice work on the enhanced members list ;) )

  • Thx. if you don't get help from anyone else and you want to post the whole routine code that I could actually run and experiment with - I would be glad to give it a try.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • That's all the code. Just try to add anywhere where you have a Form object:
    $Sender->Form->Date('date', array('Fields' => array('year','month','day')));

    Only the month and day dropdowns will be displayed.

  • peregrineperegrine MVP
    edited August 2012

    You are absolutely correct - it won't work - I think there is a bug in the code for
    /library/core/form.php

    notice the concatenation is missing in the first switch statement so the loop will always drop the previous results. I haven't confirmed if it saves correctly but it does display the option boxes correctly.

    But this will make it work change line 707
    
    from
      $Return = $this->DropDown($FieldName . '_Month', $Months, $Attributes);
    
    to
     $Return .= $this->DropDown($FieldName . '_Month', $Months, $Attributes);
    

    can you confirm please?

    if you need a year range option also - this works.

    $this->Form->Date($mydate, array('yearrange'=>'1999-2004','Fields' => array('year','month','day')));

    without the change the sort works properly with out year (so we know the sorting ability was intended).

    echo $this->Form->Date($mydate, array('Fields' => array('day','month')));

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited August 2012

    @Todd does this look like a bug and will the "change above" cause other problems.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • same issue in vanilla 2.1 on line 715

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • peregrineperegrine MVP
    edited August 2012

    For visuals before adding the period before the equal sign in
    /library/core/form.php line 707

    before

    $Return = $this->DropDown($FieldName . '_Month', $Months, $Attributes);

    results in image1 - if I use this form statement in a plugin

    echo $this->Form->Date('date', array('Fields' => array('year','month','day')));

    notice it drops the year

    after correcting library/core/form.php line 707

    changing = to .= for concatenation. results in image2

    $Return .= $this->DropDown($FieldName . '_Month', $Months, $Attributes);

    same echo statement
    echo $this->Form->Date('date', array('Fields' => array('year','month','day')));

    also modified line 698 to initialize $Return to "" .

    $Fields = ArrayValueI('fields', $Attributes, array('month', 'day', 'year'));
    // added this statement
    $Return = "";

    click on the images to see full display.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • I must have some dyslexia. I've checked that part of the code for half an hour and didn't see the missing dot. :D
    Cheers, thank you.

  • looking forward to your plugins. You have some great ideas.

    I may not provide the completed solution you might desire, but I do try to provide honest suggestions to help you solve your issue.

  • ToddTodd Vanilla Staff

    I'll fix that bug in Gdn_Form.

  • @peregrine said:
    You are absolutely correct - it won't work - I think there is a bug in the code for
    /library/core/form.php

    notice the concatenation is missing in the first switch statement so the loop will always drop the previous results. I haven't confirmed if it saves correctly but it does display the option boxes correctly.

    But this will make it work change line 707
    
    from
      $Return = $this->DropDown($FieldName . '_Month', $Months, $Attributes);
     
    to
     $Return .= $this->DropDown($FieldName . '_Month', $Months, $Attributes);
    

    can you confirm please?

    if you need a year range option also - this works.

    $this->Form->Date($mydate, array('yearrange'=>'1999-2004','Fields' => array('year','month','day')));

    without the change the sort works properly with out year (so we know the sorting ability was intended).

    echo $this->Form->Date($mydate, array('Fields' => array('day','month')));

    @peregrine said:
    For visuals before adding the period before the equal sign in
    /library/core/form.php line 707

    before

    $Return = $this->DropDown($FieldName . '_Month', $Months, $Attributes);

    results in image1 - if I use this form statement in a plugin

    echo $this->Form->Date('date', array('Fields' => array('year','month','day')));

    notice it drops the year

    after correcting library/core/form.php line 707

    changing = to .= for concatenation. results in image2

    $Return .= $this->DropDown($FieldName . '_Month', $Months, $Attributes);

    same echo statement
    echo $this->Form->Date('date', array('Fields' => array('year','month','day')));

    also modified line 698 to initialize $Return to "" .

    $Fields = ArrayValueI('fields', $Attributes, array('month', 'day', 'year'));
    // added this statement
    $Return = "";

    click on the images to see full display.
    @csakip said:
    I must have some dyslexia. I've checked that part of the code for half an hour and didn't see the missing dot. :D
    Cheers, thank you.

  • Yes Boy its all good! www.google.com

Sign In or Register to comment.