Skip to content

Commit 134ad68

Browse files
committed
Fixed a bug where dates weren't converting correctly.
1 parent 5ad7f58 commit 134ad68

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

jquery.json.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@
2525
// Yes, it polutes the Date namespace, but we'll allow it here, as
2626
// it's damned usefull.
2727
{
28-
return date.getUTCFullYear() + '-' +
29-
toIntegersAtLease(date.getUTCMonth() + 1) + '-' +
30-
toIntegersAtLease(date.getUTCDate());
28+
return this.getUTCFullYear() + '-' +
29+
toIntegersAtLease(this.getUTCMonth()) + '-' +
30+
toIntegersAtLease(this.getUTCDate());
3131
};
3232

3333
var escapeable = /["\\\x00-\x1f\x7f-\x9f]/g;

jquery.json.min.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
(function($){function toIntegersAtLease(n)
22
{return n<10?'0'+n:n;}
33
Date.prototype.toJSON=function(date)
4-
{return date.getUTCFullYear()+'-'+
5-
toIntegersAtLease(date.getUTCMonth()+1)+'-'+
6-
toIntegersAtLease(date.getUTCDate());};var escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'}
4+
{return this.getUTCFullYear()+'-'+
5+
toIntegersAtLease(this.getUTCMonth())+'-'+
6+
toIntegersAtLease(this.getUTCDate());};var escapeable=/["\\\x00-\x1f\x7f-\x9f]/g;var meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'}
77
$.quoteString=function(string)
88
{if(escapeable.test(string))
99
{return'"'+string.replace(escapeable,function(a)

jquery.json.test.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ testJSON({apple: 2}, "{\"apple\": 2}", "{\"apple\":2}");
3636
testJSON({apple: {apple: 2}}, "{\"apple\": {\"apple\": 2}}", "{\"apple\":{\"apple\":2}}");
3737
testJSON(2.5, "2.5");
3838
testJSON(25, "25");
39+
testJSON(new Date(2008, 9, 25), "2008-09-25");
3940
testJSON([2, 5], "[2, 5]", "[2,5]");
4041
testJSON(function() {}, TypeError);
4142
console.log("Done.")

0 commit comments

Comments
 (0)