fix: remaining days

This commit is contained in:
hamster1963 2024-12-19 14:23:16 +08:00
parent bc64628dad
commit 5e6f70ba42
2 changed files with 37 additions and 29 deletions

View File

@ -5,7 +5,12 @@ export default function PlanInfo({ parsedData }: { parsedData: PublicNoteData })
return null
}
const extraList = parsedData.planDataMod.extra.split(",").length > 1 ? parsedData.planDataMod.extra.split(",") : parsedData.planDataMod.extra.split(",")[0] === "" ? [] : [parsedData.planDataMod.extra]
const extraList =
parsedData.planDataMod.extra.split(",").length > 1
? parsedData.planDataMod.extra.split(",")
: parsedData.planDataMod.extra.split(",")[0] === ""
? []
: [parsedData.planDataMod.extra]
return (
<section className="flex gap-1 items-center flex-wrap mt-0.5">
@ -52,12 +57,14 @@ export default function PlanInfo({ parsedData }: { parsedData: PublicNoteData })
)}
>
{parsedData.planDataMod.networkRoute.split(",").map((route, index) => {
return route + (index === parsedData.planDataMod!.networkRoute.split(",").length - 1 ? "" : "")
return (
route +
(index === parsedData.planDataMod!.networkRoute.split(",").length - 1 ? "" : "")
)
})}
</p>
)}
{
extraList.map((extra, index) => {
{extraList.map((extra, index) => {
return (
<p
key={index}
@ -68,9 +75,7 @@ export default function PlanInfo({ parsedData }: { parsedData: PublicNoteData })
{extra}
</p>
)
})
}
})}
</section>
)
}

View File

@ -109,21 +109,24 @@ export function getDaysBetweenDatesWithAutoRenewal({
}
}
if (nowTime < endTime) {
return {
days: getDaysBetweenDates(endDate, new Date(nowTime).toISOString()),
cycleLabel: cycleLabel,
remainingPercentage:
getDaysBetweenDates(endDate, new Date(nowTime).toISOString()) /
(30 * months) >
1
? 1
: getDaysBetweenDates(endDate, new Date(nowTime).toISOString()) /
(30 * months),
}
}
const nextTime = getNextCycleTime(endTime, months, nowTime)
const diff = dayjs(nextTime).diff(dayjs(), "day") + 1
const remainingPercentage = diff / (30 * months) > 1 ? 1 : diff / (30 * months)
console.log(
"nextTime",
nextTime,
"diff",
diff,
"month",
months,
"remainingPercentage",
remainingPercentage,
)
return {
days: diff,
cycleLabel: cycleLabel,