(durationLike: unknown)
| 56 | } |
| 57 | |
| 58 | static from(durationLike: unknown): Duration { |
| 59 | if (typeof durationLike === 'string') { |
| 60 | const str = String(durationLike).trim() |
| 61 | const factor = str.startsWith('-') ? -1 : 1 |
| 62 | const parsed = str |
| 63 | .match(durationRe) |
| 64 | ?.slice(1) |
| 65 | .map(x => (Number(x) || 0) * factor) |
| 66 | if (!parsed) return new Duration() |
| 67 | return new Duration(...parsed) |
| 68 | } else if (typeof durationLike === 'object') { |
| 69 | const {years, months, weeks, days, hours, minutes, seconds, milliseconds} = durationLike as Record<string, number> |
| 70 | return new Duration(years, months, weeks, days, hours, minutes, seconds, milliseconds) |
| 71 | } |
| 72 | throw new RangeError('invalid duration') |
| 73 | } |
| 74 | |
| 75 | static compare(one: unknown, two: unknown): -1 | 0 | 1 { |
| 76 | const now = Date.now() |
no outgoing calls
no test coverage detected