Menu

#1 Only US Date formatting works. AU and HK do not - PATCHED

open
nobody
5
2014-09-04
2011-10-07
Ben J
No

I would like to start out by saying you guys have done an awesome job in the functionality of this and I love the simplicity of the interface.

Being from Australia tho, I wanted to format the calender for locale use, and part of the reason I'd chosen to go with your calender version is the option to select US, AU or HK date formatting in the sample script. Unfortunately i found out that choosing anything besides US causes the sample page to stop working.

These "option" lines can be found in sample.php and edit.php.
eg. sample.php
Line 16
<script src="src/Plugins/datepicker_lang_US.js" type="text/javascript"></script>
Line 21
<script src="src/Plugins/wdCalendar_lang_US.js" type="text/javascript"></script>

The correct files are in place for AU and HK.

Below is a "patch" so we can choose different date formatting.

php/functions.php - line 2 insert
// Choose date format to your locale.
// US, AU are only supported atm.
$config->lang='AU';

Line 10 replace with
if ($config->lang=='US') {
$ret = mktime($matches[4], $matches[5], 0, $matches[1], $matches[2], $matches[3]);
} elseif ($config->lang=='AU') {
$ret = mktime($matches[4], $matches[5], 0, $matches[2], $matches[1], $matches[3]);
}

Line 17 replace with
if ($config->lang=='US') {
$ret = mktime(0, 0, 0, $matches[1], $matches[2], $matches[3]);
} elseif ($config->lang=='AU') {
$ret = mktime(0, 0, 0, $matches[2], $matches[1], $matches[3]);
}

sample.php - line 1 insert
<?
//We load functions so that we get our date format var.
require_once('php/functions.php');
?>
Line 21 change
<script src="src/Plugins/datepicker_lang_<?echo $config->lang;?>.js" type="text/javascript"></script>
Line 26 change
<script src="src/Plugins/wdCalendar_lang_<?echo $config->lang;?>.js" type="text/javascript"></script>

edit.php
Line 1 - insert
<?
//We load functions so that we get our date format var.
require_once('php/functions.php');
?>
Line 16 - change
<script src="src/Plugins/datepicker_lang_<?echo $config->lang;?>.js" type="text/javascript"></script>

edit.db.php - line 34 change
<script src="src/Plugins/datepicker_lang_<?echo $config->lang;?>.js" type="text/javascript"></script>

"src/Plugins/wdCalendar_lang_AU.js"
line 7 change to
"Md": "W d/M",

"src/Plugins/datepicker_lang_AU.js"
Line 4 - change
"fulldayvalue": "d/M/yyyy",

Now you can simply go into functions.php and adjust the value to be US/AU without worry.

Just a suggestion in going forward, I believe correctly resolving the issue lies in all of the date processing that is done from sql time (Y-m-d H:i:s) to php (unixtimestamp) to JS time (m/d/Y H:i) and then to date display format (US,AU,HK). At current I believe there are too many date conversions going on and ideally i think everything should be handled in unixtimestamp (UTC) right up until time of formatting for display or db.

Discussion

  • Ben J

    Ben J - 2011-10-07

    further patch for correcting issue where editing an recorded entry would cause US style date, and therefore saved incorrectly .. eg 6/10/11 would show and save as 10/6/11

    php/functions.php
    replace function with this. (note HK untested)
    function php2JsTime($phpDate,$formatLocale=false){
    //echo $phpDate;
    //return "/Date(" . $phpDate*1000 . ")/";
    global $config;
    if ($formatLocale && $config->lang!='US') {
    if ($config->lang=='AU') {
    return date("d/m/Y H:i", $phpDate);
    } elseif ($config->lang=='HK') {
    return date("Y-m-d H:i", $phpDate);
    }
    } else {
    return date("m/d/Y H:i", $phpDate);
    }
    }

    edit.php
    line 227 and 228 change
    $sarr = explode(" ", php2JsTime(mySql2PhpTime($event->StartTime),true));
    $earr = explode(" ", php2JsTime(mySql2PhpTime($event->EndTime),true));

    FIXED!

     
  • Anonymous

    Anonymous - 2011-12-30

    Hello, I followed your instructions step by step to make it work the date format dd / mm / yyyy but it happens that in the Month view works perfectly but in the week and day view when I create a new event date I send out wrong capture to see. you can help me out to solve this?

     

    Last edit: Anonymous 2017-07-03
  • HaLeXz

    HaLeXz - 2014-03-07

    Hi to all! Thanks to stevendu and all contributors to share this cool calendar. I've noticed the date conversion bugs, and I'm trying to solve them. Thanks Ben J for the input...

    I'm trying to standardize the localization of the app, to make it possible for everyone to create his own localization. I've modified the sample.php and edit.php replacing all fixed texts with PHP variables, putting them in a localized PHP file, and creating a config.php file where I've defined the site title and the language code. The PHP variable containing the international code is replaced everywhere the original "US" code is found, so you can change it from the main variable for all (something like Ben J did with the $config->lang in the functions.php where I think it's not the better place to do it).

    Well, writing all this to tell you that I think to change the function.php file starting from what Ben J wrote, but to write a function that can accept all type of localization defined by the user in the file "wdCalendar_lang_US.js" where you can find the indexes for year, month and day respectively at lines 10, 11 and 12. Reading the values from there, implementing them in the functions.php's code, will do the trick.

    If someone want to help, I'm working on it. I'll post the results when finished...

    Next step I want to implement is "multi-user" calendar...

    Bye

     
  • HaLeXz

    HaLeXz - 2014-03-17

    Found a problem: the JS stuff manage itself the date format localization, with the year_index, day_index and month_index variables defined in the LANG js files. If you change the function php2JsTime to change the date format passed to JS scripts, it will be changed another time in the JS script of calendar, so the script doesn't work correctly.

    Testing now to make another function to manage the "visualized JS dates" only and the standard function to pass the dates to the JS script.

    After that, I think I can upload the new corrected scripts/pages ready for easy translations...

    Bye

     

    Last edit: HaLeXz 2014-03-17
    • Ben J

      Ben J - 2014-09-02

      Randomly stumbled upon this today, shame to see it hadn't been resolved since it was opened.

      How did you get on with your fix HaLeXz?

       
  • HaLeXz

    HaLeXz - 2014-09-03

    I was looking for a way to upload the files, but can't find it. Can you help me?

     
  • Ben J

    Ben J - 2014-09-04

    At the top of the page it says "Brought to you by: stevendu (Admin)"

    You'll need to contact him. As everything else is read only. That was why I'd originally copy/pasted into the bug my solution.

     

Log in to post a comment.