feat: add Master Admin application functionality
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
import { DateTimeFormat } from '../models/date-time-format';
|
||||
import { DateTimeFormatterService } from '../services/date-time-formatter.service';
|
||||
import { AppDateTimePipe } from './app-date-time.pipe';
|
||||
|
||||
describe('AppDateTimePipe', () => {
|
||||
let formatter: DateTimeFormatterService;
|
||||
let pipe: AppDateTimePipe;
|
||||
|
||||
beforeEach(() => {
|
||||
formatter = new DateTimeFormatterService();
|
||||
pipe = new AppDateTimePipe(formatter);
|
||||
});
|
||||
|
||||
it('matches the formatter service output', () => {
|
||||
const value = '2026-07-20T14:30:45.000Z';
|
||||
const expected = formatter.format(value, {
|
||||
format: DateTimeFormat.LongDateTime,
|
||||
timeZone: 'Asia/Dubai',
|
||||
locale: 'en-GB',
|
||||
fallback: 'N/A'
|
||||
});
|
||||
|
||||
expect(pipe.transform(
|
||||
value,
|
||||
DateTimeFormat.LongDateTime,
|
||||
'Asia/Dubai',
|
||||
'en-GB',
|
||||
'N/A'
|
||||
)).toBe(expected);
|
||||
});
|
||||
|
||||
it('passes a custom fallback through to the formatter', () => {
|
||||
expect(pipe.transform(null, DateTimeFormat.Date, 'UTC', 'en-GB', 'N/A')).toBe('N/A');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,28 @@
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
|
||||
import { DateTimeFormat } from '../models/date-time-format';
|
||||
import { DateTimeFormatterService } from '../services/date-time-formatter.service';
|
||||
|
||||
@Pipe({
|
||||
name: 'appDateTime',
|
||||
standalone: true,
|
||||
pure: true
|
||||
})
|
||||
export class AppDateTimePipe implements PipeTransform {
|
||||
constructor(private readonly dateTimeFormatter: DateTimeFormatterService) {}
|
||||
|
||||
transform(
|
||||
value: string | number | Date | null | undefined,
|
||||
format?: DateTimeFormat,
|
||||
timeZone?: string,
|
||||
locale?: string,
|
||||
fallback?: string
|
||||
): string {
|
||||
return this.dateTimeFormatter.format(value, {
|
||||
format,
|
||||
timeZone,
|
||||
locale,
|
||||
fallback
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user