mirror of
https://github.com/immich-app/immich.git
synced 2025-06-02 21:24:28 -04:00
fix(server): timezones (#13262)
This commit is contained in:
parent
34305b2eae
commit
d47def41d3
@ -61,6 +61,8 @@ describe(MetadataService.name, () => {
|
|||||||
tagMock,
|
tagMock,
|
||||||
userMock,
|
userMock,
|
||||||
} = newTestService(MetadataService));
|
} = newTestService(MetadataService));
|
||||||
|
|
||||||
|
delete process.env.TZ;
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
@ -275,6 +277,27 @@ describe(MetadataService.name, () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should account for the server being in a non-UTC timezone', async () => {
|
||||||
|
process.env.TZ = 'America/Los_Angeles';
|
||||||
|
assetMock.getByIds.mockResolvedValue([assetStub.sidecar]);
|
||||||
|
metadataMock.readTags.mockResolvedValueOnce({
|
||||||
|
DateTimeOriginal: '2022:01:01 00:00:00',
|
||||||
|
});
|
||||||
|
|
||||||
|
await sut.handleMetadataExtraction({ id: assetStub.image.id });
|
||||||
|
expect(assetMock.upsertExif).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
dateTimeOriginal: new Date('2022-01-01T08:00:00.000Z'),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(assetMock.update).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
localDateTime: new Date('2022-01-01T00:00:00.000Z'),
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
it('should handle lists of numbers', async () => {
|
it('should handle lists of numbers', async () => {
|
||||||
assetMock.getByIds.mockResolvedValue([assetStub.image]);
|
assetMock.getByIds.mockResolvedValue([assetStub.image]);
|
||||||
metadataMock.readTags.mockResolvedValue({ ISO: [160] });
|
metadataMock.readTags.mockResolvedValue({ ISO: [160] });
|
||||||
|
@ -577,13 +577,6 @@ export class MetadataService extends BaseService {
|
|||||||
const dateTime = firstDateTime(exifTags as Maybe<Tags>, EXIF_DATE_TAGS);
|
const dateTime = firstDateTime(exifTags as Maybe<Tags>, EXIF_DATE_TAGS);
|
||||||
this.logger.debug(`Asset ${asset.id} date time is ${dateTime}`);
|
this.logger.debug(`Asset ${asset.id} date time is ${dateTime}`);
|
||||||
|
|
||||||
// created
|
|
||||||
let dateTimeOriginal = dateTime?.toDate();
|
|
||||||
if (!dateTimeOriginal) {
|
|
||||||
this.logger.warn(`Asset ${asset.id} has no valid date (${dateTime}), falling back to asset.fileCreatedAt`);
|
|
||||||
dateTimeOriginal = asset.fileCreatedAt;
|
|
||||||
}
|
|
||||||
|
|
||||||
// timezone
|
// timezone
|
||||||
let timeZone = exifTags.tz ?? null;
|
let timeZone = exifTags.tz ?? null;
|
||||||
if (timeZone == null && dateTime?.rawValue?.endsWith('+00:00')) {
|
if (timeZone == null && dateTime?.rawValue?.endsWith('+00:00')) {
|
||||||
@ -598,14 +591,16 @@ export class MetadataService extends BaseService {
|
|||||||
this.logger.warn(`Asset ${asset.id} has no time zone information`);
|
this.logger.warn(`Asset ${asset.id} has no time zone information`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// offset minutes
|
let dateTimeOriginal = dateTime?.toDate();
|
||||||
const offsetMinutes = dateTime?.tzoffsetMinutes || 0;
|
let localDateTime = dateTime?.toDateTime().setZone('UTC', { keepLocalTime: true }).toJSDate();
|
||||||
let localDateTime = dateTimeOriginal;
|
if (!localDateTime || !dateTimeOriginal) {
|
||||||
if (offsetMinutes) {
|
this.logger.warn(`Asset ${asset.id} has no valid date, falling back to asset.fileCreatedAt`);
|
||||||
localDateTime = new Date(dateTimeOriginal.getTime() + offsetMinutes * 60_000);
|
dateTimeOriginal = asset.fileCreatedAt;
|
||||||
this.logger.debug(`Asset ${asset.id} local time is offset by ${offsetMinutes} minutes`);
|
localDateTime = asset.fileCreatedAt;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logger.debug(`Asset ${asset.id} has a local time of ${localDateTime.toISOString()}`);
|
||||||
|
|
||||||
let modifyDate = asset.fileModifiedAt;
|
let modifyDate = asset.fileModifiedAt;
|
||||||
try {
|
try {
|
||||||
modifyDate = (exifTags.ModifyDate as ExifDateTime)?.toDate() ?? modifyDate;
|
modifyDate = (exifTags.ModifyDate as ExifDateTime)?.toDate() ?? modifyDate;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user