Skip to main content

Date Localisation

The format of dates output or parsed as input can be configured using constants. When a new installation is created the user can select one of the following locales:

  • en_GB
  • en_US
  • de_DE
  • fr_FR

This will automatically configure the date constants for the selected locale. This will also cause the PHP locale to be set for LC_TIME (see http://uk.php.net/manual/en/function.setlocale.php).

If the locale value needs to be altered this can be done in the set_constants.php script. Sometimes the locale name will differ depending on the operating system.

On unix based systems you can list the available locales using locale -a.

## Date output

Dates are output using formatDateTime(). There are some scenarios when it's still acceptable to use date(), such as if the date doesn't need to be localised or if we're only outputting something simple such as the year.

print formatDateTime(FORMAT_DATE_SHORT, $news->newsDate);

Multiple formats can be combined by concatenating the constant values.

print formatDateTime(FORMAT_DATE_SHORT . ' ' . FORMAT_TIME_SHORT, $news->newsDate);

For a full list of available format constants please refer to the table below.

ConstantFormat (en_GB)Example output
FORMAT_DATE_FULL%A, %d %B %YMonday, 15 November 2010
FORMAT_DATE_LONG%d %B %Y15 November 2010
FORMAT_DATE_MEDIUM%d %b %Y15 Nov 2010
FORMAT_DATE_SHORT%d/%m/%Y15/11/2010
FORMAT_TIME_LONG%H:%M:%S %z10:59:29 +0000
FORMAT_TIME_MEDIUM%H:%M:%S10:59:29
FORMAT_TIME_SHORT%H:%M10:59

formatDateTime() uses strftime() internally, therefore format options available to strftime are also available to formatDateTime. For more information on strftime please refer to http://php.net/manual/en/function.strftime.php.

Parsing date inputs

Dates and times can be parsed using parseDate($date, $format).

$parts = parseDate('15/11/2010 11:22', FORMAT_DATE_INPUT . ' ' . FORMAT_TIME_INPUT); // returns an array containing the parsed date parts

To convert a date string directly to a unix-timestamp use convertDateTimeToTimeStamp($datetime, $format = FORMAT_DATE_INPUT).

$timestamp = convertDateTimeToTimeStamp('15/11/2010 11:22', FORMAT_DATE_INPUT . ' ' . FORMAT_TIME_INPUT); // returns the Unix timestamp value for the date string, which in this case would be equivalent to mktime(11,22,0,11,15,2010)

To validate a date string use validateDateTime($date, $format = FORMAT_DATE_INPUT)

if (validateDateTime('15/11/2010 11:22', FORMAT_DATE_INPUT . ' ' . FORMAT_TIME_INPUT))

Input formats are controlled by the following constants.

ConstantFormat (en_GB)Example input
FORMAT_DATE_INPUT%d/%m/%Y15/11/2010
FORMAT_TIME_INPUT%H:%M10:59

Where dates or times are being inputted an example date string is output using the following constants.

ConstantValue (en_GB)
FORMAT_DATE_INPUT_EXAMPLEdd/mm/yyyy
FORMAT_TIME_INPUT_EXAMPLEhh:mm

Calendars

In some countries the convention is for the week to start on Sunday and others Monday.

The constant CALENDAR_FIRST_DAY can be used to determine the day on which the week starts. This is the number of days to offset the calendar by, assuming Sunday is 0 and Saturday is 6. So for en_GB this value is 1 and en_US it is 0.

If a calendar is used as a date picker then is should now format the date using FORMAT_DATE_INPUT.

Timezones

Jadu Central expects that timezone should be set to the correct local value in php.ini.

The default timezone is "Europe/London". If no other values can be found, this is the timezone that will be used.

If php.ini date.timezone value is empty, the default timezone is overridden by the value of DEFAULT_TIMEZONE constant where set.

DEFAULT_TIMEZONE is not set at install and must be added to the JaduConstants database table as required.