1
0
mirror of https://github.com/bpatrik/pigallery2.git synced 2024-12-21 01:22:08 +02:00

sorting and grouping

This commit is contained in:
gras 2024-05-10 00:06:24 +02:00
parent 32632668ae
commit 517f483ffa
4 changed files with 21 additions and 8 deletions

View File

@ -123,10 +123,11 @@ export class Utils {
}
}
static makeUTCMidnight(d: number | Date) {
static makeUTCMidnight(d: number | Date, offset: string) {
if (!(d instanceof Date)) {
d = new Date(d);
}
d = new Date(new Date(d).toISOString().substring(0,19) + (offset ? offset : '+00:00'))
d.setUTCHours(0);
d.setUTCMinutes(0);
d.setUTCSeconds(0);
@ -139,7 +140,7 @@ export class Utils {
if (!(d instanceof Date)) {
d = new Date(d);
}
return new Date(new Date(d).toISOString().substring(0,19) + (offset ? offset : '')).getUTCFullYear();
return new Date(new Date(d).toISOString().substring(0,19) + (offset ? offset : '+00:00')).getUTCFullYear();
}
static getFullYear(d: number | Date, offset: string) {
@ -225,6 +226,8 @@ export class Utils {
}
}
//Get the MS of the creationDate, adjusted for the offset. Effectively getting the MS value as if the photo did not contain an offset.
//One can consider this "Local" time of the photo.
static getLocalTimeMS(creationDate: number, creationDateOffset: string) {
const offsetMinutes = Utils.getOffsetMinutes(creationDateOffset);
return creationDate + (offsetMinutes ? (offsetMinutes * 60000) : 0);

View File

@ -1087,7 +1087,7 @@ export class ClientGalleryConfig {
name: $localize`Ignore timestamp offsets`,
priority: ConfigPriority.advanced,
},
description: $localize`If enabled, timestamp offsets are ignored and the local time of photos are used for searching, sorting and grouping. If disabled, global time is used and pictures with no timestamp are assumed to be in UTC (offset +00:00).`
description: $localize`If enabled, timestamp offsets are ignored, meaning that the local times of pictures are used for searching, sorting and grouping. If disabled, global time is used and pictures with no timestamp are assumed to be in UTC (offset +00:00).`
})
ignoreTimestampOffset: boolean = true;

View File

@ -65,7 +65,7 @@ export class BlogService {
const getDateGroup = (date: Date) => {
// get UTC midnight date
const dateNum = Utils.makeUTCMidnight(date).getTime();
const dateNum = Utils.makeUTCMidnight(date, undefined).getTime();
let groupDate = dates.find((d, i) => i > dates.length - 1 ? false : dates[i + 1] > dateNum); //dates are sorted
// cant find the date. put to the last group (as it was later)

View File

@ -150,7 +150,11 @@ export class GallerySortingService {
break;
case SortByTypes.Date:
media.sort((a: PhotoDTO, b: PhotoDTO): number => {
return a.metadata.creationDate - b.metadata.creationDate; //TODO: Offset
if (Config.Gallery.ignoreTimestampOffset === true) {
return Utils.getLocalTimeMS(a.metadata.creationDate, a.metadata.creationDateOffset) - Utils.getLocalTimeMS(b.metadata.creationDate, b.metadata.creationDateOffset);
} else {
return a.metadata.creationDate - b.metadata.creationDate;
}
});
break;
case SortByTypes.Rating:
@ -196,7 +200,13 @@ export class GallerySortingService {
private getGroupByNameFn(grouping: GroupingMethod) {
switch (grouping.method) {
case SortByTypes.Date:
return (m: MediaDTO) => this.datePipe.transform(m.metadata.creationDate, 'longDate', m.metadata.creationDateOffset ? m.metadata.creationDateOffset : 'UTC'); //TODO: Offset:
if (Config.Gallery.ignoreTimestampOffset === true) {
//Datepipe used this way, converts creationDate to date in local time.
return (m: MediaDTO) => this.datePipe.transform(m.metadata.creationDate, 'longDate', m.metadata.creationDateOffset ? m.metadata.creationDateOffset : 'UTC');
} else {
//Grouping with global time, requires a common timeframe. Here and now it is UTC. (Could be config option later) //TODO: Configurable Default Timezone
return (m: MediaDTO) => this.datePipe.transform(m.metadata.creationDate, 'longDate', 'UTC');
}
case SortByTypes.Name:
return (m: MediaDTO) => m.name.at(0).toUpperCase();
@ -308,7 +318,7 @@ export class GallerySortingService {
if (grouping.method === GroupByTypes.Date) {
// We do not need the youngest as we group by day. All photos are from the same day
c.mediaGroups.forEach(g => {
g.date = Utils.makeUTCMidnight(new Date(g.media?.[0]?.metadata?.creationDate)); //TODO: Offset:
g.date = Utils.makeUTCMidnight(new Date(g.media?.[0]?.metadata?.creationDate), g.media?.[0]?.metadata?.creationDateOffset);
});
}