Development

#5701 (Date before year 1902 doesn't work)

You must first sign up to be able to contribute.

Ticket #5701 (reopened defect)

Opened 4 years ago

Last modified 4 years ago

Date before year 1902 doesn't work

Reported by: vlemaire Assigned to: fabien
Priority: major Milestone:
Component: generator Version: 1.2.5
Keywords: admin generator, input_date_tag, rich Cc:
Qualification: Unreviewed

Description

I have a model with a bu_date "created_at" field. If I enter a date before 1902, I can't edit this row in admin generator because I have an error with this stack trace :

Impossible to parse date "1901-07-23 0:00" with format "yyyy-MM-dd HH:mm:ss".

# at ()
in SF_ROOT_DIR/lib/symfony/i18n/sfDateFormat.class.php line 178 ...

       175.         $numericalTime = @strtotime($time);
       176.         if ($numericalTime === false)
       177.         {
       178.           throw new sfException(sprintf('Impossible to parse date "%s" with format "%s".', $time, $pattern));
       179.         }
       180.       }
       181.       else

# at sfDateFormat->getDate('1901-07-23 0:00', null)
in SF_ROOT_DIR/lib/symfony/i18n/sfDateFormat.class.php line 211 ...

       208.    */
       209.   public function format($time, $pattern = 'F', $inputPattern = null, $charset = 'UTF-8')
       210.   {
       211.     $date = $this->getDate($time, $inputPattern);
       212.
       213.     if (is_null($pattern))
       214.     {

# at sfDateFormat->format('1901-07-23 0:00', 'yyyy-MM-dd')
in SF_ROOT_DIR/lib/symfony/helper/FormHelper.php line 729 ...

       726.   }
       727.   else
       728.   {
       729.     $value = $dateFormat->format($value, $pattern);
       730.   }
       731.
       732.   // register our javascripts and stylesheets

# at input_date_tag('history[tooked_place_from]', '1901-07-23 0:00', array('rich' => '1', 'calendar_button_img' => '/sf/sf_admin/images/date.png', 'format' => 'i'))
in SF_ROOT_DIR/lib/symfony/helper/ObjectHelper.php line 39 ...

        36.
        37.   $value = _get_object_value($object, $method, $default_value, $param = 'Y-m-d G:i');
        38.
        39.   return input_date_tag(_convert_method_to_name($method, $options), $value, $options);
        40. }
        41.
        42. /**

# at object_input_date_tag(object('History'), 'getTookedPlaceFrom', array('rich' => '1', 'calendar_button_img' => '/sf/sf_admin/images/date.png', 'control_name' => 'history[tooked_place_from]', 'format' => 'i'))
in SF_ROOT_DIR/cache/backend/dev/modules/autoHistory/templates/_edit_form.php line 25 ...

        22.   'calendar_button_img' => '/sf/sf_admin/images/date.png',
        23.   'control_name' => 'history[tooked_place_from]',
        24.   'format' => 'i',
        25. )); echo $value ? $value : ' ' ?>
        26.     </div>
        27. </div>

If I enter 1902-07-23, It works fine but with a year before 1902, I have this exception.

Change History

01/26/09 22:52:36 changed by FabianLange

  • status changed from new to closed.
  • resolution set to wontfix.

The valid range of a timestamp is typically from Fri, 13 Dec 1901 20:45:54 UTC to Tue, 19 Jan 2038 03:14:07 UTC. (These are the dates that correspond to the minimum and maximum values for a 32-bit signed integer.)

from http://www.php.net/strtotime this is a limitation we cannot workaround.

04/17/09 18:47:07 changed by luisfaceira

  • priority changed from minor to major.
  • status changed from closed to reopened.
  • version changed from 1.2.2 to 1.2.5.
  • resolution deleted.
  • summary changed from Date before year 1902 doesn't work with rich input_date_tag to Date before year 1902 doesn't work.

Actually, I disagree that there is no workaround.

I use a Doctrine and I have some columns of type "date". If i input a date that is previous to 1901 it crashes. It's a timestamp php limitation, you say. But I'm not using a timestamp data type, I'm using a DATE datatype. If i go manually into my database (in my case, mysql) I CAN insert dates that are previous to 1901 without any problem. So the problem must be in some operation in the middle, inside symfony, that uses timestamp to manipulate the data when it's not actually a timestamp. Isn't the DateTime? php class able to deal with older dates? I think so!

So, there probably is a workaround if we look closer into it!