bfg-common 1.5.586 → 1.5.588
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/package.json
CHANGED
package/plugins/time.ts
CHANGED
|
@@ -1,17 +1,58 @@
|
|
|
1
|
-
import { defineNuxtPlugin } from '#app'
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
self
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
1
|
+
import { defineNuxtPlugin } from '#app'
|
|
2
|
+
import type { UI_T_LangValue } from '~/lib/models/types'
|
|
3
|
+
export default defineNuxtPlugin(() => {
|
|
4
|
+
const time = function (): any {
|
|
5
|
+
const self: any = {}
|
|
6
|
+
self.millisecondsToHour = function (ms: number): number {
|
|
7
|
+
return ~~(ms / 1000 / 60 / 60 / 24)
|
|
8
|
+
}
|
|
9
|
+
self.formatTime = (
|
|
10
|
+
seconds: number,
|
|
11
|
+
lang: UI_T_LangValue = 'ru_RU'
|
|
12
|
+
): string => {
|
|
13
|
+
const units = {
|
|
14
|
+
en_US: { s: 's', m: 'm', h: 'h' },
|
|
15
|
+
ru_RU: { s: 'с', m: 'м', h: 'ч' },
|
|
16
|
+
hy_AM: { s: 'վ', m: 'ր', h: 'ժ' },
|
|
17
|
+
be_BY: { s: 'с', m: 'хв', h: 'г' },
|
|
18
|
+
kk_KZ: { s: 'сек', m: 'мин', h: 'сағ' },
|
|
19
|
+
zh_CHS: { s: '秒', m: '分', h: '时' },
|
|
20
|
+
BROWSER: { s: 's', m: 'm', h: 'h' },
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const unit = units[lang] || units.en_US
|
|
24
|
+
|
|
25
|
+
if (seconds < 60) {
|
|
26
|
+
return `${seconds}${unit.s}`
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const hours = Math.floor(seconds / 3600)
|
|
30
|
+
const minutes = Math.floor((seconds % 3600) / 60)
|
|
31
|
+
const secs = seconds % 60
|
|
32
|
+
|
|
33
|
+
let result = ''
|
|
34
|
+
|
|
35
|
+
if (hours > 0) {
|
|
36
|
+
result += `${hours}${unit.h} `
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (minutes > 0) {
|
|
40
|
+
result += `${minutes}${unit.m} `
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (secs > 0) {
|
|
44
|
+
result += `${secs}${unit.s}`
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return result.trim()
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return self
|
|
51
|
+
}.call({})
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
provide: {
|
|
55
|
+
time,
|
|
56
|
+
},
|
|
57
|
+
}
|
|
58
|
+
})
|