PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 1.2.20
Booking for Appointments and Events Calendar – Amelia v1.2.20
2.4.4 2.4.3 2.4.2 2.4.1 2.4 trunk 1.2.1 1.2.10 1.2.11 1.2.12 1.2.13 1.2.14 1.2.15 1.2.16 1.2.17 1.2.18 1.2.19 1.2.2 1.2.20 1.2.21 1.2.22 1.2.23 1.2.24 1.2.25 1.2.26 1.2.27 1.2.28 1.2.29 1.2.3 1.2.30 1.2.31 1.2.32 1.2.33 1.2.34 1.2.35 1.2.36 1.2.37 1.2.38 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.2.9 2.0 2.0.1 2.0.2 2.1 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.3
ameliabooking / v3 / src / assets / js / common / date.js
ameliabooking / v3 / src / assets / js / common Last commit date
appointments.js 1 year ago attendees.js 1 year ago colorManipulation.js 3 years ago customer.js 1 year ago date.js 1 year ago defaultCustomize.js 1 year ago employee.js 1 year ago events.js 1 year ago formFieldsTemplates.js 3 years ago formatting.js 1 year ago helper.js 1 year ago image.js 1 year ago integrationApple.js 1 year ago integrationGoogle.js 1 year ago integrationOutlook.js 1 year ago integrationStripe.js 1 year ago integrationZoom.js 1 year ago licence.js 2 years ago objectAndArrayManipulation.js 3 years ago pricing.js 1 year ago recurring.js 1 year ago responsive.js 1 year ago scrollElements.js 4 years ago settings.js 1 year ago translationsElementPlus.js 1 year ago
date.js
347 lines
1 import moment from "moment";
2 import {DateTime, Settings, Info} from "luxon";
3 import {settings, shortLocale} from "../../../plugins/settings.js";
4 import {useCookies} from "vue3-cookies";
5 import {useUrlQueryParams} from "./helper";
6
7 Settings.defaultLocale = shortLocale
8
9 const months = []
10 const weekDaysLocale = []
11 const weekDaysShortLocale = []
12
13 for (let i = 1; i <= 12; i++) {
14 months.push(DateTime.local(2022, i, 1).monthLong)
15 if (i <= 7) {
16 weekDaysLocale.push(Info.weekdays('long')[i-1])
17 weekDaysShortLocale.push(Info.weekdays('short')[i-1])
18 }
19 }
20
21 const formatRegex = {
22 formatPHPtoJsMap: {
23 d: 'dd',
24 D: 'ccc',
25 j: 'd',
26 l: 'cccc',
27 N: 'c',
28 w: 'c',
29 W: 'W',
30 F: 'MMMM',
31 m: 'MM',
32 M: 'MMM',
33 n: 'M',
34 o: 'kkkk',
35 Y: 'yyyy',
36 y: 'yy',
37 a: 'a',
38 A: 'a',
39 g: 'h',
40 G: 'H',
41 h: 'hh',
42 H: 'HH',
43 i: 'mm',
44 s: 'ss',
45 O: 'ZZZ',
46 P: 'ZZ',
47 c: 'yyyy-MM-dd[T]HH:mm:ssZZ',
48 r: 'ccc, dd MMM yyyy HH:mm:ss ZZZ',
49 U: 'X',
50 T: '',
51 S: 'o'
52 },
53
54 formatPHPtoMomentMap: {
55 d: 'DD',
56 D: 'ddd',
57 j: 'D',
58 l: 'dddd',
59 N: 'E',
60 w: 'd',
61 W: 'W',
62 F: 'MMMM',
63 m: 'MM',
64 M: 'MMM',
65 n: 'M',
66 o: 'GGGG',
67 Y: 'YYYY',
68 y: 'YY',
69 a: 'a',
70 A: 'A',
71 g: 'h',
72 G: 'H',
73 h: 'hh',
74 H: 'HH',
75 i: 'mm',
76 s: 'ss',
77 O: 'ZZ',
78 P: 'Z',
79 c: 'YYYY-MM-DD[T]HH:mm:ssZ',
80 r: 'ddd, DD MMM YYYY HH:mm:ss ZZ',
81 U: 'X',
82 T: '',
83 S: 'o'
84 },
85
86 formatEx: /[dDjlNwWFmMntoYyaAgGhHisOPcrUTS]/g
87 }
88
89 function useLocalValue (value) {
90 return moment.utc(value, 'YYYY-MM-DD HH:mm').local().format('YYYY-MM-DD HH:mm')
91 }
92
93 function useUtcValue (value) {
94 return moment(value, 'YYYY-MM-DD HH:mm').utc().format('YYYY-MM-DD HH:mm')
95 }
96
97 function useUtcValueOffset (value) {
98 return value ? moment(value, 'YYYY-MM-DD HH:mm:ss').utcOffset() : moment().utcOffset()
99 }
100
101 function useStringFromDate (d) {
102 return d.getFullYear() + '-' + ('0'.concat(d.getMonth() + 1)).slice(-2) + '-' + ('0'.concat(d.getDate())).slice(-2)
103 }
104
105 function useFormatTime (t) {
106 return t.split(':')[0] + ':' + t.split(':')[1]
107 }
108
109 function useTimeInSeconds (time) {
110 return moment(time, 'HH:mm').diff(moment().startOf('day'), 'seconds')
111 }
112
113 function useSecondsInTime (seconds) {
114 return moment.utc(seconds * 1000).format('HH:mm')
115 }
116
117 function addSeconds (time, seconds) {
118 return moment(time, 'HH:mm').add(seconds, 'seconds').format('HH:mm')
119 }
120
121 // * Luxon time format
122 function jsTimeFormat () {
123 // Fix for French "G \h i \m\i\n" and "G\hi" format
124 if (settings.wordpress.timeFormat === 'G \\h i \\m\\i\\n' || settings.wordpress.timeFormat === 'G\\hi') {
125 return 'HH:mm'
126 }
127
128 return settings.wordpress.timeFormat.replace(formatRegex.formatEx, function (phpStr) {
129 return formatRegex.formatPHPtoJsMap[phpStr]
130 })
131 }
132
133 // * Moment time format
134 function momentTimeFormat () {
135 // Fix for French "G \h i \m\i\n" and "G\hi" format
136 if (settings.wordpress.timeFormat === 'G \\h i \\m\\i\\n' || settings.wordpress.timeFormat === 'G\\hi') {
137 return 'HH:mm'
138 }
139
140 return settings.wordpress.timeFormat.replace(formatRegex.formatEx, function (phpStr) {
141 return formatRegex.formatPHPtoMomentMap[phpStr]
142 })
143 }
144
145 function jsDateFormat () {
146 // Fix for Portuguese "j \d\e F, Y" format
147 if (settings.wordpress.dateFormat === 'j \\d\\e F, Y') {
148 return 'd MMMM, yyyy'
149 }
150
151 // Fix for Spanish/Catalan "j \d\e F \d\e Y" format
152 if (settings.wordpress.dateFormat === 'j \\d\\e F \\d\\e Y') {
153 return 'd MMMM yyyy'
154 }
155
156 return settings.wordpress.dateFormat.replace(formatRegex.formatEx, function (phpStr) {
157 return formatRegex.formatPHPtoJsMap[phpStr]
158 })
159 }
160
161 function momentDateFormat () {
162 // Fix for Portuguese "j \d\e F, Y" format
163 if (settings.wordpress.dateFormat === 'j \\d\\e F, Y') {
164 return 'D MMMM, YYYY'
165 }
166
167 // Fix for Spanish/Catalan "j \d\e F \d\e Y" format
168 if (settings.wordpress.dateFormat === 'j \\d\\e F \\d\\e Y') {
169 return 'D MMMM YYYY'
170 }
171
172 return settings.wordpress.dateFormat.replace(formatRegex.formatEx, function (phpStr) {
173 return formatRegex.formatPHPtoMomentMap[phpStr]
174 })
175 }
176
177 function getFrontedFormattedDateTime (dateTime) {
178 let data = dateTime.split(' ')
179
180 return getFrontedFormattedDate(data[0]) + ' ' + getFrontedFormattedTime(data[1].substring(0, 5))
181 }
182
183 function getFrontedFormattedTime (time) {
184 return DateTime.fromFormat(time, 'HH:mm').toFormat(jsTimeFormat())
185 }
186
187 function getFrontedFormattedDate (date) {
188 let dateString = DateTime.fromFormat(date, 'yyyy-MM-dd').toFormat(jsDateFormat())
189
190 // Fix for Portuguese "j \d\e F, Y" format
191 if (settings.wordpress.dateFormat === 'j \\d\\e F, Y') {
192 let result = ''
193
194 dateString.split(' ').forEach(function (value, index) {
195 if (index === 1) {
196 value = value.charAt(0).toUpperCase() + value.slice(1)
197 }
198
199 result = result + value + ' '
200
201 if (index === 0) {
202 result += 'de '
203 }
204 })
205
206 return result
207 }
208
209 // Fix for Spanish/Catalan "j \d\e F \d\e Y" format
210 if (settings.wordpress.dateFormat === 'j \\d\\e F \\d\\e Y') {
211 let result = ''
212
213 let format = !dateString.includes(' de ') ? dateString : dateString.replace('de ', '')
214
215 format.split(' ').forEach(function (value, index) {
216 if (index === 1 || index === 3) {
217 value = value.charAt(0).toUpperCase() + value.slice(1)
218 }
219
220 result = result + value + ' '
221
222 if (index === 0 || index === 1) {
223 result += 'de '
224 }
225 })
226
227 return result
228 }
229
230 return dateString
231 }
232
233 function getFirstDayOfWeek () {
234 return settings.wordpress.startOfWeek
235 }
236
237 function useSecondsToDuration (seconds, hourLabel, minuteLabel) {
238 let hours = Math.floor(seconds / 3600)
239 let minutes = seconds / 60 % 60
240
241 return (hours ? (hours + hourLabel + ' ') : '') + ' ' + (minutes ? (minutes + minuteLabel) : '')
242 }
243
244 function useConvertedUtcToLocalDateTime (period) {
245 let utcOffset = moment(period, 'YYYY-MM-DD HH:mm:ss').toDate().getTimezoneOffset()
246
247 if (utcOffset > 0) {
248 return moment.utc(period, 'YYYY-MM-DD HH:mm:ss').subtract(utcOffset, 'minutes').format('YYYY-MM-DD HH:mm:ss')
249 } else {
250 return moment.utc(period, 'YYYY-MM-DD HH:mm:ss').add(-1 * utcOffset, 'minutes').format('YYYY-MM-DD HH:mm:ss')
251 }
252 }
253
254 function getEventFrontedFormattedDateDay (date) {
255 return DateTime.fromFormat(date, 'yyyy-MM-dd').toFormat('dd')
256 }
257
258 function getEventFrontedFormattedDateMonth (date) {
259 return DateTime.fromFormat(date, 'yyyy-MM-dd').toFormat('LLL')
260 }
261
262 function getEventFrontedFormattedTime (time) {
263 return moment(time, 'HH:mm:ss').format(momentTimeFormat())
264 }
265
266 function getDatePickerInitRange () {
267 const vueCookies = useCookies()['cookies']
268
269 let ameliaRangePast = vueCookies.get('ameliaRangePast')
270 let ameliaRangeFuture = vueCookies.get('ameliaRangeFuture')
271
272 if (ameliaRangePast !== null && ameliaRangeFuture !== null) {
273 return [
274 moment().subtract(ameliaRangePast, 'days').toDate(),
275 moment().add(ameliaRangeFuture, 'days').toDate()
276 ]
277 }
278
279 return [
280 moment().toDate(),
281 moment().add(6, 'days').toDate()
282 ]
283 }
284
285 function setDatePickerSelectedDaysCount (start, end) {
286 const vueCookies = useCookies()['cookies']
287 let currentDate = moment().format('YYYY-MM-DD')
288
289 vueCookies.set('ameliaRangePast', moment(currentDate, 'YYYY-MM-DD').diff(moment(start, 'YYYY-MM-DD'), 'days'))
290 vueCookies.set('ameliaRangeFuture', moment(end, 'YYYY-MM-DD').diff(moment(currentDate, 'YYYY-MM-DD'), 'days'))
291 }
292
293 function getDateRange (cabinetType) {
294 let queryParams = useUrlQueryParams(window.location.href)
295
296 let start = 'start' in queryParams ? queryParams['start'] : null
297 let end = 'end' in queryParams ? queryParams['end'] : null
298
299 if (start && end) {
300 return [
301 moment(start).toDate(),
302 moment(end).toDate()
303 ]
304 }
305
306 if ('ameliaBooking' in window && 'cabinet' in window['ameliaBooking'] && 'pastDays' in window['ameliaBooking']['cabinet'] && 'futureDays' in window['ameliaBooking']['cabinet']) {
307 return [
308 moment().subtract(window['ameliaBooking']['cabinet']['pastDays'], 'days').toDate(),
309 moment().add(window['ameliaBooking']['cabinet']['futureDays'], 'days').toDate()
310 ]
311 }
312 // if it's customer set date range to numberOfDaysAvailableForBooking
313 if (cabinetType === 'customer') {
314 return [moment().toDate(), moment().add(settings.general.numberOfDaysAvailableForBooking, 'days').toDate()]
315 }
316
317 return getDatePickerInitRange()
318 }
319
320 export {
321 weekDaysLocale,
322 weekDaysShortLocale,
323 months,
324 useUtcValue,
325 useLocalValue,
326 useUtcValueOffset,
327 useStringFromDate,
328 useFormatTime,
329 useTimeInSeconds,
330 useSecondsInTime,
331 getFrontedFormattedTime,
332 getFrontedFormattedDate,
333 getFrontedFormattedDateTime,
334 addSeconds,
335 getFirstDayOfWeek,
336 useSecondsToDuration,
337 useConvertedUtcToLocalDateTime,
338 getEventFrontedFormattedDateDay,
339 getEventFrontedFormattedDateMonth,
340 getEventFrontedFormattedTime,
341 getDatePickerInitRange,
342 jsDateFormat,
343 momentDateFormat,
344 setDatePickerSelectedDaysCount,
345 getDateRange
346 }
347