Skip to content

Commit 80f59ff

Browse files
authored
Merge branch 'master' into editable_retroactive
2 parents 693d164 + 61ea8aa commit 80f59ff

File tree

5 files changed

+400
-211
lines changed

5 files changed

+400
-211
lines changed

Diff for: .circleci/config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ version: 2.1
33
executors:
44
node:
55
docker:
6-
- image: circleci/node:12.18
6+
- image: circleci/node:12.19
77
working_directory: ~/repo
88
environment:
99
GIT_AUTHOR_EMAIL: [email protected]

Diff for: lib/util.js

+18-22
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import moment from "moment";
1111
// for example '/Date(1198908717056)/' or '/Date(1198908717056-0700)/'
1212
// code from http://momentjs.com/
1313
const ASPDateRegex = /^\/?Date\((-?\d+)/i;
14-
14+
const NumericRegex = /^\d+$/;
1515
/**
1616
* Convert an object into another type
1717
*
@@ -59,26 +59,17 @@ export function convert(object, type) {
5959
return String(object);
6060

6161
case "Date":
62-
if (isNumber(object)) {
63-
return new Date(object);
62+
try {
63+
return convert(object, "Moment").toDate();
6464
}
65-
if (object instanceof Date) {
66-
return new Date(object.valueOf());
67-
} else if (moment.isMoment(object)) {
68-
return new Date(object.valueOf());
69-
}
70-
if (isString(object)) {
71-
match = ASPDateRegex.exec(object);
72-
if (match) {
73-
// object is an ASP date
74-
return new Date(Number(match[1])); // parse number
65+
catch(e){
66+
if (e instanceof TypeError) {
67+
throw new TypeError(
68+
"Cannot convert object of type " + getType(object) + " to type " + type
69+
);
7570
} else {
76-
return moment(new Date(object)).toDate(); // parse string
71+
throw e;
7772
}
78-
} else {
79-
throw new Error(
80-
"Cannot convert object of type " + getType(object) + " to type Date"
81-
);
8273
}
8374

8475
case "Moment":
@@ -95,12 +86,17 @@ export function convert(object, type) {
9586
if (match) {
9687
// object is an ASP date
9788
return moment(Number(match[1])); // parse number
98-
} else {
99-
return moment(object); // parse string
89+
}
90+
match = NumericRegex.exec(object);
91+
92+
if (match) {
93+
return moment(Number(object));
10094
}
95+
96+
return moment(object); // parse string
10197
} else {
102-
throw new Error(
103-
"Cannot convert object of type " + getType(object) + " to type Date"
98+
throw new TypeError(
99+
"Cannot convert object of type " + getType(object) + " to type " + type
104100
);
105101
}
106102

0 commit comments

Comments
 (0)