Jump to content
vampirehunter

Bootstrap jquery date picker not showing UK format

Recommended Posts

I have a problem, but can't work out whats causing it.

 

I've edited the english.php file and

 

defined

define('DATE_FORMAT_SHORT', '%d/%m%/Y');  // this is used for strftime()
define('DATE_FORMAT_LONG', '%A %d %B, %Y'); // this is used for strftime()
define('DATE_FORMAT', 'd/m/Y'); // this is used for date()
define('DATE_TIME_FORMAT', DATE_FORMAT_SHORT . ' %H:%M:%S');
define('JQUERY_DATEPICKER_I18N_CODE', ''); // leave empty for en_US; see http://jqueryui.com/demos/datepicker/#localization
define('JQUERY_DATEPICKER_FORMAT', 'dd/mm/yy'); // see http://docs.jquery.com/UI/Datepicker/formatDate

////
// Return date in raw format
// $date should be in format mm/dd/yyyy
// raw date is in format YYYYMMDD, or DDMMYYYY
function tep_date_raw($date, $reverse = false) {
  if ($reverse) {
    return substr($date, 3, 2) . substr($date, 0, 2) . substr($date, 6, 4);
  } else {
    return substr($date, 6, 4) . substr($date, 0, 2) . substr($date, 3, 2);
  }
}

However, when i go to the create account page and select a date, its still showing the US date format of mm/dd/yy.

 

Can anyone advise what else needs to be changed? I assumed that one change would do it, but its not working.

 

i checked my html source and this is what it says

<script>$('#dob').datepicker({dateFormat: 'dd/mm/yy',viewMode: 2});</script>
<script>var nowTemp = new Date(); var now = new Date(nowTemp.getFullYear(), nowTemp.getMonth(), nowTemp.getDate(), 0, 0, 0, 0); $('#dfrom').datepicker({dateFormat: 'dd/mm/yy',onRender: function(date) {return date.valueOf() > now.valueOf() ? 'disabled' : '';}}); </script>
<script>$('#dto').datepicker({dateFormat: 'dd/mm/yy',onRender: function(date) {return date.valueOf() > now.valueOf() ? 'disabled' : '';}});</script>
</body>
Edited by vampirehunter

Share this post


Link to post
Share on other sites

@@vampirehunter Did you ever get this sorted.


REMEMBER BACKUP, BACKUP AND BACKUP

Get the latest Responsive osCommerce CE (community edition) here

It's very easy to over complicate what are simple things in life

Share this post


Link to post
Share on other sites

I think you need to change tep_date_raw() - note that it expects to receive the date as mm/dd/yyyy (and pays no attention whatsoever to the DATE_FORMAT* etc constants), so you need to change the substrs to swap over the positions of month and day if you are providing it as dd/mm/yyyy

 

So change

function tep_date_raw($date, $reverse = false) {
  if ($reverse) {
    return substr($date, 3, 2) . substr($date, 0, 2) . substr($date, 6, 4);
  } else {
    return substr($date, 6, 4) . substr($date, 0, 2) . substr($date, 3, 2);
  }
}

to

function tep_date_raw($date, $reverse = false) {
  if ($reverse) {
    return substr($date, 0, 2) . substr($date, 3, 2) . substr($date, 6, 4);
  } else {
    return substr($date, 6, 4) . substr($date, 3, 2) . substr($date, 0, 2);
  }
}

Better yet, this function should be rewritten to parse the date using the appropriate date format constant... this is left as an exercise :)

Edited by Ben23

Share this post


Link to post
Share on other sites

I think you need to change tep_date_raw() - note that it expects to receive the date as mm/dd/yyyy (and pays no attention whatsoever to the DATE_FORMAT* etc constants), so you need to change the substrs to swap over the positions of month and day if you are providing it as dd/mm/yyyy

 

So change

function tep_date_raw($date, $reverse = false) {
  if ($reverse) {
    return substr($date, 3, 2) . substr($date, 0, 2) . substr($date, 6, 4);
  } else {
    return substr($date, 6, 4) . substr($date, 0, 2) . substr($date, 3, 2);
  }
}

to

function tep_date_raw($date, $reverse = false) {
  if ($reverse) {
    return substr($date, 0, 2) . substr($date, 3, 2) . substr($date, 6, 4);
  } else {
    return substr($date, 6, 4) . substr($date, 3, 2) . substr($date, 0, 2);
  }
}

Better yet, this function should be rewritten to parse the date using the appropriate date format constant... this is left as an exercise :)

 

Hi

thanks

will check it out

Share this post


Link to post
Share on other sites

I am working on localisation of the Datepicker in 2.3.4BS and found this pull-request https://github.com/gburton/Responsive-osCommerce/pull/134

 

Maybe this helps to solve the issue .. Did not try it myself right now ...

 

And Maybe @@burt Gary (or someone who worked on localisation) can confirm the pull-request is needed for proper localisation.

Share this post


Link to post
Share on other sites

I looked into this a bit more and made a change in this line in includes/languages/english.php

define('JQUERY_DATEPICKER_I18N_CODE', ''); // leave empty for en_US; see http://jqueryui.com/demos/datepicker/#localization

and changeg to

define('JQUERY_DATEPICKER_I18N_CODE', 'en_UK'); // leave empty for en_US; see http://jqueryui.com/demos/datepicker/#localization

It seems to have sorted my problem.


REMEMBER BACKUP, BACKUP AND BACKUP

Get the latest Responsive osCommerce CE (community edition) here

It's very easy to over complicate what are simple things in life

Share this post


Link to post
Share on other sites

I looked into this a bit more and made a change in this line in includes/languages/english.php

define('JQUERY_DATEPICKER_I18N_CODE', ''); // leave empty for en_US; see http://jqueryui.com/demos/datepicker/#localization

and changeg to

define('JQUERY_DATEPICKER_I18N_CODE', 'en_UK'); // leave empty for en_US; see http://jqueryui.com/demos/datepicker/#localization

It seems to have sorted my problem.

 

en_UK is not normally a valid locale. For the UK you should use en_GB.

 

The I18N code mainly determines the language of the text (day names, month names, prev, next etc) that appear within the datepicker.

The en_GB code does also set dateformat to dd/mm/yy.

 

So if you use this (or you set JQUERY_DATEPICKER_FORMAT to dd/mm/yy separately) you probably also need to make the change to tep_date_raw() that I outlined earlier as well, because that always expects date in mm/dd/yy.

Share this post


Link to post
Share on other sites

Hi,

 I can't get the date format right, the DATEPICKER keeps returning mm/dd/yyyy

 

I've made the changes as above but no luck, can any one advise please?

 

Mike


osC BS gold live - osC CE in development (awesome)

Share this post


Link to post
Share on other sites

@@Mikepo

 

Can you try once the following.

 

Backup first the following file

 

ext/datepicker/js/bootstrap-datepicker.js

 

then open it and find

this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'mm/dd/yyyy');

REPLACE WITH

this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'dd/mm/yyyy');

Does this work for you?

Share this post


Link to post
Share on other sites

Hi all, I have the latest version of the CE 2.3.4.1 installed and I am slowly configuring it and have come across the date problem on the catalog side.

I have adjusted all the includes/languages/english.php files as required for the format to be DD/MM/YYYY, but when I go to create a new account and input the date, it goes back to the MM/DD/YYYY format and I am unable to create an account, in fact the top error message says it must be in the dd/mm/yyyy format, but the datepicker will not allow that format.

Here are the screen shots from the create account screen and my english.php file (fyi the date works perfectly in admin)

Any suggestions would be greatly appreciated.

Cheers!

In the example below I tried to get the date to be 13 August 1976 (13/08/1976), but as you can see it comes out as August 13 1976 (08/13/1976)

 

// look in your $PATH_LOCALE/locale directory for available locales
// or type locale -a on the server.
// Array examples which should work on all servers:
// 'en_US.UTF-8', 'en_US.UTF8', 'enu_usa'
// 'en_GB.UTF-8', 'en_GB.UTF8', 'eng_gb'
// 'en_AU.UTF-8', 'en_AU.UTF8', 'ena_au'
@setlocale(LC_ALL, array('en_AU.UTF-8', 'en_AU.UTF8', 'ena_au'));

define('DATE_FORMAT_SHORT', '%d/%m/%Y');  // this is used for strftime()
define('DATE_FORMAT_LONG', '%A %d %B, %Y'); // this is used for strftime()
define('DATE_FORMAT', 'd/m/Y'); // this is used for date()
define('DATE_TIME_FORMAT', DATE_FORMAT_SHORT . ' %H:%M:%S');
define('JQUERY_DATEPICKER_FORMAT', 'dd/mm/yy'); // see http://docs.jquery.com/UI/Datepicker/formatDate

////
// Return date in raw format
// $date should be in format mm/dd/yyyy
// raw date is in format YYYYMMDD, or DDMMYYYY
function tep_date_raw($date, $reverse = true) {
  if ($reverse) {
    return substr($date, 0, 2) . substr($date, 3, 2) . substr($date, 6, 4);
  } else {
    return substr($date, 6, 4) . substr($date, 3, 2) . substr($date, 0, 2);
  }
}

Date Problem.PNG

includes english.PNG

Edited by nedragdnuos
add extra info

Share this post


Link to post
Share on other sites

Try

function tep_date_raw($date, $reverse = false) {

 


OsC 2.3.4.1 CE Frozen   PHP 7.2   MySQL 10.1.36-MariaDB-cll-lve

Share this post


Link to post
Share on other sites
11 hours ago, mhsuffolk said:

Try


function tep_date_raw($date, $reverse = false) {

 

Hi, thanks for the suggestion, but nope that did not work, still shows the date in US format and throws up the error saying it must be the other way around....

 

Quite perplexing this one...

Share this post


Link to post
Share on other sites
On 12/4/2015 at 4:05 PM, Tsimi said:

@@Mikepo

 

Can you try once the following.

 

Backup first the following file

 

ext/datepicker/js/bootstrap-datepicker.js

 

then open it and find


this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'mm/dd/yyyy');

REPLACE WITH


this.format = DPGlobal.parseFormat(options.format||this.element.data('date-format')||'dd/mm/yyyy');

Does this work for you?

Hi, thanks for the reply,

That line to change does not exist in the: catalog/ext/datepicker/js/bootstrap-datepicker.js  version I am using, I have downloaded the latest version of the responsive oscommerce 2.3.4.1 ce from here:

https://github.com/gburton/Responsive-osCommerce

I believe the update to bootstrap 4 has changed certain bits of the code, so I may be stuck until someone with coding skills has a bit of a look see.

 

 

 

Share this post


Link to post
Share on other sites

This can be changed by makeing a few edits to core files. This is not the best way but works.

First in

public_html/includes/modules/header_tags/ht_datepicker_jquery.php

find

if (in_array(basename($PHP_SELF), $pages_array)) {
          $oscTemplate->addBlock('<script src="ext/datepicker/js/bootstrap-datepicker.min.js"></script>' . "\n", $this->group);

and replace with

if (in_array(basename($PHP_SELF), $pages_array)) {
          $oscTemplate->addBlock('<script src="ext/datepicker/js/bootstrap-datepicker.js"></script>' . "\n", $this->group);

Why? well we are going to edit  of bootstrap-datepicker.js and it's easyer to edit the none minified files.

so now in /public_html/ext/datepicker/js/bootstrap-datepicker.js

find

line 1741          format: 'mm/dd/yyyy',

and change to

line 1741          format: 'dd/mm/yyyy',

That's it, you will now have the required format in date-picker. This should not be needed as if the correct region is selected in osC date picker should change the date format! Not sure why it’s not doing this.

image.png.ae86c0368bc77c5194b89a73ad3c160e.png

 


 

Share this post


Link to post
Share on other sites

Hi Jc, I just made the changes, and the date shows correctly, but when I go to create the account I get the error at the top (I have rubbed out the names etc)

So we are kind of getting there, again it is quite perplexing....

 

 

date 2.png

Share this post


Link to post
Share on other sites

No it should work. It did on my test site. I can only think that you have not changed the date format to dd/mm/yyyy in your language files! You need to do this on both shop and admin language files.

image.png.7c70a8d6833af85a54d4cd4852961bfe.png


 

Share this post


Link to post
Share on other sites

Ok, I went through the whole lot again right from the start and found a slight error in one of the obscure Australian definition files located in:

\catalog\ext\datepicker\locales\bootstrap-datepicker.en-AU.min.js

At the very end of the text line, I found that the date format was showing  
........format:"d/mm/yyyy"}}(jQuery);
so I added the extra "d" and voila all of a sudden it works
........format:"dd/mm/yyyy"}}(jQuery);

So to summarize for Australian format in oscommerce 2.3.4.1 CE, ( https://github.com/gburton/Responsive-osCommerce) check the above and do the mods JC Magpie mentioned in his previous post:

change the date format in - \catalog\ext\datepicker\js\bootstrap-datepicker.js

adjust date in catalog side - \catalog\includes\languages\english.php

// 'en_AU.UTF-8', 'en_AU.UTF8', 'ena_au'
@setlocale(LC_ALL, array('en_AU.UTF-8', 'en_AU.UTF8', 'ena_au'));
define('DATE_FORMAT_SHORT', '%d/%m/%Y');  // this is used for strftime()
define('DATE_FORMAT_LONG', '%A %d %B, %Y'); // this is used for strftime()
define('DATE_FORMAT', 'd/m/Y'); // this is used for date()
define('DATE_TIME_FORMAT', DATE_FORMAT_SHORT . ' %H:%M:%S');
define('JQUERY_DATEPICKER_FORMAT', 'dd/mm/yy'); // see http://docs.jquery.com/UI/Datepicker/formatDate
////
// Return date in raw format
// $date should be in format mm/dd/yyyy
// raw date is in format YYYYMMDD, or DDMMYYYY
function tep_date_raw($date, $reverse = false) {
  if ($reverse) {
    return substr($date, 0, 2) . substr($date, 3, 2) . substr($date, 6, 4);
  } else {
    return substr($date, 6, 4) . substr($date, 3, 2) . substr($date, 0, 2);
 
Adjust date in admin side - catalog\admin\includes\languages\english.php

// 'en_AU.UTF-8', 'en_AU.UTF8', 'ena_au'
setlocale(LC_ALL, array('en_AU.UTF-8', 'en_AU.UTF8', 'ena_au'));
define('DATE_FORMAT_SHORT', '%d/%m/%Y');  // this is used for strftime()
define('DATE_FORMAT_LONG', '%A %d %B, %Y'); // this is used for strftime()
define('DATE_FORMAT', 'd/m/Y'); // this is used for date()
define('PHP_DATE_TIME_FORMAT', 'd/m/Y H:i:s'); // this is used for date()
define('DATE_TIME_FORMAT', DATE_FORMAT_SHORT . ' %H:%M:%S');
define('JQUERY_DATEPICKER_I18N_CODE', 'ena_au'); // leave empty for en_US; see http://jqueryui.com/demos/datepicker/#localization
define('JQUERY_DATEPICKER_FORMAT', 'dd/mm/yy'); // see http://docs.jquery.com/UI/Datepicker/formatDate
////
// Return date in raw format
// $date should be in format mm/dd/yyyy
// raw date is in format YYYYMMDD, or DDMMYYYY
function tep_date_raw($date, $reverse = false) {
  if ($reverse) {
    return substr($date, 0, 2) . substr($date, 3, 2) . substr($date, 6, 4);
  } else {
    return substr($date, 6, 4) . substr($date, 3, 2) . substr($date, 0, 2);


And anywhere that the date reference is MM/DD/YYYY, change it to DD/MM/YYYY in the above english.php files, you will have to scroll down and hunt for them all.
 

Thank you to everyone for their help, it is greatly appreciated!

Enjoy your weekend, and I hope you all have a great New Year!

3.PNG

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×