aboutsummaryrefslogtreecommitdiff
path: root/src/fields/DateField.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/fields/DateField.ts')
-rw-r--r--src/fields/DateField.ts36
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));
+});