From 008bb42caee73c5738dafd0b51a57d745d99b11e Mon Sep 17 00:00:00 2001 From: Tyler Schicke Date: Sun, 14 Jul 2019 14:36:02 -0400 Subject: added d function to create date fields more easily --- src/client/util/type_decls.d | 2 ++ src/new_fields/DateField.ts | 6 ++++++ 2 files changed, 8 insertions(+) (limited to 'src') diff --git a/src/client/util/type_decls.d b/src/client/util/type_decls.d index 2cbe1dd40..1f95af00c 100644 --- a/src/client/util/type_decls.d +++ b/src/client/util/type_decls.d @@ -204,3 +204,5 @@ declare const Docs: { TreeDocument(documents: Doc[], options?: DocumentOptions): Doc; StackingDocument(documents: Doc[], options?: DocumentOptions): Doc; }; + +declare function d(...args:any[]):any; diff --git a/src/new_fields/DateField.ts b/src/new_fields/DateField.ts index fc8abb9d9..abec91e06 100644 --- a/src/new_fields/DateField.ts +++ b/src/new_fields/DateField.ts @@ -2,7 +2,9 @@ import { Deserializable } from "../client/util/SerializationHelper"; import { serializable, date } from "serializr"; import { ObjectField } from "./ObjectField"; import { Copy, ToScriptString } from "./FieldSymbols"; +import { scriptingGlobal, Scripting } from "../client/util/Scripting"; +@scriptingGlobal @Deserializable("date") export class DateField extends ObjectField { @serializable(date()) @@ -21,3 +23,7 @@ export class DateField extends ObjectField { return `new DateField(new Date(${this.date.toISOString()}))`; } } + +Scripting.addGlobal(function d(...dateArgs: any[]) { + return new DateField(new (Date as any)(...dateArgs)); +}); -- cgit v1.2.3-70-g09d2