diff --git a/src/common/Utils.ts b/src/common/Utils.ts index 2e0a758b..dcb013a4 100644 --- a/src/common/Utils.ts +++ b/src/common/Utils.ts @@ -144,11 +144,11 @@ export class Utils { //function to extract offset string from timestamp string, returns undefined if timestamp does not contain offset static timestampToOffsetString(timestamp: string) { try { - const idx = timestamp.indexOf("+"); - if (idx > 0) { - return timestamp.substring(idx, timestamp.length); - } - if (timestamp.indexOf("Z") > 0) { + const offsetRegex = /[+-]\d{2}:\d{2}$/; + var match = timestamp.match(offsetRegex); + if (match) { + return match[0]; + } else if (timestamp.indexOf("Z") > 0) { return '+00:00'; } return undefined; diff --git a/test/backend/assets/wild-2-small.jpg b/test/backend/assets/wild-2-small.jpg new file mode 100644 index 00000000..10ec42a6 Binary files /dev/null and b/test/backend/assets/wild-2-small.jpg differ diff --git a/test/backend/assets/wild-2-small.jpg_original b/test/backend/assets/wild-2-small.jpg_original new file mode 100644 index 00000000..10ec42a6 Binary files /dev/null and b/test/backend/assets/wild-2-small.jpg_original differ diff --git a/test/backend/assets/wild-2-small.json b/test/backend/assets/wild-2-small.json new file mode 100644 index 00000000..6dee39a6 --- /dev/null +++ b/test/backend/assets/wild-2-small.json @@ -0,0 +1,20 @@ +{ + "size": { + "width": 306, + "height": 204 + }, + "creationDate": 1435943085000, + "fileSize": 62306, + "positionData": { + "country": "United States", + "state": "Arizona", + "city": "Williams" + }, + "keywords": ["Akela the wolf", "Balu the bear", "Bearizona", "Hugin the raven", "USA", "USA Road trip"], + "cameraData": { + "make": "Canon", + "model": "Canon EOS 600D", + "lens": "EF-S15-85mm f/3.5-5.6 IS USM" + }, + "creationDateOffset": "-07:00" +} \ No newline at end of file diff --git a/test/backend/unit/model/threading/MetaDataLoader.spec.ts b/test/backend/unit/model/threading/MetaDataLoader.spec.ts index 9b62eb58..17bc5a44 100644 --- a/test/backend/unit/model/threading/MetaDataLoader.spec.ts +++ b/test/backend/unit/model/threading/MetaDataLoader.spec.ts @@ -179,6 +179,11 @@ describe('MetadataLoader', () => { const expected = require(path.join(__dirname, '/../../../assets/wild-1-small.json')); expect(Utils.clone(data)).to.be.deep.equal(expected); }); + it('should load wild-2-small image with xmp-CreateDate from 2015 and negative offset', async () => { + const data = await MetadataLoader.loadPhotoMetadata(path.join(__dirname, '/../../../assets/wild-2-small.jpg')); + const expected = require(path.join(__dirname, '/../../../assets/wild-2-small.json')); + expect(Utils.clone(data)).to.be.deep.equal(expected); + }); describe('should load jpg with edge case exif data', () => { const root = path.join(__dirname, '/../../../assets/edge_case_exif_data');