forked from quasarframework/quasar
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuse-datetime.js
More file actions
97 lines (77 loc) · 1.87 KB
/
use-datetime.js
File metadata and controls
97 lines (77 loc) · 1.87 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { computed } from 'vue'
import { toJalaali } from '../../utils/private/date-persian.js'
import { pad } from '../../utils/format.js'
const calendars = [ 'gregorian', 'persian' ]
export const useDatetimeProps = {
modelValue: {
required: true
},
mask: {
type: String
},
locale: Object,
calendar: {
type: String,
validator: v => calendars.includes(v),
default: 'gregorian'
},
landscape: Boolean,
color: String,
textColor: String,
square: Boolean,
flat: Boolean,
bordered: Boolean,
readonly: Boolean,
disable: Boolean
}
export const useDatetimeEmits = [ 'update:modelValue' ]
export function getDayHash (date) {
return date.year + '/' + pad(date.month) + '/' + pad(date.day)
}
export default function (props, $q) {
const editable = computed(() => {
return props.disable !== true && props.readonly !== true
})
const tabindex = computed(() => {
return props.editable === true ? 0 : -1
})
const headerClass = computed(() => {
const cls = []
props.color !== void 0 && cls.push(`bg-${ props.color }`)
props.textColor !== void 0 && cls.push(`text-${ props.textColor }`)
return cls.join(' ')
})
function getLocale () {
return props.locale !== void 0
? { ...$q.lang.date, ...props.locale }
: $q.lang.date
}
function getCurrentDate (dateOnly) {
const d = new Date()
const timeFill = dateOnly === true ? null : 0
if (props.calendar === 'persian') {
const jDate = toJalaali(d)
return {
year: jDate.jy,
month: jDate.jm,
day: jDate.jd
}
}
return {
year: d.getFullYear(),
month: d.getMonth() + 1,
day: d.getDate(),
hour: timeFill,
minute: timeFill,
second: timeFill,
millisecond: timeFill
}
}
return {
editable,
tabindex,
headerClass,
getLocale,
getCurrentDate
}
}