-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdatetime-filter.js
62 lines (52 loc) · 1.49 KB
/
datetime-filter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import Vue from 'vue';
import moment from 'moment';
function lang2locale(lang) {
return lang === 'ar'
? 'ar-JO'
: 'en-UK'
}
const fullDate = (dt, lang) => {
const options = {
day: 'numeric',
month: 'long',
year: 'numeric',
}
return new Intl.DateTimeFormat(lang2locale(lang), options).format(new Date(dt))
}
const dayDate = (dt, lang) => {
const weekday = moment(dt).locale(lang).format("dddd");
const dayMonth = new Intl.DateTimeFormat(lang2locale(lang), { day: 'numeric', month: 'long'}).format(new Date(dt))
return `${weekday} - ${dayMonth}`
}
const dayFullDate = (dt, lang) => {
const options = {
weekday: 'long',
day: 'numeric',
month: 'long',
year: 'numeric',
}
return new Intl.DateTimeFormat(lang2locale(lang), options).format(new Date(dt))
}
const monthYearDate = (dt, lang) => {
const options = {
month: 'long',
year: 'numeric',
}
return new Intl.DateTimeFormat(lang2locale(lang), options).format(new Date(dt))
}
const monthDate = (dt, lang) => {
return new Intl.DateTimeFormat(lang2locale(lang), { month: 'long' }).format(new Date(dt))
}
const time = (dt, lang) => {
return moment(dt).locale(lang).format("H:mm A");
}
const day = (dt, lang) => {
return moment(dt).locale(lang).format("dddd");
}
Vue.filter('fullDate', fullDate)
Vue.filter('dayDate', dayDate)
Vue.filter('dayFullDate', dayFullDate)
Vue.filter('time', time)
Vue.filter('day', day)
Vue.filter('monthYearDate', monthYearDate)
Vue.filter('monthDate', monthDate)