Skip to content

Commit c309b88

Browse files
jasonvargaclaude
andauthored
[6.x] Always display time zone in DatePicker (#14518)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent d01abd9 commit c309b88

2 files changed

Lines changed: 35 additions & 1 deletion

File tree

resources/js/components/fieldtypes/DateIndexFieldtype.vue

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<div v-text="formatted"></div>
2+
<div v-text="formatted" v-tooltip="tooltip"></div>
33
</template>
44

55
<script setup>
@@ -28,5 +28,22 @@ const formatted = computed(() => {
2828
return formatter.date(props.value.date).toString();
2929
});
3030
31+
const tooltip = computed(() => {
32+
if (!props.value) {
33+
return null;
34+
}
35+
36+
const formatter = new DateFormatter().options({ dateStyle: 'long', timeStyle: 'long' });
37+
38+
if (props.value.mode === 'range') {
39+
let start = new Date(props.value.start);
40+
let end = new Date(props.value.end);
41+
42+
return formatter.date(start) + '' + formatter.date(end);
43+
}
44+
45+
return formatter.date(props.value.date).toString();
46+
});
47+
3148
defineExpose(expose);
3249
</script>

resources/js/components/ui/DatePicker/DatePicker.vue

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import Card from '../Card/Card.vue';
2424
import Button from '../Button/Button.vue';
2525
import Calendar from '../Calendar/Calendar.vue';
2626
import Icon from '../Icon/Icon.vue';
27+
import Text from '../Text.vue';
2728
2829
const emit = defineEmits(['update:modelValue']);
2930
@@ -95,6 +96,16 @@ const calendarEvents = computed(() => ({
9596
},
9697
}));
9798
99+
const timeZoneName = computed(() => props.modelValue?.timeZone ?? null);
100+
101+
const timeZoneLabel = computed(() => {
102+
const tz = timeZoneName.value;
103+
if (!tz) return null;
104+
105+
const parts = new Intl.DateTimeFormat(undefined, { timeZone: tz, timeZoneName: 'short' }).formatToParts(props.modelValue.toDate());
106+
return parts.find((p) => p.type === 'timeZoneName')?.value ?? tz;
107+
});
108+
98109
const isInvalid = computed(() => {
99110
// Check if the component has invalid state from form validation
100111
return props.modelValue === null && props.required;
@@ -187,6 +198,12 @@ const getInputLabel = (part) => {
187198
</div>
188199
</template>
189200
</div>
201+
<Text
202+
class="text-gray-600 dark:text-gray-400 me-1"
203+
size="xs"
204+
v-tooltip="timeZoneName"
205+
:text="timeZoneLabel"
206+
/>
190207
<Button
191208
v-if="clearable && !readOnly"
192209
@click="emit('update:modelValue', null)"

0 commit comments

Comments
 (0)