Skip to content

Commit

Permalink
Merge pull request #193 from Venators/Increased-Date-Time-Adapter-Com…
Browse files Browse the repository at this point in the history
…patibility

Increased date time adapter compatibility
  • Loading branch information
danielmoncada authored Jan 18, 2025
2 parents aae2d21 + 58f8657 commit 87cd25f
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export abstract class DateTimeAdapter<T> {
return this._localeChanges;
}

public firstMonthOfTheYear: number;
public firstDayOfTheWeek: number;

/** total milliseconds in a day. */
protected readonly millisecondsInDay = 86400000;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ const ISO_8601_REGEX = /^\d{4}-\d{2}-\d{2}(?:T\d{2}:\d{2}:\d{2}(?:\.\d+)?(?:Z|(?

@Injectable()
export class NativeDateTimeAdapter extends DateTimeAdapter<Date> {
public firstMonthOfTheYear: number = 0;
public firstDayOfTheWeek: number = 0;

/** Whether to clamp the date between 1 and 9999 to avoid IE and Edge errors. */
private readonly _clampDate: boolean;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import {DEFAULT_DATE_NAMES, DEFAULT_DAY_OF_WEEK_NAMES, DEFAULT_MONTH_NAMES, SUPP

@Injectable()
export class UnixTimestampDateTimeAdapter extends DateTimeAdapter<number> {

public firstMonthOfTheYear: number = 0;
public firstDayOfTheWeek: number = 0;

constructor(
@Optional()
@Inject(OWL_DATE_TIME_LOCALE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -480,8 +480,8 @@ export class OwlMonthViewComponent<T>
});

this._weekdays = weekdays
.slice(firstDayOfWeek)
.concat(weekdays.slice(0, firstDayOfWeek));
.slice(firstDayOfWeek-this.dateTimeAdapter.firstDayOfTheWeek)
.concat(weekdays.slice(0, firstDayOfWeek-this.dateTimeAdapter.firstDayOfTheWeek));

this.dateNames = this.dateTimeAdapter.getDateNames();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export class OwlMultiYearViewComponent<T> implements OnInit, AfterContentInit {
}

private selectYear( year: number ): void {
this.yearSelected.emit(this.dateTimeAdapter.createDate(year, 0, 1));
this.yearSelected.emit(this.dateTimeAdapter.createDate(year, this.dateTimeAdapter.firstMonthOfTheYear, 1));
const firstDateOfMonth = this.dateTimeAdapter.createDate(
year,
this.dateTimeAdapter.getMonth(this.pickerMoment),
Expand Down Expand Up @@ -395,7 +395,7 @@ export class OwlMultiYearViewComponent<T> implements OnInit, AfterContentInit {
* Creates an CalendarCell for the given year.
*/
private createYearCell( year: number ): CalendarCell {
const startDateOfYear = this.dateTimeAdapter.createDate(year, 0, 1);
const startDateOfYear = this.dateTimeAdapter.createDate(year, this.dateTimeAdapter.firstMonthOfTheYear, 1);
const ariaLabel = this.dateTimeAdapter.getYearName(startDateOfYear);
const cellClass = 'owl-dt-year-' + year;
return new CalendarCell(year, year.toString(), ariaLabel, this.isYearEnabled(year), false, cellClass);
Expand Down Expand Up @@ -434,7 +434,7 @@ export class OwlMultiYearViewComponent<T> implements OnInit, AfterContentInit {
return true;
}

const firstOfYear = this.dateTimeAdapter.createDate(year, 0, 1);
const firstOfYear = this.dateTimeAdapter.createDate(year, this.dateTimeAdapter.firstMonthOfTheYear, 1);

// If any date in the year is enabled count the year as enabled.
for (let date = firstOfYear; this.dateTimeAdapter.getYear(date) === year;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,7 @@ export class OwlYearViewComponent<T>
const row = [];

for (let j = 0; j < MONTHS_PER_ROW; j++) {
const month = j + i * MONTHS_PER_ROW;
const month = j + i * MONTHS_PER_ROW + this.dateTimeAdapter.firstMonthOfTheYear;
const monthCell = this.createMonthCell(month);
row.push(monthCell);
}
Expand All @@ -434,7 +434,7 @@ export class OwlYearViewComponent<T>
const cellClass = 'owl-dt-month-' + month;
return new CalendarCell(
month,
this.monthNames[month],
this.monthNames[month-this.dateTimeAdapter.firstMonthOfTheYear],
ariaLabel,
this.isMonthEnabled(month),
false,
Expand Down

0 comments on commit 87cd25f

Please sign in to comment.