fluent-transpiler 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +36 -36
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -360,44 +360,44 @@ const formatTime = (value) => {
|
|
|
360
360
|
*/
|
|
361
361
|
if (functions.__formatRelativeTime) {
|
|
362
362
|
output += `
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
}
|
|
375
|
-
if (Math.abs(elapsed) < msPerHour) {
|
|
376
|
-
return [Math.round(elapsed / msPerMinute), 'minute']
|
|
377
|
-
}
|
|
378
|
-
if (Math.abs(elapsed) < msPerDay) {
|
|
379
|
-
return [Math.round(elapsed / msPerHour), 'hour']
|
|
380
|
-
}
|
|
381
|
-
if (Math.abs(elapsed) < msPerWeek * 2) {
|
|
382
|
-
return [Math.round(elapsed / msPerDay), 'day']
|
|
383
|
-
}
|
|
384
|
-
if (Math.abs(elapsed) < msPerMonth) {
|
|
385
|
-
return [Math.round(elapsed / msPerWeek), 'week']
|
|
386
|
-
}
|
|
387
|
-
if (Math.abs(elapsed) < msPerYear) {
|
|
388
|
-
return [Math.round(elapsed / msPerMonth), 'month']
|
|
389
|
-
}
|
|
390
|
-
return [Math.round(elapsed / msPerYear), 'year']
|
|
363
|
+
const __relativeTimeDiff = (d) => {
|
|
364
|
+
const msPerMinute = 60 * 1000
|
|
365
|
+
const msPerHour = msPerMinute * 60
|
|
366
|
+
const msPerDay = msPerHour * 24
|
|
367
|
+
const msPerWeek = msPerDay * 7
|
|
368
|
+
const msPerMonth = msPerDay * 30
|
|
369
|
+
const msPerYear = msPerDay * 365.25
|
|
370
|
+
const elapsed = d - new Date()
|
|
371
|
+
|
|
372
|
+
if (Math.abs(elapsed) < msPerMinute) {
|
|
373
|
+
return [Math.round(elapsed / 1000), 'second']
|
|
391
374
|
}
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
if (isNaN(value.getTime())) return value
|
|
395
|
-
try {
|
|
396
|
-
const [duration, unit] = __relativeTimeDiff(value)
|
|
397
|
-
return new Intl.RelativeTimeFormat(lang, options).format(duration, unit)
|
|
398
|
-
} catch (e) {}
|
|
399
|
-
return new Intl.DateTimeFormat(__locales, options).format(value)
|
|
375
|
+
if (Math.abs(elapsed) < msPerHour) {
|
|
376
|
+
return [Math.round(elapsed / msPerMinute), 'minute']
|
|
400
377
|
}
|
|
378
|
+
if (Math.abs(elapsed) < msPerDay) {
|
|
379
|
+
return [Math.round(elapsed / msPerHour), 'hour']
|
|
380
|
+
}
|
|
381
|
+
if (Math.abs(elapsed) < msPerWeek * 2) {
|
|
382
|
+
return [Math.round(elapsed / msPerDay), 'day']
|
|
383
|
+
}
|
|
384
|
+
if (Math.abs(elapsed) < msPerMonth) {
|
|
385
|
+
return [Math.round(elapsed / msPerWeek), 'week']
|
|
386
|
+
}
|
|
387
|
+
if (Math.abs(elapsed) < msPerYear) {
|
|
388
|
+
return [Math.round(elapsed / msPerMonth), 'month']
|
|
389
|
+
}
|
|
390
|
+
return [Math.round(elapsed / msPerYear), 'year']
|
|
391
|
+
}
|
|
392
|
+
const __formatRelativeTime = (value, options) => {
|
|
393
|
+
if (typeof value === 'string') value = new Date(value)
|
|
394
|
+
if (isNaN(value.getTime())) return value
|
|
395
|
+
try {
|
|
396
|
+
const [duration, unit] = __relativeTimeDiff(value)
|
|
397
|
+
return new Intl.RelativeTimeFormat(__locales, options).format(duration, unit)
|
|
398
|
+
} catch (e) {}
|
|
399
|
+
return new Intl.DateTimeFormat(__locales, options).format(value)
|
|
400
|
+
}
|
|
401
401
|
`
|
|
402
402
|
}
|
|
403
403
|
if (functions.__formatDateTime) {
|