Skip to content

Commit

Permalink
fix: show local dates for range in album summary (#15654)
Browse files Browse the repository at this point in the history
* fix(web): show local dates for range in album summary

* fix(server): show local dates for range in album summary
  • Loading branch information
C-Otto authored Jan 28, 2025
1 parent cb6d94c commit da580d4
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 20 deletions.
4 changes: 2 additions & 2 deletions server/src/dtos/album-response.dto.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
5 changes: 2 additions & 3 deletions server/src/dtos/album.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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];
Expand Down
4 changes: 2 additions & 2 deletions server/src/queries/album.repository.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions server/src/repositories/album.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions server/src/services/metadata.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
});
});

Expand Down
5 changes: 0 additions & 5 deletions server/src/utils/date-time.ts

This file was deleted.

4 changes: 2 additions & 2 deletions server/test/fixtures/asset.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/test/fixtures/shared-link.stub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }],
}),
};
5 changes: 4 additions & 1 deletion web/src/lib/components/album-page/album-summary.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit da580d4

Please sign in to comment.