refactor: refactor date handling across components to use date-fns and Intl.DateTimeFormat

- Replaced moment.js usage with Intl.DateTimeFormat for date formatting in various components.
- Introduced utility functions `normalizeDateLocale` and `formatWithIntl` for locale normalization and date formatting.
- Updated PlaylistSwitcher, RecentPlaylists, ContentCard, EPG components, and MultiEpgContainer to utilize the new date formatting approach.
- Removed moment-date pipe and related tests, simplifying date handling logic.
- Ensured all date displays respect the current locale settings.

Entire-Checkpoint: 271bd0162027
This commit is contained in:
4gray committed 2026-04-11 10:41:33 +02:00
1 parent d3e30056f6
commit c97673b928
29 files changed
+410 -247

No files matched your search

@@ -35,7 +35,10 @@
</div>
<div class="epg-timeline">
<span class="epg-time">{{
formatTime(program.start, program.startTimestamp)
(program.startTimestamp
? program.startTimestamp * 1000
: program.start
) | date: 'HH:mm'
}}</span>
<div class="epg-progress-track">
<div
@@ -46,7 +49,10 @@
></div>
</div>
<span class="epg-time">{{
formatTime(program.stop, program.stopTimestamp)
(program.stopTimestamp
? program.stopTimestamp * 1000
: program.stop
) | date: 'HH:mm'
}}</span>
</div>
} @else if (!isRadio()) {
@@ -1,3 +1,4 @@
import { DatePipe } from '@angular/common';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';
import { MatDialog } from '@angular/material/dialog';
@@ -58,18 +59,11 @@ describe('ChannelListItemComponent', () => {
fixture.nativeElement.querySelectorAll('.epg-time'),
(element: Element) => element.textContent?.trim() ?? ''
);
const datePipe = new DatePipe('en-US');
expect(times).toEqual([
new Date(startTimestamp * 1000).toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit',
hour12: false,
}),
new Date(stopTimestamp * 1000).toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit',
hour12: false,
}),
datePipe.transform(startTimestamp * 1000, 'HH:mm') ?? '',
datePipe.transform(stopTimestamp * 1000, 'HH:mm') ?? '',
]);
});
@@ -1,5 +1,5 @@
import { DragDropModule } from '@angular/cdk/drag-drop';
import { NgStyle } from '@angular/common';
import { DatePipe, NgStyle } from '@angular/common';
import {
ChangeDetectionStrategy,
Component,
@@ -23,6 +23,7 @@ import { EpgProgram } from 'shared-interfaces';
changeDetection: ChangeDetectionStrategy.OnPush,
templateUrl: './channel-list-item.component.html',
imports: [
DatePipe,
DragDropModule,
MatIcon,
MatIconButton,
@@ -64,30 +65,6 @@ export class ChannelListItemComponent {
});
}
/**
* Formats time for display (HH:mm)
*/
formatTime(
dateString: string | number,
timestampSeconds?: number | null
): string {
const unixTimestamp = Number(timestampSeconds);
const date =
Number.isFinite(unixTimestamp) && unixTimestamp > 0
? new Date(unixTimestamp * 1000)
: new Date(dateString);
if (Number.isNaN(date.getTime())) {
return '';
}
return date.toLocaleTimeString('en-US', {
hour: '2-digit',
minute: '2-digit',
hour12: false,
});
}
/**
* Opens the dialog with details about the current EPG program
* @param program EPG program to show details for