Skip to content

Commit

Permalink
Add "Starts" before dates for future streams to differentiate from pa…
Browse files Browse the repository at this point in the history
…st streams

This change only affects streams starting in more than 23 hours (which display dates instead of relative time).
  • Loading branch information
FlaminSarge committed Sep 22, 2024
1 parent 7f4d884 commit 0da0854
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/utils/time.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,25 +68,29 @@ export function titleTimeString(available_at, lang ) {
}

export function formatDistance(time, lang, $t, allowNegative = true, now = dayjs()) {
let diff;
if (!time) return "?";
const minutesdiff = now.diff(time, "minutes");
if (Math.abs(minutesdiff) < 1) return $t("time.soon");
if (!allowNegative && minutesdiff > 0) return $t("time.soon");
const minutesDiff = now.diff(time, "minutes");
if (Math.abs(minutesDiff) < 1) return $t("time.soon");
if (!allowNegative && minutesDiff > 0) return $t("time.soon");
// if (Math.abs(now.diff(time, "days")) > 60) return localizedDayjs(time, lang).format("ll");
if (Math.abs(now.diff(time, "hour")) > 23) {
const hourDiff = now.diff(time, "hour");
if (hourDiff < -23) {
return $t("time.diff_future_date", [
localizedDayjs(time, lang).format("l"),
localizedDayjs(time, lang).format("LT"),
]);
}
if (hourDiff > 23) {
return `${localizedDayjs(time, lang).format("l")} (${localizedDayjs(time, lang).format("LT")})`;
}
const timeObj = localizedDayjs(time, lang);
if (new Date(time) > Date.now()) {
diff = $t("time.diff_future_date", [
return $t("time.diff_future_date", [
timeObj.fromNow(),
timeObj.format(`${timeObj.isTomorrow() ? "ddd " : ""}LT`),
]);
return diff;
}
diff = $t("time.distance_past_date", [localizedDayjs(time, lang).fromNow()]);
return diff;
return $t("time.distance_past_date", [localizedDayjs(time, lang).fromNow()]);
}

export function secondsToHuman(s) {
Expand Down

0 comments on commit 0da0854

Please sign in to comment.