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

Increased date time adapter compatibility #193

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