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'; import { boot } from 'quasar/wrappers';
export default boot(({ Vue }) => { export default boot(({ Vue }) => {
function formatDate(date: Date) { function formatDateTime(
let d = date.getDate().toString(); date: Date,
if (d.length == 1) d = '0' + d; useDate = true,
let m = date.getMonth().toString(); useTime = false,
if (m.length == 1) m = '0' + m; useSeconds = false,
return `${d}.${m}.${date.getFullYear().toString()}`; 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', formatDate); Vue.filter('date', formatDateTime);
Vue.filter('time', (date: Date, seconds = false) =>
Vue.filter('dateTime', function(date: Date, seconds = false) { formatDateTime(date, false, true, seconds)
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}`;
});
}); });