feat: update date formatting to respect user locale in editor and preview components

This commit is contained in:
JOYCEQL
2025-03-01 10:44:18 +08:00
committed by qingchen
parent 8a7fd32e64
commit 387733e8b1
3 changed files with 13 additions and 6 deletions
+5 -1
View File
@@ -112,7 +112,11 @@ const Field = ({
if (type === "date") {
const formatDate = (date: Date | undefined) => {
if (!date) return "";
return format(date, "yyyy/MM/dd");
return date.toLocaleDateString(["zh-CN", "en-US"], {
year: "numeric",
month: "2-digit",
day: "2-digit",
});
};
const handleYearInput = (e: React.ChangeEvent<HTMLInputElement>) => {
+3 -2
View File
@@ -1,5 +1,5 @@
import React from "react";
import { useTranslations } from "next-intl";
import { useTranslations, useLocale } from "next-intl";
import { motion } from "framer-motion";
import * as Icons from "lucide-react";
import { cn } from "@/lib/utils";
@@ -24,6 +24,7 @@ const BaseInfo = ({
template
}: BaseInfoProps) => {
const t = useTranslations("workbench");
const locale = useLocale();
const { setActiveSection } = useResumeStore();
const useIconMode = globalSettings?.useIconMode ?? false;
const layout = basic?.layout || "left";
@@ -64,7 +65,7 @@ const BaseInfo = ({
key: field.key,
value:
field.key === "birthDate" && basic[field.key]
? new Date(basic[field.key] as string).toLocaleDateString()
? new Date(basic[field.key] as string).toLocaleDateString(locale)
: (basic[field.key] as string),
icon: basic.icons?.[field.key] || "User",
label: field.label,
+5 -3
View File
@@ -3,6 +3,7 @@ import { AnimatePresence, motion } from "framer-motion";
import { Education, GlobalSettings } from "@/types/resume";
import SectionTitle from "./SectionTitle";
import { useResumeStore } from "@/store/useResumeStore";
import { useLocale } from "next-intl";
interface EducationSectionProps {
education?: Education[];
@@ -16,6 +17,7 @@ const EducationSection = ({
showTitle = true,
}: EducationSectionProps) => {
const { setActiveSection } = useResumeStore();
const locale = useLocale();
const visibleEducation = education?.filter((edu) => edu.visible);
return (
<motion.div
@@ -74,9 +76,9 @@ const EducationSection = ({
className="text-subtitleFont shrink-0"
suppressHydrationWarning
>
{`${new Date(edu.startDate).toLocaleDateString()} - ${new Date(
edu.endDate
).toLocaleDateString()}`}
{`${new Date(edu.startDate).toLocaleDateString(
locale
)} - ${new Date(edu.endDate).toLocaleDateString(locale)}`}
</span>
</motion.div>