Fix PHP to JS date format converter to handle escaped symbols
This commit is contained in:
@@ -71,30 +71,43 @@ define('date',
|
|||||||
convertFormat: function(format) {
|
convertFormat: function(format) {
|
||||||
var format_mappings = {
|
var format_mappings = {
|
||||||
date: {
|
date: {
|
||||||
D: 'ddd',
|
|
||||||
l: 'dddd',
|
|
||||||
d: 'DD',
|
d: 'DD',
|
||||||
|
D: 'ddd',
|
||||||
j: 'D',
|
j: 'D',
|
||||||
z: 'DDDD',
|
l: 'dddd',
|
||||||
N: 'E',
|
N: 'E',
|
||||||
S: '',
|
S: 'o',
|
||||||
M: 'MMM',
|
w: 'e',
|
||||||
|
z: 'DDD',
|
||||||
|
W: 'W',
|
||||||
F: 'MMMM',
|
F: 'MMMM',
|
||||||
m: 'MM',
|
m: 'MM',
|
||||||
n: '',
|
M: 'MMM',
|
||||||
t: '',
|
n: 'M',
|
||||||
y: 'YY',
|
t: '', // no equivalent
|
||||||
|
L: '', // no equivalent
|
||||||
|
o: 'YYYY',
|
||||||
Y: 'YYYY',
|
Y: 'YYYY',
|
||||||
H: 'HH',
|
y: 'YY',
|
||||||
h: 'hh',
|
a: 'a',
|
||||||
g: 'h',
|
|
||||||
A: 'A',
|
A: 'A',
|
||||||
|
B: '', // no equivalent
|
||||||
|
g: 'h',
|
||||||
|
G: 'H',
|
||||||
|
h: 'hh',
|
||||||
|
H: 'HH',
|
||||||
i: 'mm',
|
i: 'mm',
|
||||||
s: 'ss',
|
s: 'ss',
|
||||||
T: 'z',
|
u: 'SSS',
|
||||||
O: 'ZZ',
|
e: 'zz', // deprecated since version 1.6.0 of moment.js
|
||||||
w: 'd',
|
I: '', // no equivalent
|
||||||
W: 'WW'
|
O: '', // no equivalent
|
||||||
|
P: '', // no equivalent
|
||||||
|
T: '', // no equivalent
|
||||||
|
Z: '', // no equivalent
|
||||||
|
c: '', // no equivalent
|
||||||
|
r: '', // no equivalent
|
||||||
|
U: 'X'
|
||||||
},
|
},
|
||||||
strftime: {
|
strftime: {
|
||||||
a: 'ddd',
|
a: 'ddd',
|
||||||
@@ -127,20 +140,29 @@ define('date',
|
|||||||
|
|
||||||
var replacements = format_mappings['date'];
|
var replacements = format_mappings['date'];
|
||||||
|
|
||||||
var outputFormat = '';
|
var convertedFormat = [];
|
||||||
|
var escapeToken = false;
|
||||||
|
|
||||||
Object.keys(replacements).forEach(function(key) {
|
for (var index in format) {
|
||||||
if (format.indexOf(key) !== -1) {
|
var token = format[index];
|
||||||
format = format.replace(key, '%'+key);
|
|
||||||
|
if (escapeToken === true) {
|
||||||
|
convertedFormat.push('['+token+']');
|
||||||
|
escapeToken = false;
|
||||||
|
} else {
|
||||||
|
if (token === '\\') {
|
||||||
|
// Slash escapes the next symbol to be treated as literal
|
||||||
|
escapeToken = true;
|
||||||
|
continue;
|
||||||
|
} else if (replacements[token] !== undefined) {
|
||||||
|
convertedFormat.push(replacements[token]);
|
||||||
|
} else {
|
||||||
|
convertedFormat.push('['+token+']');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
}
|
||||||
outputFormat = format;
|
|
||||||
Object.keys(replacements).forEach(function(key) {
|
return convertedFormat.join('');
|
||||||
if (outputFormat.indexOf('%'+key) !== -1) {
|
|
||||||
outputFormat = outputFormat.replace('%'+key, replacements[key]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
return outputFormat;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
@@ -39,8 +39,8 @@ jQuery('.toplevel_page_mailpoet-newsletters.menu-top-last')
|
|||||||
<% block after_css %><% endblock %>
|
<% block after_css %><% endblock %>
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
var mailpoet_date_format = "<%= wp_datetime_format() %>";
|
var mailpoet_date_format = "<%= wp_datetime_format()|escape('js') %>";
|
||||||
var mailpoet_time_format = "<%= wp_time_format() %>";
|
var mailpoet_time_format = "<%= wp_time_format()|escape('js') %>";
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- javascripts -->
|
<!-- javascripts -->
|
||||||
|
Reference in New Issue
Block a user