Skip to content

Commit

Permalink
fix(calendar): use last defined week day to determine week numb… (#1969)
Browse files Browse the repository at this point in the history
  • Loading branch information
yggg authored Sep 20, 2019
1 parent bf14c47 commit ba78d94
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
:host {
display: flex;
}

.days-container {
width: 100%;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,13 @@ import { convertToBoolProperty } from '../../../helpers';
* */
@Component({
selector: 'nb-calendar-day-picker',
styles: [` :host { display: flex; } `],
template: `
<nb-calendar-week-numbers *ngIf="showWeekNumber"
[weeks]="weeks"
[size]="size"
[weekNumberSymbol]="weekNumberSymbol">
</nb-calendar-week-numbers>
<div>
<div class="days-container">
<nb-calendar-days-names></nb-calendar-days-names>
<nb-calendar-picker
[data]="weeks"
Expand All @@ -48,6 +47,7 @@ import { convertToBoolProperty } from '../../../helpers';
</nb-calendar-picker>
</div>
`,
styleUrls: ['./calendar-day-picker.component.scss'],
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class NbCalendarDayPickerComponent<D, T> implements OnChanges {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ export class NbCalendarWeekNumberComponent<D> {

getWeeks(): number[] {
return this.weeks.map((week: D[]) => {
// Find last defined day as week could contain null days in case
// boundingMonth set to false
const lastDay = [ ...week ].reverse().find((day: D) => !!day);
// Use last day of the week to determine week number.
// This way weeks which span between sibling years is marked first
return this.dateService.getWeekNumber(week[6]);
return this.dateService.getWeekNumber(lastDay);
});
}
}

0 comments on commit ba78d94

Please sign in to comment.