Announcement

Symphony's issue tracker has been moved to Github.

Issues are displayed here for reference only and cannot be created or edited.

Browse

Closed#584: Symphony doesn't respect date and time preferences

See this discussion: http://www.getsymphony.com/discuss/thread/63273/

I think this problem is caused by PHP's strtotime() function which always expects american date formats like m/d/Y. This should be considered as a bug of the date field – and Symphony in general - where we should compare the date with the system settings first using DateTime::format and only pass it through strtotime() if DateTime::format returned false.

This could be an addition to Lang::standardizeDate().

If we change this behaviour, it should still be possible to use any the following:

  • 12. Oktober 2001
  • tomorrow
  • today 1200
  • thursday

All of these are recognized as valid input at the moment, no matter how your settings are (in my case: Y-m-d and H:i) and displayed correctly using the format from the settings.

Yes, of course. That's why I said that we should check for the given format first and pass it through strtotime() if that format didn't match. So the usage of DateTime::format() will solve the mentioned issue but won't affect the cases you mentioned as these will still be handled by strtotime().

By the way, 12. Oktober 2001 only works because Symphony does some preprocessing, as strtotime() doesn't recognize languages other than English. My proposal would expand that concept.

I need to test this over the next days, but this would be my idea of a changed Lang::standardizeDate() function. It first tries to use the system date format first which is stored in the Symphony configuration and utilizes new DateTime() (which equals strtotime()) as a fallback, if the system format doesn't match. The function now allows a date format to be passed and will default to ISO 8601 output. So it could be used as a strtotime() replacement which is able to handle localised dates as well (which strtotime() cannot).

/**
 * Standardize dates.
 *
 * @param string $string
 *  Localized date that should be standardized
 * @param string $format
 *  Date format used as output format
 * @return string
 *  Returns the given date with English month and day names
 */
public static function standardizeDate($string, $format='c') {

    // Apply system date format
    $date = DateTime::createFromFormat(
        Symphony::$Configuration->get('date_format', 'region') . 
        Symphony::$Configuration->get('datetime_separator', 'region') . 
        Symphony::$Configuration->get('time_format', 'region'), 
        $string
    );

    // Handle non-standard dates
    if($date === false) {

        // Translate locale dates
        if(self::isLocalized()) {
            foreach(self::$_dates as $english => $locale) {
                $string = str_replace($locale, $english, $string);
            }
        }               

        // Replace custom date and time separator with space:
        // This is important, otherwise PHP's strtotime() function may break
        if($separator != ' ') {
            $string = str_replace($separator, ' ', $string);
        }

        // Convert string to date
        $date = new DateTime($string);
    }

    // Return custom formatted date, use ISO 8601 date by default
    return $date->format($format);
}

What do you think?

I created a new branch datetime on by fork of Symphony which improves the date and time handling and moves it to its correct place in lib/core/class.datetimeobj.php. Have a look at https://github.com/nilshoerrmann/symphony-2/tree/datetime.

This needs to be tested thoroughly as it introduces a new function DateTimeObj::format() which handles all localisation and relative date related things. It's a Symphony replacement/enhancement of strtotime() with international date support.

This pull request has been merged into integration.

Thanks Nils

This issue is closed.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details