MCPcopy
hub / github.com/formatjs/formatjs / selectUnit

Function selectUnit

packages/react-intl/components/relative.tsx:16–32  ·  view source on GitHub ↗
(seconds: number)

Source from the content-addressed store, hash-verified

14const DAY = 60 * 60 * 24
15
16function selectUnit(seconds: number): Intl.RelativeTimeFormatUnit {
17 const absValue = Math.abs(seconds)
18
19 if (absValue < MINUTE) {
20 return 'second'
21 }
22
23 if (absValue < HOUR) {
24 return 'minute'
25 }
26
27 if (absValue < DAY) {
28 return 'hour'
29 }
30
31 return 'day'
32}
33
34function getDurationInSeconds(unit?: Intl.RelativeTimeFormatUnit): number {
35 switch (unit) {

Callers 1

FormattedRelativeTimeFunction · 0.85

Calls 1

absMethod · 0.80

Tested by

no test coverage detected