Merge pull request #222 from usual2970/feat/cert-leftday

Add remaining days
This commit is contained in:
usual2970 2024-10-20 21:00:03 +08:00 committed by GitHub
commit 364289894e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 2 deletions

View File

@ -21,6 +21,16 @@ export const getDate = (zuluTime: string) => {
return time.split(" ")[0];
};
export const getLeftDays = (zuluTime: string) => {
const time = convertZulu2Beijing(zuluTime);
const date = time.split(" ")[0];
const now = new Date();
const target = new Date(date);
const diff = target.getTime() - now.getTime();
const days = Math.floor(diff / (1000 * 60 * 60 * 24));
return days;
};
export function getTimeBefore(days: number): string {
// 获取当前时间
const currentDate = new Date();
@ -66,3 +76,4 @@ export function getTimeAfter(days: number): string {
return formattedDate;
}

View File

@ -26,7 +26,7 @@ import { Toaster } from "@/components/ui/toaster";
import { Tooltip, TooltipTrigger } from "@/components/ui/tooltip";
import { useToast } from "@/components/ui/use-toast";
import { CustomFile, saveFiles2ZIP } from "@/lib/file";
import { convertZulu2Beijing, getDate } from "@/lib/time";
import { convertZulu2Beijing, getDate, getLeftDays } from "@/lib/time";
import { Domain } from "@/domain/domain";
import { list, remove, save, subscribeId, unsubscribeId } from "@/repository/domains";
@ -213,7 +213,7 @@ const Home = () => {
<div>
{domain.expiredAt ? (
<>
<div>{t("domain.props.expiry.date1", { date: 90 })}</div>
<div>{t("domain.props.expiry.date1", { date: `${getLeftDays(domain.expiredAt)}/90` })}</div>
<div>
{t("domain.props.expiry.date2", {
date: getDate(domain.expiredAt),
@ -340,3 +340,4 @@ const Home = () => {
};
export default Home;