Skip to content

Commit

Permalink
[#2494] Add moment.js and load dates in browser timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Oderbolz committed Jul 9, 2015
1 parent 7d1d391 commit 514444f
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 2 deletions.
8 changes: 8 additions & 0 deletions ckan/public/base/javascript/main.js
Expand Up @@ -20,6 +20,7 @@ this.ckan = this.ckan || {};
ckan.initialize = function () {
var body = jQuery('body');
var locale = jQuery('html').attr('lang');
var browserLocale = window.navigator.userLanguage || window.navigator.language;
var location = window.location;
var root = location.protocol + '//' + location.host;

Expand All @@ -30,6 +31,13 @@ this.ckan = this.ckan || {};
ckan.SITE_ROOT = getRootFromData('siteRoot');
ckan.LOCALE_ROOT = getRootFromData('localeRoot');

// Convert all datetimes to the users timezone
jQuery('.datetime').each(function() {
moment.locale(browserLocale);
var date = moment(jQuery(this).data().datetime);
jQuery(this).html(date.format("LL, LT ([UTC]Z)"));
})

// Load the localisations before instantiating the modules.
ckan.sandbox().client.getLocaleData(locale).done(function (data) {
ckan.i18n.load(data);
Expand Down

0 comments on commit 514444f

Please sign in to comment.