mirror of
https://github.com/Radiquum/AniX.git
synced 2025-09-05 22:15:36 +05:00
anix/fix: incorrect format of watched time statistic
This commit is contained in:
parent
be0731cfba
commit
052e649012
3 changed files with 37 additions and 25 deletions
|
@ -248,31 +248,43 @@ export function sinceUnixDate(unixInSeconds: number) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function minutesToTime(
|
export function minutesToTime(min: number) {
|
||||||
min: number,
|
const seconds = min * 60;
|
||||||
type?: "full" | "daysOnly" | "daysHours"
|
const epoch = new Date(0);
|
||||||
) {
|
const date = new Date(seconds * 1000);
|
||||||
const d = Math.floor(min / 1440); // 60*24
|
|
||||||
const h = Math.floor((min - d * 1440) / 60);
|
|
||||||
const m = Math.round(min % 60);
|
|
||||||
|
|
||||||
var dDisplay =
|
const diffInMinutes =
|
||||||
d > 0 ? `${d} ${numberDeclension(d, "день", "дня", "дней")}` : "";
|
new Date(date.getTime() - epoch.getTime()).getTime() / 1000 / 60;
|
||||||
var hDisplay =
|
|
||||||
h > 0 ? `${h} ${numberDeclension(h, "час", "часа", "часов")}` : "";
|
|
||||||
var mDisplay =
|
|
||||||
m > 0 ? `${m} ${numberDeclension(m, "минута", "минуты", "минут")}` : "";
|
|
||||||
|
|
||||||
if (type == "daysOnly") {
|
let days = Math.floor(diffInMinutes / 1440);
|
||||||
if (d > 0) return dDisplay;
|
if (days < 0) days = 0;
|
||||||
return "? дней";
|
const daysToMinutes = days * 1440;
|
||||||
} else if (type == "daysHours") {
|
|
||||||
if (d > 0 && h > 0) return dDisplay + ", " + hDisplay;
|
let hours = Math.floor((diffInMinutes - daysToMinutes) / 60);
|
||||||
if (h > 0) return hDisplay;
|
if (hours < 0) hours = 0;
|
||||||
if (m > 0) return mDisplay;
|
const hoursToMinutes = hours * 60;
|
||||||
} else {
|
|
||||||
return `${d > 0 ? dDisplay : ""}${h > 0 ? ", " + hDisplay : ""}${m > 0 ? ", " + mDisplay : ""}`;
|
let minutes = diffInMinutes - daysToMinutes - hoursToMinutes;
|
||||||
}
|
if (minutes < 0) minutes = 0;
|
||||||
|
|
||||||
|
const dayDisplay =
|
||||||
|
days > 0 ? `${days} ${numberDeclension(days, "день", "дня", "дней")}` : "";
|
||||||
|
const hourDisplay =
|
||||||
|
hours > 0 ?
|
||||||
|
`${hours} ${numberDeclension(hours, "час", "часа", "часов")}`
|
||||||
|
: "";
|
||||||
|
const minuteDisplay =
|
||||||
|
minutes > 0 ?
|
||||||
|
`${minutes} ${numberDeclension(minutes, "минута", "минуты", "минут")}`
|
||||||
|
: "";
|
||||||
|
|
||||||
|
if (days > 0 && hours > 0 && minutes > 0) return `${dayDisplay}, ${hourDisplay}, ${minuteDisplay}`;
|
||||||
|
if (days > 0 && hours > 0) return `${dayDisplay}, ${hourDisplay}`;
|
||||||
|
if (days > 0 && minutes > 0) return `${dayDisplay}, ${minuteDisplay}`;
|
||||||
|
if (hours > 0 && minutes > 0) return `${hourDisplay}, ${minuteDisplay}`;
|
||||||
|
if (days > 0) return dayDisplay;
|
||||||
|
if (hours > 0) return hourDisplay;
|
||||||
|
if (minutes > 0) return minuteDisplay;
|
||||||
}
|
}
|
||||||
|
|
||||||
const StatusList: Record<string, null | number> = {
|
const StatusList: Record<string, null | number> = {
|
||||||
|
|
|
@ -112,7 +112,7 @@ export const ProfileStats = (props: {
|
||||||
<p>
|
<p>
|
||||||
Время просмотра:{" "}
|
Время просмотра:{" "}
|
||||||
<span className="font-bold">
|
<span className="font-bold">
|
||||||
~{minutesToTime(props.watched_time, "daysHours")}
|
~{minutesToTime(props.watched_time)}
|
||||||
</span>
|
</span>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -59,7 +59,7 @@ export const ReleaseInfoInfo = (props: {
|
||||||
{"/"}
|
{"/"}
|
||||||
{props.episodes.total ? props.episodes.total + " эп. " : "? эп. "}
|
{props.episodes.total ? props.episodes.total + " эп. " : "? эп. "}
|
||||||
{props.duration != 0 &&
|
{props.duration != 0 &&
|
||||||
`по ${minutesToTime(props.duration, "daysHours")}`}
|
`по ${minutesToTime(props.duration)}`}
|
||||||
</TableCell>
|
</TableCell>
|
||||||
</TableRow>
|
</TableRow>
|
||||||
<TableRow>
|
<TableRow>
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue