mirror of
https://github.com/immich-app/immich.git
synced 2025-07-09 03:04:16 -04:00
fix: show local dates for range in album summary (#15654)
* 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:
parent
cb6d94c7a7
commit
da580d4685
@ -4,8 +4,8 @@ import { albumStub } from 'test/fixtures/album.stub';
|
|||||||
describe('mapAlbum', () => {
|
describe('mapAlbum', () => {
|
||||||
it('should set start and end dates', () => {
|
it('should set start and end dates', () => {
|
||||||
const dto = mapAlbum(albumStub.twoAssets, false);
|
const dto = mapAlbum(albumStub.twoAssets, false);
|
||||||
expect(dto.startDate).toEqual(new Date('2023-02-22T05:06:29.716Z'));
|
expect(dto.startDate).toEqual(new Date('2020-12-31T23:59:00.000Z'));
|
||||||
expect(dto.endDate).toEqual(new Date('2023-02-23T05:06:29.716Z'));
|
expect(dto.endDate).toEqual(new Date('2025-01-01T01:02:03.456Z'));
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not set start and end dates for empty assets', () => {
|
it('should not set start and end dates for empty assets', () => {
|
||||||
|
@ -7,7 +7,6 @@ import { AuthDto } from 'src/dtos/auth.dto';
|
|||||||
import { UserResponseDto, mapUser } from 'src/dtos/user.dto';
|
import { UserResponseDto, mapUser } from 'src/dtos/user.dto';
|
||||||
import { AlbumEntity } from 'src/entities/album.entity';
|
import { AlbumEntity } from 'src/entities/album.entity';
|
||||||
import { AlbumUserRole, AssetOrder } from 'src/enum';
|
import { AlbumUserRole, AssetOrder } from 'src/enum';
|
||||||
import { getAssetDateTime } from 'src/utils/date-time';
|
|
||||||
import { Optional, ValidateBoolean, ValidateUUID } from 'src/validation';
|
import { Optional, ValidateBoolean, ValidateUUID } from 'src/validation';
|
||||||
|
|
||||||
export class AlbumInfoDto {
|
export class AlbumInfoDto {
|
||||||
@ -165,8 +164,8 @@ export const mapAlbum = (entity: AlbumEntity, withAssets: boolean, auth?: AuthDt
|
|||||||
const hasSharedLink = entity.sharedLinks?.length > 0;
|
const hasSharedLink = entity.sharedLinks?.length > 0;
|
||||||
const hasSharedUser = sharedUsers.length > 0;
|
const hasSharedUser = sharedUsers.length > 0;
|
||||||
|
|
||||||
let startDate = getAssetDateTime(assets.at(0));
|
let startDate = assets.at(0)?.localDateTime;
|
||||||
let endDate = getAssetDateTime(assets.at(-1));
|
let endDate = assets.at(-1)?.localDateTime;
|
||||||
// Swap dates if start date is greater than end date.
|
// Swap dates if start date is greater than end date.
|
||||||
if (startDate && endDate && startDate > endDate) {
|
if (startDate && endDate && startDate > endDate) {
|
||||||
[startDate, endDate] = [endDate, startDate];
|
[startDate, endDate] = [endDate, startDate];
|
||||||
|
@ -202,8 +202,8 @@ order by
|
|||||||
-- AlbumRepository.getMetadataForIds
|
-- AlbumRepository.getMetadataForIds
|
||||||
select
|
select
|
||||||
"albums"."id" as "albumId",
|
"albums"."id" as "albumId",
|
||||||
min("assets"."fileCreatedAt") as "startDate",
|
min("assets"."localDateTime") as "startDate",
|
||||||
max("assets"."fileCreatedAt") as "endDate",
|
max("assets"."localDateTime") as "endDate",
|
||||||
count("assets"."id")::int as "assetCount"
|
count("assets"."id")::int as "assetCount"
|
||||||
from
|
from
|
||||||
"albums"
|
"albums"
|
||||||
|
@ -127,8 +127,8 @@ export class AlbumRepository implements IAlbumRepository {
|
|||||||
.innerJoin('albums_assets_assets as album_assets', 'album_assets.albumsId', 'albums.id')
|
.innerJoin('albums_assets_assets as album_assets', 'album_assets.albumsId', 'albums.id')
|
||||||
.innerJoin('assets', 'assets.id', 'album_assets.assetsId')
|
.innerJoin('assets', 'assets.id', 'album_assets.assetsId')
|
||||||
.select('albums.id as albumId')
|
.select('albums.id as albumId')
|
||||||
.select((eb) => eb.fn.min('assets.fileCreatedAt').as('startDate'))
|
.select((eb) => eb.fn.min('assets.localDateTime').as('startDate'))
|
||||||
.select((eb) => eb.fn.max('assets.fileCreatedAt').as('endDate'))
|
.select((eb) => eb.fn.max('assets.localDateTime').as('endDate'))
|
||||||
.select((eb) => sql<number>`${eb.fn.count('assets.id')}::int`.as('assetCount'))
|
.select((eb) => sql<number>`${eb.fn.count('assets.id')}::int`.as('assetCount'))
|
||||||
.where('albums.id', 'in', ids)
|
.where('albums.id', 'in', ids)
|
||||||
.where('assets.deletedAt', 'is', null)
|
.where('assets.deletedAt', 'is', null)
|
||||||
|
@ -335,8 +335,8 @@ describe(MetadataService.name, () => {
|
|||||||
expect(assetMock.update).toHaveBeenCalledWith({
|
expect(assetMock.update).toHaveBeenCalledWith({
|
||||||
id: assetStub.image.id,
|
id: assetStub.image.id,
|
||||||
duration: null,
|
duration: null,
|
||||||
fileCreatedAt: assetStub.image.createdAt,
|
fileCreatedAt: assetStub.image.fileCreatedAt,
|
||||||
localDateTime: new Date('2023-02-23T05:06:29.716Z'),
|
localDateTime: assetStub.image.fileCreatedAt,
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -1,5 +0,0 @@
|
|||||||
import { AssetEntity } from 'src/entities/asset.entity';
|
|
||||||
|
|
||||||
export const getAssetDateTime = (asset: AssetEntity | undefined) => {
|
|
||||||
return asset?.exifInfo?.dateTimeOriginal || asset?.fileCreatedAt;
|
|
||||||
};
|
|
4
server/test/fixtures/asset.stub.ts
vendored
4
server/test/fixtures/asset.stub.ts
vendored
@ -210,7 +210,7 @@ export const assetStub = {
|
|||||||
encodedVideoPath: null,
|
encodedVideoPath: null,
|
||||||
createdAt: new Date('2023-02-23T05:06:29.716Z'),
|
createdAt: new Date('2023-02-23T05:06:29.716Z'),
|
||||||
updatedAt: 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,
|
isFavorite: true,
|
||||||
isArchived: false,
|
isArchived: false,
|
||||||
duration: null,
|
duration: null,
|
||||||
@ -574,7 +574,7 @@ export const assetStub = {
|
|||||||
encodedVideoPath: null,
|
encodedVideoPath: null,
|
||||||
createdAt: new Date('2023-02-22T05:06:29.716Z'),
|
createdAt: new Date('2023-02-22T05:06:29.716Z'),
|
||||||
updatedAt: 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,
|
isFavorite: false,
|
||||||
isArchived: false,
|
isArchived: false,
|
||||||
isExternal: false,
|
isExternal: false,
|
||||||
|
2
server/test/fixtures/shared-link.stub.ts
vendored
2
server/test/fixtures/shared-link.stub.ts
vendored
@ -311,7 +311,7 @@ export const sharedLinkResponseStub = {
|
|||||||
allowUpload: false,
|
allowUpload: false,
|
||||||
allowDownload: false,
|
allowDownload: false,
|
||||||
showMetadata: false,
|
showMetadata: false,
|
||||||
album: { ...albumResponse, startDate: assetResponse.fileCreatedAt, endDate: assetResponse.fileCreatedAt },
|
album: { ...albumResponse, startDate: assetResponse.localDateTime, endDate: assetResponse.localDateTime },
|
||||||
assets: [{ ...assetResponseWithoutMetadata, exifInfo: undefined }],
|
assets: [{ ...assetResponseWithoutMetadata, exifInfo: undefined }],
|
||||||
}),
|
}),
|
||||||
};
|
};
|
||||||
|
@ -11,7 +11,10 @@
|
|||||||
let { album }: Props = $props();
|
let { album }: Props = $props();
|
||||||
|
|
||||||
const formatDate = (date?: string) => {
|
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) => {
|
const getDateRange = (start?: string, end?: string) => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user