UNPKG

terriajs

Version:

Geospatial data visualization platform.

70 lines 2.61 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 { makeObservable, override } from "mobx"; import moment from "moment"; import FunctionParameter from "./FunctionParameter"; export default class DateTimeParameter extends FunctionParameter { catalogFunction; static type = "dateTime"; type = "dateTime"; variant = "complex"; clock; constructor(catalogFunction, options) { super(catalogFunction, options); this.catalogFunction = catalogFunction; this.clock = options.clock; makeObservable(this); } /** * Return current date time value. * * When no value is available and the field is marked as required, then * return the current timeline clock time. */ get value() { return (super.value ?? (this.isRequired ? this.currentClockTime() : undefined)); } /** * Validate and set datetime value */ setValue(stratumId, newValue) { super.setValue(stratumId, this.isValidDateTime(newValue) ? newValue : undefined); } isValidDateTime(value) { const date = new Date(value); return date instanceof Date && !isNaN(date.valueOf()); } /** * Returns current clock time in local time zone. */ currentClockTime() { const currentTime = this.clock.currentTime; const ct = new Date(currentTime.toString()); const date = moment.utc(ct.toISOString()).local().format("YYYY-MM-DD"); const time = moment.utc(ct.toISOString()).local().format("HH:mm"); return `${date}T${time}`; } /** * 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-time", "date-time": value } } }); } } __decorate([ override ], DateTimeParameter.prototype, "value", null); //# sourceMappingURL=DateTimeParameter.js.map