本文整理匯總了TypeScript中@nebular/theme.NbDateService類的典型用法代碼示例。如果您正苦於以下問題:TypeScript NbDateService類的具體用法?TypeScript NbDateService怎麽用?TypeScript NbDateService使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了NbDateService類的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。
示例1: describe
describe('moment-date-service', () => {
let dateService: NbDateService<Moment>;
beforeEach(() => {
TestBed.configureTestingModule({});
dateService = new NbMomentDateService(TestBed.get(LOCALE_ID));
});
it('should validate as correct if date string is valid according to the format', () => {
const isValid = dateService.isValidDateString('04.23.2018', 'MM.DD.YYYY');
expect(isValid).toBeTruthy();
});
it('should validate as incorrect if date string is invalid according to the format', () => {
const isValid = dateService.isValidDateString('23.04.2018', 'MM.DD.YYYY');
expect(isValid).toBeFalsy();
});
it('should validate as incorrect if date string is completely incorrect', () => {
const isValid = dateService.isValidDateString('hello, it is a date string', 'MM.DD.YYYY');
expect(isValid).toBeFalsy();
});
it('should create today date', () => {
const today = dateService.today();
expect(dateService.isSameDay(today, moment())).toBeTruthy();
});
it('should get date', () => {
const date = moment().year(2018).month(5).date(15);
expect(dateService.getDate(date)).toBe(15);
});
it('should get month', () => {
const month = moment().year(2018).month(5).date(15);
expect(dateService.getMonth(month)).toBe(5);
});
it('should get year', () => {
const year = moment().year(2018).month(5).date(15);
expect(dateService.getYear(year)).toBe(2018);
});
it('should get day of week', () => {
const date = moment().year(2018).month(8).date(17);
expect(dateService.getDayOfWeek(date)).toBe(1);
});
it('should get first day of week', () => {
expect(dateService.getFirstDayOfWeek()).toBe(0);
});
it('should get month name', () => {
const month = moment().year(2018).month(5).date(15);
expect(dateService.getMonthName(month)).toBe('Jun');
});
it('should get month name by index', () => {
expect(dateService.getMonthNameByIndex(5)).toBe('Jun');
});
it('should get day of week names', () => {
expect(dateService.getDayOfWeekNames()).toEqual(['Su', 'Mo', 'Tu', 'We', 'Th', 'Fr', 'Sa']);
});
it('should format date according to the MM.DD.YYYY format', () => {
const date = moment().year(2018).month(5).date(15);
expect(dateService.format(date, 'MM.DD.YYYY')).toBe('06.15.2018');
});
it('should parse date according to the MM.DD.YYYY format', () => {
const date = '06.15.2018';
const parsed = dateService.parse(date, 'MM.DD.YYYY');
expect(parsed.year()).toEqual(2018);
expect(parsed.month()).toEqual(5);
expect(parsed.date()).toEqual(15);
});
it('should parse date according to the DD.MM.YYYY format', () => {
const date = '15.06.2018';
const parsed = dateService.parse(date, 'DD.MM.YYYY');
expect(parsed.year()).toEqual(2018);
expect(parsed.month()).toEqual(5);
expect(parsed.date()).toEqual(15);
});
it('should not format if date isn\'t passed', () => {
expect(() => dateService.format(undefined, 'DD.MM.YYYY')).not.toThrow();
expect(dateService.format(undefined, 'DD.MM.YYYY')).toEqual('');
});
it('should get year end', () => {
const date = moment().year(2018).month(5).date(15);
const yearEnd = dateService.getYearEnd(date);
expect(yearEnd.year()).toEqual(2018);
expect(yearEnd.month()).toEqual(11);
expect(yearEnd.date()).toEqual(31);
//.........這裏部分代碼省略.........
示例2: constructor
constructor(protected dateService: NbDateService<Date>) {
this.min = this.dateService.addDay(this.dateService.today(), -5);
this.max = this.dateService.addDay(this.dateService.today(), 5);
}
示例3: it
it('should add month', () => {
const newDate = dateService.addMonth(moment().year(2018).month(6).date(16), 1);
expect(newDate.year()).toEqual(2018);
expect(newDate.month()).toEqual(7);
expect(newDate.date()).toEqual(16);
});
示例4: expect
expect(() => dateService.format(undefined, 'DD.MM.YYYY')).not.toThrow();
示例5: expect
expect(() => dateService.format(date, 'DD/MM/YYYY')).not.toThrow();