Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F995972
time-units.ts
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
510 B
Referenced Files
None
Subscribers
None
time-units.ts
View Options
export
type
TimeUnit
=
"h"
|
"m"
|
"s"
|
"ms"
;
const
formats
:
{
[
unit
in
TimeUnit
]
:
number
}
=
{
h
:
3600000
,
m
:
60000
,
s
:
1000
,
ms
:
1
,
};
export
default
function
time_units
(
from
:
TimeUnit
,
to
:
TimeUnit
,
amount
:
number
)
{
if
(
!
formats
[
from
]
||
!
formats
[
to
])
{
throw
new
Error
(
"Please provide a valid time format"
);
}
if
(
!
amount
||
typeof
amount
.
valueOf
()
!==
"number"
)
{
throw
new
Error
(
"Please provide a valid amount to convert"
);
}
return
(
formats
[
from
]
/
formats
[
to
]).
toPrecision
(
8
);
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Dec 24, 04:34 (20 h, 29 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
552975
Default Alt Text
time-units.ts (510 B)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment