btrz-liquid-templates 1.0.0
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/LICENSE +21 -0
- package/README.md +2 -0
- package/package.json +40 -0
- package/src/barcode.js +57 -0
- package/src/dateFormat.js +560 -0
- package/src/escp.js +133 -0
- package/src/html.js +97 -0
- package/src/httpimg.js +34 -0
- package/src/index.js +121 -0
- package/src/lines.js +40 -0
- package/src/localizer.js +25 -0
- package/src/money.js +195 -0
- package/src/object.js +11 -0
- package/src/qrstr.js +36 -0
- package/src/text.js +35 -0
- package/src/toletters.js +37 -0
- package/test/index-test.js +731 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Betterez
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "btrz-liquid-templates",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Extension and helpers for liquid templates to deal with our data and other things we need to encapsulate",
|
|
5
|
+
"main": "src/index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"tdd": "mocha --recursive test/ -w",
|
|
8
|
+
"test": "mocha --recursive test/",
|
|
9
|
+
"preversion": "npm test",
|
|
10
|
+
"postversion": "git push origin main && git push --tags",
|
|
11
|
+
"version": "git tag $1"
|
|
12
|
+
},
|
|
13
|
+
"repository": {
|
|
14
|
+
"type": "git",
|
|
15
|
+
"url": "git+https://github.com/Betterez/btrz-liquid-templates.git"
|
|
16
|
+
},
|
|
17
|
+
"author": "",
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/Betterez/btrz-liquid-templates/issues"
|
|
21
|
+
},
|
|
22
|
+
"homepage": "https://github.com/Betterez/btrz-liquid-templates#readme",
|
|
23
|
+
"dependencies": {
|
|
24
|
+
"axios": "^0.27.2",
|
|
25
|
+
"btrz-formatter": "1.3.0",
|
|
26
|
+
"bz-date": "1.3.0",
|
|
27
|
+
"liquidjs": "^10.9.2",
|
|
28
|
+
"moment": "^2.29.4",
|
|
29
|
+
"moment-timezone": "^0.5.43",
|
|
30
|
+
"symbology": "^4.0.1",
|
|
31
|
+
"written-number": "^0.11.1"
|
|
32
|
+
},
|
|
33
|
+
"devDependencies": {
|
|
34
|
+
"browserify": "^17.0.0",
|
|
35
|
+
"chai": "4.3.10",
|
|
36
|
+
"mocha": "10.2.0",
|
|
37
|
+
"tinyify": "4.0.0"
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
|
package/src/barcode.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
const {SymbologyType, createStream, OutputType} = require("symbology");
|
|
2
|
+
|
|
3
|
+
function getCode(code) {
|
|
4
|
+
return SymbologyType[code.toUpperCase()];
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
function Barcode(engine) {
|
|
8
|
+
this.registerTag("barcode", {
|
|
9
|
+
parse: function(tagToken, remainTokens) {
|
|
10
|
+
try {
|
|
11
|
+
const args = (tagToken.args || "").split(" ");
|
|
12
|
+
this.content = args[0] || "not-content-given";
|
|
13
|
+
this.type = args[1] || "code128";
|
|
14
|
+
this.height = args[2] || 30;
|
|
15
|
+
this.width = args[3] || 200;
|
|
16
|
+
this.margin = args[4] || "0,0,0,0";
|
|
17
|
+
} catch (err) {
|
|
18
|
+
this.content = "not-content-given";
|
|
19
|
+
this.type = "code128";
|
|
20
|
+
this.height = 30;
|
|
21
|
+
this.width = args[3] || 200;
|
|
22
|
+
this.margin = args[4] || "0,0,0,0";
|
|
23
|
+
}
|
|
24
|
+
},
|
|
25
|
+
render: async function(ctx) {
|
|
26
|
+
let content = await this.liquid.evalValue(this.content, ctx) || this.content;
|
|
27
|
+
let result = await createStream({
|
|
28
|
+
symbology: getCode(this.type),
|
|
29
|
+
height: this.height,
|
|
30
|
+
showHumanReadableText: false,
|
|
31
|
+
scale: 2.0,
|
|
32
|
+
}, String(content), OutputType.PNG);
|
|
33
|
+
let margin = [0,0,0,0];
|
|
34
|
+
try {
|
|
35
|
+
margin = this.margin.split(",").map((i) => {
|
|
36
|
+
return parseInt(i,10);
|
|
37
|
+
});
|
|
38
|
+
if (margin.length !== 4) {
|
|
39
|
+
margin = [0,0,0,0];
|
|
40
|
+
}
|
|
41
|
+
} catch (err) {
|
|
42
|
+
console.log("ERROR:", err);
|
|
43
|
+
margin = [0,0,0,0];
|
|
44
|
+
}
|
|
45
|
+
return `{
|
|
46
|
+
"image": "${result.data}",
|
|
47
|
+
"width": ${this.width || 200},
|
|
48
|
+
"margin": [${margin.join(",")}]
|
|
49
|
+
}`;
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
module.exports = {
|
|
55
|
+
Barcode
|
|
56
|
+
};
|
|
57
|
+
|
|
@@ -0,0 +1,560 @@
|
|
|
1
|
+
const {timezones, BzDate} = require("bz-date");
|
|
2
|
+
const formatter = require("btrz-formatter");
|
|
3
|
+
const moment = require("moment");
|
|
4
|
+
require("moment-timezone");
|
|
5
|
+
function shortLang(lang) {
|
|
6
|
+
let result = "en";
|
|
7
|
+
if (lang && lang.substring) {
|
|
8
|
+
result = lang.substring(0, 2);
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
function getFriendlyFormat(humanDate) {
|
|
13
|
+
return (humanDate === "mm") ? "ddd mmm dd, yyyy" : "ddd dd mmm, yyyy"
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function formatBzDate(bzDate, format, envs) {
|
|
17
|
+
const lang = shortLang(envs.lang);
|
|
18
|
+
const timeFormat = envs.providerPreferences.preferences.timeFormat;
|
|
19
|
+
const timeZone = envs.providerPreferences.preferences.timeZone;
|
|
20
|
+
const offset = timezones.getOffset(timeZone, bzDate);
|
|
21
|
+
const createdLocal = bzDate.addMinutes(offset);
|
|
22
|
+
return `${formatter.dateFormat(createdLocal.toString(`'yyyy-mm-dd' ${timeFormat}`), `${format}`, false, lang)}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function formatMoment(date, format, envs, applyTimeZone) {
|
|
26
|
+
const lang = shortLang(envs.lang);
|
|
27
|
+
const timeFormat = envs.providerPreferences.preferences.timeFormat;
|
|
28
|
+
const timeZone = envs.providerPreferences.preferences.timeZone;
|
|
29
|
+
const timeFormatCompatibleWithMomentJS = timeFormat.replace("TT", "A").replace(/M/g, "m");
|
|
30
|
+
let strDate = "";
|
|
31
|
+
if (applyTimeZone) {
|
|
32
|
+
strDate = moment(date).tz(timeZone.tz)
|
|
33
|
+
.format(`'YYYY-MM-DD' ${timeFormatCompatibleWithMomentJS}`);
|
|
34
|
+
} else {
|
|
35
|
+
strDate = moment(date)
|
|
36
|
+
.format(`'YYYY-MM-DD' ${timeFormatCompatibleWithMomentJS}`);
|
|
37
|
+
}
|
|
38
|
+
return `${formatter.dateFormat(strDate, `${format}`, false, lang)}`;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function formatBzDate2(bzDate, format, envs) {
|
|
42
|
+
const lang = shortLang(envs.lang);
|
|
43
|
+
const timeFormat = envs.providerPreferences.preferences.timeFormat;
|
|
44
|
+
return `${formatter.dateFormat(bzDate.toString(`'yyyy-mm-dd' ${timeFormat}`), `${format}`, false, lang)}`;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function getDate(envs, item, propName, format, applyTimeZone) {
|
|
48
|
+
let dateObjOrString = null;
|
|
49
|
+
if (item[propName]) {
|
|
50
|
+
dateObjOrString = item[propName];
|
|
51
|
+
} else {
|
|
52
|
+
dateObjOrString = envs[item][propName];
|
|
53
|
+
}
|
|
54
|
+
if (dateObjOrString && dateObjOrString.toUpperCase) {
|
|
55
|
+
return formatMoment(dateObjOrString, format, envs, applyTimeZone);
|
|
56
|
+
}
|
|
57
|
+
const date = new BzDate(dateObjOrString);
|
|
58
|
+
if (applyTimeZone == false) {
|
|
59
|
+
return formatBzDate2(date, format, envs);
|
|
60
|
+
}
|
|
61
|
+
return formatBzDate(date, format, envs);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function getTimeFromString(timeString, format) {
|
|
65
|
+
return formatter.timeFormat(timeString, format);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
function HumanDateTime(engine) {
|
|
69
|
+
this.registerTag("humanDateTime", {
|
|
70
|
+
parse: function(tagToken, remainTokens) {
|
|
71
|
+
const args = tagToken.args.split(" ");
|
|
72
|
+
this.item = args[0] || "ticket";
|
|
73
|
+
this.propName = args[1] || "createdAt";
|
|
74
|
+
this.applyTimeZone = true;
|
|
75
|
+
if (args.length > 2) {
|
|
76
|
+
this.applyTimeZone = args[2] === "true"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
render: async function(ctx) {
|
|
80
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
81
|
+
ctx.environments[this.item] && ctx.environments[this.item][this.propName]) {
|
|
82
|
+
const format = `${getFriendlyFormat(ctx.environments.humanDate || "mm")} ${ ctx.environments.providerPreferences.preferences.timeFormat}`;
|
|
83
|
+
return getDate(ctx.environments, this.item, this.propName, format, this.applyTimeZone);
|
|
84
|
+
}
|
|
85
|
+
return "PNA";
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function HumanDate(engine) {
|
|
91
|
+
this.registerTag("humanDate", {
|
|
92
|
+
parse: function(tagToken, remainTokens) {
|
|
93
|
+
const args = tagToken.args.split(" ");
|
|
94
|
+
this.item = args[0] || "ticket";
|
|
95
|
+
this.propName = args[1] || "createdAt";
|
|
96
|
+
this.applyTimeZone = true;
|
|
97
|
+
if (args.length > 2) {
|
|
98
|
+
this.applyTimeZone = args[2] === "true"
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
render: async function(ctx) {
|
|
102
|
+
|
|
103
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
104
|
+
ctx.environments[this.item] && ctx.environments[this.item][this.propName]) {
|
|
105
|
+
const format = getFriendlyFormat(ctx.environments.humanDate || "mm");
|
|
106
|
+
return getDate(ctx.environments, this.item, this.propName, format, this.applyTimeZone);
|
|
107
|
+
}
|
|
108
|
+
return "PNA";
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
async function getNameOrValue(itemName, propName, ctx, liquid) {
|
|
114
|
+
if (ctx.environments[itemName]) {
|
|
115
|
+
if (!ctx.environments[itemName][propName]) {
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return itemName;
|
|
119
|
+
}
|
|
120
|
+
const value = await liquid.evalValue(itemName, ctx);
|
|
121
|
+
if (!value || !value[propName]) {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function DateTime(engine) {
|
|
128
|
+
this.registerTag("dateTime", {
|
|
129
|
+
parse: function(tagToken, remainTokens) {
|
|
130
|
+
const args = tagToken.args.split(" ");
|
|
131
|
+
this.item = args[0] || "ticket";
|
|
132
|
+
this.propName = args[1] || "createdAt";
|
|
133
|
+
if (args.length > 2) {
|
|
134
|
+
this.format = args.slice(2).join(" ") || "";
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
render: async function(ctx) {
|
|
138
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences) {
|
|
139
|
+
const format = this.format || `${ctx.environments.providerPreferences.preferences.dateFormat} ${ctx.environments.providerPreferences.preferences.timeFormat}`;
|
|
140
|
+
const item = await getNameOrValue(this.item, this.propName, ctx, this.liquid);
|
|
141
|
+
if (item) {
|
|
142
|
+
return getDate(ctx.environments, item, this.propName, format);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return "PNA";
|
|
146
|
+
}
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
function DateF(engine) {
|
|
151
|
+
this.registerTag("dateF", {
|
|
152
|
+
parse: function(tagToken, remainTokens) {
|
|
153
|
+
const args = tagToken.args.split(" ");
|
|
154
|
+
this.item = args[0] || "ticket";
|
|
155
|
+
this.propName = args[1] || "createdAt";
|
|
156
|
+
this.applyTimeZone = true;
|
|
157
|
+
if (args.length > 2) {
|
|
158
|
+
this.applyTimeZone = args[2] === "true"
|
|
159
|
+
}
|
|
160
|
+
},
|
|
161
|
+
render: async function(ctx) {
|
|
162
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences) {
|
|
163
|
+
const format = ctx.environments.providerPreferences.preferences.dateFormat;
|
|
164
|
+
const item = await getNameOrValue(this.item, this.propName, ctx, this.liquid);
|
|
165
|
+
if (item) {
|
|
166
|
+
return getDate(ctx.environments, item, this.propName, format, this.applyTimeZone);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
return "PNA";
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function TimeF(engine) {
|
|
175
|
+
this.registerTag("timeF", {
|
|
176
|
+
parse: function(tagToken, remainTokens) {
|
|
177
|
+
const args = tagToken.args.split(" ");
|
|
178
|
+
this.item = args[0] || "ticket";
|
|
179
|
+
this.propName = args[1] || "createdAt";
|
|
180
|
+
this.applyTimeZone = true;
|
|
181
|
+
if (args.length > 2) {
|
|
182
|
+
this.applyTimeZone = args[2] === "true"
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
render: async function(ctx) {
|
|
186
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences) {
|
|
187
|
+
const format = ctx.environments.providerPreferences.preferences.timeFormat;
|
|
188
|
+
const item = await getNameOrValue(this.item, this.propName, ctx, this.liquid);
|
|
189
|
+
if (item) {
|
|
190
|
+
const dateObjOrString = item?.[this.propName] || ctx.environments[item]?.[this.propName];
|
|
191
|
+
// Keep this for compatibility with time format (HH:mm)
|
|
192
|
+
if (dateObjOrString.toUpperCase && dateObjOrString.indexOf("T") === -1) {
|
|
193
|
+
return getTimeFromString(dateObjOrString, format);
|
|
194
|
+
}
|
|
195
|
+
return getDate(ctx.environments, item, this.propName, format, this.applyTimeZone);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return "PNA";
|
|
199
|
+
}
|
|
200
|
+
});
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
function ExpDate(engine) {
|
|
204
|
+
this.registerTag("expDate", {
|
|
205
|
+
parse: function(tagToken, remainTokens) {
|
|
206
|
+
const args = tagToken.args.split(" ");
|
|
207
|
+
this.item = args[0] || "ticket";
|
|
208
|
+
if (args.length > 1) {
|
|
209
|
+
this.format = args.slice(2).join(" ") || "";
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
render: async function(ctx) {
|
|
213
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
214
|
+
ctx.environments[this.item] && ctx.environments[this.item].expirationDate) {
|
|
215
|
+
const item = ctx.environments[this.item];
|
|
216
|
+
let expireDate = new BzDate(item.expirationDate);
|
|
217
|
+
if (item.departureTime) {
|
|
218
|
+
const timeParts = item.departureTime.split(":");
|
|
219
|
+
expireDate.addHours(timeParts[0]);
|
|
220
|
+
expireDate.addMinutes(timeParts[1]);
|
|
221
|
+
}
|
|
222
|
+
if (item.expire && item.expire > 0) {
|
|
223
|
+
if (item.expireUnit === "minutes") {
|
|
224
|
+
expireDate = expireDate.addMinutes(item.expire);
|
|
225
|
+
} else {
|
|
226
|
+
expireDate = expireDate.addDays(item.expire);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
const format = this.format || `${ctx.environments.providerPreferences.preferences.dateFormat} ${ctx.environments.providerPreferences.preferences.timeFormat}`;
|
|
230
|
+
return formatBzDate2(expireDate, format, ctx.environments);
|
|
231
|
+
}
|
|
232
|
+
return "PNA";
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
function DepartureDateTime(engine) {
|
|
238
|
+
this.registerTag("departureDateTime", {
|
|
239
|
+
parse: function(tagToken, remainTokens) {
|
|
240
|
+
const args = tagToken.args.split(" ");
|
|
241
|
+
this.item = args[0] || "ticket";
|
|
242
|
+
this.applyTimeZone = true;
|
|
243
|
+
},
|
|
244
|
+
render: async function(ctx) {
|
|
245
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
246
|
+
ctx.environments[this.item] && ctx.environments[this.item].departureTimestamp && ctx.environments.fromStation) {
|
|
247
|
+
const dateFormat = ctx.environments.providerPreferences.preferences.dateFormat;
|
|
248
|
+
const timeFormat = ctx.environments.providerPreferences.preferences.timeFormat;
|
|
249
|
+
const originStationTimezone = ctx.environments.fromStation.timeZone
|
|
250
|
+
if (originStationTimezone) {
|
|
251
|
+
const lang = shortLang(ctx.environments.lang);
|
|
252
|
+
const date = moment(ctx.environments[this.item].departureTimestamp).tz(originStationTimezone).format("YYYY-MM-DD");
|
|
253
|
+
const time = moment(ctx.environments[this.item].departureTimestamp).tz(originStationTimezone).format("HH:mm");
|
|
254
|
+
const formattedDate = formatter.dateFormat(date, dateFormat, true, lang);
|
|
255
|
+
const formattedTime = formatter.timeFormat(time, timeFormat);
|
|
256
|
+
|
|
257
|
+
return `${formattedDate} ${formattedTime}`;
|
|
258
|
+
} else {
|
|
259
|
+
// Legacy logic which does not consider that the timezone of the origin station may differ from the account's timezone.
|
|
260
|
+
// For reservations, this logic may produce an incorrect / misleading date and time.
|
|
261
|
+
const format = `${dateFormat} ${timeFormat}`;
|
|
262
|
+
return getDate(ctx.environments, this.item, "departureTimestamp", format, this.applyTimeZone);
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
}
|
|
266
|
+
return "PNA";
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
function ArrivalDateTime(engine) {
|
|
272
|
+
this.registerTag("arrivalDateTime", {
|
|
273
|
+
parse: function(tagToken, remainTokens) {
|
|
274
|
+
const args = tagToken.args.split(" ");
|
|
275
|
+
this.item = args[0] || "ticket";
|
|
276
|
+
this.applyTimeZone = true;
|
|
277
|
+
},
|
|
278
|
+
render: async function(ctx) {
|
|
279
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
280
|
+
ctx.environments[this.item] && ctx.environments[this.item].arrivalTimestamp && ctx.environments.toStation) {
|
|
281
|
+
const lang = shortLang(ctx.environments.lang);
|
|
282
|
+
const dateFormat = ctx.environments.providerPreferences.preferences.dateFormat;
|
|
283
|
+
const timeFormat = ctx.environments.providerPreferences.preferences.timeFormat;
|
|
284
|
+
const originStationTimezone = ctx.environments.toStation.timeZone
|
|
285
|
+
if (originStationTimezone) {
|
|
286
|
+
const date = moment(ctx.environments[this.item].arrivalTimestamp).tz(originStationTimezone).format("YYYY-MM-DD");
|
|
287
|
+
const time = moment(ctx.environments[this.item].arrivalTimestamp).tz(originStationTimezone).format("HH:mm");
|
|
288
|
+
const formattedDate = formatter.dateFormat(date, dateFormat, true, lang);
|
|
289
|
+
const formattedTime = formatter.timeFormat(time, timeFormat);
|
|
290
|
+
|
|
291
|
+
return `${formattedDate} ${formattedTime}`;
|
|
292
|
+
} else {
|
|
293
|
+
// Legacy logic which does not consider that the timezone of the origin station may differ from the account's timezone.
|
|
294
|
+
// For reservations, this logic may produce an incorrect / misleading date and time.
|
|
295
|
+
const format = `${dateFormat} ${timeFormat}`;
|
|
296
|
+
return getDate(ctx.environments, this.item, "arrivalTimestamp", format, this.applyTimeZone);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
}
|
|
300
|
+
return "PNA";
|
|
301
|
+
}
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
function DepartureDate(engine) {
|
|
306
|
+
this.registerTag("departureDate", {
|
|
307
|
+
parse: function(tagToken, remainTokens) {
|
|
308
|
+
const args = tagToken.args.split(" ");
|
|
309
|
+
this.item = args[0] || "ticket";
|
|
310
|
+
this.applyTimeZone = true;
|
|
311
|
+
},
|
|
312
|
+
render: async function(ctx) {
|
|
313
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
314
|
+
ctx.environments[this.item] && ctx.environments[this.item].departureTimestamp && ctx.environments.fromStation) {
|
|
315
|
+
const dateFormat = ctx.environments.providerPreferences.preferences.dateFormat;
|
|
316
|
+
const originStationTimezone = ctx.environments.fromStation.timeZone
|
|
317
|
+
if (originStationTimezone) {
|
|
318
|
+
const lang = shortLang(ctx.environments.lang);
|
|
319
|
+
const date = moment(ctx.environments[this.item].departureTimestamp).tz(originStationTimezone).format("YYYY-MM-DD");
|
|
320
|
+
const formattedDate = formatter.dateFormat(date, dateFormat, true, lang);
|
|
321
|
+
|
|
322
|
+
return `${formattedDate}`;
|
|
323
|
+
} else {
|
|
324
|
+
// Legacy logic which does not consider that the timezone of the origin station may differ from the account's timezone.
|
|
325
|
+
// For reservations, this logic may produce an incorrect / misleading date and time.
|
|
326
|
+
const format = `${dateFormat}`;
|
|
327
|
+
return getDate(ctx.environments, this.item, "departureTimestamp", format, this.applyTimeZone);
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
}
|
|
331
|
+
return "PNA";
|
|
332
|
+
}
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
function ArrivalDate(engine) {
|
|
337
|
+
this.registerTag("arrivalDate", {
|
|
338
|
+
parse: function(tagToken, remainTokens) {
|
|
339
|
+
const args = tagToken.args.split(" ");
|
|
340
|
+
this.item = args[0] || "ticket";
|
|
341
|
+
this.applyTimeZone = true;
|
|
342
|
+
},
|
|
343
|
+
render: async function(ctx) {
|
|
344
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
345
|
+
ctx.environments[this.item] && ctx.environments[this.item].arrivalTimestamp && ctx.environments.toStation) {
|
|
346
|
+
const lang = shortLang(ctx.environments.lang);
|
|
347
|
+
const dateFormat = ctx.environments.providerPreferences.preferences.dateFormat;
|
|
348
|
+
const originStationTimezone = ctx.environments.toStation.timeZone
|
|
349
|
+
if (originStationTimezone) {
|
|
350
|
+
const date = moment(ctx.environments[this.item].arrivalTimestamp).tz(originStationTimezone).format("YYYY-MM-DD");
|
|
351
|
+
const formattedDate = formatter.dateFormat(date, dateFormat, true, lang);
|
|
352
|
+
|
|
353
|
+
return `${formattedDate}`;
|
|
354
|
+
} else {
|
|
355
|
+
// Legacy logic which does not consider that the timezone of the origin station may differ from the account's timezone.
|
|
356
|
+
// For reservations, this logic may produce an incorrect / misleading date and time.
|
|
357
|
+
const format = `${dateFormat}`;
|
|
358
|
+
return getDate(ctx.environments, this.item, "arrivalTimestamp", format, this.applyTimeZone);
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
}
|
|
362
|
+
return "PNA";
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
function DepartureTime(engine) {
|
|
368
|
+
this.registerTag("departureTime", {
|
|
369
|
+
parse: function(tagToken, remainTokens) {
|
|
370
|
+
const args = tagToken.args.split(" ");
|
|
371
|
+
this.item = args[0] || "ticket";
|
|
372
|
+
this.applyTimeZone = true;
|
|
373
|
+
},
|
|
374
|
+
render: async function(ctx) {
|
|
375
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
376
|
+
ctx.environments[this.item] && ctx.environments[this.item].departureTimestamp && ctx.environments.fromStation) {
|
|
377
|
+
const timeFormat = ctx.environments.providerPreferences.preferences.timeFormat;
|
|
378
|
+
const originStationTimezone = ctx.environments.fromStation.timeZone
|
|
379
|
+
if (originStationTimezone) {
|
|
380
|
+
const lang = shortLang(ctx.environments.lang);
|
|
381
|
+
const time = moment(ctx.environments[this.item].departureTimestamp).tz(originStationTimezone).format("HH:mm");
|
|
382
|
+
const formattedTime = formatter.timeFormat(time, timeFormat);
|
|
383
|
+
|
|
384
|
+
return `${formattedTime}`;
|
|
385
|
+
} else {
|
|
386
|
+
// Legacy logic which does not consider that the timezone of the origin station may differ from the account's timezone.
|
|
387
|
+
// For reservations, this logic may produce an incorrect / misleading date and time.
|
|
388
|
+
const format = `${timeFormat}`;
|
|
389
|
+
return getDate(ctx.environments, this.item, "departureTimestamp", format, this.applyTimeZone);
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
}
|
|
393
|
+
return "PNA";
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
|
|
398
|
+
function ArrivalTime(engine) {
|
|
399
|
+
this.registerTag("arrivalTime", {
|
|
400
|
+
parse: function(tagToken, remainTokens) {
|
|
401
|
+
const args = tagToken.args.split(" ");
|
|
402
|
+
this.item = args[0] || "ticket";
|
|
403
|
+
this.applyTimeZone = true;
|
|
404
|
+
},
|
|
405
|
+
render: async function(ctx) {
|
|
406
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
407
|
+
ctx.environments[this.item] && ctx.environments[this.item].arrivalTimestamp && ctx.environments.toStation) {
|
|
408
|
+
const lang = shortLang(ctx.environments.lang);
|
|
409
|
+
const timeFormat = ctx.environments.providerPreferences.preferences.timeFormat;
|
|
410
|
+
const originStationTimezone = ctx.environments.toStation.timeZone
|
|
411
|
+
if (originStationTimezone) {
|
|
412
|
+
const time = moment(ctx.environments[this.item].arrivalTimestamp).tz(originStationTimezone).format("HH:mm");
|
|
413
|
+
const formattedTime = formatter.timeFormat(time, timeFormat);
|
|
414
|
+
|
|
415
|
+
return `${formattedTime}`;
|
|
416
|
+
} else {
|
|
417
|
+
// Legacy logic which does not consider that the timezone of the origin station may differ from the account's timezone.
|
|
418
|
+
// For reservations, this logic may produce an incorrect / misleading date and time.
|
|
419
|
+
const format = `${timeFormat}`;
|
|
420
|
+
return getDate(ctx.environments, this.item, "arrivalTimestamp", format, this.applyTimeZone);
|
|
421
|
+
}
|
|
422
|
+
|
|
423
|
+
}
|
|
424
|
+
return "PNA";
|
|
425
|
+
}
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
function HumanDepartureDateTime(engine) {
|
|
430
|
+
this.registerTag("humanDepartureDateTime", {
|
|
431
|
+
parse: function(tagToken, remainTokens) {
|
|
432
|
+
const args = tagToken.args.split(" ");
|
|
433
|
+
this.item = args[0] || "ticket";
|
|
434
|
+
this.applyTimeZone = true;
|
|
435
|
+
},
|
|
436
|
+
render: async function(ctx) {
|
|
437
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
438
|
+
ctx.environments[this.item] && ctx.environments[this.item].departureTimestamp && ctx.environments.fromStation) {
|
|
439
|
+
const timeFormat = ctx.environments.providerPreferences.preferences.timeFormat;
|
|
440
|
+
const format = `${getFriendlyFormat(ctx.environments.humanDate || "mm")} ${timeFormat}`;
|
|
441
|
+
const originStationTimezone = ctx.environments.fromStation.timeZone
|
|
442
|
+
if (originStationTimezone) {
|
|
443
|
+
const lang = shortLang(ctx.environments.lang);
|
|
444
|
+
const dateTime = moment(ctx.environments[this.item].departureTimestamp).tz(originStationTimezone).format(`YYYY-MM-DD ${timeFormat.replace("TT", "A").replace(/M/g, "m")}`);
|
|
445
|
+
return `${formatter.dateFormat(dateTime, `${format}`, false, lang)}`;
|
|
446
|
+
} else {
|
|
447
|
+
// Legacy logic which does not consider that the timezone of the origin station may differ from the account's timezone.
|
|
448
|
+
// For reservations, this logic may produce an incorrect / misleading date and time.
|
|
449
|
+
return getDate(ctx.environments, this.item, "departureTimestamp", format, this.applyTimeZone);
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
return "PNA";
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
function HumanArrivalDateTime(engine) {
|
|
458
|
+
this.registerTag("humanArrivalDateTime", {
|
|
459
|
+
parse: function(tagToken, remainTokens) {
|
|
460
|
+
const args = tagToken.args.split(" ");
|
|
461
|
+
this.item = args[0] || "ticket";
|
|
462
|
+
this.applyTimeZone = true;
|
|
463
|
+
},
|
|
464
|
+
render: async function(ctx) {
|
|
465
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
466
|
+
ctx.environments[this.item] && ctx.environments[this.item].arrivalTimestamp && ctx.environments.toStation) {
|
|
467
|
+
const timeFormat = ctx.environments.providerPreferences.preferences.timeFormat;
|
|
468
|
+
const format = `${getFriendlyFormat(ctx.environments.humanDate || "mm")} ${timeFormat}`;
|
|
469
|
+
const originStationTimezone = ctx.environments.toStation.timeZone
|
|
470
|
+
if (originStationTimezone) {
|
|
471
|
+
const lang = shortLang(ctx.environments.lang);
|
|
472
|
+
const dateTime = moment(ctx.environments[this.item].arrivalTimestamp).tz(originStationTimezone).format(`YYYY-MM-DD ${timeFormat.replace("TT", "A").replace(/M/g, "m")}`);
|
|
473
|
+
return `${formatter.dateFormat(dateTime, `${format}`, false, lang)}`;
|
|
474
|
+
} else {
|
|
475
|
+
// Legacy logic which does not consider that the timezone of the origin station may differ from the account's timezone.
|
|
476
|
+
// For reservations, this logic may produce an incorrect / misleading date and time.
|
|
477
|
+
return getDate(ctx.environments, this.item, "arrivalTimestamp", format, this.applyTimeZone);
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
return "PNA";
|
|
481
|
+
}
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
function HumanDepartureDate(engine) {
|
|
486
|
+
this.registerTag("humanDepartureDate", {
|
|
487
|
+
parse: function(tagToken, remainTokens) {
|
|
488
|
+
const args = tagToken.args.split(" ");
|
|
489
|
+
this.item = args[0] || "ticket";
|
|
490
|
+
this.applyTimeZone = true;
|
|
491
|
+
},
|
|
492
|
+
render: async function(ctx) {
|
|
493
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
494
|
+
ctx.environments[this.item] && ctx.environments[this.item].departureTimestamp && ctx.environments.fromStation) {
|
|
495
|
+
const timeFormat = ctx.environments.providerPreferences.preferences.timeFormat;
|
|
496
|
+
const format = getFriendlyFormat(ctx.environments.humanDate || "mm");
|
|
497
|
+
const originStationTimezone = ctx.environments.fromStation.timeZone
|
|
498
|
+
if (originStationTimezone) {
|
|
499
|
+
const lang = shortLang(ctx.environments.lang);
|
|
500
|
+
const dateTime = moment(ctx.environments[this.item].departureTimestamp).tz(originStationTimezone).format(`YYYY-MM-DD ${timeFormat.replace("TT", "A").replace(/M/g, "m")}`);
|
|
501
|
+
return `${formatter.dateFormat(dateTime, `${format}`, false, lang)}`;
|
|
502
|
+
} else {
|
|
503
|
+
// Legacy logic which does not consider that the timezone of the origin station may differ from the account's timezone.
|
|
504
|
+
// For reservations, this logic may produce an incorrect / misleading date and time.
|
|
505
|
+
return getDate(ctx.environments, this.item, "departureTimestamp", format, this.applyTimeZone);
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
return "PNA";
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
function HumanArrivalDate(engine) {
|
|
514
|
+
this.registerTag("humanArrivalDate", {
|
|
515
|
+
parse: function(tagToken, remainTokens) {
|
|
516
|
+
const args = tagToken.args.split(" ");
|
|
517
|
+
this.item = args[0] || "ticket";
|
|
518
|
+
this.applyTimeZone = true;
|
|
519
|
+
},
|
|
520
|
+
render: async function(ctx) {
|
|
521
|
+
if (ctx && ctx.environments && ctx.environments.providerPreferences && ctx.environments.providerPreferences.preferences &&
|
|
522
|
+
ctx.environments[this.item] && ctx.environments[this.item].arrivalTimestamp && ctx.environments.toStation) {
|
|
523
|
+
const timeFormat = ctx.environments.providerPreferences.preferences.timeFormat;
|
|
524
|
+
const format = getFriendlyFormat(ctx.environments.humanDate || "mm");
|
|
525
|
+
const originStationTimezone = ctx.environments.toStation.timeZone
|
|
526
|
+
if (originStationTimezone) {
|
|
527
|
+
const lang = shortLang(ctx.environments.lang);
|
|
528
|
+
const dateTime = moment(ctx.environments[this.item].arrivalTimestamp).tz(originStationTimezone).format(`YYYY-MM-DD ${timeFormat.replace("TT", "A").replace(/M/g, "m")}`);
|
|
529
|
+
return `${formatter.dateFormat(dateTime, `${format}`, false, lang)}`;
|
|
530
|
+
} else {
|
|
531
|
+
// Legacy logic which does not consider that the timezone of the origin station may differ from the account's timezone.
|
|
532
|
+
// For reservations, this logic may produce an incorrect / misleading date and time.
|
|
533
|
+
return getDate(ctx.environments, this.item, "arrivalTimestamp", format, this.applyTimeZone);
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
return "PNA";
|
|
537
|
+
}
|
|
538
|
+
});
|
|
539
|
+
}
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
module.exports = {
|
|
543
|
+
DateF,
|
|
544
|
+
DateTime,
|
|
545
|
+
ExpDate,
|
|
546
|
+
HumanDate,
|
|
547
|
+
HumanDateTime,
|
|
548
|
+
HumanDepartureDate,
|
|
549
|
+
HumanArrivalDate,
|
|
550
|
+
HumanDepartureDateTime,
|
|
551
|
+
HumanArrivalDateTime,
|
|
552
|
+
DepartureDateTime,
|
|
553
|
+
ArrivalDateTime,
|
|
554
|
+
DepartureDate,
|
|
555
|
+
ArrivalDate,
|
|
556
|
+
DepartureTime,
|
|
557
|
+
ArrivalTime,
|
|
558
|
+
TimeF
|
|
559
|
+
};
|
|
560
|
+
|