JosephMajaseSithole / datejs

Automatically exported from code.google.com/p/datejs
0 stars 0 forks source link

[FIXED] toString doesn't format 'yyyy' properly for years w/ < 4 digits #32

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
For example, the year "0001" gets formatted as "1".

Attached is a patch to core.js which fixes this problem

Original issue reported on code.google.com by bobbyru...@gmail.com on 4 Mar 2008 at 12:29

Attachments:

GoogleCodeExporter commented 8 years ago
Thanks for pointing out the bug. I've fixed the error and committed (revision 
140)
the new code to SVN (http://www.datejs.com/svn/).

I changed the .toString function to the following...

case "yyyy":
    var y = "000" + x.getFullYear();
    return y.substring(y.length - 4);
case "yy":
    return x.toString("yyyy").substring(2);

Here are the SVN commit log notes...

--------------------

2008-3-3 [geoffrey.mcgill]
1.  Fixed .toString() bug where .toString would not return four characters if 
the
year was less than 1000.

        Example

    // Old 
    console.log(Date.today().set({year: 10}).toString("yyyy"); // "10"

    // New
    console.log(Date.today().set({year: 10}).toString("yyyy"); // "0010"

    The fix also corrected the same issue with .toString("yy") if the year was less than 10.

    // Old 
    console.log(Date.today().set({year: 5}).toString("yy"); // "5"

    // New
    console.log(Date.today().set({year: 5}).toString("yy"); // "05"

--------------------

Hope this helps.

Original comment by geoff%co...@gtempaccount.com on 4 Mar 2008 at 1:08