Localised Date Format - Documentation

Discussion of Localised Date Format extension
Post Reply
User avatar
rgbworld
Site Admin
Posts: 57
Joined: Sat Dec 05, 2015 5:42 pm

Localised Date Format - Documentation

Post by rgbworld » Mon May 29, 2017 12:20 am

Localised Date Format (LDF) Extension
Localised Date Format is an extension written by RGB World for use with OpenCart. It can be purchased from the RGB World Store or from the OpenCart Marketplace (coming soon).

The Localised Date Format (LDF) extension allows Store Owners to quickly configure:
  • How Dates are Displayed throughout an entire OpenCart store.
  • How Dates are Entered into Datepicker input and search fields.
  • Whether or not to display the Time.
This following information is intended for OpenCart extension developers. It explains code changes that may need to be applied to third party extensions and templates.

Default OpenCart Date Formatting
With a default installation of OpenCart, Date formats are configured via a language text file. The following formats are defined in: admin/language/en-gb/en-gb.php

Code: Select all

$_['date_format_short']             = 'd/m/Y';
$_['date_format_long']              = 'l dS F Y';
$_['time_format']                   = 'h:i:s A';
$_['datetime_format']               = 'd/m/Y H:i:s';
The format (text) is then accessed from the Controller via the language object.

Code: Select all

$this->language->get('date_format_short')
To format a Date, the code would be:

Code: Select all

date($this->language->get('date_format_short'))
Default Datepicker Format
In the default OpenCart templates, the Date format used by the Datepicker is statically formatted as:

Code: Select all

data-date-format="YYYY-MM-DD"
Due to the use of static text in the template files, Changing the definition of 'date_format_short' does NOT change the date format that is used by the Datepicker. The Datepicker format remains "YYYY-MM-DD". Thus, dates entered into Datepicker input fields must always be entered as 2017-05-27. The only dates that are displayed according to the language setting are the dates that appear in List views.

Localised Date Format
With the Localised Date Format extension, Date formats are stored in a database and a new 'Date Formats' Menu Item is added to the OpenCart Administration panel under: System > Localisation > Date Formats. Date formats are configured via the Admin GUI.

To format a Date with the Localised Date Format API, the code would be:

Code: Select all

date($this->dateformat->get('date_format_short'))
So, the basic change is to replace: "$this->language->get('date_format_short')" with "$this->dateformat->get('date_format_short')".

Fixing Datepicker Format
To fix the Datepicker formatting issue described above, the following code change is required in all template files...

Find:

Code: Select all

data-date-format="YYYY-MM-DD"
Replace with:

Code: Select all

data-date-format="<?php echo $datepicker_date_format; ?>"

Post Reply