Permalink
Browse files

fixed "%y" and "%g"

  • Loading branch information...
1 parent 97b2459 commit 799bf1d28ac0b165234462b28ad5135f76c686db @kotas committed Dec 9, 2011
Showing with 8 additions and 2 deletions.
  1. +2 −2 src/jarty.date.js
  2. +6 −0 tests/jarty/date_test.js
View
@@ -51,9 +51,9 @@ FormatDateTable = JD.FormatDateTable = {
'%h': function (d) { return MonthNames[d.getMonth()].substring(0, 3) },
'%m': function (d) { return JU.padNumber(d.getMonth()+1, 2) },
'%C': function (d) { return JU.padNumber(Math.floor(d.getFullYear() / 100), 2) },
- '%g': function (d) { return JU.padNumber(d.getYear(), 2) },
+ '%g': function (d) { return d.getFullYear().toString().substring(2) },
'%G': function (d) { return d.getFullYear() },
- '%y': function (d) { return JU.padNumber(d.getYear(), 2) },
+ '%y': function (d) { return d.getFullYear().toString().substring(2) },
'%Y': function (d) { return d.getFullYear() },
'%H': function (d) { return JU.padNumber(d.getHours(), 2) },
'%I': function (d) { var h = d.getHours() % 12; return JU.padNumber(h == 0 ? 12 : h, 2) },
View
@@ -13,6 +13,12 @@ new Test.Unit.Runner({
testDateFormat: function () {
var d = new Date(2009, 8, 25, 12, 34, 56);
this.assertEqual("2009-09-25 12:34:56", Jarty.Date.format("%Y-%m-%d %H:%M:%S", d));
+ },
+
+ testDateFormatYear: function () {
+ var d = new Date(1999, 1, 1, 12, 34, 56);
+ this.assertEqual("99", Jarty.Date.format("%y", d));
+ this.assertEqual("1999", Jarty.Date.format("%Y", d));
}
});

0 comments on commit 799bf1d

Please sign in to comment.