From addd30cb036d81716fb467dde47dd9787c8790f8 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Sat, 30 Mar 2019 02:47:59 -0700 Subject: [PATCH] LP1816475: fixing the datetime editor's timezone handling Signed-off-by: Jane Sandberg --- Open-ILS/src/eg2/src/app/core/format.service.ts | 16 ++++++++-------- .../share/datetime-select/datetime-select.component.ts | 16 ++++++++-------- .../eg2/src/app/share/fm-editor/fm-editor.component.ts | 4 ++-- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/core/format.service.ts b/Open-ILS/src/eg2/src/app/core/format.service.ts index f236769220..fddbed2b9a 100644 --- a/Open-ILS/src/eg2/src/app/core/format.service.ts +++ b/Open-ILS/src/eg2/src/app/core/format.service.ts @@ -137,23 +137,23 @@ export class FormatService { /** * Create an IDL-friendly display version of a human-readable date */ - idlFormatDate(date: string): string { return this.momentizeDateString(date).format('YYYY-MM-DD'); } + idlFormatDate(date: string, timezone: string): string { return this.momentizeDateString(date, timezone).format('YYYY-MM-DD'); } /** * Create an IDL-friendly display version of a human-readable datetime */ - idlFormatDatetime(datetime: string): string { return this.momentizeDateTimeString(datetime).toISOString(); } + idlFormatDatetime(datetime: string, timezone: string): string { return this.momentizeDateTimeString(datetime, timezone).toISOString(); } - momentizeDateString(date: string): Moment { + momentizeDateString(date: string, timezone: string): Moment { const parseableFormat = this.makeFormatParseable(this.dateFormat); - if (parseableFormat.length) {return Moment(date, parseableFormat, 'Asia/Tokyo')}; - return Moment(date, 'Asia/Tokyo'); + if (parseableFormat.length) {return Moment(date, parseableFormat, timezone)}; + return Moment(date, timezone); } - momentizeDateTimeString(datetime: string): Moment { + momentizeDateTimeString(datetime: string, timezone: string): Moment { const parseableFormat = this.makeFormatParseable(this.dateTimeFormat); - if (parseableFormat.length) {return Moment(datetime, parseableFormat, 'Asia/Tokyo')}; - return Moment(datetime, 'Asia/Tokyo'); + if (parseableFormat.length) {return Moment(datetime, parseableFormat, timezone)}; + return Moment(datetime, timezone); } /** diff --git a/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts index 2cdef975b9..de8fa86c0b 100644 --- a/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts +++ b/Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts @@ -14,9 +14,9 @@ export class DateTimeSelectComponent implements OnInit { @Input() domId = ''; @Input() fieldName: string; @Input() required: boolean; - @Input() minuteStep: number; + @Input() minuteStep: number = 15; @Input() showTZ = true; - @Input() timezone: string; + @Input() timezone: string = this.format.wsOrgTimezone; @Input() readOnly = false; @Input() initialIso: string; @@ -33,7 +33,7 @@ export class DateTimeSelectComponent implements OnInit { } ngOnInit() { - const start = this.initialIso ? Moment(this.initialIso) : Moment(); + const start = this.initialIso ? Moment(this.initialIso, this.timezone) : Moment(new Date(), this.timezone); this.setDefaultDate(start); this.setDefaultTime(start); @@ -47,10 +47,10 @@ export class DateTimeSelectComponent implements OnInit { } setDefaultTime(start: any) { - const remainder = 5 - start.minute() % 5, - final = Moment(start).add(remainder, 'minutes'); + const remainder = this.minuteStep - start.minute() % this.minuteStep, + final = Moment(start, this.timezone).add(remainder, 'minutes'); - // Seed time model with current, rounding up to nearest 5 minutes (does roll hour over if needed) + // Seed time model with current, rounding up to nearest granularity minutes (does roll hour over if needed) this.timeModel = { hour: final.hour(), minute: final.minute(), second: 0 }; } @@ -63,10 +63,10 @@ export class DateTimeSelectComponent implements OnInit { let newDate: Moment; if (event) { // if the change came from the input field - newDate = this.format.momentizeDateTimeString(this.stringVersion); + newDate = this.format.momentizeDateTimeString(this.stringVersion, this.timezone); } else { newDate = Moment(new Date(this.dateModel.year, (this.dateModel.month - 1), this.dateModel.day, - this.timeModel.hour, this.timeModel.minute, this.timeModel.second)); + this.timeModel.hour, this.timeModel.minute, this.timeModel.second), this.timezone); } if (newDate && !isNaN(newDate)) { diff --git a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts index fdb880ab17..789895cac5 100644 --- a/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts +++ b/Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts @@ -87,7 +87,7 @@ export class FmRecordEditorComponent recId: any; // Show datetime fields in this particular timezone - timezone: string; + timezone: string = this.format.wsOrgTimezone; // IDL record we are editing // TODO: allow this to be update in real time by the caller? @@ -270,7 +270,7 @@ export class FmRecordEditorComponent rec[field.name]('f'); } } else if ( field.datatype === 'timestamp' && field.datetime && rec[field.name]() ) { - rec[field.name] = this.format.idlFormatDatetime(rec[field.name]()) + rec[field.name] = this.format.idlFormatDatetime(rec[field.name](), this.timezone); } else if (field.datatype === 'org_unit') { const org = rec[field.name](); if (org && typeof org === 'object') { -- 2.11.0