1
0
Fork 0
mirror of https://github.com/immich-app/immich.git synced 2025-02-03 01:22:44 +01:00

fix: show local dates for range in album summary ()

* fix(web): show local dates for range in album summary

* fix(server): show local dates for range in album summary
This commit is contained in:
Carsten Otto 2025-01-28 21:33:38 +01:00 committed by GitHub
parent cb6d94c7a7
commit da580d4685
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 17 additions and 20 deletions

View file

@ -4,8 +4,8 @@ import { albumStub } from 'test/fixtures/album.stub';
describe('mapAlbum', () => {
it('should set start and end dates', () => {
const dto = mapAlbum(albumStub.twoAssets, false);
expect(dto.startDate).toEqual(new Date('2023-02-22T05:06:29.716Z'));
expect(dto.endDate).toEqual(new Date('2023-02-23T05:06:29.716Z'));
expect(dto.startDate).toEqual(new Date('2020-12-31T23:59:00.000Z'));
expect(dto.endDate).toEqual(new Date('2025-01-01T01:02:03.456Z'));
});
it('should not set start and end dates for empty assets', () => {

View file

@ -7,7 +7,6 @@ import { AuthDto } from 'src/dtos/auth.dto';
import { UserResponseDto, mapUser } from 'src/dtos/user.dto';
import { AlbumEntity } from 'src/entities/album.entity';
import { AlbumUserRole, AssetOrder } from 'src/enum';
import { getAssetDateTime } from 'src/utils/date-time';
import { Optional, ValidateBoolean, ValidateUUID } from 'src/validation';
export class AlbumInfoDto {
@ -165,8 +164,8 @@ export const mapAlbum = (entity: AlbumEntity, withAssets: boolean, auth?: AuthDt
const hasSharedLink = entity.sharedLinks?.length > 0;
const hasSharedUser = sharedUsers.length > 0;
let startDate = getAssetDateTime(assets.at(0));
let endDate = getAssetDateTime(assets.at(-1));
let startDate = assets.at(0)?.localDateTime;
let endDate = assets.at(-1)?.localDateTime;
// Swap dates if start date is greater than end date.
if (startDate && endDate && startDate > endDate) {
[startDate, endDate] = [endDate, startDate];

View file

@ -202,8 +202,8 @@ order by
-- AlbumRepository.getMetadataForIds
select
"albums"."id" as "albumId",
min("assets"."fileCreatedAt") as "startDate",
max("assets"."fileCreatedAt") as "endDate",
min("assets"."localDateTime") as "startDate",
max("assets"."localDateTime") as "endDate",
count("assets"."id")::int as "assetCount"
from
"albums"

View file

@ -127,8 +127,8 @@ export class AlbumRepository implements IAlbumRepository {
.innerJoin('albums_assets_assets as album_assets', 'album_assets.albumsId', 'albums.id')
.innerJoin('assets', 'assets.id', 'album_assets.assetsId')
.select('albums.id as albumId')
.select((eb) => eb.fn.min('assets.fileCreatedAt').as('startDate'))
.select((eb) => eb.fn.max('assets.fileCreatedAt').as('endDate'))
.select((eb) => eb.fn.min('assets.localDateTime').as('startDate'))
.select((eb) => eb.fn.max('assets.localDateTime').as('endDate'))
.select((eb) => sql<number>`${eb.fn.count('assets.id')}::int`.as('assetCount'))
.where('albums.id', 'in', ids)
.where('assets.deletedAt', 'is', null)

View file

@ -335,8 +335,8 @@ describe(MetadataService.name, () => {
expect(assetMock.update).toHaveBeenCalledWith({
id: assetStub.image.id,
duration: null,
fileCreatedAt: assetStub.image.createdAt,
localDateTime: new Date('2023-02-23T05:06:29.716Z'),
fileCreatedAt: assetStub.image.fileCreatedAt,
localDateTime: assetStub.image.fileCreatedAt,
});
});

View file

@ -1,5 +0,0 @@
import { AssetEntity } from 'src/entities/asset.entity';
export const getAssetDateTime = (asset: AssetEntity | undefined) => {
return asset?.exifInfo?.dateTimeOriginal || asset?.fileCreatedAt;
};

View file

@ -210,7 +210,7 @@ export const assetStub = {
encodedVideoPath: null,
createdAt: new Date('2023-02-23T05:06:29.716Z'),
updatedAt: new Date('2023-02-23T05:06:29.716Z'),
localDateTime: new Date('2023-02-23T05:06:29.716Z'),
localDateTime: new Date('2025-01-01T01:02:03.456Z'),
isFavorite: true,
isArchived: false,
duration: null,
@ -574,7 +574,7 @@ export const assetStub = {
encodedVideoPath: null,
createdAt: new Date('2023-02-22T05:06:29.716Z'),
updatedAt: new Date('2023-02-22T05:06:29.716Z'),
localDateTime: new Date('2023-02-22T05:06:29.716Z'),
localDateTime: new Date('2020-12-31T23:59:00.000Z'),
isFavorite: false,
isArchived: false,
isExternal: false,

View file

@ -311,7 +311,7 @@ export const sharedLinkResponseStub = {
allowUpload: false,
allowDownload: false,
showMetadata: false,
album: { ...albumResponse, startDate: assetResponse.fileCreatedAt, endDate: assetResponse.fileCreatedAt },
album: { ...albumResponse, startDate: assetResponse.localDateTime, endDate: assetResponse.localDateTime },
assets: [{ ...assetResponseWithoutMetadata, exifInfo: undefined }],
}),
};

View file

@ -11,7 +11,10 @@
let { album }: Props = $props();
const formatDate = (date?: string) => {
return date ? new Date(date).toLocaleDateString($locale, dateFormats.album) : undefined;
const dateWithoutTimeZone = date?.slice(0, -1);
return dateWithoutTimeZone
? new Date(dateWithoutTimeZone).toLocaleDateString($locale, dateFormats.album)
: undefined;
};
const getDateRange = (start?: string, end?: string) => {