PluginProbe ʕ •ᴥ•ʔ
Booking for Appointments and Events Calendar – Amelia / 2.4.6
Booking for Appointments and Events Calendar – Amelia v2.4.6
2.4.7 2.4.6 2.4.5 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 month ago attendees.js 1 month ago colorManipulation.js 1 month ago customer.js 1 month ago date.js 3 weeks ago defaultCustomize.js 3 weeks ago employee.js 6 days ago events.js 1 month ago formFieldsTemplates.js 1 month ago formatting.js 1 month ago helper.js 6 days ago image.js 1 month ago integrationApple.js 1 month ago integrationGoogle.js 1 month ago integrationOutlook.js 1 month ago integrationStripe.js 1 month ago integrationZoom.js 1 month ago licence.js 1 month ago liveAnnouncer.js 3 weeks ago phone.js 3 weeks ago pricing.js 1 month ago recurring.js 6 days ago responsive.js 1 month ago scrollElements.js 1 month ago settings.js 1 month ago translationsElementPlus.js 1 month ago utilHeaderHeight.js 1 month ago
date.js
383 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 (
103 d.getFullYear() +
104 '-' +
105 '0'.concat(d.getMonth() + 1).slice(-2) +
106 '-' +
107 '0'.concat(d.getDate()).slice(-2)
108 )
109 }
110
111 function useFormatTime(t) {
112 return t.split(':')[0] + ':' + t.split(':')[1]
113 }
114
115 function useTimeInSeconds(time) {
116 return moment(time, 'HH:mm').diff(moment().startOf('day'), 'seconds')
117 }
118
119 function useSecondsInTime(seconds) {
120 return moment.utc(seconds * 1000).format('HH:mm')
121 }
122
123 function addSeconds(time, seconds) {
124 return moment(time, 'HH:mm').add(seconds, 'seconds').format('HH:mm')
125 }
126
127 // * Luxon time format
128 function jsTimeFormat() {
129 // Fix for French "G \h i \m\i\n" and "G\hi" format
130 if (
131 settings.wordpress.timeFormat === 'G \\h i \\m\\i\\n' ||
132 settings.wordpress.timeFormat === 'G\\hi'
133 ) {
134 return 'HH:mm'
135 }
136
137 return settings.wordpress.timeFormat.replace(formatRegex.formatEx, function (phpStr) {
138 return formatRegex.formatPHPtoJsMap[phpStr]
139 })
140 }
141
142 // * Moment time format
143 function momentTimeFormat() {
144 // Fix for French "G \h i \m\i\n" and "G\hi" format
145 if (
146 settings.wordpress.timeFormat === 'G \\h i \\m\\i\\n' ||
147 settings.wordpress.timeFormat === 'G\\hi'
148 ) {
149 return 'HH:mm'
150 }
151
152 return settings.wordpress.timeFormat.replace(formatRegex.formatEx, function (phpStr) {
153 return formatRegex.formatPHPtoMomentMap[phpStr]
154 })
155 }
156
157 function jsDateFormat() {
158 // Fix for Portuguese "j \d\e F, Y" format
159 if (settings.wordpress.dateFormat === 'j \\d\\e F, Y') {
160 return 'd MMMM, yyyy'
161 }
162
163 // Fix for Spanish/Catalan "j \d\e F \d\e Y" format
164 if (settings.wordpress.dateFormat === 'j \\d\\e F \\d\\e Y') {
165 return 'd MMMM yyyy'
166 }
167
168 // Remove ordinal suffix (S) as it's not supported in all languages
169 let format = settings.wordpress.dateFormat.replace(/S/g, '')
170
171 return format.replace(formatRegex.formatEx, function (phpStr) {
172 return formatRegex.formatPHPtoJsMap[phpStr]
173 })
174 }
175
176 function momentDateFormat() {
177 // Fix for Portuguese "j \d\e F, Y" format
178 if (settings.wordpress.dateFormat === 'j \\d\\e F, Y') {
179 return 'D MMMM, YYYY'
180 }
181
182 // Fix for Spanish/Catalan "j \d\e F \d\e Y" format
183 if (settings.wordpress.dateFormat === 'j \\d\\e F \\d\\e Y') {
184 return 'D MMMM YYYY'
185 }
186
187 return settings.wordpress.dateFormat.replace(formatRegex.formatEx, function (phpStr) {
188 return formatRegex.formatPHPtoMomentMap[phpStr]
189 })
190 }
191
192 function getFrontedFormattedDateTime(dateTime) {
193 let data = dateTime.split(' ')
194
195 return getFrontedFormattedDate(data[0]) + ' ' + getFrontedFormattedTime(data[1].substring(0, 5))
196 }
197
198 function getFrontedFormattedTime(time, zone = '') {
199 return zone
200 ? DateTime.fromFormat(time, 'HH:mm', { zone: zone }).toFormat(jsTimeFormat())
201 : DateTime.fromFormat(time, 'HH:mm').toFormat(jsTimeFormat())
202 }
203
204 function getFrontedFormattedDate(date) {
205 let dateString = DateTime.fromFormat(date, 'yyyy-MM-dd').toFormat(jsDateFormat())
206
207 // Fix for Portuguese "j \d\e F, Y" format
208 if (settings.wordpress.dateFormat === 'j \\d\\e F, Y') {
209 let result = ''
210
211 dateString.split(' ').forEach(function (value, index) {
212 if (index === 1) {
213 value = value.charAt(0).toUpperCase() + value.slice(1)
214 }
215
216 result = result + value + ' '
217
218 if (index === 0) {
219 result += 'de '
220 }
221 })
222
223 return result
224 }
225
226 // Fix for Spanish/Catalan "j \d\e F \d\e Y" format
227 if (settings.wordpress.dateFormat === 'j \\d\\e F \\d\\e Y') {
228 let result = ''
229
230 let format = !dateString.includes(' de ') ? dateString : dateString.replace('de ', '')
231
232 format.split(' ').forEach(function (value, index) {
233 if (index === 1 || index === 3) {
234 value = value.charAt(0).toUpperCase() + value.slice(1)
235 }
236
237 result = result + value + ' '
238
239 if (index === 0 || index === 1) {
240 result += 'de '
241 }
242 })
243
244 return result
245 }
246
247 return dateString
248 }
249
250 function getFirstDayOfWeek() {
251 return settings.wordpress.startOfWeek
252 }
253
254 function useSecondsToDuration(seconds, hourLabel, minuteLabel) {
255 let hours = Math.floor(seconds / 3600)
256 let minutes = (seconds / 60) % 60
257
258 return (hours ? hours + hourLabel + ' ' : '') + ' ' + (minutes ? minutes + minuteLabel : '')
259 }
260
261 function useConvertedUtcToLocalDateTime(period) {
262 let utcOffset = moment(period, 'YYYY-MM-DD HH:mm:ss').toDate().getTimezoneOffset()
263
264 if (utcOffset > 0) {
265 return moment
266 .utc(period, 'YYYY-MM-DD HH:mm:ss')
267 .subtract(utcOffset, 'minutes')
268 .format('YYYY-MM-DD HH:mm:ss')
269 } else {
270 return moment
271 .utc(period, 'YYYY-MM-DD HH:mm:ss')
272 .add(-1 * utcOffset, 'minutes')
273 .format('YYYY-MM-DD HH:mm:ss')
274 }
275 }
276
277 function getEventFrontedFormattedDateYear(date) {
278 return DateTime.fromFormat(date, 'yyyy-MM-dd').toFormat('yyyy')
279 }
280
281 function getEventFrontedFormattedDateDay(date) {
282 return DateTime.fromFormat(date, 'yyyy-MM-dd').toFormat('dd')
283 }
284
285 function getEventFrontedFormattedDateMonth(date) {
286 return DateTime.fromFormat(date, 'yyyy-MM-dd').toFormat('LLL')
287 }
288
289 function getEventFrontedFormattedTime(time) {
290 return moment(time, 'HH:mm:ss').format(momentTimeFormat())
291 }
292
293 function getDatePickerInitRange() {
294 const vueCookies = useCookies()['cookies']
295
296 let ameliaRangePast = vueCookies.get('ameliaRangePast')
297 let ameliaRangeFuture = vueCookies.get('ameliaRangeFuture')
298
299 if (ameliaRangePast !== null && ameliaRangeFuture !== null) {
300 return [
301 moment().subtract(ameliaRangePast, 'days').toDate(),
302 moment().add(ameliaRangeFuture, 'days').toDate(),
303 ]
304 }
305
306 return [moment().toDate(), moment().add(6, 'days').toDate()]
307 }
308
309 function setDatePickerSelectedDaysCount(start, end) {
310 const vueCookies = useCookies()['cookies']
311 let currentDate = moment().format('YYYY-MM-DD')
312
313 vueCookies.set(
314 'ameliaRangePast',
315 moment(currentDate, 'YYYY-MM-DD').diff(moment(start, 'YYYY-MM-DD'), 'days'),
316 )
317 vueCookies.set(
318 'ameliaRangeFuture',
319 moment(end, 'YYYY-MM-DD').diff(moment(currentDate, 'YYYY-MM-DD'), 'days'),
320 )
321 }
322
323 function getDateRange(cabinetType) {
324 let queryParams = useUrlQueryParams(window.location.href)
325
326 let start = 'start' in queryParams ? queryParams['start'] : null
327 let end = 'end' in queryParams ? queryParams['end'] : null
328
329 if (start && end) {
330 return [moment(start).toDate(), moment(end).toDate()]
331 }
332
333 if (
334 'ameliaBooking' in window &&
335 'cabinet' in window['ameliaBooking'] &&
336 'pastDays' in window['ameliaBooking']['cabinet'] &&
337 'futureDays' in window['ameliaBooking']['cabinet']
338 ) {
339 return [
340 moment().subtract(window['ameliaBooking']['cabinet']['pastDays'], 'days').toDate(),
341 moment().add(window['ameliaBooking']['cabinet']['futureDays'], 'days').toDate(),
342 ]
343 }
344 // if it's customer set date range to numberOfDaysAvailableForBooking
345 if (cabinetType === 'customer') {
346 return [
347 moment().toDate(),
348 moment().add(settings.general.numberOfDaysAvailableForBooking, 'days').toDate(),
349 ]
350 }
351
352 return getDatePickerInitRange()
353 }
354
355 export {
356 weekDaysLocale,
357 weekDaysShortLocale,
358 months,
359 useUtcValue,
360 useLocalValue,
361 useUtcValueOffset,
362 useStringFromDate,
363 useFormatTime,
364 useTimeInSeconds,
365 useSecondsInTime,
366 getFrontedFormattedTime,
367 getFrontedFormattedDate,
368 getFrontedFormattedDateTime,
369 addSeconds,
370 getFirstDayOfWeek,
371 useSecondsToDuration,
372 useConvertedUtcToLocalDateTime,
373 getEventFrontedFormattedDateYear,
374 getEventFrontedFormattedDateDay,
375 getEventFrontedFormattedDateMonth,
376 getEventFrontedFormattedTime,
377 getDatePickerInitRange,
378 jsDateFormat,
379 momentDateFormat,
380 setDatePickerSelectedDaysCount,
381 getDateRange,
382 }
383