github
34 of 36 branches covered (94.44%)
Branch coverage included in aggregate %.
435 of 802 relevant lines covered (54.24%)
1.45 hits per line
| 1 |
import Time from "decentraland-gatsby/dist/utils/date/Time"
|
1✔ |
| 2 |
|
1✔ |
| 3 |
/**
|
1✔ |
| 4 |
* Return a formatted label like (UTC) of with different timezone than UTC like (UTC -3) |
1✔ |
| 5 |
* @param time |
1✔ |
| 6 |
* @param useLocalTime |
1✔ |
| 7 |
* @returns |
1✔ |
| 8 |
*/ |
1✔ |
| 9 |
const showTimezoneLabel = (
|
|
| 10 |
time: Time.Dayjs | Date, |
24✔ |
| 11 |
useLocalTime: boolean | null | undefined = true
|
24✔ |
| 12 |
) => {
|
24✔ |
| 13 |
time = Time.from(time) |
24✔ |
| 14 |
if (!useLocalTime || time.isUTC()) {
|
|
| 15 |
return "(UTC)" |
5✔ |
| 16 |
} |
5✔ |
| 17 |
|
|
| 18 |
const zone = time.format("ZZ") // ±HHmm |
19✔ |
| 19 |
const sign = zone.slice(0, 1) |
19✔ |
| 20 |
const hours = zone.slice(1, 3) |
19✔ |
| 21 |
const minutes = zone.slice(3) |
19✔ |
| 22 |
|
19✔ |
| 23 |
if (hours === "00" && minutes === "00") { |
|
| 24 |
return "(UTC)" |
× |
| 25 |
} |
× |
| 26 |
|
|
| 27 |
let result = "(UTC" + sign + String(Number(hours))
|
19✔ |
| 28 |
|
19✔ |
| 29 |
if (minutes !== "00") { |
|
| 30 |
result += ":" + minutes
|
6✔ |
| 31 |
} |
6✔ |
| 32 |
|
|
| 33 |
result += ")"
|
19✔ |
| 34 |
|
19✔ |
| 35 |
return result
|
19✔ |
| 36 |
} |
19✔ |
| 37 |
|
1✔ |
| 38 |
export { showTimezoneLabel }
|
1✔ |