diff options
author | Melissa Zhang <mzhang19096@gmail.com> | 2020-05-15 19:10:07 -0700 |
---|---|---|
committer | Melissa Zhang <mzhang19096@gmail.com> | 2020-05-15 19:10:07 -0700 |
commit | 253d5efbbafe4a44c350fef7dda6d553a70a94c9 (patch) | |
tree | b43a55e1efddc86e25df4bb7d90a99f3c7b52a17 /src/fields/DateField.ts | |
parent | 36c01920e3874e1484222a7012745b581405f67d (diff) | |
parent | 08b6bf8b51ab631c8cfe9c3e12bfb0ae2dd7b4c7 (diff) |
merge with master
Diffstat (limited to 'src/fields/DateField.ts')
-rw-r--r-- | src/fields/DateField.ts | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/fields/DateField.ts b/src/fields/DateField.ts new file mode 100644 index 000000000..a925148c2 --- /dev/null +++ b/src/fields/DateField.ts @@ -0,0 +1,36 @@ +import { Deserializable } from "../client/util/SerializationHelper"; +import { serializable, date } from "serializr"; +import { ObjectField } from "./ObjectField"; +import { Copy, ToScriptString, ToString } from "./FieldSymbols"; +import { scriptingGlobal, Scripting } from "../client/util/Scripting"; + +@scriptingGlobal +@Deserializable("date") +export class DateField extends ObjectField { + @serializable(date()) + readonly date: Date; + + constructor(date: Date = new Date()) { + super(); + this.date = date; + } + + [Copy]() { + return new DateField(this.date); + } + + toString() { + return `${this.date.toISOString()}`; + } + + [ToScriptString]() { + return `new DateField(new Date(${this.date.toISOString()}))`; + } + [ToString]() { + return this.date.toISOString(); + } +} + +Scripting.addGlobal(function d(...dateArgs: any[]) { + return new DateField(new (Date as any)(...dateArgs)); +}); |