Skip to content

Commit 771e28c

Browse files
duncanmccleanclaude
andcommitted
Expose DateFormatter presets and reuse in DateIndexFieldtype
Add a static presets getter to DateFormatter instead of duplicating the preset objects in the index fieldtype component. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 997c0b4 commit 771e28c

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

resources/js/components/DateFormatter.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,14 @@ export default class DateFormatter {
9696
return new DateFormatter(this.#date, this.#options.fallback || 'datetime').toString();
9797
}
9898

99+
static get presets() {
100+
return {
101+
datetime: { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric' },
102+
date: { year: 'numeric', month: 'numeric', day: 'numeric' },
103+
time: { timeStyle: 'short' },
104+
};
105+
}
106+
99107
static format(date, options) {
100108
return new DateFormatter(date, options).toString();
101109
}

resources/js/components/fieldtypes/DateIndexFieldtype.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,6 @@ const emit = defineEmits(Fieldtype.emits);
1111
const props = defineProps(Fieldtype.props);
1212
const { expose } = Fieldtype.use(emit, props);
1313
14-
const datePresets = {
15-
datetime: { year: 'numeric', month: 'numeric', day: 'numeric', hour: 'numeric', minute: 'numeric' },
16-
date: { year: 'numeric', month: 'numeric', day: 'numeric' },
17-
};
18-
1914
const timezoneOption = computed(() => {
2015
const tz = props.value?.timezone;
2116
@@ -28,7 +23,7 @@ const formatted = computed(() => {
2823
}
2924
3025
const preset = props.value.time_enabled ? 'datetime' : 'date';
31-
const formatter = new DateFormatter().options({ ...datePresets[preset], ...timezoneOption.value });
26+
const formatter = new DateFormatter().options({ ...DateFormatter.presets[preset], ...timezoneOption.value });
3227
3328
if (props.value.mode === 'range') {
3429
return formatter.date(new Date(props.value.start)) + '' + formatter.date(new Date(props.value.end));

0 commit comments

Comments
 (0)