onthisday: fix on year boundaries (fix #333)

pull/363/head
Varun Patil 2023-01-17 20:03:50 -08:00
parent 62ae3c910a
commit c6ef65f69a
1 changed files with 15 additions and 8 deletions

View File

@ -124,20 +124,27 @@ export default defineComponent({
this.years = []; this.years = [];
let currentYear = 9999; let currentYear = 9999;
let currentText = "";
for (const photo of photos) { for (const photo of photos) {
const dateTaken = utils.dayIdToDate(photo.dayid); const dateTaken = utils.dayIdToDate(photo.dayid);
const year = dateTaken.getUTCFullYear(); const year = dateTaken.getUTCFullYear();
photo.key = `${photo.fileid}`; 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) { if (year !== currentYear) {
this.years.push({ const text = utils.getFromNowStr(dateTaken);
year, if (text !== currentText) {
url: "", this.years.push({
preview: null, year,
photos: [], text,
text: utils.getFromNowStr(dateTaken), url: "",
}); preview: null,
photos: [],
});
currentText = text;
}
currentYear = year; currentYear = year;
} }
@ -315,4 +322,4 @@ $mobHeight: 150px;
} }
} }
} }
</style> </style>