Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

year select with range #11426

Closed
wants to merge 3 commits into from
Closed
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 47 additions & 4 deletions src/app/components/calendar/calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ export interface LocaleSettings {
</span>
</div>
<div class="p-yearpicker" *ngIf="currentView === 'year'">
<span *ngFor="let y of yearPickerValues()" (click)="onYearSelect($event, y)" (keydown)="onYearCellKeydown($event,y)" class="p-yearpicker-year" [ngClass]="{'p-highlight': isYearSelected(y)}" pRipple>
<span *ngFor="let y of yearPickerValues()" (click)="onYearSelect($event, y)" (keydown)="onYearCellKeydown($event,y)" class="p-yearpicker-year" [ngClass]="{'p-highlight': isYearSelected(y), 'p-disabled': isLessThanMinYear(y) || isGreaterThanMaxYear(y)}" pRipple>
{{y}}
</span>
</div>
Expand Down Expand Up @@ -1243,9 +1243,18 @@ export class Calendar implements OnInit,OnDestroy,ControlValueAccessor {

isYearSelected(year) {
if (this.isComparable()) {
let value = this.isRangeSelection() ? this.value[0] : this.value;

return !this.isMultipleSelection() ? (value.getFullYear() === year) : false;
if (this.isMultipleSelection()) {
return false
}
else if (this.isRangeSelection()) {
if (this.value[1])
return this.isYearEquals(this.value[0], year) || this.isYearEquals(this.value[1], year) || this.isYearBetween(this.value[0], this.value[1], year);
else
return this.isYearEquals(this.value[0], year)
}
else {
return this.isYearEquals(this.value, year);
}
}

return false;
Expand All @@ -1268,6 +1277,40 @@ export class Calendar implements OnInit,OnDestroy,ControlValueAccessor {
return between;
}

isYearEquals(value, year) {
if (value && value instanceof Date) return value.getFullYear() === year;
jiyeol-lee marked this conversation as resolved.
Show resolved Hide resolved
else return false;
}

isYearBetween(start, end, year) {
let between: boolean = false;
jiyeol-lee marked this conversation as resolved.
Show resolved Hide resolved
if (start && start instanceof Date && end && end instanceof Date) {
return start.getFullYear() <= year && end.getFullYear() >= year;
}

return between;
}

isLessThanMinYear(year) {
if (this.minDate) {
jiyeol-lee marked this conversation as resolved.
Show resolved Hide resolved
if (year < this.minDate.getFullYear()) {
return true;
}
}

return false;
}

isGreaterThanMaxYear(year) {
if (this.maxDate) {
jiyeol-lee marked this conversation as resolved.
Show resolved Hide resolved
if (this.maxDate.getFullYear() < year) {
return true;
}
}

return false;
}

isSingleSelection(): boolean {
return this.selectionMode === 'single';
}
Expand Down