当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript theme.NbDateService类代码示例

本文整理汇总了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);
//.........这里部分代码省略.........
开发者ID:kevinheader,项目名称:nebular,代码行数:101,代码来源:moment-date.service.spec.ts

示例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);
 }
开发者ID:akveo,项目名称:ng2-admin,代码行数:4,代码来源:datepicker.component.ts

示例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);
 });
开发者ID:kevinheader,项目名称:nebular,代码行数:6,代码来源:moment-date.service.spec.ts

示例4: expect

 expect(() => dateService.format(undefined, 'DD.MM.YYYY')).not.toThrow();
开发者ID:kevinheader,项目名称:nebular,代码行数:1,代码来源:moment-date.service.spec.ts

示例5: expect

 expect(() => dateService.format(date, 'DD/MM/YYYY')).not.toThrow();
开发者ID:kevinheader,项目名称:nebular,代码行数:1,代码来源:date-fns-date.service.spec.ts


注:本文中的@nebular/theme.NbDateService类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。