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 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 ( return (
<section className="flex gap-1 items-center flex-wrap mt-0.5"> <section className="flex gap-1 items-center flex-wrap mt-0.5">
@ -51,26 +56,26 @@ export default function PlanInfo({ parsedData }: { parsedData: PublicNoteData })
"text-[9px] bg-blue-600 text-blue-200 dark:bg-blue-800 dark:text-blue-300 w-fit rounded-[5px] px-[3px] py-[1.5px]", "text-[9px] bg-blue-600 text-blue-200 dark:bg-blue-800 dark:text-blue-300 w-fit rounded-[5px] px-[3px] py-[1.5px]",
)} )}
> >
{parsedData.planDataMod.networkRoute.split(",").map((route,index) => { {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> </p>
)} )}
{ {extraList.map((extra, index) => {
extraList.map((extra, index) => { return (
return ( <p
<p key={index}
key={index} className={cn(
className={cn( "text-[9px] bg-stone-600 text-stone-200 dark:bg-stone-800 dark:text-stone-300 w-fit rounded-[5px] px-[3px] py-[1.5px]",
"text-[9px] bg-stone-600 text-stone-200 dark:bg-stone-800 dark:text-stone-300 w-fit rounded-[5px] px-[3px] py-[1.5px]", )}
)} >
> {extra}
{extra} </p>
</p> )
) })}
})
}
</section> </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 nextTime = getNextCycleTime(endTime, months, nowTime)
const diff = dayjs(nextTime).diff(dayjs(), "day") + 1 const diff = dayjs(nextTime).diff(dayjs(), "day") + 1
const remainingPercentage = diff / (30 * months) > 1 ? 1 : diff / (30 * months) const remainingPercentage = diff / (30 * months) > 1 ? 1 : diff / (30 * months)
console.log(
"nextTime",
nextTime,
"diff",
diff,
"month",
months,
"remainingPercentage",
remainingPercentage,
)
return { return {
days: diff, days: diff,
cycleLabel: cycleLabel, cycleLabel: cycleLabel,