feat: format date based on language for repacks

This commit is contained in:
Zamitto 2024-10-13 21:24:24 -03:00
parent a4475d2145
commit 8cc8b5fe6f
4 changed files with 19 additions and 11 deletions

View file

@ -68,12 +68,17 @@ export function useDate() {
} }
}, },
format: (timestamp: number): string => { formatDateTime: (date: number | Date | string): string => {
const locale = getDateLocale(); const locale = getDateLocale();
return format( return format(
timestamp, date,
locale == enUS ? "MM/dd/yyyy - HH:mm" : "dd/MM/yyyy - HH:mm" locale == enUS ? "MM/dd/yyyy - HH:mm" : "dd/MM/yyyy - HH:mm"
); );
}, },
formatDate: (date: number | Date | string): string => {
const locale = getDateLocale();
return format(date, locale == enUS ? "MM/dd/yyyy" : "dd/MM/yyyy");
},
}; };
} }

View file

@ -27,7 +27,7 @@ export function Achievement() {
const { t } = useTranslation("achievement"); const { t } = useTranslation("achievement");
const { format } = useDate(); const { formatDateTime } = useDate();
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
@ -163,7 +163,8 @@ export function Achievement() {
<p>{achievement.displayName}</p> <p>{achievement.displayName}</p>
<p>{achievement.description}</p> <p>{achievement.description}</p>
<small> <small>
{achievement.unlockTime && format(achievement.unlockTime)} {achievement.unlockTime &&
formatDateTime(achievement.unlockTime)}
</small> </small>
</div> </div>
</li> </li>

View file

@ -7,11 +7,11 @@ import type { GameRepack } from "@types";
import * as styles from "./repacks-modal.css"; import * as styles from "./repacks-modal.css";
import { SPACING_UNIT } from "@renderer/theme.css"; import { SPACING_UNIT } from "@renderer/theme.css";
import { format } from "date-fns";
import { DownloadSettingsModal } from "./download-settings-modal"; import { DownloadSettingsModal } from "./download-settings-modal";
import { gameDetailsContext } from "@renderer/context"; import { gameDetailsContext } from "@renderer/context";
import { Downloader } from "@shared"; import { Downloader } from "@shared";
import { orderBy } from "lodash-es"; import { orderBy } from "lodash-es";
import { useDate } from "@renderer/hooks";
export interface RepacksModalProps { export interface RepacksModalProps {
visible: boolean; visible: boolean;
@ -36,6 +36,8 @@ export function RepacksModal({
const { t } = useTranslation("game_details"); const { t } = useTranslation("game_details");
const { formatDate } = useDate();
const sortedRepacks = useMemo(() => { const sortedRepacks = useMemo(() => {
return orderBy(repacks, (repack) => repack.uploadDate, "desc"); return orderBy(repacks, (repack) => repack.uploadDate, "desc");
}, [repacks]); }, [repacks]);
@ -109,9 +111,7 @@ export function RepacksModal({
<p style={{ fontSize: "12px" }}> <p style={{ fontSize: "12px" }}>
{repack.fileSize} - {repack.repacker} -{" "} {repack.fileSize} - {repack.repacker} -{" "}
{repack.uploadDate {repack.uploadDate ? formatDate(repack.uploadDate!) : ""}
? format(repack.uploadDate, "dd/MM/yyyy")
: ""}
</p> </p>
</Button> </Button>
); );

View file

@ -60,7 +60,7 @@ export function Sidebar() {
useContext(gameDetailsContext); useContext(gameDetailsContext);
const { t } = useTranslation("game_details"); const { t } = useTranslation("game_details");
const { format } = useDate(); const { formatDateTime } = useDate();
const { numberFormatter } = useFormat(); const { numberFormatter } = useFormat();
@ -138,7 +138,8 @@ export function Sidebar() {
<div> <div>
<p>{achievement.displayName}</p> <p>{achievement.displayName}</p>
<small> <small>
{achievement.unlockTime && format(achievement.unlockTime)} {achievement.unlockTime &&
formatDateTime(achievement.unlockTime)}
</small> </small>
</div> </div>
</div> </div>
@ -176,7 +177,8 @@ export function Sidebar() {
<div> <div>
<p>{achievement.displayName}</p> <p>{achievement.displayName}</p>
<small> <small>
{achievement.unlockTime && format(achievement.unlockTime)} {achievement.unlockTime &&
formatDateTime(achievement.unlockTime)}
</small> </small>
</div> </div>
</Link> </Link>