Frontend: Don't change UTC when original time was in UTC #1668
This commit is contained in:
parent
d813171204
commit
d432584041
3 changed files with 52 additions and 10 deletions
|
@ -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');
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in a new issue