import { ODATA_TYPE } from "../utils/constants" ; import { AnnotationLevel } from "./EntityProperty" ; import { IEdmType } from "./IEdmType" ; export class EdmDateTime implements IEdmType { public static validate ( value ) { if ( typeof value !== "string" ) { throw TypeError ( `Not a valid EdmDateTime string.` ) ; } return value ; } public typedValue : string ; public constructor ( public value ) { const utcTimeString = value + "Z" ; const utcTime = new Date ( value + "Z" ) ; if ( ! isNaN ( utcTime . getDay ( ) ) ) { this . typedValue = utcTimeString ; } else { this . typedValue = EdmDateTime . validate ( value ) ; } } public toJsonPropertyValuePair ( name ) { return [ name , this . typedValue ] ; } public toJsonPropertyValueString ( name ) { return `"${ name }":${ JSON . stringify ( this . typedValue ) }` ; } public toJsonPropertyTypePair ( name , annotationLevel , isSystemProperty ) { if ( annotationLevel === AnnotationLevel . MINIMAL || annotationLevel === AnnotationLevel . FULL ) { if ( annotationLevel === AnnotationLevel . MINIMAL && isSystemProperty ) { return ; } return [ `${ name }${ ODATA_TYPE }` , "Edm.DateTime" ] ; } } public toJsonPropertyTypeString ( name , annotationLevel , isSystemProperty ) { const res = this . toJsonPropertyTypePair ( name , annotationLevel , isSystemProperty ) ; if ( ! res ) { return ; } const [ key , value ] = res ; return `"${ key }":"${ value }"` ; } }