Skip to content

Commit

Permalink
feat(datepicker): add Gregorian conversion methods to Hebrew calendar
Browse files Browse the repository at this point in the history
  • Loading branch information
maxokorokov authored and pkozlowski-opensource committed Oct 19, 2018
1 parent 107ea44 commit 565cfda
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
12 changes: 11 additions & 1 deletion src/datepicker/hebrew/ngb-calendar-hebrew.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {NgbDate} from '../ngb-date';
import {NgbCalendar, NgbPeriod} from '../ngb-calendar';
import {fromJSDate, NgbCalendar, NgbPeriod, toJSDate} from '../ngb-calendar';
import {Injectable} from '@angular/core';
import {isNumber} from '../../util/util';
import {
Expand Down Expand Up @@ -70,4 +70,14 @@ export class NgbCalendarHebrew extends NgbCalendar {
}

getToday(): NgbDate { return fromGregorian(new Date()); }

/**
* @since 3.4.0
*/
toGregorian(date: NgbDate): NgbDate { return fromJSDate(toGregorian(date)); }

/**
* @since 3.4.0
*/
fromGregorian(date: NgbDate): NgbDate { return fromGregorian(toJSDate(date)); }
}
4 changes: 2 additions & 2 deletions src/datepicker/ngb-calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ import {NgbDate} from './ngb-date';
import {Injectable} from '@angular/core';
import {isInteger} from '../util/util';

function fromJSDate(jsDate: Date) {
export function fromJSDate(jsDate: Date) {
return new NgbDate(jsDate.getFullYear(), jsDate.getMonth() + 1, jsDate.getDate());
}
function toJSDate(date: NgbDate) {
export function toJSDate(date: NgbDate) {
const jsDate = new Date(date.year, date.month - 1, date.day, 12);
// this is done avoid 30 -> 1930 conversion
if (!isNaN(jsDate.getTime())) {
Expand Down

0 comments on commit 565cfda

Please sign in to comment.