Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhance date and time format settings to reflect system preferences #7274

Merged
merged 3 commits into from
Oct 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ export const detectTimeFormat = () => {
const isHour12 = Intl.DateTimeFormat(navigator.language, {
hour: 'numeric',
}).resolvedOptions().hour12;
if (isDefined(isHour12) && isHour12) return TimeFormat.HOUR_12;

if (isDefined(isHour12) && isHour12) {
return TimeFormat.HOUR_12;
}

return TimeFormat.HOUR_24;
};
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { formatInTimeZone } from 'date-fns-tz';

import { DateFormat } from '@/localization/constants/DateFormat';
import { detectDateFormat } from '@/localization/utils/detectDateFormat';
import { detectTimeZone } from '@/localization/utils/detectTimeZone';
import { Select } from '@/ui/input/components/Select';

Expand All @@ -15,7 +16,12 @@ export const DateTimeSettingsDateFormatSelect = ({
timeZone,
value,
}: DateTimeSettingsDateFormatSelectProps) => {
const setTimeZone = timeZone === 'system' ? detectTimeZone() : timeZone;
const systemTimeZone = detectTimeZone();

const usedTimeZone = timeZone === 'system' ? systemTimeZone : timeZone;

const systemDateFormat = detectDateFormat();

return (
<Select
dropdownId="datetime-settings-date-format"
Expand All @@ -25,29 +31,33 @@ export const DateTimeSettingsDateFormatSelect = ({
value={value}
options={[
{
label: `System settings`,
label: `System settings - ${formatInTimeZone(
Date.now(),
usedTimeZone,
systemDateFormat,
)}`,
value: DateFormat.SYSTEM,
},
{
label: `${formatInTimeZone(
Date.now(),
setTimeZone,
usedTimeZone,
DateFormat.MONTH_FIRST,
)}`,
value: DateFormat.MONTH_FIRST,
},
{
label: `${formatInTimeZone(
Date.now(),
setTimeZone,
usedTimeZone,
DateFormat.DAY_FIRST,
)}`,
value: DateFormat.DAY_FIRST,
},
{
label: `${formatInTimeZone(
Date.now(),
setTimeZone,
usedTimeZone,
DateFormat.YEAR_FIRST,
)}`,
value: DateFormat.YEAR_FIRST,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { formatInTimeZone } from 'date-fns-tz';

import { TimeFormat } from '@/localization/constants/TimeFormat';
import { detectTimeFormat } from '@/localization/utils/detectTimeFormat';
import { detectTimeZone } from '@/localization/utils/detectTimeZone';
import { Select } from '@/ui/input/components/Select';

Expand All @@ -15,7 +16,12 @@ export const DateTimeSettingsTimeFormatSelect = ({
timeZone,
value,
}: DateTimeSettingsTimeFormatSelectProps) => {
const setTimeZone = timeZone === 'system' ? detectTimeZone() : timeZone;
const systemTimeZone = detectTimeZone();

const usedTimeZone = timeZone === 'system' ? systemTimeZone : timeZone;

const systemTimeFormat = detectTimeFormat();

return (
<Select
dropdownId="datetime-settings-time-format"
Expand All @@ -25,21 +31,25 @@ export const DateTimeSettingsTimeFormatSelect = ({
value={value}
options={[
{
label: 'System settings',
label: `System Settings - ${formatInTimeZone(
Date.now(),
usedTimeZone,
systemTimeFormat,
)}`,
value: TimeFormat.SYSTEM,
},
{
label: `24h (${formatInTimeZone(
Date.now(),
setTimeZone,
usedTimeZone,
TimeFormat.HOUR_24,
)})`,
value: TimeFormat.HOUR_24,
},
{
label: `12h (${formatInTimeZone(
Date.now(),
setTimeZone,
usedTimeZone,
TimeFormat.HOUR_12,
)})`,
value: TimeFormat.HOUR_12,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,22 @@ export const DateTimeSettingsTimeZoneSelect = ({
value = detectTimeZone(),
onChange,
}: DateTimeSettingsTimeZoneSelectProps) => {
const systemTimeZone = detectTimeZone();

const systemTimeZoneOption = findAvailableTimeZoneOption(systemTimeZone);

return (
<Select
dropdownId="settings-accounts-calendar-time-zone"
dropdownWidth={416}
label="Time zone"
fullWidth
value={
value === 'system'
? 'System settings'
: findAvailableTimeZoneOption(value)?.value
}
value={value}
options={[
{ label: 'System settings', value: 'system' },
{
label: `System settings - ${systemTimeZoneOption.label}`,
value: 'system',
},
...AVAILABLE_TIMEZONE_OPTIONS,
]}
onChange={onChange}
Expand Down
Loading