-
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added Timestamp * feat: localization to JST from UTC --------- Co-authored-by: KTheAsianimeBoi <[email protected]>
- Loading branch information
1 parent
3e585fa
commit 226e8c8
Showing
5 changed files
with
49 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import CommentType from "@app/types/comment"; | ||
import ThreadType from "@app/types/thread"; | ||
|
||
type threadOrComment = CommentType | ThreadType; | ||
|
||
export function timeFormatter(newComment: threadOrComment): string { | ||
const utcTimestamp = newComment.created_at; | ||
const date = new Date(utcTimestamp); | ||
|
||
// Add 9 hours to UTC time | ||
date.setUTCHours(date.getUTCHours() + 9); | ||
|
||
// Extract year, month, date, hours, and minutes | ||
const year = date.getUTCFullYear(); | ||
const month = date.getUTCMonth() + 1; // Months are 0-based, so add 1 | ||
const day = date.getUTCDate(); | ||
const hours = date.getUTCHours(); | ||
const minutes = date.getUTCMinutes(); | ||
|
||
// Format the components as a string | ||
const formattedTimestamp = `${year}-${month.toString().padStart(2, "0")}-${day | ||
.toString() | ||
.padStart(2, "0")} ${hours.toString().padStart(2, "0")}:${minutes | ||
.toString() | ||
.padStart(2, "0")}`; | ||
|
||
return formattedTimestamp; | ||
} |