FIX: Support for local-date email preview without time attribute

This commit is contained in:
Vinoth Kannan 2018-10-16 16:19:43 +05:30
parent e3c6dd26c4
commit bfa25487eb
2 changed files with 13 additions and 3 deletions

View File

@ -32,19 +32,20 @@ function addLocalDate(buffer, matches, state) {
["data-timezones", state.md.utils.escapeHtml(config.timezones)]
];
let dateTime = config.date;
if (config.time) {
token.attrs.push(["data-time", state.md.utils.escapeHtml(config.time)]);
dateTime = `${dateTime} ${config.time}`;
}
let dateTime;
if (config.timezone) {
token.attrs.push([
"data-timezone",
state.md.utils.escapeHtml(config.timezone)
]);
dateTime = moment.tz(`${config.date} ${config.time}`, config.timezone);
dateTime = moment.tz(dateTime, config.timezone);
} else {
dateTime = moment.utc(`${config.date} ${config.time}`);
dateTime = moment.utc(dateTime);
}
if (config.recurring) {

View File

@ -11,5 +11,14 @@ describe PrettyText do
HTML
expect(PrettyText.format_for_email(cooked)).to match_html(cooked_mail)
cooked = PrettyText.cook <<~MD
[date=2018-05-08 format=LLL timezone="Europe/Berlin" timezones="Europe/Paris|America/Los_Angeles"]
MD
cooked_mail = <<~HTML
<p><span class="discourse-local-date" data-date="2018-05-08" data-format="LLL" data-timezones="Europe/Paris|America/Los_Angeles" data-timezone="Europe/Berlin" data-email-preview="May 8, 2018 12:00 AM (Europe: Paris)">May 8, 2018 12:00 AM (Europe: Paris)</span></p>
HTML
expect(PrettyText.format_for_email(cooked)).to match_html(cooked_mail)
end
end