Browse Source

feat: Convert short date,time and datetime functions to pipe #11909

pull/11912/head
Mahmut Gundogdu 4 years ago
parent
commit
b73781874a
  1. 10
      npm/ng-packs/packages/core/src/lib/core.module.ts
  2. 3
      npm/ng-packs/packages/core/src/lib/pipes/index.ts
  3. 32
      npm/ng-packs/packages/core/src/lib/pipes/short-date-time.pipe.ts
  4. 32
      npm/ng-packs/packages/core/src/lib/pipes/short-date.pipe.ts
  5. 32
      npm/ng-packs/packages/core/src/lib/pipes/short-time.pipe.ts

10
npm/ng-packs/packages/core/src/lib/core.module.ts

@ -34,6 +34,9 @@ import { TENANT_KEY } from './tokens/tenant-key.token';
import { noop } from './utils/common-utils';
import './utils/date-extensions';
import { getInitialData, localeInitializer } from './utils/initial-utils';
import { ShortDateTimePipe } from './pipes/short-date-time.pipe';
import { ShortTimePipe } from './pipes/short-time.pipe';
import { ShortDatePipe } from './pipes/short-date.pipe';
export function storageFactory(): OAuthStorage {
return oAuthStorage;
@ -67,6 +70,9 @@ export function storageFactory(): OAuthStorage {
SortPipe,
StopPropagationDirective,
ToInjectorPipe,
ShortDateTimePipe,
ShortTimePipe,
ShortDatePipe
],
imports: [
OAuthModule,
@ -92,6 +98,10 @@ export function storageFactory(): OAuthStorage {
SortPipe,
StopPropagationDirective,
ToInjectorPipe,
ShortDateTimePipe,
ShortTimePipe,
ShortDatePipe
],
providers: [LocalizationPipe]
})

3
npm/ng-packs/packages/core/src/lib/pipes/index.ts

@ -1,3 +1,6 @@
export * from './localization.pipe';
export * from './sort.pipe';
export * from './to-injector.pipe';
export * from './short-date.pipe';
export * from './short-time.pipe';
export * from './short-date-time.pipe';

32
npm/ng-packs/packages/core/src/lib/pipes/short-date-time.pipe.ts

@ -0,0 +1,32 @@
import { DatePipe, DATE_PIPE_DEFAULT_TIMEZONE } from '@angular/common';
import { Inject, LOCALE_ID, Optional, Pipe, PipeTransform } from '@angular/core';
import { ConfigStateService } from '../services';
import { getShortDateShortTimeFormat } from '../utils/date-utils';
@Pipe({
name: 'shortDateTime',
pure: true,
})
export class ShortDateTimePipe extends DatePipe implements PipeTransform {
constructor(private configStateService: ConfigStateService,
@Inject(LOCALE_ID) locale: string,
@Inject(DATE_PIPE_DEFAULT_TIMEZONE) @Optional() defaultTimezone?: string|null
) {
super(locale, defaultTimezone)
}
transform(value: Date | string | number, format?: string, timezone?: string, locale?: string): string | null;
transform(value: null | undefined, format?: string, timezone?: string, locale?: string): null;
transform(
value: string|number|Date|null|undefined, timezone?: string,
locale?: string): string|null {
const format = getShortDateShortTimeFormat(this.configStateService);
return super.transform(value,format,timezone,locale)
}
}

32
npm/ng-packs/packages/core/src/lib/pipes/short-date.pipe.ts

@ -0,0 +1,32 @@
import { DatePipe, DATE_PIPE_DEFAULT_TIMEZONE } from '@angular/common';
import { Inject, LOCALE_ID, Optional, Pipe, PipeTransform } from '@angular/core';
import { ConfigStateService } from '../services';
import { getShortDateFormat } from '../utils/date-utils';
@Pipe({
name: 'shortDate',
pure: true,
})
export class ShortDatePipe extends DatePipe implements PipeTransform {
constructor(private configStateService: ConfigStateService,
@Inject(LOCALE_ID) locale: string,
@Inject(DATE_PIPE_DEFAULT_TIMEZONE) @Optional() defaultTimezone?: string|null
) {
super(locale, defaultTimezone)
}
transform(value: Date | string | number, format?: string, timezone?: string, locale?: string): string | null;
transform(value: null | undefined, format?: string, timezone?: string, locale?: string): null;
transform(
value: string|number|Date|null|undefined, timezone?: string,
locale?: string): string|null {
const format = getShortDateFormat(this.configStateService);
return super.transform(value,format,timezone,locale)
}
}

32
npm/ng-packs/packages/core/src/lib/pipes/short-time.pipe.ts

@ -0,0 +1,32 @@
import { DatePipe, DATE_PIPE_DEFAULT_TIMEZONE } from '@angular/common';
import { Inject, LOCALE_ID, Optional, Pipe, PipeTransform } from '@angular/core';
import { ConfigStateService } from '../services';
import { getShortTimeFormat } from '../utils/date-utils';
@Pipe({
name: 'shortTime',
pure: true,
})
export class ShortTimePipe extends DatePipe implements PipeTransform {
constructor(private configStateService: ConfigStateService,
@Inject(LOCALE_ID) locale: string,
@Inject(DATE_PIPE_DEFAULT_TIMEZONE) @Optional() defaultTimezone?: string|null
) {
super(locale, defaultTimezone)
}
transform(value: Date | string | number, format?: string, timezone?: string, locale?: string): string | null;
transform(value: null | undefined, format?: string, timezone?: string, locale?: string): null;
transform(
value: string|number|Date|null|undefined, timezone?: string,
locale?: string): string|null {
const format = getShortTimeFormat(this.configStateService);
return super.transform(value,format,timezone,locale)
}
}
Loading…
Cancel
Save