@eventconnectors/ndtrc_model 1.0.0 → 1.0.2
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/package.json +2 -2
- package/src/model/ndtrc/Calendar.js +211 -202
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@eventconnectors/ndtrc_model",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.2",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"test": "jest"
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"xmlbuilder": "^15.1.1"
|
|
12
12
|
},
|
|
13
13
|
"devDependencies": {
|
|
14
|
-
"jest": "^29.
|
|
14
|
+
"jest": "^29.7.0"
|
|
15
15
|
},
|
|
16
16
|
"private": false,
|
|
17
17
|
"author": "wwwappz",
|
|
@@ -1,240 +1,249 @@
|
|
|
1
1
|
// Calendar.js
|
|
2
2
|
|
|
3
|
-
const moment = require(
|
|
3
|
+
const moment = require("moment");
|
|
4
4
|
|
|
5
5
|
class Calendar {
|
|
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
|
-
}
|
|
6
|
+
constructor() {
|
|
7
|
+
this.singleDates = [];
|
|
8
|
+
this.patternDates = [];
|
|
9
|
+
|
|
10
|
+
this.opens = [];
|
|
11
|
+
this.closeds = [];
|
|
12
|
+
this.soldouts = [];
|
|
13
|
+
this.cancelleds = [];
|
|
14
|
+
|
|
15
|
+
this.excludeholidays = false;
|
|
16
|
+
this.cancelled = false;
|
|
17
|
+
this.soldout = false;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static CalendarType = {
|
|
21
|
+
NONE: "NONE",
|
|
22
|
+
ALWAYSOPEN: "ALWAYSOPEN",
|
|
23
|
+
ONREQUEST: "ONREQUEST",
|
|
24
|
+
OPENINGTIMES: "OPENINGTIMES",
|
|
25
|
+
PATTERNDATES: "PATTERNDATES",
|
|
26
|
+
SINGLEDATES: "SINGLEDATES",
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
cleanupData() {
|
|
30
|
+
this.singleDates.forEach((singleDate) => {
|
|
31
|
+
if (singleDate.when) {
|
|
32
|
+
singleDate.when = singleDate.when.filter((when) => when.isValid());
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
this.patternDates.forEach((patternDate) => {
|
|
37
|
+
patternDate.opens.forEach((open) => {
|
|
38
|
+
open.whens = open.whens.filter((when) => when.isValid());
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
if (patternDate.opens.length && !patternDate.recurrencyType) {
|
|
42
|
+
patternDate.recurrencyType = PatternDate.RecurrencyType.WEEKLY;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
["opens", "closeds", "cancelleds", "soldouts"].forEach((prop) => {
|
|
47
|
+
this[prop].forEach((exceptionDate) => {
|
|
48
|
+
exceptionDate.whens = exceptionDate.whens.filter((when) =>
|
|
49
|
+
when.isValid()
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
determineCalendarType() {
|
|
56
|
+
if (this.calendarType !== null) return;
|
|
57
|
+
|
|
58
|
+
if (this.alwaysopen) {
|
|
59
|
+
this.calendarType = Calendar.CalendarType.ALWAYSOPEN;
|
|
60
|
+
} else if (this.onrequest) {
|
|
61
|
+
this.calendarType = Calendar.CalendarType.ONREQUEST;
|
|
62
|
+
} else if (this.singleDates.length > 0) {
|
|
63
|
+
this.calendarType = Calendar.CalendarType.SINGLEDATES;
|
|
64
|
+
} else if (this.patternDates.length > 0) {
|
|
65
|
+
const firstPattern = this.patternDates[0];
|
|
66
|
+
if (!firstPattern.enddate && !firstPattern.startdate) {
|
|
67
|
+
this.calendarType = Calendar.CalendarType.OPENINGTIMES;
|
|
68
|
+
} else {
|
|
69
|
+
this.calendarType = Calendar.CalendarType.PATTERNDATES;
|
|
70
|
+
}
|
|
71
|
+
} else {
|
|
72
|
+
this.calendarType = Calendar.CalendarType.NONE;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
class SingleDate {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
constructor(date = null, when = []) {
|
|
79
|
+
this.date = date ? moment(date) : null;
|
|
80
|
+
this.when = when;
|
|
81
|
+
}
|
|
81
82
|
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
83
|
+
equals(other) {
|
|
84
|
+
if (this === other) return true;
|
|
85
|
+
if (!(other instanceof SingleDate)) return false;
|
|
85
86
|
|
|
86
|
-
|
|
87
|
-
|
|
87
|
+
if (!this.date.isSame(other.date)) return false;
|
|
88
|
+
if (this.when.length !== other.when.length) return false;
|
|
88
89
|
|
|
89
|
-
|
|
90
|
-
|
|
90
|
+
return this.when.every((when, index) => when.equals(other.when[index]));
|
|
91
|
+
}
|
|
91
92
|
}
|
|
92
93
|
|
|
93
94
|
class PatternDate {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
95
|
+
constructor() {
|
|
96
|
+
this.startdate = null;
|
|
97
|
+
this.enddate = null;
|
|
98
|
+
this.recurrencyType = null;
|
|
99
|
+
|
|
100
|
+
this.occurrence = null;
|
|
101
|
+
this.recurrence = null;
|
|
102
|
+
this.opens = [];
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
static RecurrencyType = {
|
|
106
|
+
DAILY: "daily",
|
|
107
|
+
WEEKLY: "weekly",
|
|
108
|
+
MONTHLY_SIMPLE: "monthlySimple",
|
|
109
|
+
MONTHLY_COMPLEX: "monthlyComplex",
|
|
110
|
+
YEARLY: "yearly",
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
equals(other) {
|
|
114
|
+
if (this === other) return true;
|
|
115
|
+
if (!(other instanceof PatternDate)) return false;
|
|
116
|
+
|
|
117
|
+
const datesEqual =
|
|
118
|
+
(!this.startdate && !other.startdate) ||
|
|
119
|
+
this.startdate.isSame(other.startdate);
|
|
120
|
+
const endDatesEqual =
|
|
121
|
+
(!this.enddate && !other.enddate) || this.enddate.isSame(other.enddate);
|
|
122
|
+
|
|
123
|
+
return (
|
|
124
|
+
datesEqual &&
|
|
125
|
+
endDatesEqual &&
|
|
126
|
+
this.recurrencyType === other.recurrencyType &&
|
|
127
|
+
this.occurrence === other.occurrence &&
|
|
128
|
+
this.recurrence === other.recurrence &&
|
|
129
|
+
this.opensEquals(other.opens)
|
|
130
|
+
);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
opensEquals(otherOpens) {
|
|
134
|
+
if (this.opens.length !== otherOpens.length) return false;
|
|
135
|
+
return this.opens.every((open, index) => open.equals(otherOpens[index]));
|
|
136
|
+
}
|
|
131
137
|
}
|
|
132
138
|
|
|
133
139
|
class Open {
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
140
|
+
constructor() {
|
|
141
|
+
this.month = null;
|
|
142
|
+
this.weeknumber = null;
|
|
143
|
+
this.daynumber = null;
|
|
144
|
+
this.day = null;
|
|
145
|
+
this.whens = [];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
equals(other) {
|
|
149
|
+
if (this === other) return true;
|
|
150
|
+
if (!(other instanceof Open)) return false;
|
|
151
|
+
|
|
152
|
+
return (
|
|
153
|
+
this.month === other.month &&
|
|
154
|
+
this.weeknumber === other.weeknumber &&
|
|
155
|
+
this.daynumber === other.daynumber &&
|
|
156
|
+
this.day === other.day &&
|
|
157
|
+
this.whensEquals(other.whens)
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
whensEquals(otherWhens) {
|
|
162
|
+
if (this.whens.length !== otherWhens.length) return false;
|
|
163
|
+
return this.whens.every((when, index) => when.equals(otherWhens[index]));
|
|
164
|
+
}
|
|
157
165
|
}
|
|
158
166
|
|
|
159
167
|
class When {
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
168
|
+
constructor(timestart = null, timeend = null, status = null, valid=null) {
|
|
169
|
+
this.timestart = timestart;
|
|
170
|
+
this.valid = valid;
|
|
171
|
+
this.timeend = timeend;
|
|
172
|
+
this.status = status;
|
|
173
|
+
this.statustranslations = [];
|
|
174
|
+
this.extrainformations = [];
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
equals(other) {
|
|
178
|
+
if (this === other) return true;
|
|
179
|
+
if (!(other instanceof When)) return false;
|
|
180
|
+
|
|
181
|
+
return this.timestart === other.timestart && this.timeend === other.timeend;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
isValid() {
|
|
185
|
+
return this.isTimeValid(this.timestart) || this.isTimeValid(this.timeend);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
isTimeValid(time) {
|
|
189
|
+
return time && time.trim().length > 0;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
static Status = {
|
|
193
|
+
NORMAL: "normal",
|
|
194
|
+
CANCELLED: "cancelled",
|
|
195
|
+
SOLDOUT: "soldout",
|
|
196
|
+
MOVEDTO: "movedto",
|
|
197
|
+
PREMIERE: "premiere",
|
|
198
|
+
REPRISE: "reprise",
|
|
199
|
+
};
|
|
191
200
|
}
|
|
192
201
|
|
|
193
202
|
class StatusTranslation {
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
203
|
+
constructor(lang = null, text = null) {
|
|
204
|
+
this.lang = lang;
|
|
205
|
+
this.text = text;
|
|
206
|
+
}
|
|
198
207
|
}
|
|
199
208
|
|
|
200
209
|
class ExtraInformation {
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
210
|
+
constructor(lang = null, text = null) {
|
|
211
|
+
this.lang = lang;
|
|
212
|
+
this.text = text;
|
|
213
|
+
}
|
|
205
214
|
}
|
|
206
215
|
|
|
207
216
|
class ExceptionDate {
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
217
|
+
constructor(date = null, whens = []) {
|
|
218
|
+
this.date = date ? moment(date) : null;
|
|
219
|
+
this.whens = whens;
|
|
220
|
+
}
|
|
212
221
|
}
|
|
213
222
|
|
|
214
223
|
class Comment {
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
224
|
+
constructor(label = null, commentTranslations = []) {
|
|
225
|
+
this.label = label;
|
|
226
|
+
this.commentTranslations = commentTranslations;
|
|
227
|
+
}
|
|
219
228
|
}
|
|
220
229
|
|
|
221
230
|
class CommentTranslation {
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
231
|
+
constructor(label = null, lang = null) {
|
|
232
|
+
this.label = label;
|
|
233
|
+
this.lang = lang;
|
|
234
|
+
}
|
|
226
235
|
}
|
|
227
236
|
|
|
228
237
|
// Export the classes
|
|
229
238
|
module.exports = {
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
};
|
|
239
|
+
Calendar,
|
|
240
|
+
SingleDate,
|
|
241
|
+
PatternDate,
|
|
242
|
+
Open,
|
|
243
|
+
When,
|
|
244
|
+
StatusTranslation,
|
|
245
|
+
ExtraInformation,
|
|
246
|
+
ExceptionDate,
|
|
247
|
+
Comment,
|
|
248
|
+
CommentTranslation,
|
|
249
|
+
};
|