Improved Mi 11. Nov 13:22:28 CET 2020 and filter

This commit is contained in:
Ferdinand Thiessen 2020-11-11 13:22:28 +01:00
parent 390e0fc95b
commit 296245457d
1 changed files with 21 additions and 23 deletions

View File

@ -1,29 +1,27 @@
import { boot } from 'quasar/wrappers';
export default boot(({ Vue }) => {
function formatDate(date: Date) {
let d = date.getDate().toString();
if (d.length == 1) d = '0' + d;
let m = date.getMonth().toString();
if (m.length == 1) m = '0' + m;
return `${d}.${m}.${date.getFullYear().toString()}`;
}
Vue.filter('date', formatDate);
Vue.filter('dateTime', function(date: Date, seconds = false) {
let H = date.getHours().toString();
if (H.length == 1) H = `0${H}`;
let M = date.getMinutes().toString();
if (M.length == 1) M = `0${M}`;
let S = '';
if (seconds) {
S =
':' +
(date.getSeconds() > 9
? date.getSeconds().toString()
: `0${date.getSeconds().toString()}`);
}
return `${formatDate(date)} ${H}:${M}${S}`;
function formatDateTime(
date: Date,
useDate = true,
useTime = false,
useSeconds = false,
useWeekday = false
) {
const dateTimeFormat = new Intl.DateTimeFormat([], {
year: useDate ? 'numeric' : undefined,
month: useDate ? '2-digit' : undefined,
day: useDate ? '2-digit' : undefined,
weekday: useWeekday ? 'long' : undefined,
hour: useTime ? '2-digit' : undefined,
minute: useTime ? '2-digit' : undefined,
second: useTime && useSeconds ? '2-digit' : undefined
});
return dateTimeFormat.format(date);
}
Vue.filter('date', formatDateTime);
Vue.filter('time', (date: Date, seconds = false) =>
formatDateTime(date, false, true, seconds)
);
});