-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import {TestBed} from '@angular/core/testing'; | ||
import {NgbDate} from '../ngb-date'; | ||
import {NgbDatepickerI18nHebrew} from './datepicker-i18n-hebrew'; | ||
|
||
describe('datepicker-i18n-hebrew', () => { | ||
|
||
let i18n: NgbDatepickerI18nHebrew; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({providers: [NgbDatepickerI18nHebrew]}); | ||
i18n = TestBed.get(NgbDatepickerI18nHebrew); | ||
}); | ||
|
||
it('should return abbreviated month name', () => { | ||
expect(i18n.getMonthShortName(0, 5778)).toBe(undefined); | ||
expect(i18n.getMonthShortName(1, 5778)).toBe('תשרי'); | ||
expect(i18n.getMonthShortName(6, 5778)).toBe('אדר'); | ||
expect(i18n.getMonthShortName(7, 5778)).toBe('ניסן'); | ||
expect(i18n.getMonthShortName(12, 5778)).toBe('אלול'); | ||
expect(i18n.getMonthShortName(13, 5778)).toBe(undefined); | ||
}); | ||
|
||
it('should return abbreviated month name (leap year)', () => { | ||
expect(i18n.getMonthShortName(0, 5779)).toBe(undefined); | ||
expect(i18n.getMonthShortName(1, 5779)).toBe('תשרי'); | ||
expect(i18n.getMonthShortName(6, 5779)).toBe('אדר א׳'); | ||
expect(i18n.getMonthShortName(7, 5779)).toBe('אדר ב׳'); | ||
expect(i18n.getMonthShortName(12, 5779)).toBe('אב'); | ||
expect(i18n.getMonthShortName(13, 5779)).toBe('אלול'); | ||
expect(i18n.getMonthShortName(14, 5779)).toBe(undefined); | ||
}); | ||
|
||
it('should return wide month name', () => { | ||
expect(i18n.getMonthFullName(0, 5778)).toBe(undefined); | ||
expect(i18n.getMonthFullName(1, 5778)).toBe('תשרי'); | ||
expect(i18n.getMonthFullName(6, 5778)).toBe('אדר'); | ||
expect(i18n.getMonthFullName(7, 5778)).toBe('ניסן'); | ||
expect(i18n.getMonthFullName(12, 5778)).toBe('אלול'); | ||
expect(i18n.getMonthFullName(13, 5778)).toBe(undefined); | ||
}); | ||
|
||
it('should return wide month name (leap year)', () => { | ||
expect(i18n.getMonthFullName(0, 5779)).toBe(undefined); | ||
expect(i18n.getMonthFullName(1, 5779)).toBe('תשרי'); | ||
expect(i18n.getMonthFullName(6, 5779)).toBe('אדר א׳'); | ||
expect(i18n.getMonthFullName(7, 5779)).toBe('אדר ב׳'); | ||
expect(i18n.getMonthFullName(12, 5779)).toBe('אב'); | ||
expect(i18n.getMonthFullName(13, 5779)).toBe('אלול'); | ||
expect(i18n.getMonthFullName(14, 5779)).toBe(undefined); | ||
}); | ||
|
||
it('should return weekday name', () => { | ||
expect(i18n.getWeekdayShortName(0)).toBe(undefined); | ||
expect(i18n.getWeekdayShortName(1)).toBe('ב׳'); | ||
expect(i18n.getWeekdayShortName(7)).toBe('א׳'); | ||
expect(i18n.getWeekdayShortName(8)).toBe(undefined); | ||
}); | ||
|
||
it('should generate aria label for a date', | ||
() => { expect(i18n.getDayAriaLabel(new NgbDate(5778, 10, 8))).toBe('ח׳ תמוז תשע״ח'); }); | ||
|
||
it('should generate week number numerals', () => { | ||
expect(i18n.getWeekNumerals(1)).toBe('א׳'); | ||
expect(i18n.getWeekNumerals(50)).toBe('נ׳'); | ||
}); | ||
|
||
it('should generate day numerals', () => { | ||
expect(i18n.getDayNumerals(new NgbDate(5778, 10, 1))).toBe('א׳'); | ||
expect(i18n.getDayNumerals(new NgbDate(5778, 10, 29))).toBe('כ״ט'); | ||
}); | ||
|
||
it('should generate year numerals', () => { | ||
expect(i18n.getYearNumerals(0)).toBe(''); | ||
expect(i18n.getYearNumerals(5778)).toBe('תשע״ח'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {NgbDatepickerI18n} from '../datepicker-i18n'; | ||
import {NgbDateStruct} from '../../index'; | ||
import {hebrewNumerals, isHebrewLeapYear} from './hebrew'; | ||
import {Injectable} from '@angular/core'; | ||
|
||
|
||
const WEEKDAYS = ['ב׳', 'ג׳', 'ד׳', 'ה׳', 'ו׳', 'ש׳', 'א׳']; | ||
const MONTHS = ['תשרי', 'חשון', 'כסלו', 'טבת', 'שבט', 'אדר', 'ניסן', 'אייר', 'סיון', 'תמוז', 'אב', 'אלול']; | ||
const MONTHS_LEAP = | ||
['תשרי', 'חשון', 'כסלו', 'טבת', 'שבט', 'אדר א׳', 'אדר ב׳', 'ניסן', 'אייר', 'סיון', 'תמוז', 'אב', 'אלול']; | ||
|
||
@Injectable() | ||
export class NgbDatepickerI18nHebrew extends NgbDatepickerI18n { | ||
getMonthShortName(month: number, year?: number): string { return this.getMonthFullName(month, year); } | ||
|
||
getMonthFullName(month: number, year?: number): string { | ||
return isHebrewLeapYear(year) ? MONTHS_LEAP[month - 1] : MONTHS[month - 1]; | ||
} | ||
|
||
getWeekdayShortName(weekday: number): string { return WEEKDAYS[weekday - 1]; } | ||
|
||
getDayAriaLabel(date: NgbDateStruct): string { | ||
return `${hebrewNumerals(date.day)} ${this.getMonthFullName(date.month, date.year)} ${hebrewNumerals(date.year)}`; | ||
} | ||
|
||
getDayNumerals(date: NgbDateStruct): string { return hebrewNumerals(date.day); } | ||
|
||
getWeekNumerals(weekNumber: number): string { return hebrewNumerals(weekNumber); } | ||
|
||
getYearNumerals(year: number): string { return hebrewNumerals(year); } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters