Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions server/src/services/metadata.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ describe(MetadataService.name, () => {
Orientation: 0,
ProfileDescription: 'extensive description',
ProjectionType: 'equirectangular',
tz: 'UTC-11:30',
zone: 'UTC-11:30',
TagsList: ['parent/child'],
Rating: 3,
};
Expand Down Expand Up @@ -955,7 +955,7 @@ describe(MetadataService.name, () => {
orientation: tags.Orientation?.toString(),
profileDescription: tags.ProfileDescription,
projectionType: 'EQUIRECTANGULAR',
timeZone: tags.tz,
timeZone: tags.zone,
rating: tags.Rating,
country: null,
state: null,
Expand Down Expand Up @@ -987,7 +987,7 @@ describe(MetadataService.name, () => {

const tags: ImmichTags = {
DateTimeOriginal: ExifDateTime.fromISO(someDate + '+00:00'),
tz: undefined,
zone: undefined,
};
mocks.assetJob.getForMetadataExtraction.mockResolvedValue(asset);
mockReadTags(tags);
Expand Down
15 changes: 12 additions & 3 deletions server/src/services/metadata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,15 @@ export class MetadataService extends BaseService {
for (const tag of EXIF_DATE_TAGS) {
delete mediaTags[tag];
}

// exiftool-vendored derives tz information from the date.
// if the sidecar file has date information, we also assume the tz information come from there.
//
// this is especially important in the case of UTC+0 where exiftool-vendored does not return tz/zone fields
// and as such the tags aren't overwritten when returning all tags.
for (const tag of ['zone', 'tz', 'tzSource'] as const) {
delete mediaTags[tag];
}
}
}

Expand Down Expand Up @@ -897,16 +906,16 @@ export class MetadataService extends BaseService {
}

// timezone
let timeZone = exifTags.tz ?? null;
if (timeZone == null && dateTime?.rawValue?.endsWith('+00:00')) {
let timeZone = exifTags.zone ?? null;
if (timeZone == null && (dateTime?.rawValue?.endsWith('Z') || dateTime?.rawValue?.endsWith('+00:00'))) {
// exiftool-vendored returns "no timezone" information even though "+00:00" might be set explicitly
// https://github.com/photostructure/exiftool-vendored.js/issues/203
timeZone = 'UTC+0';
}

if (timeZone) {
this.logger.verbose(
`Found timezone ${timeZone} via ${exifTags.tzSource} for asset ${asset.id}: ${asset.originalPath}`,
`Found timezone ${timeZone} via ${exifTags.zoneSource} for asset ${asset.id}: ${asset.originalPath}`,
);
} else {
this.logger.debug(`No timezone information found for asset ${asset.id}: ${asset.originalPath}`);
Expand Down
58 changes: 56 additions & 2 deletions server/test/medium/specs/services/asset.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,23 @@ describe(AssetService.name, () => {
}),
);
});

it('should update dateTimeOriginal with time zone UTC+0', async () => {
const { sut, ctx } = setup();
ctx.getMock(JobRepository).queue.mockResolvedValue();
const { user } = await ctx.newUser();
const auth = factory.auth({ user });
const { asset } = await ctx.newAsset({ ownerId: user.id });
await ctx.newExif({ assetId: asset.id, description: 'test', timeZone: 'UTC-7' });

await sut.update(auth, asset.id, { dateTimeOriginal: '2023-11-19T18:11:00.000Z' });

await expect(ctx.get(AssetRepository).getById(asset.id, { exifInfo: true })).resolves.toEqual(
expect.objectContaining({
exifInfo: expect.objectContaining({ dateTimeOriginal: '2023-11-19T18:11:00+00:00', timeZone: 'UTC' }),
}),
);
});
});

describe('updateAll', () => {
Expand Down Expand Up @@ -456,7 +473,7 @@ describe(AssetService.name, () => {
);
});

it('should relatively update an assets with timezone', async () => {
it('should relatively update assets with timezone', async () => {
const { sut, ctx } = setup();
ctx.getMock(JobRepository).queueAll.mockResolvedValue();
const { user } = await ctx.newUser();
Expand All @@ -477,7 +494,7 @@ describe(AssetService.name, () => {
);
});

it('should relatively update an assets and set a timezone', async () => {
it('should relatively update assets and set a timezone', async () => {
const { sut, ctx } = setup();
ctx.getMock(JobRepository).queueAll.mockResolvedValue();
const { user } = await ctx.newUser();
Expand All @@ -497,6 +514,26 @@ describe(AssetService.name, () => {
);
});

it('should set asset time zones to UTC', async () => {
const { sut, ctx } = setup();
ctx.getMock(JobRepository).queueAll.mockResolvedValue();
const { user } = await ctx.newUser();
const auth = factory.auth({ user });
const { asset } = await ctx.newAsset({ ownerId: user.id });
await ctx.newExif({ assetId: asset.id, dateTimeOriginal: '2023-11-19T18:11:00', timeZone: 'UTC-7' });

await sut.updateAll(auth, { ids: [asset.id], timeZone: 'UTC' });

await expect(ctx.get(AssetRepository).getById(asset.id, { exifInfo: true })).resolves.toEqual(
expect.objectContaining({
exifInfo: expect.objectContaining({
dateTimeOriginal: '2023-11-19T18:11:00+00:00',
timeZone: 'UTC',
}),
}),
);
});

it('should update dateTimeOriginal', async () => {
const { sut, ctx } = setup();
ctx.getMock(JobRepository).queueAll.mockResolvedValue();
Expand Down Expand Up @@ -530,6 +567,23 @@ describe(AssetService.name, () => {
}),
);
});

it('should update dateTimeOriginal with UTC time zone', async () => {
const { sut, ctx } = setup();
ctx.getMock(JobRepository).queueAll.mockResolvedValue();
const { user } = await ctx.newUser();
const auth = factory.auth({ user });
const { asset } = await ctx.newAsset({ ownerId: user.id });
await ctx.newExif({ assetId: asset.id, description: 'test', timeZone: 'UTC-7' });

await sut.updateAll(auth, { ids: [asset.id], dateTimeOriginal: '2023-11-19T18:11:00.000Z' });

await expect(ctx.get(AssetRepository).getById(asset.id, { exifInfo: true })).resolves.toEqual(
expect.objectContaining({
exifInfo: expect.objectContaining({ dateTimeOriginal: '2023-11-19T18:11:00+00:00', timeZone: 'UTC' }),
}),
);
});
});

describe('upsertBulkMetadata', () => {
Expand Down
Loading