@bagelink/vue 0.0.1216 → 0.0.1220
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/Calendar/Index.vue.d.ts +510 -0
- package/dist/components/Calendar/Index.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/header/Header.vue.d.ts +117 -0
- package/dist/components/Calendar/components/header/Header.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/month/AgendaEventTile.vue.d.ts +37 -0
- package/dist/components/Calendar/components/month/AgendaEventTile.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/month/AgendaEvents.vue.d.ts +37 -0
- package/dist/components/Calendar/components/month/AgendaEvents.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/month/Day.vue.d.ts +84 -0
- package/dist/components/Calendar/components/month/Day.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/month/Event.vue.d.ts +69 -0
- package/dist/components/Calendar/components/month/Event.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/month/Month.vue.d.ts +134 -0
- package/dist/components/Calendar/components/month/Month.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/month/WeekDay.vue.d.ts +7 -0
- package/dist/components/Calendar/components/month/WeekDay.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/partials/EventFlyout.vue.d.ts +122 -0
- package/dist/components/Calendar/components/partials/EventFlyout.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/week/Day.vue.d.ts +152 -0
- package/dist/components/Calendar/components/week/Day.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/week/DayEvent.vue.d.ts +136 -0
- package/dist/components/Calendar/components/week/DayEvent.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/week/DayTimeline.vue.d.ts +23 -0
- package/dist/components/Calendar/components/week/DayTimeline.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/week/FullDayEvent.vue.d.ts +42 -0
- package/dist/components/Calendar/components/week/FullDayEvent.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/week/Week.vue.d.ts +196 -0
- package/dist/components/Calendar/components/week/Week.vue.d.ts.map +1 -0
- package/dist/components/Calendar/components/week/WeekTimeline.vue.d.ts +21 -0
- package/dist/components/Calendar/components/week/WeekTimeline.vue.d.ts.map +1 -0
- package/dist/components/Calendar/constants.d.ts +13 -0
- package/dist/components/Calendar/constants.d.ts.map +1 -0
- package/dist/components/Calendar/helpers/DayIntervals.d.ts +17 -0
- package/dist/components/Calendar/helpers/DayIntervals.d.ts.map +1 -0
- package/dist/components/Calendar/helpers/EDate.d.ts +10 -0
- package/dist/components/Calendar/helpers/EDate.d.ts.map +1 -0
- package/dist/components/Calendar/helpers/Errors.d.ts +18 -0
- package/dist/components/Calendar/helpers/Errors.d.ts.map +1 -0
- package/dist/components/Calendar/helpers/EventChange.d.ts +19 -0
- package/dist/components/Calendar/helpers/EventChange.d.ts.map +1 -0
- package/dist/components/Calendar/helpers/EventConcurrency.d.ts +12 -0
- package/dist/components/Calendar/helpers/EventConcurrency.d.ts.map +1 -0
- package/dist/components/Calendar/helpers/EventFlyoutPosition.d.ts +14 -0
- package/dist/components/Calendar/helpers/EventFlyoutPosition.d.ts.map +1 -0
- package/dist/components/Calendar/helpers/EventPosition.d.ts +11 -0
- package/dist/components/Calendar/helpers/EventPosition.d.ts.map +1 -0
- package/dist/components/Calendar/helpers/EventsFilter.d.ts +11 -0
- package/dist/components/Calendar/helpers/EventsFilter.d.ts.map +1 -0
- package/dist/components/Calendar/helpers/Helpers.d.ts +19 -0
- package/dist/components/Calendar/helpers/Helpers.d.ts.map +1 -0
- package/dist/components/Calendar/helpers/Time.d.ts +118 -0
- package/dist/components/Calendar/helpers/Time.d.ts.map +1 -0
- package/dist/components/Calendar/helpers/Week.d.ts +10 -0
- package/dist/components/Calendar/helpers/Week.d.ts.map +1 -0
- package/dist/components/Calendar/index.d.ts +4 -0
- package/dist/components/Calendar/index.d.ts.map +1 -0
- package/dist/components/Calendar/language/index.d.ts +6 -0
- package/dist/components/Calendar/language/index.d.ts.map +1 -0
- package/dist/components/Calendar/language/keys.d.ts +90 -0
- package/dist/components/Calendar/language/keys.d.ts.map +1 -0
- package/dist/components/Calendar/models/Event.d.ts +50 -0
- package/dist/components/Calendar/models/Event.d.ts.map +1 -0
- package/dist/components/Calendar/typings/config.interface.d.ts +77 -0
- package/dist/components/Calendar/typings/config.interface.d.ts.map +1 -0
- package/dist/components/Calendar/typings/interfaces/day.interface.d.ts +10 -0
- package/dist/components/Calendar/typings/interfaces/day.interface.d.ts.map +1 -0
- package/dist/components/Calendar/typings/interfaces/event.interface.d.ts +32 -0
- package/dist/components/Calendar/typings/interfaces/event.interface.d.ts.map +1 -0
- package/dist/components/Calendar/typings/interfaces/full-day-events-week.type.d.ts +7 -0
- package/dist/components/Calendar/typings/interfaces/full-day-events-week.type.d.ts.map +1 -0
- package/dist/components/Calendar/typings/interfaces/period.interface.d.ts +6 -0
- package/dist/components/Calendar/typings/interfaces/period.interface.d.ts.map +1 -0
- package/dist/components/Calendar/typings/interfaces/time-modes.d.ts +6 -0
- package/dist/components/Calendar/typings/interfaces/time-modes.d.ts.map +1 -0
- package/dist/components/Calendar/typings/types.d.ts +21 -0
- package/dist/components/Calendar/typings/types.d.ts.map +1 -0
- package/dist/components/DataTable/DataTable.vue.d.ts.map +1 -1
- package/dist/components/Draggable/useDraggable.d.ts.map +1 -1
- package/dist/components/form/inputs/DatePick.vue.d.ts +8 -0
- package/dist/components/form/inputs/DatePick.vue.d.ts.map +1 -1
- package/dist/components/form/inputs/NumberInput.vue.d.ts.map +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/index.d.ts.map +1 -1
- package/dist/directives/index.d.ts +2 -0
- package/dist/directives/index.d.ts.map +1 -1
- package/dist/directives/vResize.d.ts +18 -0
- package/dist/directives/vResize.d.ts.map +1 -0
- package/dist/index.cjs +3657 -169
- package/dist/index.mjs +3658 -170
- package/dist/style.css +843 -77
- package/package.json +2 -1
- package/src/components/Calendar/Index.vue +420 -0
- package/src/components/Calendar/assets/base.css +60 -0
- package/src/components/Calendar/components/header/Header.vue +274 -0
- package/src/components/Calendar/components/month/AgendaEventTile.vue +137 -0
- package/src/components/Calendar/components/month/AgendaEvents.vue +107 -0
- package/src/components/Calendar/components/month/Day.vue +271 -0
- package/src/components/Calendar/components/month/Event.vue +221 -0
- package/src/components/Calendar/components/month/Month.vue +278 -0
- package/src/components/Calendar/components/month/WeekDay.vue +25 -0
- package/src/components/Calendar/components/partials/EventFlyout.vue +429 -0
- package/src/components/Calendar/components/week/Day.vue +212 -0
- package/src/components/Calendar/components/week/DayEvent.vue +585 -0
- package/src/components/Calendar/components/week/DayTimeline.vue +86 -0
- package/src/components/Calendar/components/week/FullDayEvent.vue +121 -0
- package/src/components/Calendar/components/week/Week.vue +414 -0
- package/src/components/Calendar/components/week/WeekTimeline.vue +126 -0
- package/src/components/Calendar/constants.ts +13 -0
- package/src/components/Calendar/env.d.ts +8 -0
- package/src/components/Calendar/helpers/DayIntervals.ts +48 -0
- package/src/components/Calendar/helpers/EDate.ts +18 -0
- package/src/components/Calendar/helpers/Errors.ts +69 -0
- package/src/components/Calendar/helpers/EventChange.ts +88 -0
- package/src/components/Calendar/helpers/EventConcurrency.ts +69 -0
- package/src/components/Calendar/helpers/EventFlyoutPosition.ts +96 -0
- package/src/components/Calendar/helpers/EventPosition.ts +154 -0
- package/src/components/Calendar/helpers/EventsFilter.ts +50 -0
- package/src/components/Calendar/helpers/Helpers.ts +86 -0
- package/src/components/Calendar/helpers/Time.ts +588 -0
- package/src/components/Calendar/helpers/Week.ts +37 -0
- package/src/components/Calendar/index.ts +4 -0
- package/src/components/Calendar/language/index.ts +37 -0
- package/src/components/Calendar/language/keys.ts +90 -0
- package/src/components/Calendar/models/Event.ts +112 -0
- package/src/components/Calendar/styles/_mixins.css +21 -0
- package/src/components/Calendar/styles/_variables.css +51 -0
- package/src/components/Calendar/typings/config.interface.ts +87 -0
- package/src/components/Calendar/typings/interfaces/day.interface.ts +10 -0
- package/src/components/Calendar/typings/interfaces/event.interface.ts +32 -0
- package/src/components/Calendar/typings/interfaces/full-day-events-week.type.ts +8 -0
- package/src/components/Calendar/typings/interfaces/period.interface.ts +5 -0
- package/src/components/Calendar/typings/interfaces/time-modes.ts +9 -0
- package/src/components/Calendar/typings/types.ts +23 -0
- package/src/components/DataTable/DataTable.vue +4 -0
- package/src/components/Draggable/useDraggable.ts +53 -37
- package/src/components/form/inputs/DatePick.vue +189 -152
- package/src/components/form/inputs/NumberInput.vue +1 -3
- package/src/components/index.ts +3 -6
- package/src/directives/index.ts +2 -0
- package/src/directives/vResize.ts +205 -0
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
import { DAY_TIME_POINT } from '../typings/config.interface'
|
|
2
|
+
import { DAY_MODE } from '../typings/interfaces/time-modes'
|
|
3
|
+
import EDate from './EDate'
|
|
4
|
+
import Helpers from './Helpers'
|
|
5
|
+
|
|
6
|
+
export type calendarWeekType = Date[]
|
|
7
|
+
export type calendarMonthType = calendarWeekType[]
|
|
8
|
+
export type calendarYearMonths = Date[]
|
|
9
|
+
|
|
10
|
+
export enum WEEK_START_DAY {
|
|
11
|
+
SUNDAY = 'sunday',
|
|
12
|
+
MONDAY = 'monday'
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export default class Time {
|
|
16
|
+
FIRST_DAY_OF_WEEK: WEEK_START_DAY
|
|
17
|
+
CALENDAR_LOCALE: string
|
|
18
|
+
ALL_HOURS: DAY_TIME_POINT[] = [
|
|
19
|
+
0,
|
|
20
|
+
100,
|
|
21
|
+
200,
|
|
22
|
+
300,
|
|
23
|
+
400,
|
|
24
|
+
500,
|
|
25
|
+
600,
|
|
26
|
+
700,
|
|
27
|
+
800,
|
|
28
|
+
900,
|
|
29
|
+
1000,
|
|
30
|
+
1100,
|
|
31
|
+
1200,
|
|
32
|
+
1300,
|
|
33
|
+
1400,
|
|
34
|
+
1500,
|
|
35
|
+
1600,
|
|
36
|
+
1700,
|
|
37
|
+
1800,
|
|
38
|
+
1900,
|
|
39
|
+
2000,
|
|
40
|
+
2100,
|
|
41
|
+
2200,
|
|
42
|
+
2300
|
|
43
|
+
]
|
|
44
|
+
DAY_START: DAY_TIME_POINT
|
|
45
|
+
DAY_END: DAY_TIME_POINT
|
|
46
|
+
HOURS_PER_DAY = 24
|
|
47
|
+
MS_PER_DAY: number
|
|
48
|
+
|
|
49
|
+
constructor(
|
|
50
|
+
firstDayOfWeek: WEEK_START_DAY = WEEK_START_DAY.MONDAY,
|
|
51
|
+
locale: string | null = null,
|
|
52
|
+
dayBoundaries: { start: DAY_TIME_POINT, end: DAY_TIME_POINT } = { start: 0, end: 2400 }
|
|
53
|
+
) {
|
|
54
|
+
this.FIRST_DAY_OF_WEEK = firstDayOfWeek
|
|
55
|
+
this.CALENDAR_LOCALE = locale || Helpers.getBrowserNavigatorLocale()
|
|
56
|
+
this.DAY_START = dayBoundaries.start
|
|
57
|
+
this.DAY_END = dayBoundaries.end
|
|
58
|
+
this.HOURS_PER_DAY = (() => {
|
|
59
|
+
const dayEnd = Time.getHourFromTimePoints(this.DAY_END)
|
|
60
|
+
const dayStart = Time.getHourFromTimePoints(this.DAY_START)
|
|
61
|
+
|
|
62
|
+
if (dayEnd > dayStart) return dayEnd - dayStart
|
|
63
|
+
|
|
64
|
+
return this.HOURS_PER_DAY - dayStart + dayEnd
|
|
65
|
+
})()
|
|
66
|
+
this.MS_PER_DAY = 86400000
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
get dayMode() {
|
|
70
|
+
if (this.DAY_START === 0 && this.DAY_END === 2400) return DAY_MODE.REGULAR
|
|
71
|
+
|
|
72
|
+
if (this.DAY_START >= this.DAY_END) return DAY_MODE.FLEXIBLE
|
|
73
|
+
|
|
74
|
+
return DAY_MODE.SHORTENED
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getDatesBetweenTwoDates(start: Date, end: Date): Date[] {
|
|
78
|
+
let arr = []
|
|
79
|
+
let dt = new Date(start)
|
|
80
|
+
// eslint-disable-next-line no-unmodified-loop-condition
|
|
81
|
+
while (dt <= end) {
|
|
82
|
+
arr.push(new Date(dt.getFullYear(), dt.getMonth(), dt.getDate()))
|
|
83
|
+
dt.setDate(dt.getDate() + 1)
|
|
84
|
+
}
|
|
85
|
+
return arr
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
getCalendarWeekDateObjects(date: Date): calendarWeekType {
|
|
89
|
+
// If week starts on Sunday, we can get the first date of the week, by simply counting selectedDate.getDate() - selectedDate.getDay()
|
|
90
|
+
let subtractedDaysToGetFirstDate
|
|
91
|
+
if (this.FIRST_DAY_OF_WEEK === 'sunday') {
|
|
92
|
+
subtractedDaysToGetFirstDate = date.getDay()
|
|
93
|
+
}
|
|
94
|
+
// However, if week starts on Monday, we need to make sure Mondays are represented as 0, instead of Sundays
|
|
95
|
+
else {
|
|
96
|
+
subtractedDaysToGetFirstDate
|
|
97
|
+
= date.getDay() === 0 ? 6 : date.getDay() - 1
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
const dateOfFirstDayOfWeek = date.getDate() - subtractedDaysToGetFirstDate // First date of week is the date of the month - the day of the week
|
|
101
|
+
const firstDay = new Date(
|
|
102
|
+
date.getFullYear(),
|
|
103
|
+
date.getMonth(),
|
|
104
|
+
dateOfFirstDayOfWeek
|
|
105
|
+
)
|
|
106
|
+
|
|
107
|
+
return this.getDatesBetweenTwoDates(
|
|
108
|
+
firstDay,
|
|
109
|
+
new Date(
|
|
110
|
+
firstDay.getFullYear(),
|
|
111
|
+
firstDay.getMonth(),
|
|
112
|
+
firstDay.getDate() + 6
|
|
113
|
+
)
|
|
114
|
+
)
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Returns an array of the weeks that comprise a month
|
|
119
|
+
*
|
|
120
|
+
* @param {number} yyyy
|
|
121
|
+
* @param {number} mm - zero indexed (January === 0)
|
|
122
|
+
*/
|
|
123
|
+
getCalendarMonthSplitInWeeks(yyyy: number, mm: number): calendarMonthType {
|
|
124
|
+
const month: calendarMonthType = []
|
|
125
|
+
const selectedDate = new Date(yyyy, mm, 1)
|
|
126
|
+
|
|
127
|
+
// 1. Get the first date of the month, and push the full week of this date into the month list
|
|
128
|
+
const firstDateOfMonth = new Date(
|
|
129
|
+
selectedDate.getFullYear(),
|
|
130
|
+
selectedDate.getMonth(),
|
|
131
|
+
1
|
|
132
|
+
)
|
|
133
|
+
const firstWeekOfMonth = this.getCalendarWeekDateObjects(firstDateOfMonth)
|
|
134
|
+
month.push(firstWeekOfMonth)
|
|
135
|
+
|
|
136
|
+
// 2. Then enter a while-loop, which pushes weeks onto the month,
|
|
137
|
+
// until the first Monday is reached, that is not in the specified month
|
|
138
|
+
let isInMonth = true
|
|
139
|
+
let mondayOfWeekToPush = firstWeekOfMonth[0]
|
|
140
|
+
const specifiedMonth = selectedDate.getMonth()
|
|
141
|
+
|
|
142
|
+
while (isInMonth) {
|
|
143
|
+
const newMonday = new Date(
|
|
144
|
+
mondayOfWeekToPush.getFullYear(),
|
|
145
|
+
mondayOfWeekToPush.getMonth(),
|
|
146
|
+
mondayOfWeekToPush.getDate() + 7
|
|
147
|
+
)
|
|
148
|
+
|
|
149
|
+
if (newMonday.getMonth() === specifiedMonth) {
|
|
150
|
+
month.push(this.getCalendarWeekDateObjects(newMonday))
|
|
151
|
+
mondayOfWeekToPush = newMonday
|
|
152
|
+
} else {
|
|
153
|
+
isInMonth = false
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return month
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Returns an array with the length of 12 dates,
|
|
162
|
+
* one date for the first day of each month of the year
|
|
163
|
+
*/
|
|
164
|
+
getCalendarYearMonths(year: number): calendarYearMonths {
|
|
165
|
+
const yearList: calendarYearMonths = []
|
|
166
|
+
let month = 0
|
|
167
|
+
|
|
168
|
+
while (month <= 11) {
|
|
169
|
+
yearList.push(new Date(year, month, 1))
|
|
170
|
+
month++
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
return yearList
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
getHourAndMinutesFromTimePoints(timePoints: number) {
|
|
177
|
+
const time = timePoints.toString()
|
|
178
|
+
let hour = '0'
|
|
179
|
+
let minutes = '0'
|
|
180
|
+
|
|
181
|
+
if (time.length === 4) {
|
|
182
|
+
hour = time[0] + time[1]
|
|
183
|
+
minutes = time[2] + time[3]
|
|
184
|
+
} else if (time.length === 3) {
|
|
185
|
+
hour = time[0]
|
|
186
|
+
minutes = time[1] + time[2]
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return {
|
|
190
|
+
hour: +hour,
|
|
191
|
+
minutes: +minutes,
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Given timePoints (0, 100, 200 etc.), this function returns
|
|
197
|
+
* a localized string with the respective hour
|
|
198
|
+
* (in en-US for example: 0 => 12 AM, 1600 => 4 PM )
|
|
199
|
+
*/
|
|
200
|
+
getHourLocaleStringFromHourDigits(timePoints: number) {
|
|
201
|
+
const { hour, minutes } = this.getHourAndMinutesFromTimePoints(timePoints)
|
|
202
|
+
|
|
203
|
+
const hourLocaleString = new Date(
|
|
204
|
+
2100,
|
|
205
|
+
0,
|
|
206
|
+
1,
|
|
207
|
+
+hour,
|
|
208
|
+
+minutes,
|
|
209
|
+
0
|
|
210
|
+
).toLocaleTimeString(this.CALENDAR_LOCALE, {
|
|
211
|
+
hour: '2-digit',
|
|
212
|
+
})
|
|
213
|
+
|
|
214
|
+
if (hourLocaleString[0] === '0') return hourLocaleString.substring(1)
|
|
215
|
+
|
|
216
|
+
return hourLocaleString
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
getLocalizedNameOfWeekday(
|
|
220
|
+
date: Date,
|
|
221
|
+
weekdayNameLength: 'long' | 'short' = 'short'
|
|
222
|
+
): string {
|
|
223
|
+
return date.toLocaleDateString(this.CALENDAR_LOCALE, {
|
|
224
|
+
weekday: weekdayNameLength,
|
|
225
|
+
})
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
getLocalizedNameOfMonth(
|
|
229
|
+
date: Date,
|
|
230
|
+
monthNameLength: 'long' | 'short' = 'short'
|
|
231
|
+
): string {
|
|
232
|
+
return date.toLocaleDateString(this.CALENDAR_LOCALE, {
|
|
233
|
+
month: monthNameLength,
|
|
234
|
+
})
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
getLocalizedDateString(date: Date): string {
|
|
238
|
+
return date.toLocaleDateString(this.CALENDAR_LOCALE)
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Takes a date object, and creates a time string from it, in the format of
|
|
243
|
+
* YYYY-MM-DD hh:mm
|
|
244
|
+
*/
|
|
245
|
+
getDateTimeStringFromDate(
|
|
246
|
+
date: Date,
|
|
247
|
+
timeIsStartOrEndOfDay?: 'start' | 'end'
|
|
248
|
+
): string {
|
|
249
|
+
const y = date.getFullYear()
|
|
250
|
+
const m = date.getMonth() + 1
|
|
251
|
+
const d = date.getDate()
|
|
252
|
+
const fullDate = `${y}-${m >= 10 ? m : `0${m}`}-${d >= 10 ? d : `0${d}`}`
|
|
253
|
+
|
|
254
|
+
if (!timeIsStartOrEndOfDay) {
|
|
255
|
+
const hour = date.getHours()
|
|
256
|
+
const minutes = date.getMinutes()
|
|
257
|
+
|
|
258
|
+
return `${fullDate} ${hour >= 10 ? hour : `0${hour}`}:${
|
|
259
|
+
minutes >= 10 ? minutes : `0${minutes}`
|
|
260
|
+
}`
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
const fullTime = timeIsStartOrEndOfDay === 'start' ? '00:00' : '23:59'
|
|
264
|
+
|
|
265
|
+
return `${fullDate} ${fullTime}`
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
getLocalizedTime(dateTimeString: string) {
|
|
269
|
+
// Though only displaying time, the exact date is needed, because otherwise time will be displayed
|
|
270
|
+
// incorrectly on days when daylight saving time changes
|
|
271
|
+
const {
|
|
272
|
+
year,
|
|
273
|
+
month,
|
|
274
|
+
date,
|
|
275
|
+
hour,
|
|
276
|
+
minutes,
|
|
277
|
+
} = this.getAllVariablesFromDateTimeString(dateTimeString)
|
|
278
|
+
const d = new Date(year, month, date, hour, minutes)
|
|
279
|
+
|
|
280
|
+
return d.toLocaleTimeString(this.CALENDAR_LOCALE, {
|
|
281
|
+
hour: 'numeric',
|
|
282
|
+
minute: 'numeric',
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
getLocalizedHour(date: Date) {
|
|
287
|
+
return date.toLocaleTimeString(this.CALENDAR_LOCALE, { hour: '2-digit' })
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
getLocalizedTimeRange(start: string, end: string) {
|
|
291
|
+
return `${this.getLocalizedTime(start)} - ${this.getLocalizedTime(end)}`
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
/**
|
|
295
|
+
* Returns numeric values for year, month, date, hour and minutes, given a dateTimeString
|
|
296
|
+
* All variables are Date-Object compatible, meaning "month" is zero-indexed
|
|
297
|
+
*/
|
|
298
|
+
getAllVariablesFromDateTimeString(dateTimeString: string) {
|
|
299
|
+
return {
|
|
300
|
+
year: +dateTimeString.substring(0, 4),
|
|
301
|
+
month: +dateTimeString.substring(5, 7) - 1,
|
|
302
|
+
date: +dateTimeString.substring(8, 10),
|
|
303
|
+
hour: this.hourFrom(dateTimeString),
|
|
304
|
+
minutes: this.minutesFrom(dateTimeString),
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
dateIsToday(date: Date) {
|
|
309
|
+
const {
|
|
310
|
+
fullYear: yearToday,
|
|
311
|
+
month: monthToday,
|
|
312
|
+
date: dateToday,
|
|
313
|
+
} = new EDate()
|
|
314
|
+
const {
|
|
315
|
+
fullYear: dateYear,
|
|
316
|
+
month: dateMonth,
|
|
317
|
+
date: dateDate,
|
|
318
|
+
} = new EDate(date)
|
|
319
|
+
|
|
320
|
+
return (
|
|
321
|
+
yearToday === dateYear
|
|
322
|
+
&& monthToday === dateMonth
|
|
323
|
+
&& dateToday === dateDate
|
|
324
|
+
)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
dateIsInWeek(dateToCheck: Date, week: Date[]) {
|
|
328
|
+
const { date, month, fullYear } = new EDate(dateToCheck)
|
|
329
|
+
|
|
330
|
+
for (const weekDay of week) {
|
|
331
|
+
const dateIsSame = date === weekDay.getDate()
|
|
332
|
+
const monthIsSame = month === weekDay.getMonth()
|
|
333
|
+
const yearIsSame = fullYear === weekDay.getFullYear()
|
|
334
|
+
|
|
335
|
+
if (dateIsSame && monthIsSame && yearIsSame) return true
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
return false
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
getDateStringFromDate(date: Date) {
|
|
342
|
+
const yyyy = date.getFullYear()
|
|
343
|
+
const mm = (date.getMonth() + 1)
|
|
344
|
+
const dd = date.getDate()
|
|
345
|
+
|
|
346
|
+
return `${yyyy}-${mm >= 10 ? mm : `0${mm}`}-${dd >= 10 ? dd : `0${dd}`}`
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
addMinutesToDateTimeString(minutes: number, dateTimeString: string) {
|
|
350
|
+
const {
|
|
351
|
+
year: oldYear,
|
|
352
|
+
month: oldMonth,
|
|
353
|
+
date: oldDate,
|
|
354
|
+
hour: oldHour,
|
|
355
|
+
minutes: oldMinutes
|
|
356
|
+
} = this.getAllVariablesFromDateTimeString(dateTimeString)
|
|
357
|
+
|
|
358
|
+
const oldDateObject = new Date(oldYear, oldMonth, oldDate, oldHour, oldMinutes)
|
|
359
|
+
const newDateObject = new Date(oldDateObject.getTime() + (minutes * 60000))
|
|
360
|
+
|
|
361
|
+
return this.getDateTimeStringFromDate(newDateObject)
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
addDaysToDateTimeString(days: number, dateTimeString: string) {
|
|
365
|
+
return this.addMinutesToDateTimeString((days * 1440), dateTimeString)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
dateStringsHaveEqualDates(dateTimeString1: string, dateTimeString2: string) {
|
|
369
|
+
const { year: year1, month: month1, date: date1 } = this.getAllVariablesFromDateTimeString(dateTimeString1)
|
|
370
|
+
const { year: year2, month: month2, date: date2 } = this.getAllVariablesFromDateTimeString(dateTimeString2)
|
|
371
|
+
|
|
372
|
+
return (year1 === year2) && (month1 === month2) && (date1 === date2)
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
setDateToEndOfDay(date: Date) {
|
|
376
|
+
return new Date(
|
|
377
|
+
date.getFullYear(),
|
|
378
|
+
date.getMonth(),
|
|
379
|
+
date.getDate(),
|
|
380
|
+
23,
|
|
381
|
+
59,
|
|
382
|
+
59,
|
|
383
|
+
999
|
|
384
|
+
)
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
protected turnMinutesIntoPercentageOfHour(minutes: number): string {
|
|
388
|
+
const oneMinutePercentage = 100 / 60
|
|
389
|
+
const minutePoints = oneMinutePercentage * minutes
|
|
390
|
+
|
|
391
|
+
if (minutePoints < 10) return `0${minutePoints}`
|
|
392
|
+
|
|
393
|
+
return minutePoints.toString()
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
/**
|
|
397
|
+
* Every hour between 'dayStart' and 'dayEnd' is 100, in this function referred to as 100 points
|
|
398
|
+
* If an event starts 30 minutes after 'dayStart', it should have 50 pointsIntoDay
|
|
399
|
+
* If a day consists of 4 hours (400 points), we then have to count
|
|
400
|
+
* (50 / 400) * 100 = 12.5 => event starts after 12.5 percent of the day
|
|
401
|
+
*
|
|
402
|
+
* Result is supposed to be a number between 0 and 100, and is used for setting the CSS- top- and height-attributes for events
|
|
403
|
+
*/
|
|
404
|
+
getPercentageOfDayFromDateTimeString(
|
|
405
|
+
dateTimeString: string,
|
|
406
|
+
dayStart: number,
|
|
407
|
+
dayEnd: number,
|
|
408
|
+
) {
|
|
409
|
+
const hour = this.hourFrom(dateTimeString)
|
|
410
|
+
const hourPoints = hour * 100
|
|
411
|
+
const minutes = +dateTimeString.substring(14, 16)
|
|
412
|
+
const minutesPoints = +this.turnMinutesIntoPercentageOfHour(+minutes)
|
|
413
|
+
|
|
414
|
+
if (dayEnd > dayStart) {
|
|
415
|
+
const pointsInDay = dayEnd - dayStart
|
|
416
|
+
const eventPoints = hourPoints + minutesPoints
|
|
417
|
+
const eventPointsIntoDay = eventPoints - dayStart
|
|
418
|
+
|
|
419
|
+
return (eventPointsIntoDay / pointsInDay) * 100
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
const hourPointsInOriginalDay = DAY_TIME_POINT.TWELVE_AM - dayStart
|
|
423
|
+
const pointsInDay = hourPointsInOriginalDay + dayEnd
|
|
424
|
+
const eventPoints = hourPoints + minutesPoints
|
|
425
|
+
const pointsIntoDay = eventPoints >= dayStart ? eventPoints - dayStart : hourPointsInOriginalDay + eventPoints
|
|
426
|
+
|
|
427
|
+
return (pointsIntoDay / pointsInDay) * 100
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
getTimeFromClick(
|
|
431
|
+
clickOffsetY: number,
|
|
432
|
+
weekHeight: number,
|
|
433
|
+
): string {
|
|
434
|
+
if (weekHeight <= 0) throw new Error('weekHeight cannot be a negative number')
|
|
435
|
+
if (clickOffsetY < 0) throw new Error('clickOffsetY cannot be a negative number')
|
|
436
|
+
|
|
437
|
+
const dayStartHour = this.DAY_START / 100
|
|
438
|
+
const hourHeight = weekHeight / this.HOURS_PER_DAY
|
|
439
|
+
const minutes = Math.floor((clickOffsetY % hourHeight) / (hourHeight / 60))
|
|
440
|
+
|
|
441
|
+
if (this.DAY_END <= this.DAY_START) {
|
|
442
|
+
const dayEndHour = this.DAY_END / 100
|
|
443
|
+
const nightHeight = (dayEndHour) * hourHeight
|
|
444
|
+
const nightOffset = weekHeight - nightHeight
|
|
445
|
+
|
|
446
|
+
if (clickOffsetY > nightOffset) {
|
|
447
|
+
const hour = Math.floor((clickOffsetY - nightOffset) / hourHeight)
|
|
448
|
+
return `${this.doubleDigit(hour)}:${this.doubleDigit(minutes)}`
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const hour = Math.floor(clickOffsetY / hourHeight) + dayStartHour
|
|
453
|
+
|
|
454
|
+
return `${this.doubleDigit(hour)}:${this.doubleDigit(minutes)}`
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
setSegmentOfDateTimeString(dateTimeString: string, segments: { hour: number }) {
|
|
458
|
+
if (segments.hour < 0 || segments.hour > 23) throw new Error('Invalid hour')
|
|
459
|
+
const newHour = this.doubleDigit(segments.hour)
|
|
460
|
+
dateTimeString = dateTimeString.replace(/\d{2}:/, `${newHour}:`)
|
|
461
|
+
|
|
462
|
+
return dateTimeString
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
isTrailingOrLeadingDate(date: Date, month: number) {
|
|
466
|
+
const { month: dateMonth } = new EDate(date)
|
|
467
|
+
|
|
468
|
+
return month !== dateMonth
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
static getTimePointsFromHour(boundary: number) {
|
|
472
|
+
if (boundary < 0 || boundary > 24 || boundary % 1 !== 0) {
|
|
473
|
+
throw new Error('Invalid day boundary')
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
if (boundary === 0) return boundary
|
|
477
|
+
|
|
478
|
+
return boundary * 100
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
static getHourFromTimePoints(timePoints: number) {
|
|
482
|
+
if (timePoints < 0 || timePoints > 2400 || timePoints % 100 !== 0) {
|
|
483
|
+
throw new Error('Invalid time points')
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
if (timePoints === 0) return timePoints
|
|
487
|
+
|
|
488
|
+
return timePoints / 100
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
getTimelineHours(): DAY_TIME_POINT[] {
|
|
492
|
+
if (this.dayMode !== DAY_MODE.FLEXIBLE) {
|
|
493
|
+
return this.ALL_HOURS.filter((hour) => {
|
|
494
|
+
return hour >= this.DAY_START && hour < this.DAY_END
|
|
495
|
+
})
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
return [
|
|
499
|
+
...this.ALL_HOURS.filter(hour => hour >= this.DAY_START),
|
|
500
|
+
...this.ALL_HOURS.filter(hour => hour < this.DAY_END)
|
|
501
|
+
]
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
dateStringFrom(dateTimeString: string) {
|
|
505
|
+
return dateTimeString.substring(0, 10)
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
timeStringFrom(dateTimeString: string) {
|
|
509
|
+
return dateTimeString.substring(11, 16)
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
hourFrom(dateTimeString: string) {
|
|
513
|
+
return +dateTimeString.substring(11, 13)
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
minutesFrom(dateTimeString: string) {
|
|
517
|
+
return +dateTimeString.substring(14, 16)
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
areDaysConsecutive(dayOne: string, dayTwo: string) {
|
|
521
|
+
const dayOnePlusOneDay = this.dateStringFrom(this.addDaysToDateTimeString(1, dayOne))
|
|
522
|
+
|
|
523
|
+
return dayOnePlusOneDay === this.dateStringFrom(dayTwo)
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
setHourInDateTimeString(dateTimeString: string, hour: number) {
|
|
527
|
+
const hourString = this.doubleDigit(hour)
|
|
528
|
+
dateTimeString = dateTimeString.replace(/\d{2}:/, `${hourString}:`)
|
|
529
|
+
|
|
530
|
+
return dateTimeString
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
setMinutesInDateTimeString(dateTimeString: string, minutes: number) {
|
|
534
|
+
const minutesString = this.doubleDigit(minutes)
|
|
535
|
+
dateTimeString = dateTimeString.replace(/:\d{2}/, `:${minutesString}`)
|
|
536
|
+
|
|
537
|
+
return dateTimeString
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
getDateTimeStringDayBoundariesFrom(dateString: string): { start: string, end: string } {
|
|
541
|
+
if (this.DAY_END <= this.DAY_START) {
|
|
542
|
+
const nextDay = this.addDaysToDateTimeString(1, dateString)
|
|
543
|
+
const endOfDay = this.setHourInDateTimeString(nextDay, this.getHourAndMinutesFromTimePoints(this.DAY_END).hour)
|
|
544
|
+
const startOfDay = this.setHourInDateTimeString(dateString, this.getHourAndMinutesFromTimePoints(this.DAY_START).hour)
|
|
545
|
+
|
|
546
|
+
return { start: startOfDay, end: endOfDay }
|
|
547
|
+
}
|
|
548
|
+
|
|
549
|
+
const startOfDay = this.setHourInDateTimeString(dateString, this.getHourAndMinutesFromTimePoints(this.DAY_START).hour)
|
|
550
|
+
let endOfDay
|
|
551
|
+
if (this.DAY_END === DAY_TIME_POINT.TWELVE_AM) {
|
|
552
|
+
endOfDay = this.setHourInDateTimeString(dateString, 23)
|
|
553
|
+
endOfDay = this.setMinutesInDateTimeString(endOfDay, 59)
|
|
554
|
+
} else {
|
|
555
|
+
endOfDay = this.setHourInDateTimeString(dateString, this.getHourAndMinutesFromTimePoints(this.DAY_END).hour)
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
return { start: startOfDay, end: endOfDay }
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
doubleDigit(number: number) {
|
|
562
|
+
if (number < 0 || number > 60) throw new Error('Invalid number. This is not a valid hour or minute')
|
|
563
|
+
|
|
564
|
+
return number < 10 ? `0${number}` : String(number)
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
export class TimeBuilder {
|
|
569
|
+
private weekStartsOn: WEEK_START_DAY = WEEK_START_DAY.MONDAY
|
|
570
|
+
private locale: string | null = null
|
|
571
|
+
private dayBoundaries: { start: DAY_TIME_POINT, end: DAY_TIME_POINT } = { start: 0, end: 2400 }
|
|
572
|
+
|
|
573
|
+
build() {
|
|
574
|
+
return new Time(this.weekStartsOn, this.locale, this.dayBoundaries)
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
withDayBoundaries(dayBoundaries: { start: DAY_TIME_POINT, end: DAY_TIME_POINT }) {
|
|
578
|
+
this.dayBoundaries = dayBoundaries
|
|
579
|
+
|
|
580
|
+
return this
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
withLocale(locale: string) {
|
|
584
|
+
this.locale = locale
|
|
585
|
+
|
|
586
|
+
return this
|
|
587
|
+
}
|
|
588
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import type { EventInterface } from '../typings/interfaces/event.interface'
|
|
2
|
+
import { DAY_MODE } from '../typings/interfaces/time-modes'
|
|
3
|
+
import Helpers from './Helpers'
|
|
4
|
+
import Time from './Time'
|
|
5
|
+
|
|
6
|
+
export class WeekHelper {
|
|
7
|
+
public static getNHoursIntoDayFromHour(hour: number, timeInstance: Time): number {
|
|
8
|
+
const dayStartHour = Time.getHourFromTimePoints(timeInstance.DAY_START)
|
|
9
|
+
|
|
10
|
+
if (timeInstance.dayMode === DAY_MODE.REGULAR) return hour
|
|
11
|
+
|
|
12
|
+
if (
|
|
13
|
+
timeInstance.dayMode === DAY_MODE.SHORTENED
|
|
14
|
+
|| (timeInstance.dayMode === DAY_MODE.FLEXIBLE && hour >= dayStartHour)
|
|
15
|
+
) {
|
|
16
|
+
return hour - dayStartHour
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
return (24 - dayStartHour) + hour
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
public static eventSeparator(events: EventInterface[], time: Time) {
|
|
23
|
+
const singleDayTimedEvents: EventInterface[] = []
|
|
24
|
+
const fullDayAndMultipleDayEvents: EventInterface[] = []
|
|
25
|
+
|
|
26
|
+
for (const scheduleEvent of events) {
|
|
27
|
+
const eventType = Helpers.getEventType(scheduleEvent, time)
|
|
28
|
+
if (['SINGLE_DAY_TIMED', 'SINGLE_HYBRID_DAY_TIMED'].includes(eventType)) {
|
|
29
|
+
singleDayTimedEvents.push(scheduleEvent)
|
|
30
|
+
} else {
|
|
31
|
+
fullDayAndMultipleDayEvents.push(scheduleEvent)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return { fullDayAndMultipleDayEvents, singleDayTimedEvents }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { languageKeys } from './keys'
|
|
2
|
+
|
|
3
|
+
export const localeMap = new Map<string, string>([
|
|
4
|
+
['de', 'de-DE'],
|
|
5
|
+
['en', 'en-US'],
|
|
6
|
+
['it', 'it-IT'],
|
|
7
|
+
['sv', 'sv-SE'],
|
|
8
|
+
['zh', 'zh-CN'],
|
|
9
|
+
['pt', 'pt-BR'],
|
|
10
|
+
['fr', 'fr-FR'],
|
|
11
|
+
['th', 'th-TH'],
|
|
12
|
+
['nl', 'nl-NL'],
|
|
13
|
+
['ru', 'ru-RU'],
|
|
14
|
+
['ar', 'ar-YE'],
|
|
15
|
+
['es', 'es-ES'],
|
|
16
|
+
['ja', 'ja-JP'],
|
|
17
|
+
['pl', 'pl-PL'],
|
|
18
|
+
['hu', 'hu-HU'],
|
|
19
|
+
])
|
|
20
|
+
|
|
21
|
+
export function overrideShortLocaleWithLongLocale(locale: string): string {
|
|
22
|
+
if (localeMap.has(locale)) {
|
|
23
|
+
locale = localeMap.get(locale) as string
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return locale
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export function getLanguage(languageKeys: any, locale: string) {
|
|
30
|
+
locale = overrideShortLocaleWithLongLocale(locale)
|
|
31
|
+
|
|
32
|
+
return languageKeys[locale]
|
|
33
|
+
? languageKeys[locale]
|
|
34
|
+
: languageKeys['en-US']
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export { languageKeys }
|