Skip to content

Commit 373ca56

Browse files
committed
Hide redundant 'This field' timezone row when it matches site or local time
1 parent 4a20fe3 commit 373ca56

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Calendar from '../Calendar/Calendar.vue';
2727
import Icon from '../Icon/Icon.vue';
2828
import Text from '../Text.vue';
2929
import TimezoneHoverCard from '../TimezoneHoverCard.vue';
30+
import { getAdditionalTimezones } from './util.js';
3031
3132
const emit = defineEmits(['update:modelValue']);
3233
@@ -108,6 +109,8 @@ const timeZoneLabel = computed(() => {
108109
return parts.find((p) => p.type === 'timeZoneName')?.value ?? tz;
109110
});
110111
112+
const additionalTimezones = computed(() => getAdditionalTimezones(timeZoneName.value));
113+
111114
const isInvalid = computed(() => {
112115
// Check if the component has invalid state from form validation
113116
return props.modelValue === null && props.required;
@@ -203,7 +206,7 @@ const getInputLabel = (part) => {
203206
<TimezoneHoverCard
204207
v-if="timeZoneLabel"
205208
:date="modelValue.toDate()"
206-
:additional-timezones="[{ timezone: timeZoneName, label: __('This field') }]"
209+
:additional-timezones="additionalTimezones"
207210
side="top"
208211
>
209212
<Text class="text-gray-600 dark:text-gray-400 me-1" size="xs" :text="timeZoneLabel" />
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { config } from '@api';
2+
import { getLocalTimeZone } from '@internationalized/date';
3+
4+
export function getAdditionalTimezones(timeZone) {
5+
if (!timeZone) return [];
6+
if (timeZone === (config.get('displayTimezone') ?? 'UTC')) return [];
7+
if (timeZone === getLocalTimeZone()) return [];
8+
return [{ timezone: timeZone, label: __('This field') }];
9+
}

resources/js/components/ui/DateRangePicker/DateRangePicker.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import Icon from '../Icon/Icon.vue';
2727
import Text from '../Text.vue';
2828
import TimezoneHoverCard from '../TimezoneHoverCard.vue';
2929
import { parseAbsoluteToLocal } from '@internationalized/date';
30+
import { getAdditionalTimezones } from '../DatePicker/util.js';
3031
3132
const emit = defineEmits(['update:modelValue']);
3233
@@ -110,6 +111,8 @@ const timeZoneLabel = computed(() => {
110111
return parts.find((p) => p.type === 'timeZoneName')?.value ?? tz;
111112
});
112113
114+
const additionalTimezones = computed(() => getAdditionalTimezones(timeZoneName.value));
115+
113116
const hoverCardDate = computed(() => {
114117
if (!props.modelValue?.start || !props.modelValue?.end) return null;
115118
return { start: props.modelValue.start.toDate(), end: props.modelValue.end.toDate() };
@@ -182,7 +185,7 @@ const hoverCardDate = computed(() => {
182185
<TimezoneHoverCard
183186
v-if="timeZoneLabel && hoverCardDate"
184187
:date="hoverCardDate"
185-
:additional-timezones="[{ timezone: timeZoneName, label: __('This field') }]"
188+
:additional-timezones="additionalTimezones"
186189
side="top"
187190
>
188191
<Text class="text-gray-600 dark:text-gray-400 me-1" size="xs" :text="timeZoneLabel" />

0 commit comments

Comments
 (0)