Page Menu
Home
Sealhub
Search
Configure Global Search
Log In
Files
F22398133
datetime.ts
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
datetime.ts
View Options
import
{
Context
}
from
"koa"
;
import
{
SimpleInput
}
from
"../controls/controls.js"
;
import
{
FormControlContext
}
from
"../controls/form-control.js"
;
import
{
FormDataValue
}
from
"../form-types.js"
;
import
{
FieldParseResult
}
from
"./field.js"
;
import
{
SimpleFormField
}
from
"./simple-form-field.js"
;
function
pad
(
n
:
number
)
{
return
String
(
n
).
padStart
(
2
,
"0"
);
}
export
class
DateTime
<
Required
extends
boolean
>
extends
SimpleFormField
<
Required
,
SimpleInput
,
Date
|
null
>
{
constructor
(
required
:
Required
)
{
super
(
required
,
"datetime-local"
);
}
public
getEmptyValue
()
:
Date
|
null
{
return
null
;
}
async
parse
(
ctx
:
Context
,
raw_value
:
FormDataValue
)
:
Promise
<
FieldParseResult
<
Date
|
null
>>
{
const
parsed_value
=
new
Date
(
raw_value
as
string
);
return
{
parsable
:
true
,
error
:
null
,
parsed_value
};
}
async
getSealiousCreateValue
(
fctx
:
FormControlContext
)
:
Promise
<
number
|
null
>
{
const
{
parsed
}
=
await
this
.
getParsedValue
(
fctx
.
ctx
,
fctx
.
data
.
raw_values
);
if
(
parsed
==
null
)
{
return
null
;
}
return
new
Date
(
parsed
).
getTime
();
}
getControl
()
:
SimpleInput
{
return
new
SimpleInput
(
this
,
{
label
:
this
.
label
||
this
.
name
,
type
:
this
.
type
,
});
}
async
sealiousValueToForm
(
ctx
:
Context
,
value
:
number
|
null
)
:
Promise
<
FormDataValue
>
{
if
(
value
==
null
)
{
return
""
;
}
const
d
=
new
Date
(
value
);
return
`
${
d
.
getFullYear
()
}
-
${
pad
(
d
.
getMonth
()
+
1
)
}
-
${
pad
(
d
.
getDate
()
)
}
T
${
pad
(
d
.
getHours
())
}
:
${
pad
(
d
.
getMinutes
())
}
`
;
}
}
File Metadata
Details
Attached
Mime Type
application/javascript
Expires
Fri, Nov 27, 17:19 (1 d, 17 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1200147
Default Alt Text
datetime.ts (1 KB)
Attached To
Mode
rSGEN sealgen
Attached
Detach File
Event Timeline