FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
codetime-vscode/src/getDurationText.ts at master · codetime-dev/codetime-vscode · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
codetime-dev
/
codetime-vscode
Public
Notifications
You must be signed in to change notification settings
Fork
19
Star
103
Code
Issues
1
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
codetime-vscode
/
src
/
getDurationText.ts
Copy path
More file actions
More file actions
Latest commit
History
History
History
88 lines (78 loc) · 2.61 KB
Breadcrumbs
codetime-vscode
/
src
/
getDurationText.ts
Copy path
File metadata and controls
88 lines (78 loc) · 2.61 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import
{
formatDuration
,
type
Locale
}
from
'date-fns'
export
const
urduLocale
:
Locale
=
{
code
:
'ur'
,
formatDistance
:
(
_token
,
count
)
=>
{
return
`
${
count
}
`
}
,
formatLong
:
{
date
:
(
)
=>
''
,
time
:
(
)
=>
''
,
dateTime
:
(
)
=>
''
}
,
formatRelative
:
(
)
=>
''
,
localize
:
{
ordinalNumber
:
(
n
)
=>
`
${
n
}
`
,
era
:
(
)
=>
''
,
quarter
:
(
)
=>
''
,
month
:
(
)
=>
''
,
day
:
(
)
=>
''
,
dayPeriod
:
(
)
=>
''
}
,
match
:
{
ordinalNumber
:
(
)
=>
null
,
era
:
(
)
=>
null
,
quarter
:
(
)
=>
null
,
month
:
(
)
=>
null
,
day
:
(
)
=>
null
,
dayPeriod
:
(
)
=>
null
}
,
options
:
{
weekStartsOn
:
0
,
firstWeekContainsDate
:
1
}
}
const
localeMap
:
Record
<
string
,
(
)
=>
Promise
<
any
>
>
=
{
'en-US'
:
(
)
=>
import
(
'date-fns/locale/en-US'
)
,
'zh-CN'
:
(
)
=>
import
(
'date-fns/locale/zh-CN'
)
,
'zh-TW'
:
(
)
=>
import
(
'date-fns/locale/zh-TW'
)
,
'ja'
:
(
)
=>
import
(
'date-fns/locale/ja'
)
,
'de'
:
(
)
=>
import
(
'date-fns/locale/de'
)
,
'fr'
:
(
)
=>
import
(
'date-fns/locale/fr'
)
,
'es'
:
(
)
=>
import
(
'date-fns/locale/es'
)
,
'it'
:
(
)
=>
import
(
'date-fns/locale/it'
)
,
'pt-BR'
:
(
)
=>
import
(
'date-fns/locale/pt-BR'
)
,
'ru'
:
(
)
=>
import
(
'date-fns/locale/ru'
)
,
'ko'
:
(
)
=>
import
(
'date-fns/locale/ko'
)
,
'hi'
:
(
)
=>
import
(
'date-fns/locale/hi'
)
,
'ur'
:
async
(
)
=>
urduLocale
}
async
function
getLocale
(
locale
:
string
=
'en'
)
{
const
key
=
Object
.
keys
(
localeMap
)
.
find
(
k
=>
k
.
toLowerCase
(
)
===
locale
.
toLowerCase
(
)
)
||
'en-US'
const
localeModule
=
await
localeMap
[
key
]
(
)
return
localeModule
.
default
||
localeModule
}
async
function
toUrduNumber
(
n
:
number
)
:
Promise
<
string
>
{
const
urduDigits
=
[
'۰'
,
'۱'
,
'۲'
,
'۳'
,
'۴'
,
'۵'
,
'۶'
,
'۷'
,
'۸'
,
'۹'
]
return
n
.
toString
(
)
.
split
(
''
)
.
map
(
d
=>
urduDigits
[
+
d
]
||
d
)
.
join
(
''
)
}
/**
* 获取本地化的“xh ym”时长文本
*
@param
minutes 分钟数
*
@param
locale 语言(如 "en"、"zh-CN"、"ja"),默认 "en"
*
@returns
Promise<string>
*/
export
async
function
getDurationText
(
minutes
:
number
,
locale
:
string
=
'en'
)
:
Promise
<
string
>
{
const
hours
=
Math
.
floor
(
minutes
/
60
)
const
mins
=
minutes
%
60
const
l
=
await
getLocale
(
locale
)
let
text
=
formatDuration
(
{
hours
,
minutes
:
mins
}
,
{
locale
:
l
,
format
:
[
'hours'
,
'minutes'
]
,
zero
:
false
}
,
)
if
(
locale
.
toLowerCase
(
)
===
'ur'
)
{
const
parts
=
[
]
// Using custom Urdu numbers & text because date-fns doesn't support Urdu yet
// Pending PR: https://github.com/date-fns/date-fns/pull/3776
if
(
hours
>
0
)
parts
.
push
(
`
${
await
toUrduNumber
(
hours
)
}
گھنٹے`
)
if
(
mins
>
0
)
parts
.
push
(
`
${
await
toUrduNumber
(
mins
)
}
منٹ`
)
text
=
parts
.
join
(
' '
)
}
return
text
}
Back
|
FazBrowse Home
|
New Git URL