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

12h default time format #858

Merged
merged 2 commits into from
Feb 11, 2025
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
2 changes: 1 addition & 1 deletion backend/src/appointment/database/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class Subscriber(HasSoftDelete, Base):
language = Column(encrypted_type(String), nullable=False, default=FALLBACK_LOCALE, index=True)
timezone = Column(encrypted_type(String), index=True)
colour_scheme = Column(Enum(ColourScheme), default=ColourScheme.system, nullable=False, index=True)
time_mode = Column(Enum(TimeMode), default=TimeMode.h24, nullable=False, index=True)
time_mode = Column(Enum(TimeMode), default=TimeMode.h12, nullable=False, index=True)

# Only accept the times greater than the one specified in the `iat` claim of the jwt token
minimum_valid_iat_time = Column('minimum_valid_iat_time', encrypted_type(DateTime))
Expand Down
2 changes: 1 addition & 1 deletion backend/src/appointment/database/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ class SubscriberIn(BaseModel):
secondary_email: str | None = None
language: str | None = FALLBACK_LOCALE
colour_scheme: ColourScheme = ColourScheme.system
time_mode: TimeMode = TimeMode.h24
time_mode: TimeMode = TimeMode.h12


class SubscriberBase(SubscriberIn):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
"""modify subscribers table

Revision ID: 330fdd8cd0f8
Revises: 4a15d01919b8
Create Date: 2025-02-11 12:54:51.256163

"""
from alembic import op
import sqlalchemy as sa
from appointment.database.models import TimeMode


# revision identifiers, used by Alembic.
revision = '330fdd8cd0f8'
down_revision = '16c0299eff23'
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the last revision id from #854, so when both are merged, there shouldn't be conflicts about branching revision numbers.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm running that now.

branch_labels = None
depends_on = None


def upgrade() -> None:
op.alter_column('subscribers', 'time_mode', default=TimeMode.h12)


def downgrade() -> None:
op.alter_column('subscribers', 'time_mode', default=TimeMode.h24)
6 changes: 3 additions & 3 deletions frontend/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
const browserPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;

if (
(user?.settings?.colourScheme === 'dark'
|| (user?.settings?.colourScheme === 'system' && browserPrefersDark)
|| (!user?.settings?.colourScheme && browserPrefersDark))
(user.settings?.colourScheme === 'dark'
|| (user.settings?.colourScheme === 'system' && browserPrefersDark)
|| (!user.settings?.colourScheme && browserPrefersDark))
Comment on lines -14 to +16
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately we can't use TS at this place (or do we?), so we can't imply types here. But the user object is always to be expected, so I removed those first question marks.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo, we should remove this and just default to system.

Copy link
Collaborator Author

@devmount devmount Feb 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I can remove that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh wait, actually we currently need that to apply the user settings on a fresh page reload. Also this ensures no "flashing" if the user setting differs from the system theme. I would leave it like this for now.

) {
document.documentElement.classList.add('dark');
} else {
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import { Ref } from 'vue';
import { i18nType } from '@/composables/i18n';
import {
CustomEventData, Coloring, EventPopup, HTMLElementEvent, CalendarEvent, PydanticException,
} from './models';
User,
} from '@/models';

/**
* Lowercases the first character of a string
Expand Down Expand Up @@ -80,9 +81,9 @@ export const download = (data: BlobPart, filename: string, contenttype: string =
// This functions works independent from Pinia stores so that
// it can be called even if stores are not initialized yet.
export const timeFormat = (): string => {
const user = JSON.parse(localStorage?.getItem('tba/user') ?? '{}');
const is12HourTime = Intl.DateTimeFormat().resolvedOptions().hour12 ? 12 : 24;
const format = Number(user?.setttings?.timeFormat ?? is12HourTime);
const user = JSON.parse(localStorage?.getItem('tba/user') ?? '{}') as User;
const detected = Intl.DateTimeFormat().resolvedOptions().hour12 ? 12 : 24;
const format = Number(user.settings?.timeFormat ?? detected);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The actual fix. A typo. What else. 😅

return format === 24 ? 'HH:mm' : 'hh:mm A';
};

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

Expand Down
Loading