Skip to content

Commit

Permalink
onthisday: fix on year boundaries (fix #333)
Browse files Browse the repository at this point in the history
  • Loading branch information
pulsejet committed Jan 18, 2023
1 parent 62ae3c9 commit c6ef65f
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/components/top-matter/OnThisDay.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -315,4 +322,4 @@ $mobHeight: 150px;
}
}
}
</style>
</style>

0 comments on commit c6ef65f

Please sign in to comment.