* 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({
FormatValuePipe
],
providers: [
- DatePipe,
CurrencyPipe
]
})
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';
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
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);
// 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'];
});
}
}