import { $NAME, $CONSTRUCTOR, MetaContext } from '../../MetaContext'; import { $ASSIGN } from '../../operations/base/$assign'; import { $CLONE } from '../../operations/base/$clone'; import { $COMPARE } from '../../operations/base/$compare'; import { $CONSTRUCT, genericConstruct } from '../../operations/base/$construct'; import { $DUMP } from '../../operations/base/$dump'; import { $EQUAL } from '../../operations/base/$equal'; import { $HASH, HashNumber } from '../../operations/base/$hash'; import { $INTERPOLATE, $Interpolate } from '../../operations/base/$interpolate'; import { $RESTORE, $CREATE } from '../../operations/base/$restore'; import { $SERIALIZE, genericSerialize } from '../../operations/base/$serialize'; import { $STRINGIFY, deepStringify, quoteString, stringifyObjectLikeWrapper } from '../../operations/base/$stringify'; export function $assign(lhs: Date, rhs: Date) { lhs.setTime(rhs.getTime()); return lhs; } export function $clone(date: Date) { return new Date(date.getTime()); } export function $compare(lhs: Date, rhs: Date) { return lhs.getTime() - rhs.getTime(); } export const $construct = genericConstruct; export function $create(state: number) { return new Date(state); } export function $dump(value: Date) { return value.getTime(); } export function $equal(lhs: Date, rhs: Date) { return lhs.getTime() === rhs.getTime(); } export function $hash(value: Date, seed: number, context: MetaContext & HashNumber) { return context.hashNumber(value.getTime(), seed); } export function $interpolate(from: Date, to: Date, progress: number, context: MetaContext & $Interpolate) { return new Date(context[$INTERPOLATE](from.getTime(), to.getTime(), progress)); } export function $restore(value: Date, state: number) { value.setTime(state); return value; } export const $serialize = genericSerialize; export const $stringify = deepStringify((date: Date) => quoteString(date.toISOString()), stringifyObjectLikeWrapper); export const $constructor = Date; export const $name = 'Date'; export const $tag = { [$CONSTRUCTOR]: $constructor, [$NAME]: $name }; export default { [$CONSTRUCTOR]: $constructor, [$NAME]: $name, [$ASSIGN]: $assign, [$CLONE]: $clone, [$COMPARE]: $compare, [$CONSTRUCT]: $construct, [$CREATE]: $create, [$DUMP]: $dump, [$EQUAL]: $equal, [$HASH]: $hash, [$INTERPOLATE]: $interpolate, [$RESTORE]: $restore, [$SERIALIZE]: $serialize, [$STRINGIFY]: $stringify };