LP1840782 Avoid Angular DatePipe, support time-only in format service.
authorBill Erickson <berickxx@gmail.com>
Thu, 22 Aug 2019 21:14:41 +0000 (17:14 -0400)
committerBill Erickson <berickxx@gmail.com>
Thu, 22 Aug 2019 21:14:54 +0000 (17:14 -0400)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/src/eg2/src/app/core/core.module.ts
Open-ILS/src/eg2/src/app/core/format.service.ts
Open-ILS/src/eg2/src/app/share/grid/grid.ts
Open-ILS/src/eg2/src/app/staff/resolver.service.ts

index 82052f5..f07328b 100644 (file)
@@ -5,7 +5,7 @@
  * and do not require entry in our 'providers' array.
  */
 import {NgModule} from '@angular/core';
-import {CommonModule, DatePipe, CurrencyPipe} from '@angular/common';
+import {CommonModule, CurrencyPipe} from '@angular/common';
 import {FormatService, FormatValuePipe} from './format.service';
 
 @NgModule({
@@ -20,7 +20,6 @@ import {FormatService, FormatValuePipe} from './format.service';
     FormatValuePipe
   ],
   providers: [
-    DatePipe,
     CurrencyPipe
   ]
 })
index 06a6e19..03fcdb3 100644 (file)
@@ -1,5 +1,5 @@
 import {Injectable, Pipe, PipeTransform} from '@angular/core';
-import {DatePipe, CurrencyPipe} from '@angular/common';
+import {CurrencyPipe} from '@angular/common';
 import {IdlService, IdlObject} from '@eg/core/idl.service';
 import {OrgService} from '@eg/core/org.service';
 import {DateUtil} from '@eg/share/util/date';
@@ -16,18 +16,18 @@ export interface FormatParams {
     idlField?: string;
     datatype?: string;
     orgField?: string; // 'shortname' || 'name'
-    datePlusTime?: boolean;
+    withDate?: boolean;
+    withTime?: boolean;
+    locale?: string;
+    timeZone?: string;
 }
 
 @Injectable({providedIn: 'root'})
 export class FormatService {
 
-    dateFormat = 'shortDate';
-    dateTimeFormat = 'short';
     wsOrgTimezone: string = OpenSRF.tz;
 
     constructor(
-        private datePipe: DatePipe,
         private currencyPipe: CurrencyPipe,
         private idl: IdlService,
         private org: OrgService
@@ -127,12 +127,14 @@ export class FormatService {
                     return '';
                 }
 
-                let fmt = this.dateFormat || 'shortDate';
-                if (params.datePlusTime) {
-                    fmt = this.dateTimeFormat || 'short';
-                }
+                const dateOps = {
+                    locale: params.locale,
+                    timeZone: params.timeZone,
+                    withDate: params.withDate,
+                    withTime: params.withTime
+                };
 
-                return this.datePipe.transform(date, fmt);
+                return DateUtil.dateToLocaleString(date, dateOps);
 
             case 'money':
                 return this.currencyPipe.transform(value);
index 600f815..f6af103 100644 (file)
@@ -732,7 +732,7 @@ export class GridContext {
             idlClass: col.idlClass,
             idlField: col.idlFieldDef ? col.idlFieldDef.name : col.name,
             datatype: col.datatype,
-            datePlusTime: Boolean(col.datePlusTime)
+            withTime: Boolean(col.datePlusTime)
         });
     }
 
index 2c94ec7..292bddf 100644 (file)
@@ -128,14 +128,10 @@ export class StaffResolver implements Resolve<Observable<any>> {
         // in the org service.
         return this.org.settings([
             'lib.timezone',
-            'webstaff.format.dates',
-            'webstaff.format.date_and_time',
             'ui.staff.max_recent_patrons',
             'ui.staff.angular_catalog.enabled' // navbar
         ]).then(settings => {
             this.format.wsOrgTimezone = settings['lib.timezone'];
-            this.format.dateFormat = settings['webstaff.format.dates'];
-            this.format.dateTimeFormat = settings['webstaff.format.date_and_time'];
         });
     }
 }