Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Substitutes parser doesn't handle custom date format for variables #2207

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion modules/src/xibo-substitutes-parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jQuery.fn.extend({
) {
const items = [];
const parser = new RegExp('\\[.*?\\]', 'g');
const pipeParser = new RegExp('\\|{1}', 'g');
this.each(function() {
// Parse the template for a list of things to substitute, and match those
// with content from items.
Expand All @@ -42,6 +43,17 @@ jQuery.fn.extend({
.replace(']', '');
variable = variable.charAt(0).toLowerCase() + variable.substring(1);

// Check if variable has its own formatting
// Then, parse it and use later as dateFormat
let formatFromTemplate = null;

if (variable.match(pipeParser) !== null &&
variable.match(pipeParser).length === 1) {
const variableWithFormat = variable.split('|');
formatFromTemplate = variableWithFormat[1];
variable = variableWithFormat[0];
}

if (mapping[variable]) {
variable = mapping[variable];
}
Expand All @@ -55,7 +67,8 @@ jQuery.fn.extend({
// Is it a date field?
dateFields.forEach((field) => {
if (field === variable) {
value = moment(value).format(dateFormat);
value = moment(value).format(formatFromTemplate !== null ?
formatFromTemplate : dateFormat);
}
});
}
Expand Down
Loading