UNPKG

ngx-timeago

Version:

Live updating timestamps in Angular 6+.

27 lines (26 loc) 805 B
export function isDefined(value) { return typeof value !== 'undefined' && value !== null; } export function coerceBooleanProperty(value) { return value != null && `${value}` !== 'false'; } export function dateParser(date) { const parsed = new Date(date); if (!Number.isNaN(parsed.valueOf())) { return parsed; } const parts = String(date).match(/\d+/g); if (parts === null || parts.length <= 2) { return parsed; } else { const [firstP, secondP, ...restPs] = parts.map(x => parseInt(x, 10)); return new Date(Date.UTC(firstP, secondP - 1, ...restPs)); } } export const MINUTE = 60; export const HOUR = MINUTE * 60; export const DAY = HOUR * 24; export const WEEK = DAY * 7; export const MONTH = DAY * 30; export const YEAR = DAY * 365;