Skip to content
Open
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
25 changes: 25 additions & 0 deletions src/jquery.rss.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
tokens: {},
outputMode: 'json',
dateFormat: 'dddd MMM Do',
timeFormat: 'HH:mm',
dateLocale: 'en',
effect: 'show',
offsetStart: false,
Expand Down Expand Up @@ -261,6 +262,29 @@
}
};

RSS.prototype.getFormattedTime = function (dateString) {
// If a custom formatting function is provided, use that.
if (this.options.timeFormatFunction) {
return this.options.timeFormatFunction(dateString);
} else if (typeof moment !== 'undefined') {
// If moment.js is available and dateFormatFunction is not overriding it,
// use it to format the time.
var time = moment(new Date(dateString));

if (time.locale) {
time = time.locale(this.options.dateLocale);
} else {
time = time.lang(this.options.dateLocale);
}

return time.format(this.options.timeFormat);
} else {
// If all else fails, just use the date as-is.
return dateString;
}
};


RSS.prototype.getTokenMap = function (entry) {
if (!this.feedTokens) {
var feed = JSON.parse(JSON.stringify(this.feed));
Expand All @@ -274,6 +298,7 @@
url: entry.link,
author: entry.author,
date: this.getFormattedDate(entry.publishedDate),
time: this.getFormattedTime(entry.publishedDate),
title: entry.title,
body: entry.content,
shortBody: entry.contentSnippet,
Expand Down