Skip to content

Commit 6adcc49

Browse files
authored
Merge pull request #48 from gwicke/restore_date_parsing
Restore improved date parsing from fd87fc3
2 parents 8b74a9a + 23a45cd commit 6adcc49

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

lib/reqTemplate.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,12 +115,13 @@ var globalMethods = {
115115
if (!isValidDate(date)) {
116116
var origDate = date;
117117

118-
if (typeof date === 'string' && !Number.isNaN(date)) {
118+
if (typeof date === 'string' && /^\d+$/.test(date)) {
119119
// It's a string, but may be it's just a stringified timestamp.
120120
// Check if it actually is.
121-
date = parseInt(date);
121+
date = new Date(parseInt(date));
122+
} else {
123+
date = new Date(Date.parse(date));
122124
}
123-
date = new Date(date);
124125

125126
if (!isValidDate(date)) {
126127
throw new Error('Invalid date: ' + origDate);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "swagger-router",
3-
"version": "0.5.0",
3+
"version": "0.5.1",
44
"description": "An efficient swagger 2 based router with support for multiple APIs. For use in RESTBase.",
55
"main": "index.js",
66
"scripts": {

test/features/reqTemplate.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -567,6 +567,19 @@ describe('Request template', function() {
567567
}
568568
});
569569
var result = template.expand({
570+
request: {
571+
body: {
572+
date: '1990-02-20T19:31:13+00:00'
573+
}
574+
}
575+
});
576+
assert.deepEqual(result, {
577+
body: {
578+
date_iso: '1990-02-20T19:31:13.000Z',
579+
date_rfc822: 'Tue, 20 Feb 1990 19:31:13 +0000'
580+
}
581+
});
582+
result = template.expand({
570583
request: {
571584
body: {
572585
date: '1234'

0 commit comments

Comments
 (0)