datetimejs
Advanced tools
Comparing version 0.3.1 to 0.3.2
@@ -503,2 +503,15 @@ // Generated by CoffeeScript 1.6.3 | ||
return format.strftime(d, dt.ISO_FORMAT); | ||
}, | ||
reformat: function(s, input, output) { | ||
var d; | ||
if (output == null) { | ||
output = input; | ||
input = null; | ||
} | ||
if (input == null) { | ||
d = parse.isoparse(s); | ||
} else { | ||
d = parse.strptime(s, input); | ||
} | ||
return format.strftime(d, output); | ||
} | ||
@@ -571,3 +584,4 @@ }; | ||
dt.isoparse = parse.isoparse; | ||
dt.reformat = format.reformat; | ||
return dt; | ||
}); |
@@ -40,3 +40,3 @@ { | ||
}, | ||
"version" : "0.3.1" | ||
"version" : "0.3.2" | ||
} |
// Generated by CoffeeScript 1.6.3 | ||
var assert, chai, d, d1, datetime; | ||
var assert, chai, d, d1, datetime, | ||
__slice = [].slice; | ||
@@ -110,3 +111,3 @@ if (typeof require !== "undefined" && require !== null) { | ||
}); | ||
return describe('#isoformat()', function() { | ||
describe('#isoformat()', function() { | ||
return it('should format date as ISO', function() { | ||
@@ -118,2 +119,24 @@ d = new Date(2013, 8, 1, 16); | ||
}); | ||
return describe('#reformat()', function() { | ||
it('should reformat date', function() { | ||
var s; | ||
s = '12 May 2013'; | ||
return assert.equal(datetime.reformat(s, '%D %B %Y', '%Y-%m-%d'), '2013-05-12'); | ||
}); | ||
return it('should isoparse if only output format is specified', function() { | ||
var isoparseArgs, origIsoparse, s; | ||
s = '2013-05-12T12:00:00.00'; | ||
origIsoparse = datetime.parse.isoparse; | ||
isoparseArgs = []; | ||
datetime.parse.isoparse = function() { | ||
var args; | ||
args = 1 <= arguments.length ? __slice.call(arguments, 0) : []; | ||
isoparseArgs = args; | ||
return origIsoparse.apply(null, args); | ||
}; | ||
datetime.reformat(s, '%Y %B %d'); | ||
assert.deepEqual(isoparseArgs, [s]); | ||
return datetime.parse.isoparse = origIsoparse; | ||
}); | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
345241
9796
649