Skip to content

Commit

Permalink
Catch invalid Date instances in time label
Browse files Browse the repository at this point in the history
  • Loading branch information
Tom Van Laerhoven committed Sep 28, 2022
1 parent c731461 commit 36d2433
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions example/src/components/timelabel/TimeLabel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,16 @@ export const TimeLabel = (props: TimeLabelProps) => {
return <Text style={[styles.timeLabel, style]}>{LIVE_LABEL}</Text>;
}

const renderHours = duration >= 3600 * 1e3;
const s = renderHours ? 11 : 14;
const currentTimeLabel = new Date(currentTime).toISOString().substring(s, 19);
const durationLabel = new Date(duration).toISOString().substring(s, 19);
const label = showDuration ? `${currentTimeLabel} / ${durationLabel}` : currentTimeLabel;
return <Text style={[styles.timeLabel, style]}>{label}</Text>;
try {
const renderHours = duration >= 3600 * 1e3;
const s = renderHours ? 11 : 14;
const currentTimeLabel = new Date(currentTime).toISOString().substring(s, 19);
const durationLabel = new Date(duration).toISOString().substring(s, 19);
const label = showDuration ? `${currentTimeLabel} / ${durationLabel}` : currentTimeLabel;
return <Text style={[styles.timeLabel, style]}>{label}</Text>;
} catch (ignore) {
return <></>;
}
};

TimeLabel.defaultProps = {
Expand Down

0 comments on commit 36d2433

Please sign in to comment.