diff --git a/frontend/src/dialog/photo/details.vue b/frontend/src/dialog/photo/details.vue index 3d3c1b38c..76a8dd333 100644 --- a/frontend/src/dialog/photo/details.vue +++ b/frontend/src/dialog/photo/details.vue @@ -472,7 +472,13 @@ export default { return; } - const utcDate = localDate.toUTC(); + let utcDate; + + if (this.model.originalTimeZoneUTC()) { + utcDate = this.model.utcDate(); + } else { + utcDate = localDate.toUTC(); + } this.localTime = localDate.toFormat("HH:mm:ss"); this.utcTime = utcDate.toFormat("HH:mm:ss"); @@ -494,10 +500,12 @@ export default { includeOffset: false, }) + "Z"; - this.model.TakenAt = localDate.toUTC().toISO({ - suppressMilliseconds: true, - includeOffset: false, - }) + "Z"; + if (!this.model.originalTimeZoneUTC()) { + this.model.TakenAt = localDate.toUTC().toISO({ + suppressMilliseconds: true, + includeOffset: false, + }) + "Z"; + } }, left() { this.$emit('next'); diff --git a/frontend/src/model/photo.js b/frontend/src/model/photo.js index f73451476..72bb1f65b 100644 --- a/frontend/src/model/photo.js +++ b/frontend/src/model/photo.js @@ -52,6 +52,7 @@ export const TypeRaw = "raw"; export const YearUnknown = -1; export const MonthUnknown = -1; export const DayUnknown = -1; +export const TimeZoneUTC = "UTC"; const num = "numeric"; const short = "short"; @@ -231,7 +232,13 @@ export class Photo extends RestModel { time = this.TakenAtLocal.substr(11, 8); } - return `${date}T${time}`; + let iso = `${date}T${time}`; + + if (this.originalTimeZoneUTC()) { + iso += "Z"; + } + + return iso; } getTimeZone() { @@ -239,17 +246,30 @@ export class Photo extends RestModel { return this.TimeZone; } - return "utc"; + return ""; + } + + originalTimeZoneUTC() { + const tz = this.originalValue("TimeZone"); + + if (tz) { + return tz.toLowerCase() === TimeZoneUTC.toLowerCase(); + } + + return false; } localDate(time) { - if (!this.TakenAtLocal) { + if (!this.TakenAtLocal || this.getTimeZone().toLowerCase() === TimeZoneUTC.toLowerCase()) { return this.utcDate(); + } else if (this.getTimeZone() === "") { + return DateTime.fromISO(this.localDateString(time)); } let zone = this.getTimeZone(); + let iso = this.localDateString(time); - return DateTime.fromISO(this.localDateString(time), { zone }); + return DateTime.fromISO(iso, { zone }); } utcDate() { diff --git a/frontend/tests/unit/model/photo_test.js b/frontend/tests/unit/model/photo_test.js index fb7ab898a..e3a0da532 100644 --- a/frontend/tests/unit/model/photo_test.js +++ b/frontend/tests/unit/model/photo_test.js @@ -213,7 +213,7 @@ describe("model/photo", () => { }; const photo = new Photo(values); const result = photo.localDateString(); - assert.equal(result, "2012-07-08T14:45:39"); + assert.equal(result, "2012-07-08T14:45:39Z"); }); it("should get local date", () => { @@ -228,6 +228,20 @@ describe("model/photo", () => { assert.equal(String(result), "2012-07-08T14:45:39.000Z"); }); + it("UTC", () => { + const values = { + ID: 9999, + Title: "Video", + TakenAt: "2012-07-08T14:45:39Z", + TakenAtLocal: "2012-07-08T14:45:39Z", + TimeZone: "UTC", + }; + const photo = new Photo(values); + assert.equal(String(photo.localDateString("10:00:00")), "2012-07-08T10:00:00Z"); + const result = photo.localDate(); + assert.equal(String(result), "2012-07-08T14:45:39.000Z"); + }); + it("should get date string", () => { const values = { ID: 5,