Skip to content

Commit

Permalink
fix: remaining days
Browse files Browse the repository at this point in the history
  • Loading branch information
hamster1963 committed Dec 19, 2024
1 parent bc64628 commit 5e6f70b
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 29 deletions.
41 changes: 23 additions & 18 deletions src/components/PlanInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand Down Expand Up @@ -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]",
)}
>
{parsedData.planDataMod.networkRoute.split(",").map((route,index) => {
return route + (index === parsedData.planDataMod!.networkRoute.split(",").length - 1 ? "" : "|")
{parsedData.planDataMod.networkRoute.split(",").map((route, index) => {
return (
route +
(index === parsedData.planDataMod!.networkRoute.split(",").length - 1 ? "" : "|")
)
})}
</p>
)}
{
extraList.map((extra, index) => {
return (
<p
key={index}
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]",
)}
>
{extra}
</p>
)
})
}

{extraList.map((extra, index) => {
return (
<p
key={index}
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]",
)}
>
{extra}
</p>
)
})}
</section>
)
}
25 changes: 14 additions & 11 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 5e6f70b

Please sign in to comment.