Page MenuHomeSealhub

date.ts
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None
import { Context } from "koa";
import { FormControlContext } from "../controls/form-control.js";
import { SimpleInput, SimpleInputOptions } from "../controls/simple-input.js";
import { FormDataValue } from "../form-types.js";
import { FieldParseResult } from "./field.js";
import { SimpleFormField } from "./simple-form-field.js";
export class DateField<Required extends boolean> extends SimpleFormField<
Required,
SimpleInput,
Date
> {
constructor(required: Required) {
super(required, "date");
}
public getEmptyValue(): Date {
return new Date("1970-01-01 00:00");
}
async parse(
ctx: Context,
raw_value: FormDataValue
): Promise<FieldParseResult<Date>> {
return {
error: null,
parsable: true,
parsed_value: new Date(raw_value as string),
};
}
getControl(): SimpleInput<SimpleInputOptions> {
return new SimpleInput(this, {
label: this.label || this.name,
type: this.type,
});
}
async getSealiousCreateValue(
fctx: FormControlContext
): Promise<string | null> {
const { parsed } = await this.getParsedValue(
fctx.ctx,
fctx.data.raw_values
);
if (!parsed) {
return null;
}
return `${parsed.getFullYear()}-${(parsed.getMonth() + 1)
.toString()
.padStart(2, "0")}-${parsed.getDate().toString().padStart(2, "0")}`;
}
}

File Metadata

Mime Type
application/javascript
Expires
Fri, Nov 27, 16:54 (1 d, 23 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1200130
Default Alt Text
date.ts (1 KB)

Event Timeline