summaryrefslogtreecommitdiff
path: root/src/util/date-time.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/util/date-time.js')
-rw-r--r--src/util/date-time.js121
1 files changed, 66 insertions, 55 deletions
diff --git a/src/util/date-time.js b/src/util/date-time.js
index e9d7664f..2664b8ca 100644
--- a/src/util/date-time.js
+++ b/src/util/date-time.js
@@ -7,7 +7,7 @@
* @returns {string} A human-friendly string version of that date and time.
*/
export function parseAndFormatDateTime(dateTimeString) {
- return formatDateTime(parseDateTime(dateTimeString));
+ return formatDateTime(parseDateTime(dateTimeString));
}
/**
@@ -19,27 +19,27 @@ export function parseAndFormatDateTime(dateTimeString) {
* @returns {object} An rack with the parsed date and time information as content.
*/
export function parseDateTime(dateTimeString) {
- const output = {
- year: 0,
- month: 0,
- day: 0,
- hour: 0,
- minute: 0,
- second: 0,
- };
+ const output = {
+ year: 0,
+ month: 0,
+ day: 0,
+ hour: 0,
+ minute: 0,
+ second: 0
+ };
- const dateAndTime = dateTimeString.split("T");
- const dateComponents = dateAndTime[0].split("-");
- output.year = parseInt(dateComponents[0], 10);
- output.month = parseInt(dateComponents[1], 10);
- output.day = parseInt(dateComponents[2], 10);
+ const dateAndTime = dateTimeString.split("T");
+ const dateComponents = dateAndTime[0].split("-");
+ output.year = parseInt(dateComponents[0], 10);
+ output.month = parseInt(dateComponents[1], 10);
+ output.day = parseInt(dateComponents[2], 10);
- const timeComponents = dateAndTime[1].split(":");
- output.hour = parseInt(timeComponents[0], 10);
- output.minute = parseInt(timeComponents[1], 10);
- output.second = parseInt(timeComponents[2], 10);
+ const timeComponents = dateAndTime[1].split(":");
+ output.hour = parseInt(timeComponents[0], 10);
+ output.minute = parseInt(timeComponents[1], 10);
+ output.second = parseInt(timeComponents[2], 10);
- return output;
+ return output;
}
/**
@@ -49,25 +49,34 @@ export function parseDateTime(dateTimeString) {
* @returns {string} A human-friendly string version of that date and time.
*/
export function formatDateTime(dateTime) {
- let date;
- const currentDate = new Date();
+ let date;
+ const currentDate = new Date();
- date = addPaddingToTwo(dateTime.day) + "/" +
- addPaddingToTwo(dateTime.month) + "/" +
- addPaddingToTwo(dateTime.year);
+ date =
+ addPaddingToTwo(dateTime.day) +
+ "/" +
+ addPaddingToTwo(dateTime.month) +
+ "/" +
+ addPaddingToTwo(dateTime.year);
- if (dateTime.year === currentDate.getFullYear() &&
- dateTime.month === currentDate.getMonth() + 1) {
- if (dateTime.day === currentDate.getDate()) {
- date = "Today";
- } else if (dateTime.day === currentDate.getDate() - 1) {
- date = "Yesterday";
- }
+ if (
+ dateTime.year === currentDate.getFullYear() &&
+ dateTime.month === currentDate.getMonth() + 1
+ ) {
+ if (dateTime.day === currentDate.getDate()) {
+ date = "Today";
+ } else if (dateTime.day === currentDate.getDate() - 1) {
+ date = "Yesterday";
}
+ }
- return date + ", " +
- addPaddingToTwo(dateTime.hour) + ":" +
- addPaddingToTwo(dateTime.minute);
+ return (
+ date +
+ ", " +
+ addPaddingToTwo(dateTime.hour) +
+ ":" +
+ addPaddingToTwo(dateTime.minute)
+ );
}
/**
@@ -77,25 +86,27 @@ export function formatDateTime(dateTime) {
* @returns {string} A string representation of that amount of second, in the from of HH:MM:SS.
*/
export function convertSecondsToFormattedTime(seconds) {
- if (seconds <= 0) {
- return "0s";
- }
+ if (seconds <= 0) {
+ return "0s";
+ }
- let hour = Math.floor(seconds / 3600);
- let minute = Math.floor(seconds / 60) % 60;
- let second = seconds % 60;
+ let hour = Math.floor(seconds / 3600);
+ let minute = Math.floor(seconds / 60) % 60;
+ let second = seconds % 60;
- hour = isNaN(hour) ? 0 : hour;
- minute = isNaN(minute) ? 0 : minute;
- second = isNaN(second) ? 0 : second;
+ hour = isNaN(hour) ? 0 : hour;
+ minute = isNaN(minute) ? 0 : minute;
+ second = isNaN(second) ? 0 : second;
- if (hour === 0 && minute === 0) {
- return second + "s";
- } else if (hour === 0) {
- return minute + "m" + addPaddingToTwo(second) + "s";
- } else {
- return hour + "h" + addPaddingToTwo(minute) + "m" + addPaddingToTwo(second) + "s";
- }
+ if (hour === 0 && minute === 0) {
+ return second + "s";
+ } else if (hour === 0) {
+ return minute + "m" + addPaddingToTwo(second) + "s";
+ } else {
+ return (
+ hour + "h" + addPaddingToTwo(minute) + "m" + addPaddingToTwo(second) + "s"
+ );
+ }
}
/**
@@ -105,9 +116,9 @@ export function convertSecondsToFormattedTime(seconds) {
* @returns {string} A string containing the padded integer.
*/
function addPaddingToTwo(integer) {
- if (integer < 10) {
- return "0" + integer.toString();
- } else {
- return integer.toString();
- }
+ if (integer < 10) {
+ return "0" + integer.toString();
+ } else {
+ return integer.toString();
+ }
}