Skip to content

Commit 574c57f

Browse files
committed
fix: throw if unrecognised
1 parent df30f94 commit 574c57f

File tree

2 files changed

+11
-21
lines changed

2 files changed

+11
-21
lines changed

index.js

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -64,33 +64,16 @@ class Time {
6464
);
6565
}
6666

67-
respond(result) {
68-
if (Number.isNaN(result[0])) {
69-
return new Error('Unrecognised time');
70-
}
71-
72-
return result;
73-
}
74-
7567
get original() {
76-
return this.respond([
77-
this.timeObject.getHours(),
78-
this.timeObject.getMinutes(),
79-
]);
68+
return [this.timeObject.getHours(), this.timeObject.getMinutes()];
8069
}
8170

8271
get utc() {
83-
return this.respond([
84-
this.timeObjectUTC.getHours(),
85-
this.timeObjectUTC.getMinutes(),
86-
]);
72+
return [this.timeObjectUTC.getHours(), this.timeObjectUTC.getMinutes()];
8773
}
8874

8975
get local() {
90-
return this.respond([
91-
this.timeObjectLocal.getHours(),
92-
this.timeObjectLocal.getMinutes(),
93-
]);
76+
return [this.timeObjectLocal.getHours(), this.timeObjectLocal.getMinutes()];
9477
}
9578

9679
get timezones() {
@@ -114,5 +97,12 @@ module.exports = input => {
11497
timezone: formattedInputArr[4] || 'utc',
11598
};
11699

100+
if (
101+
Number.isNaN(formattedInput.hours) ||
102+
Number.isNaN(formattedInput.minutes)
103+
) {
104+
return new Error('Unrecognised time');
105+
}
106+
117107
return new Time(formattedInput);
118108
};

test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test('wrong arg', t => {
4545

4646
test('throw if unrecognised', t => {
4747
const res = tizo('');
48-
t.is(res, 'Unrecognised time');
48+
t.deepEqual(res, new Error('Unrecognised time'));
4949
});
5050

5151
test('am/pm', t => {

0 commit comments

Comments
 (0)