(el: RelativeTimeElement)
| 26 | } |
| 27 | |
| 28 | function getUnitFactor(el: RelativeTimeElement): number { |
| 29 | const date = el.date |
| 30 | if (!date) return Infinity |
| 31 | const now = Date.now() |
| 32 | if (el.format === 'duration' || el.format === 'elapsed') { |
| 33 | const precision = el.precision |
| 34 | if (precision === 'second') { |
| 35 | return 1000 |
| 36 | } else if (precision === 'minute') { |
| 37 | return 60 * 1000 |
| 38 | } |
| 39 | } |
| 40 | const ms = Math.abs(now - date.getTime()) |
| 41 | let factor = 60 * 60 * 1000 |
| 42 | if (ms < 60 * 1000) { |
| 43 | factor = 1000 |
| 44 | } else if (ms < 60 * 60 * 1000) { |
| 45 | factor = 60 * 1000 |
| 46 | } |
| 47 | const threshold = getExplicitThreshold(el) |
| 48 | if (el.format === 'micro' && threshold) { |
| 49 | const thresholdDuration = Duration.from(threshold) |
| 50 | const signedThresholdDuration = date.getTime() > now ? negateDuration(thresholdDuration) : thresholdDuration |
| 51 | const thresholdTime = applyDuration(date, signedThresholdDuration).getTime() |
| 52 | const msUntilThreshold = thresholdTime - now |
| 53 | if (msUntilThreshold > 0) factor = Math.min(factor, msUntilThreshold) |
| 54 | } |
| 55 | return factor |
| 56 | } |
| 57 | |
| 58 | function negateDuration(duration: Duration): Duration { |
| 59 | return new Duration( |
no test coverage detected
searching dependent graphs…