Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

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>
Link to comment
Share on other sites

  • 3 months later...

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 :)

Link to comment
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

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
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

Link to comment
Share on other sites

  • 3 months later...

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.

Link to comment
Share on other sites

  • 2 months later...

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 CE live - developing osC Phoenix adding modules with no core changes(awesome and easy!)

Link to comment
Share on other sites

  • 2 weeks later...

@@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?

Link to comment
Share on other sites

  • 3 years later...

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

Link to comment
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...

Link to comment
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.

 

 

 

Link to comment
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

 

 

Link to comment
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

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...