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

get day/time from locale #31

Merged
merged 1 commit into from
Feb 19, 2024
Merged
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
23 changes: 13 additions & 10 deletions src/lib/DataUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ interface Meeting {
latitude: string;
weekday_tinyint: string;
start_time: string;
lang_enum: string;
location_text: string;
location_street: string;
location_city_subsection: string;
Expand Down Expand Up @@ -130,18 +131,20 @@ function prepareSimpleLine(meeting: Meeting, withDate: boolean = true): string {
};

const getDateString = () => {
const weekday_strings = ['All', 'Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const weekday = parseInt(meeting.weekday_tinyint?.trim() ?? '0');
const weekdayString = weekday_strings[weekday];
const startTime = `2000-01-01 ${meeting.start_time}`;
const time = new Date(startTime);
if (weekdayString && withDate) {
let dateString = weekdayString;
if (!isNaN(time.getTime())) {
dateString += `, ${time.toLocaleTimeString('en-US', {
const dayOfWeekInt = parseInt(meeting.weekday_tinyint?.trim() ?? '0');
const adjustedDay = dayOfWeekInt % 7;
// January 1, 2023, was a Sunday.
const baseDate = new Date('2023-01-01');
baseDate.setDate(baseDate.getDate() + adjustedDay);
const lang = meeting.lang_enum === 'dk' ? 'da' : meeting.lang_enum;
const twelveHrLangs: string[] = ['en', 'es'];
if (dayOfWeekInt && withDate) {
let dateString = baseDate.toLocaleDateString(lang, { weekday: 'long' });
if (!isNaN(baseDate.getTime())) {
dateString += `, ${baseDate.toLocaleTimeString(lang, {
hour: 'numeric',
minute: 'numeric',
hour12: true
hour12: twelveHrLangs.includes(lang)
})}`;
}
return dateString;
Expand Down