Skip to content

Commit

Permalink
better formatting in presence
Browse files Browse the repository at this point in the history
  • Loading branch information
Hartaithan committed Feb 9, 2024
1 parent c626a2f commit a7e7d23
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
9 changes: 5 additions & 4 deletions utils/profile.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { type NullablePSNProfile, type Presence } from "@/models/AuthModel";
import dayjs from "dayjs";

export const getName = (profile: NullablePSNProfile | undefined): string => {
if (profile == null) return "Name Not Found";
Expand All @@ -17,10 +18,10 @@ export const getName = (profile: NullablePSNProfile | undefined): string => {

export const getLastOnlineDate = (presence: Presence): string | null => {
if (presence.lastOnlineDate == null) return null;
const date = new Date(presence.lastOnlineDate);
const formattedDate = `${date.getDay()}.${date.getMonth()}.${date.getFullYear()}`;
const formattedTime = `${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
return `Last online: ${formattedDate}, ${formattedTime}`;
const value = dayjs(presence.lastOnlineDate);
const date = value.format("DD.MM.YYYY");
const time = value.format("HH:mm:ss");
return `Last online: ${date}, ${time}`;
};

export const getPresence = (
Expand Down
8 changes: 8 additions & 0 deletions utils/string.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
export const capitalize = (value: string): string => {
return value[0].toUpperCase() + value.substring(1);
};

export const pad = (
num: number,
length: number,
value: string = "0",
): string => {
return String(num).padStart(length, value);
};

0 comments on commit a7e7d23

Please sign in to comment.