當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。