release v2.0.0 #4
|
@ -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()}`;
|
||||
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', 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}`;
|
||||
});
|
||||
Vue.filter('date', formatDateTime);
|
||||
Vue.filter('time', (date: Date, seconds = false) =>
|
||||
formatDateTime(date, false, true, seconds)
|
||||
);
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue