Skip to content

Commit ffa3bda

Browse files
authored
Merge pull request #1180 from X2Style/fix/duration-validation
Fixed duration validation rules
2 parents 6a30562 + 10a9664 commit ffa3bda

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

packages/abstractions/src/duration.ts

+15-12
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,26 @@ export class Duration implements DurationInterface {
2626
if (years < 0 || years > 9999) {
2727
throw new Error("Year must be between 0 and 9999");
2828
}
29-
if (months < 0 || months > 11) {
30-
throw new Error("Month must be between 0 and 11");
29+
if (months < 0) {
30+
throw new Error("Month must be greater or equal to 0");
3131
}
32-
if (weeks < 0 || weeks > 53) {
33-
throw new Error("Week must be between 0 and 53");
32+
if (weeks < 0) {
33+
throw new Error("Week must be greater or equal to 0");
3434
}
35-
if (days < 0 || days > 6) {
36-
throw new Error("Day must be between 0 and 6");
35+
if (days < 0) {
36+
throw new Error("Day must be greater or equal to 0");
3737
}
38-
if (hours < 0 || hours > 23) {
39-
throw new Error("Hour must be between 0 and 23");
38+
if (hours < 0) {
39+
throw new Error("Hour must be greater or equal to 0");
4040
}
41-
if (minutes < 0 || minutes > 59) {
42-
throw new Error("Minute must be between 0 and 59");
41+
if (minutes < 0) {
42+
throw new Error("Minute must be greater or equal to 0");
4343
}
44-
if (seconds < 0 || seconds > 59) {
45-
throw new Error("Second must be between 0 and 59");
44+
if (seconds < 0) {
45+
throw new Error("Second must be greater or equal to 0");
46+
}
47+
if (weeks > 0 && (days > 0 || hours > 0 || minutes > 0 || seconds > 0)) {
48+
throw new Error("Cannot have weeks and days or hours or minutes or seconds");
4649
}
4750
if ((years > 0 || months > 0) && weeks > 0) {
4851
throw new Error("Cannot have weeks and months or weeks and years");

0 commit comments

Comments
 (0)