mirror of
https://github.com/chinchang/web-maker.git
synced 2025-07-26 08:11:17 +02:00
add subs details in profile modal
This commit is contained in:
35
src/utils.js
35
src/utils.js
@@ -205,6 +205,41 @@ export function getHumanDate(timestamp) {
|
||||
return retVal;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert any date-ish string/obj to human readable form -> Jul 02, 2021
|
||||
* @param {string?object} date date to be formatted
|
||||
* @returns string
|
||||
*/
|
||||
export function getHumanReadableDate(
|
||||
date,
|
||||
{ showTime = true, utc = false } = {}
|
||||
) {
|
||||
if (!date) return '';
|
||||
let d = typeof date.toDate === 'function' ? date.toDate() : new Date(date);
|
||||
if (utc) {
|
||||
d = new Date(
|
||||
Date.UTC(d.getFullYear(), d.getMonth(), d.getDate(), d.getHours())
|
||||
);
|
||||
}
|
||||
|
||||
let options = {
|
||||
year: 'numeric',
|
||||
month: 'short',
|
||||
day: 'numeric'
|
||||
};
|
||||
if (showTime) {
|
||||
options = {
|
||||
...options,
|
||||
hour: '2-digit',
|
||||
minute: '2-digit',
|
||||
second: '2-digit',
|
||||
hour12: true
|
||||
};
|
||||
}
|
||||
const dateTimeString = d.toLocaleString(false, options);
|
||||
return dateTimeString;
|
||||
}
|
||||
|
||||
// create a one-time event
|
||||
export function once(node, type, callback) {
|
||||
// create event
|
||||
|
Reference in New Issue
Block a user