Merge pull request 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
2 changed files with 14 additions and 2 deletions
ui/src
lib
pages
domains

@@ -21,6 +21,16 @@ export const getDate = (zuluTime: string) => {
return time.split(" ")[0]; 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 { export function getTimeBefore(days: number): string {
// 获取当前时间 // 获取当前时间
const currentDate = new Date(); const currentDate = new Date();
@@ -66,3 +76,4 @@ export function getTimeAfter(days: number): string {
return formattedDate; return formattedDate;
} }

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