mirror of
https://github.com/Radiquum/AniX.git
synced 2025-09-04 13:35: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(
|
||||
min: number,
|
||||
type?: "full" | "daysOnly" | "daysHours"
|
||||
) {
|
||||
const d = Math.floor(min / 1440); // 60*24
|
||||
const h = Math.floor((min - d * 1440) / 60);
|
||||
const m = Math.round(min % 60);
|
||||
export function minutesToTime(min: number) {
|
||||
const seconds = min * 60;
|
||||
const epoch = new Date(0);
|
||||
const date = new Date(seconds * 1000);
|
||||
|
||||
var dDisplay =
|
||||
d > 0 ? `${d} ${numberDeclension(d, "день", "дня", "дней")}` : "";
|
||||
var hDisplay =
|
||||
h > 0 ? `${h} ${numberDeclension(h, "час", "часа", "часов")}` : "";
|
||||
var mDisplay =
|
||||
m > 0 ? `${m} ${numberDeclension(m, "минута", "минуты", "минут")}` : "";
|
||||
const diffInMinutes =
|
||||
new Date(date.getTime() - epoch.getTime()).getTime() / 1000 / 60;
|
||||
|
||||
if (type == "daysOnly") {
|
||||
if (d > 0) return dDisplay;
|
||||
return "? дней";
|
||||
} else if (type == "daysHours") {
|
||||
if (d > 0 && h > 0) return dDisplay + ", " + hDisplay;
|
||||
if (h > 0) return hDisplay;
|
||||
if (m > 0) return mDisplay;
|
||||
} else {
|
||||
return `${d > 0 ? dDisplay : ""}${h > 0 ? ", " + hDisplay : ""}${m > 0 ? ", " + mDisplay : ""}`;
|
||||
}
|
||||
let days = Math.floor(diffInMinutes / 1440);
|
||||
if (days < 0) days = 0;
|
||||
const daysToMinutes = days * 1440;
|
||||
|
||||
let hours = Math.floor((diffInMinutes - daysToMinutes) / 60);
|
||||
if (hours < 0) hours = 0;
|
||||
const hoursToMinutes = hours * 60;
|
||||
|
||||
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> = {
|
||||
|
|
|
@ -112,7 +112,7 @@ export const ProfileStats = (props: {
|
|||
<p>
|
||||
Время просмотра:{" "}
|
||||
<span className="font-bold">
|
||||
~{minutesToTime(props.watched_time, "daysHours")}
|
||||
~{minutesToTime(props.watched_time)}
|
||||
</span>
|
||||
</p>
|
||||
</div>
|
||||
|
|
|
@ -59,7 +59,7 @@ export const ReleaseInfoInfo = (props: {
|
|||
{"/"}
|
||||
{props.episodes.total ? props.episodes.total + " эп. " : "? эп. "}
|
||||
{props.duration != 0 &&
|
||||
`по ${minutesToTime(props.duration, "daysHours")}`}
|
||||
`по ${minutesToTime(props.duration)}`}
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
<TableRow>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue