UNPKG

azurite

Version:

An open source Azure Storage API compatible server

52 lines 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.EdmDateTime = void 0; const constants_1 = require("../utils/constants"); const EntityProperty_1 = require("./EntityProperty"); class EdmDateTime { static validate(value) { if (typeof value !== "string") { throw TypeError(`Not a valid EdmDateTime string.`); } // TODO: Check data time string format return value; } constructor(value) { this.value = value; // Azure Server will take time string like "2012-01-02T23:00:00" as UTC time, so Azurite need be aligned by adding suffix "Z" const utcTimeString = value + "Z"; const utcTime = new Date(value + "Z"); if (!isNaN(utcTime.getDay())) { // When add suffix "Z" is still a validate date string, use the string with suffix "Z"; else use original string this.typedValue = utcTimeString; } else { this.typedValue = EdmDateTime.validate(value); } } toJsonPropertyValuePair(name) { return [name, this.typedValue]; } toJsonPropertyValueString(name) { return `"${name}":${JSON.stringify(this.typedValue)}`; } toJsonPropertyTypePair(name, annotationLevel, isSystemProperty) { if (annotationLevel === EntityProperty_1.AnnotationLevel.MINIMAL || annotationLevel === EntityProperty_1.AnnotationLevel.FULL) { if (annotationLevel === EntityProperty_1.AnnotationLevel.MINIMAL && isSystemProperty) { return; } return [`${name}${constants_1.ODATA_TYPE}`, "Edm.DateTime"]; } } toJsonPropertyTypeString(name, annotationLevel, isSystemProperty) { const res = this.toJsonPropertyTypePair(name, annotationLevel, isSystemProperty); if (!res) { return; } const [key, value] = res; return `"${key}":"${value}"`; } } exports.EdmDateTime = EdmDateTime; //# sourceMappingURL=EdmDateTime.js.map