mirror of https://github.com/abpframework/abp.git
committed by
GitHub
3 changed files with 58 additions and 0 deletions
@ -0,0 +1,39 @@ |
|||
import { ConfigStateService, getShortDateFormat, getShortDateShortTimeFormat } from '@abp/ng.core'; |
|||
|
|||
const dateTimeFormat = { |
|||
calendarAlgorithmType: 'SolarCalendar', |
|||
dateSeparator: '/', |
|||
dateTimeFormatLong: 'dddd, MMMM d, yyyy', |
|||
fullDateTimePattern: 'dddd, MMMM d, yyyy h:mm:ss tt', |
|||
longTimePattern: 'h:mm:ss tt', |
|||
shortDatePattern: 'M/d/yyyy', |
|||
shortTimePattern: 'h:mm tt', |
|||
}; |
|||
|
|||
describe('Date Utils', () => { |
|||
let config: ConfigStateService; |
|||
|
|||
beforeEach(() => { |
|||
config = new ConfigStateService(undefined); |
|||
}); |
|||
|
|||
describe('#getShortDateFormat', () => { |
|||
test('should get the short date format from ConfigState and return it', () => { |
|||
const getDeepSpy = jest.spyOn(config, 'getDeep'); |
|||
getDeepSpy.mockReturnValueOnce(dateTimeFormat); |
|||
|
|||
expect(getShortDateFormat(config)).toBe('M/d/yyyy'); |
|||
expect(getDeepSpy).toHaveBeenCalledWith('localization.currentCulture.dateTimeFormat'); |
|||
}); |
|||
}); |
|||
|
|||
describe('#getShortDateShortTimeFormat', () => { |
|||
test('should get the short date time format from ConfigState and return it', () => { |
|||
const getDeepSpy = jest.spyOn(config, 'getDeep'); |
|||
getDeepSpy.mockReturnValueOnce(dateTimeFormat); |
|||
|
|||
expect(getShortDateShortTimeFormat(config)).toBe('M/d/yyyy h:mm a'); |
|||
expect(getDeepSpy).toHaveBeenCalledWith('localization.currentCulture.dateTimeFormat'); |
|||
}); |
|||
}); |
|||
}); |
|||
@ -0,0 +1,18 @@ |
|||
import { ApplicationConfiguration } from '../models/application-configuration'; |
|||
import { ConfigStateService } from '../services'; |
|||
|
|||
export function getShortDateFormat(configStateService: ConfigStateService) { |
|||
const dateTimeFormat = configStateService.getDeep( |
|||
'localization.currentCulture.dateTimeFormat', |
|||
) as ApplicationConfiguration.DateTimeFormat; |
|||
|
|||
return dateTimeFormat.shortDatePattern; |
|||
} |
|||
|
|||
export function getShortDateShortTimeFormat(configStateService: ConfigStateService) { |
|||
const dateTimeFormat = configStateService.getDeep( |
|||
'localization.currentCulture.dateTimeFormat', |
|||
) as ApplicationConfiguration.DateTimeFormat; |
|||
|
|||
return `${dateTimeFormat.shortDatePattern} ${dateTimeFormat.shortTimePattern.replace('tt', 'a')}`; |
|||
} |
|||
Loading…
Reference in new issue