From c6ef65f69a51136b5ff2074144a5709422aabc8b Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Tue, 17 Jan 2023 20:03:50 -0800 Subject: [PATCH] onthisday: fix on year boundaries (fix #333) --- src/components/top-matter/OnThisDay.vue | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/components/top-matter/OnThisDay.vue b/src/components/top-matter/OnThisDay.vue index 29c31c71..1f84d1c5 100644 --- a/src/components/top-matter/OnThisDay.vue +++ b/src/components/top-matter/OnThisDay.vue @@ -124,20 +124,27 @@ export default defineComponent({ this.years = []; let currentYear = 9999; + let currentText = ""; for (const photo of photos) { const dateTaken = utils.dayIdToDate(photo.dayid); const year = dateTaken.getUTCFullYear(); photo.key = `${photo.fileid}`; + // DateTime calls are expensive, so check if the year + // itself is different first, then also check the text if (year !== currentYear) { - this.years.push({ - year, - url: "", - preview: null, - photos: [], - text: utils.getFromNowStr(dateTaken), - }); + const text = utils.getFromNowStr(dateTaken); + if (text !== currentText) { + this.years.push({ + year, + text, + url: "", + preview: null, + photos: [], + }); + currentText = text; + } currentYear = year; } @@ -315,4 +322,4 @@ $mobHeight: 150px; } } } - \ No newline at end of file +