Skip to content
Open
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
10 changes: 7 additions & 3 deletions src/helpers/global.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ export const parseISO8601Duration = (iso: string): number => {
return +duration.hours * 60 + +duration.minutes;
};

const PARSE_DATE_DOTS_REGEX = /^(\d{1,2})\.\s*(\d{1,2})\.\s*(\d{4})$/;
const PARSE_DATE_SLASH_REGEX = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
const PARSE_DATE_YEAR_REGEX = /^(\d{4})$/;

/**
* Parses a date string into a standardized YYYY-MM-DD format.
* Supports:
Expand All @@ -117,7 +121,7 @@ export const parseDate = (date: string): string | null => {
const cleanDate = date.trim();

// Try parsing DD.MM.YYYY or D.M.YYYY with optional spaces
const dateMatch = cleanDate.match(/^(\d{1,2})\.\s*(\d{1,2})\.\s*(\d{4})$/);
const dateMatch = PARSE_DATE_DOTS_REGEX.exec(cleanDate);
if (dateMatch) {
const day = dateMatch[1].padStart(2, '0');
const month = dateMatch[2].padStart(2, '0');
Expand All @@ -126,7 +130,7 @@ export const parseDate = (date: string): string | null => {
}

// Try parsing MM/DD/YYYY
const slashMatch = cleanDate.match(/^(\d{1,2})\/(\d{1,2})\/(\d{4})$/);
const slashMatch = PARSE_DATE_SLASH_REGEX.exec(cleanDate);
if (slashMatch) {
const month = slashMatch[1].padStart(2, '0');
const day = slashMatch[2].padStart(2, '0');
Expand All @@ -135,7 +139,7 @@ export const parseDate = (date: string): string | null => {
}

// Try parsing YYYY
const yearMatch = cleanDate.match(/^(\d{4})$/);
const yearMatch = PARSE_DATE_YEAR_REGEX.exec(cleanDate);
if (yearMatch) {
return `${yearMatch[1]}-01-01`;
}
Expand Down
13 changes: 10 additions & 3 deletions src/helpers/search.helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,16 @@ export const parseSearchPeople = (
if (type === 'directors') who = 'Režie:';
if (type === 'actors') who = 'Hrají:';

const peopleNode = Array.from(el && el.querySelectorAll('.article-content p')).find((el) =>
el.textContent.includes(who)
);
let peopleNode: HTMLElement | undefined;
if (el) {
const pNodes = el.querySelectorAll('.article-content p');
for (const node of pNodes) {
if (node.textContent.includes(who)) {
peopleNode = node;
break;
}
}
}

if (peopleNode) {
const people = Array.from(peopleNode.querySelectorAll('a')) as unknown as HTMLElement[];
Expand Down
Loading