Skip to content

Commit 4fef5df

Browse files
authored
12h default time format (#858)
* 🔨 Fix time formatting * 🔨 Switch to h12 time format default
1 parent 7625b54 commit 4fef5df

File tree

5 files changed

+36
-10
lines changed

5 files changed

+36
-10
lines changed

backend/src/appointment/database/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class Subscriber(HasSoftDelete, Base):
160160
language = Column(encrypted_type(String), nullable=False, default=FALLBACK_LOCALE, index=True)
161161
timezone = Column(encrypted_type(String), index=True)
162162
colour_scheme = Column(Enum(ColourScheme), default=ColourScheme.system, nullable=False, index=True)
163-
time_mode = Column(Enum(TimeMode), default=TimeMode.h24, nullable=False, index=True)
163+
time_mode = Column(Enum(TimeMode), default=TimeMode.h12, nullable=False, index=True)
164164

165165
# Only accept the times greater than the one specified in the `iat` claim of the jwt token
166166
minimum_valid_iat_time = Column('minimum_valid_iat_time', encrypted_type(DateTime))

backend/src/appointment/database/schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,7 @@ class SubscriberIn(BaseModel):
311311
secondary_email: str | None = None
312312
language: str | None = FALLBACK_LOCALE
313313
colour_scheme: ColourScheme = ColourScheme.system
314-
time_mode: TimeMode = TimeMode.h24
314+
time_mode: TimeMode = TimeMode.h12
315315

316316

317317
class SubscriberBase(SubscriberIn):
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"""modify subscribers table
2+
3+
Revision ID: 330fdd8cd0f8
4+
Revises: 4a15d01919b8
5+
Create Date: 2025-02-11 12:54:51.256163
6+
7+
"""
8+
from alembic import op
9+
import sqlalchemy as sa
10+
from appointment.database.models import TimeMode
11+
12+
13+
# revision identifiers, used by Alembic.
14+
revision = '330fdd8cd0f8'
15+
down_revision = '16c0299eff23'
16+
branch_labels = None
17+
depends_on = None
18+
19+
20+
def upgrade() -> None:
21+
op.alter_column('subscribers', 'time_mode', default=TimeMode.h12)
22+
23+
24+
def downgrade() -> None:
25+
op.alter_column('subscribers', 'time_mode', default=TimeMode.h24)

frontend/index.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111
const browserPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
1212

1313
if (
14-
(user?.settings?.colourScheme === 'dark'
15-
|| (user?.settings?.colourScheme === 'system' && browserPrefersDark)
16-
|| (!user?.settings?.colourScheme && browserPrefersDark))
14+
(user.settings?.colourScheme === 'dark'
15+
|| (user.settings?.colourScheme === 'system' && browserPrefersDark)
16+
|| (!user.settings?.colourScheme && browserPrefersDark))
1717
) {
1818
document.documentElement.classList.add('dark');
1919
} else {

frontend/src/utils.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { Ref } from 'vue';
33
import { i18nType } from '@/composables/i18n';
44
import {
55
CustomEventData, Coloring, EventPopup, HTMLElementEvent, CalendarEvent, PydanticException,
6-
} from './models';
6+
User,
7+
} from '@/models';
78

89
/**
910
* Lowercases the first character of a string
@@ -80,9 +81,9 @@ export const download = (data: BlobPart, filename: string, contenttype: string =
8081
// This functions works independent from Pinia stores so that
8182
// it can be called even if stores are not initialized yet.
8283
export const timeFormat = (): string => {
83-
const user = JSON.parse(localStorage?.getItem('tba/user') ?? '{}');
84-
const is12HourTime = Intl.DateTimeFormat().resolvedOptions().hour12 ? 12 : 24;
85-
const format = Number(user?.setttings?.timeFormat ?? is12HourTime);
84+
const user = JSON.parse(localStorage?.getItem('tba/user') ?? '{}') as User;
85+
const detected = Intl.DateTimeFormat().resolvedOptions().hour12 ? 12 : 24;
86+
const format = Number(user.settings?.timeFormat ?? detected);
8687
return format === 24 ? 'HH:mm' : 'hh:mm A';
8788
};
8889

@@ -91,7 +92,7 @@ export const timeFormat = (): string => {
9192
// This functions works independent from Pinia stores so that
9293
// it can be called even if stores are not initialized yet.
9394
export const defaultLocale = () => {
94-
const user = JSON.parse(localStorage?.getItem('tba/user') ?? '{}');
95+
const user = JSON.parse(localStorage?.getItem('tba/user') ?? '{}') as User;
9596
return user?.settings?.language ?? navigator.language.split('-')[0];
9697
}
9798

0 commit comments

Comments
 (0)