mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Fix strict relative dates showing "incorrect" (#14390)
* Set rounding method of relative formatted date to floor when strict option is selected * Add round fn as an option Co-authored-by: rijkvanzanten <rijkvanzanten@me.com>
This commit is contained in:
@@ -16,6 +16,7 @@ interface Props {
|
||||
format?: string;
|
||||
relative?: boolean;
|
||||
strict?: boolean;
|
||||
round?: string;
|
||||
suffix?: boolean;
|
||||
}
|
||||
|
||||
@@ -23,6 +24,7 @@ const props = withDefaults(defineProps<Props>(), {
|
||||
format: 'long',
|
||||
relative: false,
|
||||
strict: false,
|
||||
round: 'round',
|
||||
suffix: true,
|
||||
});
|
||||
|
||||
@@ -50,6 +52,7 @@ const relativeFormat = (value: Date) => {
|
||||
const fn = props.strict ? localizedFormatDistanceStrict : localizedFormatDistance;
|
||||
return fn(value, new Date(), {
|
||||
addSuffix: props.suffix,
|
||||
roundingMethod: props.round,
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
@@ -123,6 +123,26 @@ export default defineDisplay({
|
||||
schema: {
|
||||
default_value: false,
|
||||
},
|
||||
},
|
||||
{
|
||||
field: 'round',
|
||||
name: '$t:displays.datetime.round',
|
||||
type: 'string',
|
||||
meta: {
|
||||
width: 'half',
|
||||
interface: 'select-dropdown',
|
||||
options: {
|
||||
choices: [
|
||||
{ text: '$t:displays.datetime.down', value: 'floor' },
|
||||
{ text: '$t:displays.datetime.nearest', value: 'round' },
|
||||
{ text: '$t:displays.datetime.up', value: 'ceil' },
|
||||
],
|
||||
},
|
||||
note: '$t:displays.datetime.round_note',
|
||||
},
|
||||
schema: {
|
||||
default_value: 'round',
|
||||
},
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1768,6 +1768,11 @@ displays:
|
||||
strict: Strict
|
||||
strict_label: Use strict units
|
||||
strict_note: Removes words like 'almost', 'over', 'less than'
|
||||
round: Round
|
||||
round_note: Choose a rounding function to use
|
||||
down: Down
|
||||
nearest: Nearest
|
||||
up: Up
|
||||
file:
|
||||
file: File
|
||||
description: Display files
|
||||
|
||||
Reference in New Issue
Block a user