release v2.0.0 #4
|
@ -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([], {
|
||||||
Vue.filter('date', formatDate);
|
year: useDate ? 'numeric' : undefined,
|
||||||
|
month: useDate ? '2-digit' : undefined,
|
||||||
Vue.filter('dateTime', function(date: Date, seconds = false) {
|
day: useDate ? '2-digit' : undefined,
|
||||||
let H = date.getHours().toString();
|
weekday: useWeekday ? 'long' : undefined,
|
||||||
if (H.length == 1) H = `0${H}`;
|
hour: useTime ? '2-digit' : undefined,
|
||||||
let M = date.getMinutes().toString();
|
minute: useTime ? '2-digit' : undefined,
|
||||||
if (M.length == 1) M = `0${M}`;
|
second: useTime && useSeconds ? '2-digit' : undefined
|
||||||
let S = '';
|
|
||||||
if (seconds) {
|
|
||||||
S =
|
|
||||||
':' +
|
|
||||||
(date.getSeconds() > 9
|
|
||||||
? date.getSeconds().toString()
|
|
||||||
: `0${date.getSeconds().toString()}`);
|
|
||||||
}
|
|
||||||
return `${formatDate(date)} ${H}:${M}${S}`;
|
|
||||||
});
|
});
|
||||||
|
return dateTimeFormat.format(date);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vue.filter('date', formatDateTime);
|
||||||
|
Vue.filter('time', (date: Date, seconds = false) =>
|
||||||
|
formatDateTime(date, false, true, seconds)
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue