UNPKG

terriajs

Version:

Geospatial data visualization platform.

69 lines 2.48 kB
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; import FunctionParameter from "./FunctionParameter"; import { makeObservable, override } from "mobx"; import moment from "moment"; export default class DateParameter extends FunctionParameter { catalogFunction; static type = "date"; type = "date"; variant = "complex"; clock; constructor(catalogFunction, options) { super(catalogFunction, options); this.catalogFunction = catalogFunction; this.clock = options.clock; makeObservable(this); } /** * Return current date value. * * When no value is available and the field is marked as required, then * return the current timeline clock date. */ get value() { return (super.value ?? (this.isRequired ? this.currentClockDate() : undefined)); } /** * Validate and set datetime value */ setValue(stratumId, newValue) { super.setValue(stratumId, this.isValidDate(newValue) ? newValue : undefined); } isValidDate(value) { const date = new Date(value); return date instanceof Date && !isNaN(date.valueOf()); } /** * Returns current clock time in local time zone. */ currentClockDate() { const currentTime = this.clock.currentTime; const ct = new Date(currentTime.toString()); const date = moment.utc(ct.toISOString()).local().format("YYYY-MM-DD"); return date; } /** * Process value so that it can be used in an URL. */ static formatValueForUrl(value) { return JSON.stringify({ type: "object", properties: { timestamp: { type: "string", format: "date", date: value } } }); } } __decorate([ override ], DateParameter.prototype, "value", null); //# sourceMappingURL=DateParameter.js.map