mirror of https://github.com/abpframework/abp.git
committed by
GitHub
7 changed files with 144 additions and 2 deletions
@ -0,0 +1,29 @@ |
|||||
|
# DateTime Format Pipes |
||||
|
|
||||
|
You can format date by Date pipe of angular. |
||||
|
|
||||
|
Example |
||||
|
|
||||
|
```html |
||||
|
<span> {{today | date 'dd/mm/yy'}}</span> |
||||
|
``` |
||||
|
|
||||
|
ShortDate, ShortTime and ShortDateTime format data like angular's data pipe but easier. Also the pipes get format from config service by culture. |
||||
|
|
||||
|
# ShortDate Pipe |
||||
|
|
||||
|
```html |
||||
|
<span> {{today | shortDatePipe }}</span> |
||||
|
``` |
||||
|
|
||||
|
# ShortTime Pipe |
||||
|
|
||||
|
```html |
||||
|
<span> {{today | shortTimePipe }}</span> |
||||
|
``` |
||||
|
|
||||
|
# ShortDateTime Pipe |
||||
|
|
||||
|
```html |
||||
|
<span> {{today | shortDateTimePipe }}</span> |
||||
|
``` |
||||
@ -1,3 +1,6 @@ |
|||||
export * from './localization.pipe'; |
export * from './localization.pipe'; |
||||
export * from './sort.pipe'; |
export * from './sort.pipe'; |
||||
export * from './to-injector.pipe'; |
export * from './to-injector.pipe'; |
||||
|
export * from './short-date.pipe'; |
||||
|
export * from './short-time.pipe'; |
||||
|
export * from './short-date-time.pipe'; |
||||
|
|||||
@ -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) |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
@ -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) |
||||
|
} |
||||
|
|
||||
|
|
||||
|
} |
||||
|
|
||||
|
|
||||
@ -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…
Reference in new issue