LP1816475: fixing the datetime editor's timezone handling
authorJane Sandberg <sandbej@linnbenton.edu>
Sat, 30 Mar 2019 09:47:59 +0000 (02:47 -0700)
committerJane Sandberg <sandbej@linnbenton.edu>
Wed, 17 Apr 2019 20:22:00 +0000 (13:22 -0700)
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/eg2/src/app/core/format.service.ts
Open-ILS/src/eg2/src/app/share/datetime-select/datetime-select.component.ts
Open-ILS/src/eg2/src/app/share/fm-editor/fm-editor.component.ts

index f236769..fddbed2 100644 (file)
@@ -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);
     }
 
     /**
index 2cdef97..de8fa86 100644 (file)
@@ -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)) {
index fdb880a..789895c 100644 (file)
@@ -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') {