40 lines
1001 B
TypeScript
Raw Normal View History

2019-07-19 19:14:04 -06:00
import {Context, custom, ModelSchema, primitive, PropSchema} from 'serializr';
import * as s from '..';
2017-10-10 16:34:02 -06:00
export const duration: PropSchema = primitive();
2019-07-19 19:14:04 -06:00
export const date: PropSchema = custom(
(jsDate: Date|null) => jsDate != null ? jsDate.toISOString() : null,
(json: any, context: Context, oldValue: any,
done: (err: any, value: any) => void) => {
if (json === null) {
return done(null, null);
}
try {
done(null, new Date(json));
} catch (e) {
done(e, undefined);
}
});
export const dateOfYear: ModelSchema<s.DateOfYear> = {
2018-09-02 02:57:55 -06:00
factory: () => new s.DateOfYear(),
props: {
year: primitive(),
2019-07-19 19:14:04 -06:00
month:
primitive(), // this only works if it is represented as a # from 0-12
2018-09-02 02:57:55 -06:00
day: primitive()
}
};
export const timeOfDay: ModelSchema<s.TimeOfDay> = {
2018-09-02 02:57:55 -06:00
factory: () => new s.TimeOfDay(),
props: {
hour: primitive(),
minute: primitive(),
second: primitive(),
millisecond: primitive()
}
};