mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
31 lines
933 B
TypeScript
31 lines
933 B
TypeScript
import { format } from 'date-fns/format';
|
|
import { parse } from 'date-fns/parse';
|
|
import zod from 'zod';
|
|
|
|
import { t } from '../../core/logical/type-presets.js';
|
|
import { propertyType } from '../../core/property/property-config.js';
|
|
export const datePropertyType = propertyType('date');
|
|
export const datePropertyModelConfig = datePropertyType.modelConfig({
|
|
name: 'Date',
|
|
propertyData: {
|
|
schema: zod.object({}),
|
|
default: () => ({}),
|
|
},
|
|
jsonValue: {
|
|
schema: zod.number().nullable(),
|
|
isEmpty: () => false,
|
|
type: () => t.date.instance(),
|
|
},
|
|
rawValue: {
|
|
schema: zod.number().nullable(),
|
|
default: () => null,
|
|
toString: ({ value }) => (value != null ? format(value, 'yyyy-MM-dd') : ''),
|
|
fromString: ({ value }) => {
|
|
const date = parse(value, 'yyyy-MM-dd', new Date());
|
|
return { value: +date };
|
|
},
|
|
toJson: ({ value }) => value,
|
|
fromJson: ({ value }) => value,
|
|
},
|
|
});
|