3f0ee0139c
This PR prepares the refactor of record field definition and column definition. We need to separate the two concepts of FieldInput and FieldContext at the cell level, and the new RecordField concept that will replace FieldDefinition at the metadata and state level. So we create a new ui sub-folder in the already existing record-field folder, in order to separate those two concepts that are still very close.
62 lines
1.8 KiB
TypeScript
62 lines
1.8 KiB
TypeScript
import { type DateFormat } from '@/localization/constants/DateFormat';
|
|
import { type TimeFormat } from '@/localization/constants/TimeFormat';
|
|
import { formatDateISOStringToCustomUnicodeFormat } from '@/localization/utils/formatDateISOStringToCustomUnicodeFormat';
|
|
import { formatDateISOStringToDateTime } from '@/localization/utils/formatDateISOStringToDateTime';
|
|
import { formatDateISOStringToRelativeDate } from '@/localization/utils/formatDateISOStringToRelativeDate';
|
|
import {
|
|
FieldDateDisplayFormat,
|
|
type FieldDateMetadataSettings,
|
|
} from '@/object-record/record-field/ui/types/FieldMetadata';
|
|
import { type Locale } from 'date-fns';
|
|
|
|
export const formatDateTimeString = ({
|
|
value,
|
|
timeZone,
|
|
dateFormat,
|
|
timeFormat,
|
|
dateFieldSettings,
|
|
localeCatalog,
|
|
}: {
|
|
timeZone: string;
|
|
dateFormat: DateFormat;
|
|
timeFormat: TimeFormat;
|
|
value?: string | null;
|
|
dateFieldSettings?: FieldDateMetadataSettings;
|
|
localeCatalog: Locale;
|
|
}) => {
|
|
if (!value) {
|
|
return '';
|
|
}
|
|
|
|
switch (dateFieldSettings?.displayFormat) {
|
|
case FieldDateDisplayFormat.RELATIVE:
|
|
return formatDateISOStringToRelativeDate({
|
|
isoDate: value,
|
|
localeCatalog: localeCatalog,
|
|
});
|
|
case FieldDateDisplayFormat.USER_SETTINGS:
|
|
return formatDateISOStringToDateTime({
|
|
date: value,
|
|
timeZone,
|
|
dateFormat,
|
|
timeFormat,
|
|
localeCatalog,
|
|
});
|
|
case FieldDateDisplayFormat.CUSTOM:
|
|
return formatDateISOStringToCustomUnicodeFormat({
|
|
date: value,
|
|
timeZone,
|
|
dateFormat: dateFieldSettings.customUnicodeDateFormat,
|
|
localeCatalog,
|
|
});
|
|
default:
|
|
return formatDateISOStringToDateTime({
|
|
date: value,
|
|
timeZone,
|
|
dateFormat,
|
|
timeFormat,
|
|
localeCatalog,
|
|
});
|
|
}
|
|
};
|