From e40f07211f5f15dcb138e2520a76d13afd3c0cfd Mon Sep 17 00:00:00 2001 From: FifthWit Date: Thu, 30 Jan 2025 10:44:30 -0600 Subject: formatted with prettier --- frontend/src/utils/Jwt.ts | 12 ++++++--- frontend/src/utils/Time.ts | 62 ++++++++++++++++++++++++++++++---------------- 2 files changed, 49 insertions(+), 25 deletions(-) (limited to 'frontend/src/utils') diff --git a/frontend/src/utils/Jwt.ts b/frontend/src/utils/Jwt.ts index ce351fb..affcd36 100644 --- a/frontend/src/utils/Jwt.ts +++ b/frontend/src/utils/Jwt.ts @@ -1,5 +1,7 @@ // llm ahh funcs -export function get_user_id_from_token(token: string | undefined): string | undefined { +export function get_user_id_from_token( + token: string | undefined +): string | undefined { if (!token) { return undefined; } @@ -19,9 +21,11 @@ export function get_user_id_from_token(token: string | undefined): string | unde .join('') ); return JSON.parse(jsonPayload).sub; -}; +} -export function get_user_mod_from_token(token: string | undefined): boolean | undefined { +export function get_user_mod_from_token( + token: string | undefined +): boolean | undefined { if (!token) { return undefined; } @@ -41,4 +45,4 @@ export function get_user_mod_from_token(token: string | undefined): boolean | un .join('') ); return JSON.parse(jsonPayload).mod; -}; +} diff --git a/frontend/src/utils/Time.ts b/frontend/src/utils/Time.ts index b83a7ed..34830b0 100644 --- a/frontend/src/utils/Time.ts +++ b/frontend/src/utils/Time.ts @@ -1,42 +1,62 @@ export function time_ago(date: any) { const now = new Date().getTime(); - - const localDate = new Date(date.getTime() - (date.getTimezoneOffset() * 60000)); - const seconds = Math.floor((now - localDate.getTime()) / 1000); + + const localDate = new Date(date.getTime() - date.getTimezoneOffset() * 60000); + const seconds = Math.floor((now - localDate.getTime()) / 1000); let interval = Math.floor(seconds / 31536000); - if (interval === 1) {return interval + ' year ago';} - if (interval > 1) {return interval + ' years ago';} + if (interval === 1) { + return interval + ' year ago'; + } + if (interval > 1) { + return interval + ' years ago'; + } interval = Math.floor(seconds / 2592000); - if (interval === 1) {return interval + ' month ago';} - if (interval > 1) {return interval + ' months ago';} + if (interval === 1) { + return interval + ' month ago'; + } + if (interval > 1) { + return interval + ' months ago'; + } interval = Math.floor(seconds / 86400); - if (interval === 1) {return interval + ' day ago';} - if (interval > 1) {return interval + ' days ago';} + if (interval === 1) { + return interval + ' day ago'; + } + if (interval > 1) { + return interval + ' days ago'; + } interval = Math.floor(seconds / 3600); - if (interval === 1) {return interval + ' hour ago';} - if (interval > 1) {return interval + ' hours ago';} + if (interval === 1) { + return interval + ' hour ago'; + } + if (interval > 1) { + return interval + ' hours ago'; + } interval = Math.floor(seconds / 60); - if (interval === 1) {return interval + ' minute ago';} - if (interval > 1) {return interval + ' minutes ago';} + if (interval === 1) { + return interval + ' minute ago'; + } + if (interval > 1) { + return interval + ' minutes ago'; + } - if(seconds < 10) return 'just now'; + if (seconds < 10) return 'just now'; return Math.floor(seconds) + ' seconds ago'; -}; +} export function ticks_to_time(ticks: number) { - let seconds = Math.floor(ticks / 60) - let minutes = Math.floor(seconds / 60) - let hours = Math.floor(minutes / 60) + let seconds = Math.floor(ticks / 60); + let minutes = Math.floor(seconds / 60); + let hours = Math.floor(minutes / 60); - let milliseconds = Math.floor((ticks % 60) * 1000 / 60) + let milliseconds = Math.floor(((ticks % 60) * 1000) / 60); seconds = seconds % 60; minutes = minutes % 60; - return `${hours === 0 ? "" : hours + ":"}${minutes === 0 ? "" : hours > 0 ? minutes.toString().padStart(2, '0') + ":" : (minutes + ":")}${minutes > 0 ? seconds.toString().padStart(2, '0') : seconds}.${milliseconds.toString().padStart(3, '0')}`; -}; \ No newline at end of file + return `${hours === 0 ? '' : hours + ':'}${minutes === 0 ? '' : hours > 0 ? minutes.toString().padStart(2, '0') + ':' : minutes + ':'}${minutes > 0 ? seconds.toString().padStart(2, '0') : seconds}.${milliseconds.toString().padStart(3, '0')}`; +} -- cgit v1.2.3