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

fix(home): parse the "scheduled" date #417

Merged
merged 1 commit into from
Dec 8, 2023
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
17 changes: 14 additions & 3 deletions src/services/api.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { parseISO } from 'date-fns';
import { parseISO, isValid } from 'date-fns';
import { injectable } from 'inversify';

import { getMediaStatusFromEventState } from '../utils/liveEvent';
Expand Down Expand Up @@ -33,6 +33,17 @@ export default class ApiService {
return url;
};

private parseDate = (item: PlaylistItem, prop: string) => {
const date = item[prop];
dbudzins marked this conversation as resolved.
Show resolved Hide resolved

if (date && !isValid(date)) {
console.error(`Invalid "${prop}" date provided for the "${item.title}" media item`);
return undefined;
}

return typeof date === 'string' ? parseISO(date) : undefined;
};

/**
* Transform incoming media items
* - Parses productId into MediaOffer[] for all cleeng offers
Expand All @@ -48,8 +59,8 @@ export default class ApiService {
channelLogoImage: this.generateAlternateImageURL({ item, label: ImageProperty.CHANNEL_LOGO, playlistLabel }),
backgroundImage: this.generateAlternateImageURL({ item, label: ImageProperty.BACKGROUND }),
mediaOffers: item.productIds ? filterMediaOffers(offerKeys, item.productIds) : undefined,
scheduledStart: item['VCH.ScheduledStart'] ? parseISO(item['VCH.ScheduledStart'] as string) : undefined,
scheduledEnd: item['VCH.ScheduledEnd'] ? parseISO(item['VCH.ScheduledEnd'] as string) : undefined,
scheduledStart: this.parseDate(item, 'VCH.ScheduledStart'),
scheduledEnd: this.parseDate(item, 'VCH.ScheduledEnd'),
dbudzins marked this conversation as resolved.
Show resolved Hide resolved
};

// add the media status to the media item after the transformation because the live media status depends on the scheduledStart and scheduledEnd
Expand Down