Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F10360582
datetime.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
1007 B
Referenced Files
None
Subscribers
None
datetime.ts
View Options
import
{
IntStorage
}
from
"./int"
;
import
{
Context
,
Field
}
from
"../../../main"
;
import
{
getDateTime
}
from
"../../../utils/get-datetime"
;
// cannot extends because that changes the output of `decode`. I should use composition here
export
default
class
Datetime
extends
IntStorage
<
number
|
string
,
number
|
string
>
{
getTypeName
=
()
=>
"datetime"
;
async
isProperValue
(
_
:
Context
,
value
:
number
|
string
)
{
const
int_result
=
await
super
.
isProperValue
(
_
,
value
);
if
(
!
int_result
.
valid
)
{
return
Field
.
invalid
(
`Value '
${
value
}
' is not datetime format. Only timestamps are accepted.`
);
}
return
int_result
;
}
async
decode
(
_
:
Context
,
db_value
:
number
|
null
,
__
:
number
,
format
?:
"human_readable"
)
{
if
(
db_value
===
null
||
db_value
===
undefined
)
{
return
db_value
;
}
if
(
format
===
undefined
)
{
return
db_value
;
}
if
(
format
===
"human_readable"
)
{
const
date
=
new
Date
(
db_value
);
return
getDateTime
(
date
);
}
return
db_value
;
}
}
File Metadata
Details
Attached
Mime Type
text/x-java
Expires
Sat, Nov 8, 07:25 (1 d, 14 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1034284
Default Alt Text
datetime.ts (1007 B)
Attached To
Mode
rS Sealious
Attached
Detach File
Event Timeline
Log In to Comment