Localised Date Format - Documentation

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

Localised Date Format - Documentation

Post by rgbworld »

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; ?>"

BarrySew
Posts: 7
Joined: Fri Jun 28, 2019 11:13 am

Localised Date Format Documentation

Post by BarrySew »

Yea, I thought about that. I figured by the time I actually learned DocBook, I could be done with the whole thing writing in another format.

AnnaLudvigovna
Posts: 5
Joined: Wed Jul 31, 2019 5:42 pm

Localised Date Format Documentation

Post by AnnaLudvigovna »

but then your short date format is not MM/dd/yyyy

or if an english win installation really does this, its broken, and its safer to count from the end.
Мои отзывы - [url=https://real-shopper.club]https://real-shopper.club[/url]

Kamfeft
Posts: 15
Joined: Sat Jul 27, 2019 4:44 am

Localised Date Format Documentation

Post by Kamfeft »

Hi,

I'm interested to see each of you Date format
In many country and/or language, format is different

If having interest, I'll consider to include more Date format

So, What is your prefered Date/Time format??

Your friendly Weathermaster,
Jacques

Post Reply