Skip to content

Commit

Permalink
fix navigation bug
Browse files Browse the repository at this point in the history
  • Loading branch information
tiampersian committed Feb 10, 2024
1 parent 3451f20 commit d051a13
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion projects/tiampersian/kendo-jalali-date-inputs/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@tiampersian/kendo-jalali-date-inputs",
"version": "0.1.341",
"version": "0.1.346",
"license": "MIT",
"description": "angular jalali ( persian ) date time picker base on kendo-angular-dateinputs ",
"homepage": "https://github.com/tiampersian/kendo-jalali-date-inputs",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { debounceTime } from 'rxjs/operators';
import { JalaliCldrIntlService } from '../services/jalali-cldr-intl.service';
import { TemplateRef } from '@angular/core';
import { CalendarComponent, MultiViewCalendarComponent } from '@progress/kendo-angular-dateinputs';
import { debounceTime } from 'rxjs/operators';
import { services } from '../providers';
import { IntlService } from '@progress/kendo-angular-intl';
import { JalaliCldrIntlService } from '../services/jalali-cldr-intl.service';
import { dateInRange, firstDayOfMonth, getDayJsValue } from '../services/kendo-util-overrides';

let headerTitleTemplate: TemplateRef<any>;
Object.defineProperty(CalendarComponent.prototype, 'headerTitleTemplate', {
Expand Down Expand Up @@ -81,3 +81,12 @@ MultiViewCalendarComponent.prototype.ngOnInit = function (): void {
this.cdr.detectChanges();
});
};

CalendarComponent.prototype.handleNavigation = function (candidate: Date) {
if (this.disabled) {
return;
}
const focusTarget = candidate ? firstDayOfMonth(candidate, this.bus.service(0).intl.localeIdByDatePickerType) : this.focusedDate;
this.focusedDate = dateInRange(focusTarget, this.min, this.max);
this.detectChanges();
}
Original file line number Diff line number Diff line change
Expand Up @@ -111,12 +111,18 @@ export class JalaliCldrIntlService extends CldrIntlService {
localeId = localeId || this.localeId;
if (this.isJalali && (localeId === 'fa' || localeId === 'ar')) {
try {
return super.formatNumber(value, format, localeId).toPerNumber();
return super.formatNumber(+value, format, localeId).toPerNumber();
} catch (error) {

}
}
return super.formatNumber(value, format, localeId);

try {
return super.formatNumber(+value, format, localeId);
} catch (error) {
}

return '';
}

getDayJsValue(value?: Date | string, localeId?: string): Dayjs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const addDecades = (dt, value, localeId?) => {
const getCalendarType = (localeId: string) => {
return (localeId === 'fa' || localeId === 'fa-IR') ? 'jalali' : 'gregory';
}
const getDayJsValue = (dt: any, localeId: string) => {
export const getDayJsValue = (dt: any, localeId: string) => {
return dayjs(dt).calendar(getCalendarType(localeId))
}

Expand All @@ -81,6 +81,18 @@ export const lastDecadeOfCentury = (dt, localeId?) => {
return getDayJsValue(dt, localeId).add((-(getYear(dt, localeId) % 100)) + 90, 'year').toDate();

}
export const dateInRange = (candidate, min, max) => {
if (!candidate) {
return candidate;
}
if (min && candidate < min) {
return new Date(min);
}
if (max && candidate > max) {
return new Date(max);
}
return candidate;
};

export const shiftWeekNames = (names, offset) => (names.slice(offset).concat(names.slice(0, offset)));

Expand Down

0 comments on commit d051a13

Please sign in to comment.