2021-11-10 14:19:41 +01:00
|
|
|
import { parseTime } from '../../../../utility';
|
|
|
|
|
2021-11-05 16:39:42 +01:00
|
|
|
export const getDateTime = (): string => {
|
2021-11-05 17:16:19 +01:00
|
|
|
const days = localStorage.getItem('daySchema')?.split(';') || [
|
2021-10-22 15:51:11 +02:00
|
|
|
'Sunday',
|
|
|
|
'Monday',
|
|
|
|
'Tuesday',
|
|
|
|
'Wednesday',
|
|
|
|
'Thursday',
|
|
|
|
'Friday',
|
|
|
|
'Saturday',
|
|
|
|
];
|
2021-11-05 17:16:19 +01:00
|
|
|
|
|
|
|
const months = localStorage.getItem('monthSchema')?.split(';') || [
|
2021-10-22 15:51:11 +02:00
|
|
|
'January',
|
|
|
|
'February',
|
|
|
|
'March',
|
|
|
|
'April',
|
|
|
|
'May',
|
|
|
|
'June',
|
|
|
|
'July',
|
|
|
|
'August',
|
|
|
|
'September',
|
|
|
|
'October',
|
|
|
|
'November',
|
|
|
|
'December',
|
|
|
|
];
|
2021-06-13 01:06:42 +02:00
|
|
|
|
|
|
|
const now = new Date();
|
|
|
|
|
2021-10-22 15:51:11 +02:00
|
|
|
const useAmericanDate = localStorage.useAmericanDate === 'true';
|
2021-11-10 14:19:41 +01:00
|
|
|
const showTime = localStorage.showTime === 'true';
|
2021-11-18 16:03:44 +01:00
|
|
|
const hideDate = localStorage.hideDate === 'true';
|
2021-11-10 14:19:41 +01:00
|
|
|
|
2021-11-18 16:03:44 +01:00
|
|
|
// Date
|
|
|
|
let dateEl = '';
|
|
|
|
|
|
|
|
if (!hideDate) {
|
|
|
|
if (!useAmericanDate) {
|
|
|
|
dateEl = `${days[now.getDay()]}, ${now.getDate()} ${
|
|
|
|
months[now.getMonth()]
|
|
|
|
} ${now.getFullYear()}`;
|
|
|
|
} else {
|
|
|
|
dateEl = `${days[now.getDay()]}, ${
|
|
|
|
months[now.getMonth()]
|
|
|
|
} ${now.getDate()} ${now.getFullYear()}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Time
|
2021-11-10 14:19:41 +01:00
|
|
|
const p = parseTime;
|
2021-11-18 16:03:44 +01:00
|
|
|
let timeEl = '';
|
2021-11-10 14:19:41 +01:00
|
|
|
|
2021-11-18 16:03:44 +01:00
|
|
|
if (showTime) {
|
|
|
|
const time = `${p(now.getHours())}:${p(now.getMinutes())}:${p(
|
|
|
|
now.getSeconds()
|
|
|
|
)}`;
|
2021-11-10 14:19:41 +01:00
|
|
|
|
2021-11-18 16:03:44 +01:00
|
|
|
timeEl = time;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Separator
|
|
|
|
let separator = '';
|
2021-10-22 15:51:11 +02:00
|
|
|
|
2021-11-18 16:03:44 +01:00
|
|
|
if (!hideDate && showTime) {
|
|
|
|
separator = ' - ';
|
2021-10-22 15:51:11 +02:00
|
|
|
}
|
2021-11-18 16:03:44 +01:00
|
|
|
|
|
|
|
// Output
|
|
|
|
return `${dateEl}${separator}${timeEl}`;
|
2021-10-22 15:51:11 +02:00
|
|
|
};
|