Enhance date and time format settings to reflect system preferences (#7274)
Closes https://github.com/twentyhq/twenty/issues/6880 --------- Co-authored-by: Lucas Bordeau <bordeau.lucas@gmail.com>
This commit is contained in:
@ -5,6 +5,10 @@ export const detectTimeFormat = () => {
|
|||||||
const isHour12 = Intl.DateTimeFormat(navigator.language, {
|
const isHour12 = Intl.DateTimeFormat(navigator.language, {
|
||||||
hour: 'numeric',
|
hour: 'numeric',
|
||||||
}).resolvedOptions().hour12;
|
}).resolvedOptions().hour12;
|
||||||
if (isDefined(isHour12) && isHour12) return TimeFormat.HOUR_12;
|
|
||||||
|
if (isDefined(isHour12) && isHour12) {
|
||||||
|
return TimeFormat.HOUR_12;
|
||||||
|
}
|
||||||
|
|
||||||
return TimeFormat.HOUR_24;
|
return TimeFormat.HOUR_24;
|
||||||
};
|
};
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { formatInTimeZone } from 'date-fns-tz';
|
import { formatInTimeZone } from 'date-fns-tz';
|
||||||
|
|
||||||
import { DateFormat } from '@/localization/constants/DateFormat';
|
import { DateFormat } from '@/localization/constants/DateFormat';
|
||||||
|
import { detectDateFormat } from '@/localization/utils/detectDateFormat';
|
||||||
import { detectTimeZone } from '@/localization/utils/detectTimeZone';
|
import { detectTimeZone } from '@/localization/utils/detectTimeZone';
|
||||||
import { Select } from '@/ui/input/components/Select';
|
import { Select } from '@/ui/input/components/Select';
|
||||||
|
|
||||||
@ -15,7 +16,12 @@ export const DateTimeSettingsDateFormatSelect = ({
|
|||||||
timeZone,
|
timeZone,
|
||||||
value,
|
value,
|
||||||
}: DateTimeSettingsDateFormatSelectProps) => {
|
}: DateTimeSettingsDateFormatSelectProps) => {
|
||||||
const setTimeZone = timeZone === 'system' ? detectTimeZone() : timeZone;
|
const systemTimeZone = detectTimeZone();
|
||||||
|
|
||||||
|
const usedTimeZone = timeZone === 'system' ? systemTimeZone : timeZone;
|
||||||
|
|
||||||
|
const systemDateFormat = detectDateFormat();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
dropdownId="datetime-settings-date-format"
|
dropdownId="datetime-settings-date-format"
|
||||||
@ -25,13 +31,17 @@ export const DateTimeSettingsDateFormatSelect = ({
|
|||||||
value={value}
|
value={value}
|
||||||
options={[
|
options={[
|
||||||
{
|
{
|
||||||
label: `System settings`,
|
label: `System settings - ${formatInTimeZone(
|
||||||
|
Date.now(),
|
||||||
|
usedTimeZone,
|
||||||
|
systemDateFormat,
|
||||||
|
)}`,
|
||||||
value: DateFormat.SYSTEM,
|
value: DateFormat.SYSTEM,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: `${formatInTimeZone(
|
label: `${formatInTimeZone(
|
||||||
Date.now(),
|
Date.now(),
|
||||||
setTimeZone,
|
usedTimeZone,
|
||||||
DateFormat.MONTH_FIRST,
|
DateFormat.MONTH_FIRST,
|
||||||
)}`,
|
)}`,
|
||||||
value: DateFormat.MONTH_FIRST,
|
value: DateFormat.MONTH_FIRST,
|
||||||
@ -39,7 +49,7 @@ export const DateTimeSettingsDateFormatSelect = ({
|
|||||||
{
|
{
|
||||||
label: `${formatInTimeZone(
|
label: `${formatInTimeZone(
|
||||||
Date.now(),
|
Date.now(),
|
||||||
setTimeZone,
|
usedTimeZone,
|
||||||
DateFormat.DAY_FIRST,
|
DateFormat.DAY_FIRST,
|
||||||
)}`,
|
)}`,
|
||||||
value: DateFormat.DAY_FIRST,
|
value: DateFormat.DAY_FIRST,
|
||||||
@ -47,7 +57,7 @@ export const DateTimeSettingsDateFormatSelect = ({
|
|||||||
{
|
{
|
||||||
label: `${formatInTimeZone(
|
label: `${formatInTimeZone(
|
||||||
Date.now(),
|
Date.now(),
|
||||||
setTimeZone,
|
usedTimeZone,
|
||||||
DateFormat.YEAR_FIRST,
|
DateFormat.YEAR_FIRST,
|
||||||
)}`,
|
)}`,
|
||||||
value: DateFormat.YEAR_FIRST,
|
value: DateFormat.YEAR_FIRST,
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
import { formatInTimeZone } from 'date-fns-tz';
|
import { formatInTimeZone } from 'date-fns-tz';
|
||||||
|
|
||||||
import { TimeFormat } from '@/localization/constants/TimeFormat';
|
import { TimeFormat } from '@/localization/constants/TimeFormat';
|
||||||
|
import { detectTimeFormat } from '@/localization/utils/detectTimeFormat';
|
||||||
import { detectTimeZone } from '@/localization/utils/detectTimeZone';
|
import { detectTimeZone } from '@/localization/utils/detectTimeZone';
|
||||||
import { Select } from '@/ui/input/components/Select';
|
import { Select } from '@/ui/input/components/Select';
|
||||||
|
|
||||||
@ -15,7 +16,12 @@ export const DateTimeSettingsTimeFormatSelect = ({
|
|||||||
timeZone,
|
timeZone,
|
||||||
value,
|
value,
|
||||||
}: DateTimeSettingsTimeFormatSelectProps) => {
|
}: DateTimeSettingsTimeFormatSelectProps) => {
|
||||||
const setTimeZone = timeZone === 'system' ? detectTimeZone() : timeZone;
|
const systemTimeZone = detectTimeZone();
|
||||||
|
|
||||||
|
const usedTimeZone = timeZone === 'system' ? systemTimeZone : timeZone;
|
||||||
|
|
||||||
|
const systemTimeFormat = detectTimeFormat();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
dropdownId="datetime-settings-time-format"
|
dropdownId="datetime-settings-time-format"
|
||||||
@ -25,13 +31,17 @@ export const DateTimeSettingsTimeFormatSelect = ({
|
|||||||
value={value}
|
value={value}
|
||||||
options={[
|
options={[
|
||||||
{
|
{
|
||||||
label: 'System settings',
|
label: `System Settings - ${formatInTimeZone(
|
||||||
|
Date.now(),
|
||||||
|
usedTimeZone,
|
||||||
|
systemTimeFormat,
|
||||||
|
)}`,
|
||||||
value: TimeFormat.SYSTEM,
|
value: TimeFormat.SYSTEM,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
label: `24h (${formatInTimeZone(
|
label: `24h (${formatInTimeZone(
|
||||||
Date.now(),
|
Date.now(),
|
||||||
setTimeZone,
|
usedTimeZone,
|
||||||
TimeFormat.HOUR_24,
|
TimeFormat.HOUR_24,
|
||||||
)})`,
|
)})`,
|
||||||
value: TimeFormat.HOUR_24,
|
value: TimeFormat.HOUR_24,
|
||||||
@ -39,7 +49,7 @@ export const DateTimeSettingsTimeFormatSelect = ({
|
|||||||
{
|
{
|
||||||
label: `12h (${formatInTimeZone(
|
label: `12h (${formatInTimeZone(
|
||||||
Date.now(),
|
Date.now(),
|
||||||
setTimeZone,
|
usedTimeZone,
|
||||||
TimeFormat.HOUR_12,
|
TimeFormat.HOUR_12,
|
||||||
)})`,
|
)})`,
|
||||||
value: TimeFormat.HOUR_12,
|
value: TimeFormat.HOUR_12,
|
||||||
|
|||||||
@ -12,19 +12,22 @@ export const DateTimeSettingsTimeZoneSelect = ({
|
|||||||
value = detectTimeZone(),
|
value = detectTimeZone(),
|
||||||
onChange,
|
onChange,
|
||||||
}: DateTimeSettingsTimeZoneSelectProps) => {
|
}: DateTimeSettingsTimeZoneSelectProps) => {
|
||||||
|
const systemTimeZone = detectTimeZone();
|
||||||
|
|
||||||
|
const systemTimeZoneOption = findAvailableTimeZoneOption(systemTimeZone);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Select
|
<Select
|
||||||
dropdownId="settings-accounts-calendar-time-zone"
|
dropdownId="settings-accounts-calendar-time-zone"
|
||||||
dropdownWidth={416}
|
dropdownWidth={416}
|
||||||
label="Time zone"
|
label="Time zone"
|
||||||
fullWidth
|
fullWidth
|
||||||
value={
|
value={value}
|
||||||
value === 'system'
|
|
||||||
? 'System settings'
|
|
||||||
: findAvailableTimeZoneOption(value)?.value
|
|
||||||
}
|
|
||||||
options={[
|
options={[
|
||||||
{ label: 'System settings', value: 'system' },
|
{
|
||||||
|
label: `System settings - ${systemTimeZoneOption.label}`,
|
||||||
|
value: 'system',
|
||||||
|
},
|
||||||
...AVAILABLE_TIMEZONE_OPTIONS,
|
...AVAILABLE_TIMEZONE_OPTIONS,
|
||||||
]}
|
]}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
|
|||||||
Reference in New Issue
Block a user