aboutsummaryrefslogtreecommitdiff
path: root/utils/getTimes.js
diff options
context:
space:
mode:
authorFactiven <[email protected]>2023-09-13 00:45:53 +0700
committerGitHub <[email protected]>2023-09-13 00:45:53 +0700
commit7327a69b55a20b99b14ee0803d6cf5f8b88c45ef (patch)
treecbcca777593a8cc4b0282e7d85a6fc51ba517e25 /utils/getTimes.js
parentUpdate issue templates (diff)
downloadmoopa-7327a69b55a20b99b14ee0803d6cf5f8b88c45ef.tar.xz
moopa-7327a69b55a20b99b14ee0803d6cf5f8b88c45ef.zip
Update v4 - Merge pre-push to main (#71)
* Create build-test.yml * initial v4 commit * update: github workflow * update: push on branch * Update .github/ISSUE_TEMPLATE/bug_report.md * configuring next.config.js file
Diffstat (limited to 'utils/getTimes.js')
-rw-r--r--utils/getTimes.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/utils/getTimes.js b/utils/getTimes.js
index 4bb8031..8bbc2ee 100644
--- a/utils/getTimes.js
+++ b/utils/getTimes.js
@@ -34,10 +34,34 @@ export function getCurrentSeason() {
}
}
+export function convertUnixToCountdown(time) {
+ let date = new Date(time * 1000);
+ let days = date.getDay();
+ let hours = date.getHours();
+ let minutes = date.getMinutes();
+
+ let countdown = "";
+
+ if (days > 0) {
+ countdown += `${days}d `;
+ }
+
+ if (hours > 0) {
+ countdown += `${hours}h `;
+ }
+
+ if (minutes > 0) {
+ countdown += `${minutes}m `;
+ }
+
+ return countdown.trim();
+}
+
export function convertSecondsToTime(sec) {
let days = Math.floor(sec / (3600 * 24));
let hours = Math.floor((sec % (3600 * 24)) / 3600);
let minutes = Math.floor((sec % 3600) / 60);
+ let seconds = Math.floor(sec % 60);
let time = "";
@@ -53,5 +77,32 @@ export function convertSecondsToTime(sec) {
time += `${minutes}m `;
}
+ if (days <= 0) {
+ time += `${seconds}s `;
+ }
+
return time.trim();
}
+
+// Function to convert timestamp to AM/PM time format
+export const timeStamptoAMPM = (timestamp) => {
+ const date = new Date(timestamp * 1000);
+ const hours = date.getHours();
+ const minutes = date.getMinutes();
+ const ampm = hours >= 12 ? "PM" : "AM";
+ const formattedHours = hours % 12 || 12; // Convert to 12-hour format
+
+ return `${formattedHours}:${minutes.toString().padStart(2, "0")} ${ampm}`;
+};
+
+export const timeStamptoHour = (timestamp) => {
+ const options = { hour: "numeric", minute: "numeric", hour12: true };
+ const currentTime = new Date().getTime() / 1000;
+ const formattedTime = new Date(timestamp * 1000).toLocaleTimeString(
+ undefined,
+ options
+ );
+ const status = timestamp <= currentTime ? "aired" : "airing";
+
+ return `${status} at ${formattedTime}`;
+};