From: Bill Erickson Date: Thu, 22 Aug 2019 21:14:41 +0000 (-0400) Subject: LP1840782 Avoid Angular DatePipe, support time-only in format service. X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=241e2985b38eca08bc342c642e719a2054f916ab;p=working%2FEvergreen.git LP1840782 Avoid Angular DatePipe, support time-only in format service. Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/core/core.module.ts b/Open-ILS/src/eg2/src/app/core/core.module.ts index 82052f591d..f07328bd0f 100644 --- a/Open-ILS/src/eg2/src/app/core/core.module.ts +++ b/Open-ILS/src/eg2/src/app/core/core.module.ts @@ -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 ] }) 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 06a6e19841..03fcdb3b01 100644 --- a/Open-ILS/src/eg2/src/app/core/format.service.ts +++ b/Open-ILS/src/eg2/src/app/core/format.service.ts @@ -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); diff --git a/Open-ILS/src/eg2/src/app/share/grid/grid.ts b/Open-ILS/src/eg2/src/app/share/grid/grid.ts index 600f815564..f6af10345d 100644 --- a/Open-ILS/src/eg2/src/app/share/grid/grid.ts +++ b/Open-ILS/src/eg2/src/app/share/grid/grid.ts @@ -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) }); } diff --git a/Open-ILS/src/eg2/src/app/staff/resolver.service.ts b/Open-ILS/src/eg2/src/app/staff/resolver.service.ts index 2c94ec76d3..292bddf651 100644 --- a/Open-ILS/src/eg2/src/app/staff/resolver.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/resolver.service.ts @@ -128,14 +128,10 @@ export class StaffResolver implements Resolve> { // 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']; }); } }