diff options
author | Stanley Yip <stanley_yip@brown.edu> | 2020-05-20 22:18:13 -0700 |
---|---|---|
committer | Stanley Yip <stanley_yip@brown.edu> | 2020-05-20 22:18:13 -0700 |
commit | 1113da5f2db22bd2b2b457b1f5b183d7f1f2e68d (patch) | |
tree | a559fa400fedb87799cba4f85451460f649c46dd /src/fields/DateField.ts | |
parent | 4109fea6787608022c8f5c147fa4fb9ad26e92eb (diff) | |
parent | 45386f6950e5ae8390486900a430061bfe9e4846 (diff) |
Merge branch 'master' of https://github.com/browngraphicslab/Dash-Web
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)); +}); |