diff --git a/src/common/Utils.ts b/src/common/Utils.ts index fcdc2d95..776bff2b 100644 --- a/src/common/Utils.ts +++ b/src/common/Utils.ts @@ -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,7 +226,9 @@ export class Utils { } } - static getLocalTimeMS(creationDate: number, creationDateOffset: string) { + //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); } diff --git a/src/common/config/public/ClientConfig.ts b/src/common/config/public/ClientConfig.ts index 7e003a75..5db92a75 100644 --- a/src/common/config/public/ClientConfig.ts +++ b/src/common/config/public/ClientConfig.ts @@ -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; diff --git a/src/frontend/app/ui/gallery/blog/blog.service.ts b/src/frontend/app/ui/gallery/blog/blog.service.ts index fb3500ae..73a8580c 100644 --- a/src/frontend/app/ui/gallery/blog/blog.service.ts +++ b/src/frontend/app/ui/gallery/blog/blog.service.ts @@ -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) diff --git a/src/frontend/app/ui/gallery/navigator/sorting.service.ts b/src/frontend/app/ui/gallery/navigator/sorting.service.ts index ffcbb202..d5a81993 100644 --- a/src/frontend/app/ui/gallery/navigator/sorting.service.ts +++ b/src/frontend/app/ui/gallery/navigator/sorting.service.ts @@ -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); }); }