Skip to content
Snippets Groups Projects
Commit dd3f4c03 authored by Bernard Roland (Student Com20)'s avatar Bernard Roland (Student Com20)
Browse files

Added some utility functions

parent 836a35d6
No related branches found
No related tags found
No related merge requests found
...@@ -164,7 +164,7 @@ export function formatDate(date: Date, precision: Unit = 'day', weekday?: 'short ...@@ -164,7 +164,7 @@ export function formatDate(date: Date, precision: Unit = 'day', weekday?: 'short
} }
export function formatRelativeTime(target: Date, origin = new Date(), precision?: Unit): string { export function formatRelativeTime(target: Date, origin = new Date(), precision?: Unit): string {
const delta = target.getTime() - origin.getTime(); const delta = durationBetween(origin, target);
if (delta > 0) { if (delta > 0) {
return 'in ' + formatDuration(delta, precision); return 'in ' + formatDuration(delta, precision);
} else { } else {
...@@ -195,3 +195,11 @@ export function subtractTime(date: Date, time: number, unit: Unit): Date { ...@@ -195,3 +195,11 @@ export function subtractTime(date: Date, time: number, unit: Unit): Date {
return addTime(date, -time, unit); return addTime(date, -time, unit);
} }
export function durationBetween(from: Date, to: Date): number {
return to.getTime() - from.getTime();
}
export function currentTime(): Date {
return new Date();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment