Skip to content

Commit

Permalink
fix(datepicker): Datepicker should keep the day when navigating betwe…
Browse files Browse the repository at this point in the history
…en months (ng-bootstrap#3398)
  • Loading branch information
gpolychronis-amadeus committed Dec 10, 2019
1 parent 36ce6fb commit 62b43ae
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
Expand Up @@ -7,8 +7,10 @@
[dayTemplateData]="dayTemplateData">
</ngb-datepicker>

<ng-template #dt let-date let-data="data" let-selected="selected" let-currentMonth="currentMonth">
<div class="hebrew-day" [class.outside]="date.month !== currentMonth" [class.selected]="selected">
<ng-template #dt let-date let-data="data" let-selected="selected" let-currentMonth="currentMonth" let-focused="focused">
<div class="hebrew-day" [class.outside]="date.month !== currentMonth" [class.selected]="selected"
[class.active]="focused"
[class.btn-light]="focused && !selected">
<div class="gregorian-num">{{ data.gregorian.day + '/' + (data.gregorian.month) }}</div>
<div class="hebrew-num">{{ i18n.getDayNumerals(date) }}</div>
</div>
Expand Down
8 changes: 5 additions & 3 deletions src/datepicker/hijri/ngb-calendar-hijri.ts
Expand Up @@ -31,16 +31,18 @@ export abstract class NgbCalendarHijri extends NgbCalendar {

getNext(date: NgbDate, period: NgbPeriod = 'd', number = 1) {
date = new NgbDate(date.year, date.month, date.day);
let days;

switch (period) {
case 'y':
date = this._setYear(date, date.year + number);
date.month = 1;
date.day = 1;
days = this.getDaysPerMonth(date.month, date.year);
date.day = date.day <= days ? date.day : days;
return date;
case 'm':
date = this._setMonth(date, date.month + number);
date.day = 1;
days = this.getDaysPerMonth(date.month, date.year);
date.day = date.day <= days ? date.day : days;
return date;
case 'd':
return this._setDay(date, date.day + number);
Expand Down
2 changes: 1 addition & 1 deletion src/datepicker/jalali/jalali.ts
Expand Up @@ -213,7 +213,7 @@ function jalaliToJulian(jYear: number, jMonth: number, jDay: number) {
/**
* Returns the number of days in a specific jalali month.
*/
function getDaysPerMonth(month: number, year: number): number {
export function getDaysPerMonth(month: number, year: number): number {
if (month <= 6) {
return 31;
}
Expand Down
10 changes: 6 additions & 4 deletions src/datepicker/jalali/ngb-calendar-persian.ts
Expand Up @@ -3,7 +3,7 @@ import {NgbDate} from '../ngb-date';
import {NgbCalendar, NgbPeriod} from '../ngb-calendar';
import {isInteger} from '../../util/util';

import {fromGregorian, setJalaliDay, setJalaliMonth, setJalaliYear, toGregorian} from './jalali';
import {fromGregorian, setJalaliDay, setJalaliMonth, setJalaliYear, toGregorian, getDaysPerMonth} from './jalali';

@Injectable()
export class NgbCalendarPersian extends NgbCalendar {
Expand All @@ -15,16 +15,18 @@ export class NgbCalendarPersian extends NgbCalendar {

getNext(date: NgbDate, period: NgbPeriod = 'd', number = 1) {
date = new NgbDate(date.year, date.month, date.day);
let days;

switch (period) {
case 'y':
date = setJalaliYear(date, date.year + number);
date.month = 1;
date.day = 1;
days = getDaysPerMonth(date.month, date.year);
date.day = date.day <= days ? date.day : days;
return date;
case 'm':
date = setJalaliMonth(date, date.month + number);
date.day = 1;
days = getDaysPerMonth(date.month, date.year);
date.day = date.day <= days ? date.day : days;
return date;
case 'd':
return setJalaliDay(date, date.day + number);
Expand Down

0 comments on commit 62b43ae

Please sign in to comment.