git ssb

30+

cel / git-ssb-web



Commit 2271e8aa0dd4246f6fa1f331208e63368eb5a762

Handle invalid date locale

Charles E. Lehner committed on 7/4/2022, 6:48:49 PM
Parent: 2b3549a44739b6c2e7b68be4f1d833ad68f7d654

Files changed

lib/repos/index.jschanged
lib/util.jschanged
lib/repos/index.jsView
@@ -509,9 +509,9 @@
509509 .push({name: m[2], value: c.refs[name]})
510510 }
511511 var numObjects = c.objects ? Object.keys(c.objects).length : 0
512512
513- var dateStr = new Date(msg.value.timestamp).toLocaleString(req._locale)
513 + const dateStr = u.dateLocaleString(new Date(msg.value.timestamp), req._locale)
514514
515515 this.web.about.getName(msg.value.author, function (err, name) {
516516 if (err) return cb(err)
517517 cb(null, '<section class="collapse">' +
@@ -638,9 +638,9 @@
638638 '</span>' +
639639 '<span class="float-right">' +
640640 req._t('LatestOn', {
641641 commitId: commitId && commitId.slice(0, 7),
642- date: commit[actor].date.toLocaleString(req._locale)
642 + date: u.dateLocaleString(commit[actor].date, req._locale)
643643 }) +
644644 '</span>'
645645 )
646646 })
@@ -762,13 +762,13 @@
762762 '<h4>' + u.linkify(u.escape(commit.title)) + '</h4>' +
763763 (commit.body ? u.linkify(u.pre(commit.body)) : '') +
764764 (commit.separateAuthor ? req._t('AuthoredOn', {
765765 name: u.escape(commit.author.name),
766- date: commit.author.date.toLocaleString(req._locale)
766 + date: u.dateLocaleString(commit.author.date, req._locale)
767767 }) + '<br/>' : '') +
768768 req._t('CommittedOn', {
769769 name: u.escape(commit.committer.name),
770- date: commit.committer.date.toLocaleString(req._locale)
770 + date: u.dateLocaleString(commit.committer.date, req._locale)
771771 }) + '<br/>' +
772772 commit.parents.map(function (id) {
773773 return req._t('Parent') + ': ' +
774774 u.link([repo.id, 'commit', id], id)
lib/util.jsView
@@ -90,11 +90,20 @@
9090 u.timestamp = function (time, req) {
9191 time = Number(time)
9292 var d = new Date(time)
9393 return '<span title="' + time + '">' +
94- d.toLocaleString(req._locale) + '</span>'
94 + u.dateLocaleString(d) + '</span>'
9595 }
9696
97 +u.dateLocaleString = function (date, locale) {
98 + const dateLocale = locale && locale !== '@' ? locale : undefined
99 + try {
100 + return date.toLocaleString(dateLocale)
101 + } catch(e) {
102 + return date.toLocaleString()
103 + }
104 +}
105 +
97106 u.nav = function (links, page, after) {
98107 return h('nav', [
99108 u.sourceMap(pull.values(links), link => {
100109 return h('a', {

Built with git-ssb-web