diff --git a/classes/DlDateAdapter.html b/classes/DlDateAdapter.html new file mode 100644 index 00000000..d0f8b136 --- /dev/null +++ b/classes/DlDateAdapter.html @@ -0,0 +1,450 @@ + + +
+ + ++
+ src/lib/core/dl-date-adapter.ts
+
+
+
Determines the model type of the Date/Time picker another type.
+ + + + + + +
+ Methods+ |
+
+
|
+
+ + + Abstract + fromMilliseconds + + + | +||||||||
+
+ fromMilliseconds(milliseconds: number)
+ |
+ ||||||||
+ Defined in src/lib/core/dl-date-adapter.ts:13
+ |
+ ||||||||
+ Create a new instance of a
+ Parameters :
+
+
+
+ Returns :
+ D
+
+
+
+ an instance of |
+
+ + + Abstract + toMilliseconds + + + | +||||||||
+
+ toMilliseconds(value: D | null)
+ |
+ ||||||||
+ Defined in src/lib/core/dl-date-adapter.ts:22
+ |
+ ||||||||
+ Returns a moment in time value as milliseconds (local time zone).
+ a moment in time value as
+ Parameters :
+
+
+
+ Returns :
+ number | null
+
+
+
+ a moment in |
+
export abstract class DlDateAdapter<D> {
+
+ /**
+ * Create a new instance of a `D` type from milliseconds.
+ * @param milliseconds
+ * a moment in time value as milliseconds (local time zone)
+ * @returns
+ * an instance of `D` for the specified moment in time.
+ */
+ abstract fromMilliseconds(milliseconds: number): D;
+
+ /**
+ * Returns a moment in time value as milliseconds (local time zone).
+ * @param value
+ * a moment in time value as `D` or `null`.
+ * @returns
+ * a moment in` for the specified value or `null`
+ */
+ abstract toMilliseconds(value: D | null): number | null;
+}
+
+ +
+ src/lib/core/dl-date-adapter-moment.ts
+
+
+
Adapts moment
to be usable as a date by date/time components that work with dates.
+
+ DlDateAdapter
+
+ Methods+ |
+
+
|
+
+ + + fromMilliseconds + + + | +||||||||
+fromMilliseconds(milliseconds: number)
+ |
+ ||||||||
+ Inherited from
+ DlDateAdapter
+ |
+ ||||||||
+ Defined in
+ DlDateAdapter:17
+ |
+ ||||||||
+ Create a new instance of a
+ Parameters :
+
+
+
+ Returns :
+ Moment
+
+
+
+ an instance of |
+
+ + + toMilliseconds + + + | +||||||||
+toMilliseconds(value: Moment | null)
+ |
+ ||||||||
+ Inherited from
+ DlDateAdapter
+ |
+ ||||||||
+ Defined in
+ DlDateAdapter:28
+ |
+ ||||||||
+ Returns a moment in time value as milliseconds (local time zone).
+ a moment or
+ Parameters :
+
+
+
+ Returns :
+ number | null
+
+
+
+ a |
+
import moment from 'moment';
+import {Moment} from 'moment';
+import {DlDateAdapter} from './dl-date-adapter';
+
+/**
+ * Adapts `moment` to be usable as a date by date/time components that work with dates.
+ **/
+export class DlDateAdapterMoment extends DlDateAdapter<Moment> {
+
+ /**
+ * Create a new instance of a `moment` type from milliseconds.
+ * @param milliseconds
+ * a time value as milliseconds (local time zone)
+ * @returns
+ * an instance of `moment` for the specified moment in time.
+ */
+ fromMilliseconds(milliseconds: number): Moment {
+ return moment(milliseconds);
+ }
+
+ /**
+ * Returns a moment in time value as milliseconds (local time zone).
+ * @param value
+ * a moment or `null`.
+ * @returns
+ * a `moment.valueOf()` result for the specified `moment` or `null`
+ */
+ toMilliseconds(value: Moment | null): number | null {
+ return (value) ? value.valueOf() : undefined;
+ }
+}
+
+ +
+ src/lib/core/dl-date-adapter-native.ts
+
+
+
Adapts Date
to be usable as a date by date/time components that work with dates.
+
+ DlDateAdapter
+
+ Methods+ |
+
+
|
+
+ + + fromMilliseconds + + + | +||||||||
+fromMilliseconds(milliseconds: number)
+ |
+ ||||||||
+ Inherited from
+ DlDateAdapter
+ |
+ ||||||||
+ Defined in
+ DlDateAdapter:14
+ |
+ ||||||||
+ Create a new instance of a
+ Parameters :
+
+
+
+ Returns :
+ Date
+
+
+
+ an instance of |
+
+ + + toMilliseconds + + + | +||||||||
+toMilliseconds(value: Date | null)
+ |
+ ||||||||
+ Inherited from
+ DlDateAdapter
+ |
+ ||||||||
+ Defined in
+ DlDateAdapter:26
+ |
+ ||||||||
+ Returns a moment in time value as milliseconds (local time zone).
+ a Date or null.
+ a
+ Parameters :
+
+
+
+ Returns :
+ number | null
+
+
+
+ a |
+
import {DlDateAdapter} from './dl-date-adapter';
+
+/**
+ * Adapts `Date` to be usable as a date by date/time components that work with dates.
+ **/
+export class DlDateAdapterNative extends DlDateAdapter<Date> {
+ /**
+ * Create a new instance of a `moment` type from milliseconds.
+ * @param milliseconds
+ * a time value as milliseconds (local time zone)
+ * @returns
+ * an instance of `moment` for the specified moment in time.
+ */
+ fromMilliseconds(milliseconds: number): Date {
+ return new Date(milliseconds);
+ }
+
+
+ /**
+ * Returns a moment in time value as milliseconds (local time zone).
+ * @param value
+ * a Date or null.
+ * @returns
+ * a `value.getTime()` result for the specified `Date` or `null`.
+ */
+ toMilliseconds(value: Date | null): number | null {
+ return (value) ? value.getTime() : undefined;
+ }
+}
+
+ +
+ src/lib/core/dl-date-adapter-number.ts
+
+
+
Adapts number
to be usable as a date by date/time components that work with dates.
+No op adapter.
+
+ DlDateAdapter
+
+ Methods+ |
+
+
|
+
+ + + fromMilliseconds + + + | +||||||||
+fromMilliseconds(milliseconds: number)
+ |
+ ||||||||
+ Inherited from
+ DlDateAdapter
+ |
+ ||||||||
+ Defined in
+ DlDateAdapter:15
+ |
+ ||||||||
+ Returns the specified number. + a moment time time. + the specified moment in time. +
+ Parameters :
+
+
+
+ Returns :
+ number
+
+
+
+ the specified moment in time. + + |
+
+ + + toMilliseconds + + + | +||||||||
+toMilliseconds(value: number | null)
+ |
+ ||||||||
+ Inherited from
+ DlDateAdapter
+ |
+ ||||||||
+ Defined in
+ DlDateAdapter:26
+ |
+ ||||||||
+ Returns the specified number.
+ a moment time time or
+ Parameters :
+
+
+
+ Returns :
+ number | null
+
+
+
+ the specified moment in time or |
+
import {DlDateAdapter} from './dl-date-adapter';
+
+/**
+ * Adapts `number` to be usable as a date by date/time components that work with dates.
+ * No op adapter.
+ **/
+export class DlDateAdapterNumber extends DlDateAdapter<number> {
+ /**
+ * Returns the specified number.
+ * @param milliseconds
+ * a moment time time.
+ * @returns
+ * the specified moment in time.
+ */
+ fromMilliseconds(milliseconds: number): number {
+ return milliseconds;
+ }
+
+ /**
+ * Returns the specified number.
+ * @param value
+ * a moment time time or `null`
+ * @returns
+ * the specified moment in time or `null`
+ */
+ toMilliseconds(value: number | null): number | null {
+ return value;
+ }
+}
+
+ +
+ src/lib/dl-date-time-input/dl-date-time-input-change.ts
+
+
+
Emitted when the value of a date/time input changes.
+ + + + + + +
+ Accessors+ |
+
+
|
+
+constructor(newValue: D)
+ |
+ ||||||||
+ + | +||||||||
+ Constructs a new instance. + the new value of the date/time picker. +
+ Parameters :
+
+
|
+
+ + value + | +
+ getvalue()
+ |
+
+ + | +
+ Get the new value of the date/time picker. +
+
+
+ Returns :
+ D
+
+ |
+
export class DlDateTimeInputChange<D> {
+
+ /**
+ * The new value of the picker.
+ */
+ private readonly _value: D;
+
+ /**
+ * Constructs a new instance.
+ * @param newValue
+ * the new value of the date/time picker.
+ */
+ constructor(newValue: D) {
+ this._value = newValue;
+ }
+
+ /**
+ * Get the new value of the date/time picker.
+ * @returns the new value or null.
+ */
+ get value(): D {
+ return this._value;
+ }
+}
+
+ +
+ src/lib/dl-date-time-picker/dl-date-time-picker-change.ts
+
+
+
Emitted when the value of a date/time picker changes.
+ + + + + + +
+ Accessors+ |
+
+
|
+
+constructor(newValue: D)
+ |
+ ||||||||
+ + | +||||||||
+ Constructs a new instance. + the new value of the date/time picker. +
+ Parameters :
+
+
|
+
+ + value + | +
+ getvalue()
+ |
+
+ + | +
+ Get the new value of the date/time picker. +
+
+
+ Returns :
+ D
+
+ |
+
export class DlDateTimePickerChange<D> {
+
+ /**
+ * The new value of the picker.
+ */
+ private readonly _value: D;
+
+ /**
+ * Constructs a new instance.
+ * @param newValue
+ * the new value of the date/time picker.
+ */
+ constructor(newValue: D) {
+ this._value = newValue;
+ }
+
+ /**
+ * Get the new value of the date/time picker.
+ * @returns the new value or null.
+ */
+ get value(): D {
+ return this._value;
+ }
+}
+
+ +
+ src/lib/dl-date-time-picker/dl-model-provider-day.ts
+
+
+
Default implementation for the day
view.
+
+ DlModelProvider
+
+ Methods+ |
+
+ + | +
+ + + getModel + + + | +||||||||||||
+getModel(milliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Returns the The The Each cell represents a one-day increment at midnight. +the moment in time from which the minute model will be created. + the current value of the date/time picker. + the model representing the specified moment in time. +
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ the model representing the specified moment in time. + + |
+
+ + + goDown + + + | +||||||||||||
+goDown(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Moving the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goEnd + + + | +||||||||||||
+goEnd(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The view or time range will not change unless the the moment in time from which the last day of the month will be calculated.
+ the current value of the date/time picker.
+ a model with the last cell in the view as the active
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ a model with the last cell in the view as the active |
+
+ + + goHome + + + | +||||||||||||
+goHome(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The view or time range will not change unless the the moment in time from which the first day of the month will be calculated.
+ the current value of the date/time picker.
+ a model with the first cell in the view as the active
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ a model with the first cell in the view as the active |
+
+ + + goLeft + + + | +||||||||||||
+goLeft(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the Moving the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goRight + + + | +||||||||||||
+goRight(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the Moving the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goUp + + + | +||||||||||||
+goUp(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Moving the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + onChanges + + + | +||||||
+onChanges(_changes: SimpleChanges)
+ |
+ ||||||
+ + | +||||||
+ Receives input changes detected by Angular. +the input changes detected by Angular. +
+ Parameters :
+
+
+
+ Returns :
+ void
+
+
+
+
+ |
+
+ + + pageDown + + + | +||||||||||||
+pageDown(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Paging the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + pageUp + + + | +||||||||||||
+pageUp(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Paging the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
import {SimpleChanges} from '@angular/core';
+import moment from 'moment';
+import {DlDateTimePickerModel} from './dl-date-time-picker-model';
+import {DlModelProvider} from './dl-model-provider';
+
+/**
+ * Default implementation for the `day` view.
+ */
+export class DlDayModelProvider implements DlModelProvider {
+
+ /**
+ * Receives input changes detected by Angular.
+ *
+ * @param changes
+ * the input changes detected by Angular.
+ */
+ onChanges(
+ _changes: SimpleChanges
+ ): void {}
+
+ /**
+ * Returns the `day` model for the specified moment in `local` time with the
+ * `active` day set to the first day of the month.
+ *
+ * The `day` model represents a month (42 days) as six rows with seven columns
+ * and each cell representing one-day increments.
+ *
+ * The `day` always starts at midnight.
+ *
+ * Each cell represents a one-day increment at midnight.
+ *
+ * @param milliseconds
+ * the moment in time from which the minute model will be created.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * the model representing the specified moment in time.
+ */
+ getModel(milliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+
+ const startOfMonth = moment(milliseconds).startOf('month');
+ const endOfMonth = moment(milliseconds).endOf('month');
+ const startOfView = moment(startOfMonth).subtract(Math.abs(startOfMonth.weekday()), 'days');
+
+ const rowNumbers = [0, 1, 2, 3, 4, 5];
+ const columnNumbers = [0, 1, 2, 3, 4, 5, 6];
+
+ const previousMonth = moment(startOfMonth).subtract(1, 'month');
+ const nextMonth = moment(startOfMonth).add(1, 'month');
+ const activeValue = moment(milliseconds).startOf('day').valueOf();
+ const selectedValue = selectedMilliseconds === null || selectedMilliseconds === undefined
+ ? selectedMilliseconds
+ : moment(selectedMilliseconds).startOf('day').valueOf();
+
+ return {
+ viewName: 'day',
+ viewLabel: startOfMonth.format('MMM YYYY'),
+ activeDate: activeValue,
+ leftButton: {
+ value: previousMonth.valueOf(),
+ ariaLabel: `Go to ${previousMonth.format('MMM YYYY')}`,
+ classes: {},
+ },
+ upButton: {
+ value: startOfMonth.valueOf(),
+ ariaLabel: `Go to month view`,
+ classes: {},
+ },
+ rightButton: {
+ value: nextMonth.valueOf(),
+ ariaLabel: `Go to ${nextMonth.format('MMM YYYY')}`,
+ classes: {},
+ },
+ rowLabels: columnNumbers.map((column) => moment().weekday(column).format('dd')),
+ rows: rowNumbers.map(rowOfDays)
+ };
+
+ function rowOfDays(rowNumber) {
+ const currentMoment = moment();
+ const cells = columnNumbers.map((columnNumber) => {
+ const dayMoment = moment(startOfView).add((rowNumber * columnNumbers.length) + columnNumber, 'days');
+ return {
+ display: dayMoment.format('D'),
+ ariaLabel: dayMoment.format('ll'),
+ value: dayMoment.valueOf(),
+ classes: {
+ 'dl-abdtp-active': activeValue === dayMoment.valueOf(),
+ 'dl-abdtp-future': dayMoment.isAfter(endOfMonth),
+ 'dl-abdtp-past': dayMoment.isBefore(startOfMonth),
+ 'dl-abdtp-selected': selectedValue === dayMoment.valueOf(),
+ 'dl-abdtp-now': dayMoment.isSame(currentMoment, 'day'),
+ }
+ };
+ });
+ return {cells};
+ }
+ }
+
+ /**
+ * Move the active `day` one row `down` from the specified moment in time.
+ *
+ * Moving `down` can result in the `active` day being part of a different month than
+ * the specified `fromMilliseconds`, in this case the month represented by the model
+ * will change to show the correct hour.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `day` model `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `day` one row `down` from the specified moment in time.
+ */
+ goDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(7, 'days').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `day` one row `up` from the specified moment in time.
+ *
+ * Moving `up` can result in the `active` day being part of a different month than
+ * the specified `fromMilliseconds`, in this case the month represented by the model
+ * will change to show the correct hour.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `day` model `up` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `day` one row `up` from the specified moment in time.
+ */
+ goUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(7, 'days').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` day one cell `left` in the current `day` view.
+ *
+ * Moving `left` can result in the `active` day being part of a different month than
+ * the specified `fromMilliseconds`, in this case the month represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `day` model to the `left` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `day` one cell to the `left` of the specified moment in time.
+ */
+ goLeft(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(1, 'day').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` day one cell `right` in the current `day` view.
+ *
+ * Moving `right` can result in the `active` day being part of a different month than
+ * the specified `fromMilliseconds`, in this case the month represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `day` model to the `right` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `day` one cell to the `right` of the specified moment in time.
+ */
+ goRight(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(1, 'day').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `day` one month `down` from the specified moment in time.
+ *
+ * Paging `down` will result in the `active` day being part of a different month than
+ * the specified `fromMilliseconds`. As a result, the month represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `day` model page `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `day` one month `down` from the specified moment in time.
+ */
+ pageDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(1, 'month').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `day` one month `up` from the specified moment in time.
+ *
+ * Paging `up` will result in the `active` day being part of a different month than
+ * the specified `fromMilliseconds`. As a result, the month represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `day` model page `up` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `day` one month `up` from the specified moment in time.
+ */
+ pageUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(1, 'month').valueOf(), selectedMilliseconds);
+ }
+
+
+ /**
+ * Move the `active` `day` to the last day of the month.
+ *
+ * The view or time range will not change unless the `fromMilliseconds` value
+ * is in a different day than the displayed decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the last day of the month will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * a model with the last cell in the view as the active `day`.
+ */
+ goEnd(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds)
+ .endOf('month').startOf('day').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `day` to the first day of the month.
+ *
+ * The view or time range will not change unless the `fromMilliseconds` value
+ * is in a different day than the displayed decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the first day of the month will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * a model with the first cell in the view as the active `day`.
+ */
+ goHome(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).startOf('month').valueOf(), selectedMilliseconds);
+ }
+}
+
+ +
+ src/lib/dl-date-time-picker/dl-model-provider-hour.ts
+
+
+
Default implementation for the hour
view.
+
+ DlModelProvider
+
+ Methods+ |
+
+ + | +
+ + + getModel + + + | +||||||||||||
+getModel(milliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Returns the The The hour always starts at the beginning of the hour. +Each cell represents a one-hour increment starting at midnight. +the moment in time from which the minute model will be created. + the current value of the date/time picker. + the model representing the specified moment in time. +
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ the model representing the specified moment in time. + + |
+
+ + + goDown + + + | +||||||||||||
+goDown(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Moving the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goEnd + + + | +||||||||||||
+goEnd(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The view or time range will not change unless the the moment in time from which
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ a model with the |
+
+ + + goHome + + + | +||||||||||||
+goHome(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The view or time range will not change unless the the moment in time from which
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ a model with the |
+
+ + + goLeft + + + | +||||||||||||
+goLeft(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the Moving the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goRight + + + | +||||||||||||
+goRight(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the Moving the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goUp + + + | +||||||||||||
+goUp(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Moving the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + onChanges + + + | +||||||
+onChanges(_changes: SimpleChanges)
+ |
+ ||||||
+ + | +||||||
+ Receives input changes detected by Angular. +the input changes detected by Angular. +
+ Parameters :
+
+
+
+ Returns :
+ void
+
+
+
+
+ |
+
+ + + pageDown + + + | +||||||||||||
+pageDown(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Paging the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + pageUp + + + | +||||||||||||
+pageUp(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Paging the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
import {SimpleChanges} from '@angular/core';
+import moment from 'moment';
+import {DlDateTimePickerModel} from './dl-date-time-picker-model';
+import {DlModelProvider} from './dl-model-provider';
+
+/**
+ * Default implementation for the `hour` view.
+ */
+export class DlHourModelProvider implements DlModelProvider {
+
+ /**
+ * Receives input changes detected by Angular.
+ *
+ * @param changes
+ * the input changes detected by Angular.
+ */
+ onChanges(
+ _changes: SimpleChanges
+ ): void {}
+
+
+ /**
+ * Returns the `hour` model for the specified moment in `local` time with the
+ * `active` hour set to the beginning of the day.
+ *
+ * The `hour` model represents a day (24 hours) as six rows with four columns
+ * and each cell representing one-hour increments.
+ *
+ * The hour always starts at the beginning of the hour.
+ *
+ * Each cell represents a one-hour increment starting at midnight.
+ *
+ * @param milliseconds
+ * the moment in time from which the minute model will be created.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * the model representing the specified moment in time.
+ */
+ getModel(milliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ const startDate = moment(milliseconds).startOf('day');
+
+ const rowNumbers = [0, 1, 2, 3, 4, 5];
+ const columnNumbers = [0, 1, 2, 3];
+
+ const previousDay = moment(startDate).subtract(1, 'day');
+ const nextDay = moment(startDate).add(1, 'day');
+ const activeValue = moment(milliseconds).startOf('hour').valueOf();
+ const selectedValue = selectedMilliseconds === null || selectedMilliseconds === undefined
+ ? selectedMilliseconds
+ : moment(selectedMilliseconds).startOf('hour').valueOf();
+
+ return {
+ viewName: 'hour',
+ viewLabel: startDate.format('ll'),
+ activeDate: activeValue,
+ leftButton: {
+ value: previousDay.valueOf(),
+ ariaLabel: `Go to ${previousDay.format('ll')}`,
+ classes: {},
+ },
+ upButton: {
+ value: startDate.valueOf(),
+ ariaLabel: `Go to ${startDate.format('MMM YYYY')}`,
+ classes: {},
+ },
+ rightButton: {
+ value: nextDay.valueOf(),
+ ariaLabel: `Go to ${nextDay.format('ll')}`,
+ classes: {},
+ },
+ rows: rowNumbers.map(rowOfHours)
+ };
+
+ function rowOfHours(rowNumber) {
+
+ const currentMoment = moment();
+ const cells = columnNumbers.map((columnNumber) => {
+ const hourMoment = moment(startDate).add((rowNumber * columnNumbers.length) + columnNumber, 'hours');
+ return {
+ display: hourMoment.format('LT'),
+ ariaLabel: hourMoment.format('LLL'),
+ value: hourMoment.valueOf(),
+ classes: {
+ 'dl-abdtp-active': activeValue === hourMoment.valueOf(),
+ 'dl-abdtp-selected': selectedValue === hourMoment.valueOf(),
+ 'dl-abdtp-now': hourMoment.isSame(currentMoment, 'hour'),
+ }
+ };
+ });
+ return {cells};
+ }
+ }
+
+ /**
+ * Move the active `hour` one row `down` from the specified moment in time.
+ *
+ * Moving `down` can result in the `active` hour being part of a different day than
+ * the specified `fromMilliseconds`, in this case the day represented by the model
+ * will change to show the correct hour.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `hour` model `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `hour` one row `down` from the specified moment in time.
+ */
+ goDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(4, 'hour').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `hour` one row `up` from the specified moment in time.
+ *
+ * Moving `up` can result in the `active` hour being part of a different day than
+ * the specified `fromMilliseconds`, in this case the day represented by the model
+ * will change to show the correct hour.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `hour` model `up` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `hour` one row `up` from the specified moment in time.
+ */
+ goUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(4, 'hour').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` hour one cell `left` in the current `hour` view.
+ *
+ * Moving `left` can result in the `active` hour being part of a different day than
+ * the specified `fromMilliseconds`, in this case the day represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `hour` model to the `left` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `hour` one cell to the `left` of the specified moment in time.
+ */
+ goLeft(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(1, 'hour').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` hour one cell `right` in the current `hour` view.
+ *
+ * Moving `right` can result in the `active` hour being part of a different day than
+ * the specified `fromMilliseconds`, in this case the day represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `hour` model to the `right` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `hour` one cell to the `right` of the specified moment in time.
+ */
+ goRight(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(1, 'hour').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `hour` one day `down` from the specified moment in time.
+ *
+ * Paging `down` will result in the `active` hour being part of a different day than
+ * the specified `fromMilliseconds`. As a result, the day represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `hour` model page `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `hour` one day `down` from the specified moment in time.
+ */
+ pageDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(1, 'day').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `hour` one day `up` from the specified moment in time.
+ *
+ * Paging `up` will result in the `active` hour being part of a different day than
+ * the specified `fromMilliseconds`. As a result, the day represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `hour` model page `up` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `hour` one day `up` from the specified moment in time.
+ */
+ pageUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(1, 'day').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `hour` to `11:00 pm` of the current day.
+ *
+ * The view or time range will not change unless the `fromMilliseconds` value
+ * is in a different day than the displayed decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which `11:00 pm` will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * a model with the `11:00 pm` cell in the view as the active `hour`.
+ */
+ goEnd(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment
+ (fromMilliseconds)
+ .endOf('day')
+ .startOf('hour')
+ .valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `hour` to `midnight` of the current day.
+ *
+ * The view or time range will not change unless the `fromMilliseconds` value
+ * is in a different day than the displayed decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which `midnight` will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * a model with the `midnight` cell in the view as the active `hour`.
+ */
+ goHome(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).startOf('day').valueOf(), selectedMilliseconds);
+ }
+}
+
+ +
+ src/lib/dl-date-time-picker/dl-model-provider-minute.ts
+
+
+
Default implementation for the minute
view.
+
+ DlModelProvider
+
+ Methods+ |
+
+ + | +
+ + + getModel + + + | +||||||||||||
+getModel(milliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Returns the The The hour always starts at midnight. +Each cell represents a 5-minute increment starting at midnight. +The the moment in time from which the minute model will be created. + the current value of the date/time picker. + the model representing the specified moment in time. +
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ the model representing the specified moment in time. + + |
+
+ + + goDown + + + | +||||||||||||
+goDown(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Moving the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goEnd + + + | +||||||||||||
+goEnd(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The view or time range will not change unless the the moment in time from which the last cell will be calculated.
+ the current value of the date/time picker.
+ a model with the last cell in the view as the active
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ a model with the last cell in the view as the active |
+
+ + + goHome + + + | +||||||||||||
+goHome(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The view or time range will not change unless the the moment in time from which the first cell will be calculated.
+ the current value of the date/time picker.
+ a model with the first cell in the view as the active
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ a model with the first cell in the view as the active |
+
+ + + goLeft + + + | +||||||||||||
+goLeft(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the Moving the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goRight + + + | +||||||||||||
+goRight(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move Moving the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goUp + + + | +||||||||||||
+goUp(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Moving the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + onChanges + + + | +||||||||
+onChanges(changes: SimpleChanges)
+ |
+ ||||||||
+ + | +||||||||
+ Receives Changes where the value has not changed are ignored. +Setting the input changes detected by Angular. +
+ Parameters :
+
+
+
+ Returns :
+ void
+
+
+
+
+ |
+
+ + + pageDown + + + | +||||||||||||
+pageDown(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active The The next cell the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + pageUp + + + | +||||||||||||
+pageUp(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active The The next cell the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
import {SimpleChanges} from '@angular/core';
+import moment from 'moment';
+import {DlDateTimePickerModel} from './dl-date-time-picker-model';
+import {DlModelProvider} from './dl-model-provider';
+
+/**
+ * Default implementation for the `minute` view.
+ */
+export class DlMinuteModelProvider implements DlModelProvider {
+
+ private step = 5;
+
+ /**
+ * Receives `minuteStep` configuration changes detected by Angular.
+ *
+ * Changes where the value has not changed are ignored.
+ *
+ * Setting `minuteStep` to `null` or `undefined` will result in a
+ * minuteStep of `5`.
+ *
+ * @param changes
+ * the input changes detected by Angular.
+ */
+
+ onChanges(changes: SimpleChanges): void {
+
+ const minuteStepChange = changes['minuteStep'];
+
+ if (minuteStepChange
+ && (minuteStepChange.previousValue !== minuteStepChange.currentValue)
+ ) {
+ this.step = minuteStepChange.currentValue;
+ if (this.step === null || this.step === undefined) {
+ this.step = 5;
+ }
+ }
+ }
+
+
+ /**
+ * Returns the `minute` model for the specified moment in `local` time with the
+ * `active` minute set to the beginning of the hour.
+ *
+ * The `minute` model represents an hour (60 minutes) as three rows with four columns
+ * and each cell representing 5-minute increments.
+ *
+ * The hour always starts at midnight.
+ *
+ * Each cell represents a 5-minute increment starting at midnight.
+ *
+ * The `active` minute will be the 5-minute increments less than or equal to the specified milliseconds.
+ *
+ * @param milliseconds
+ * the moment in time from which the minute model will be created.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * the model representing the specified moment in time.
+ */
+ getModel(milliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ const startDate = moment(milliseconds).startOf('hour');
+ const currentMilliseconds = moment().valueOf();
+
+ const minuteSteps = new Array(Math.ceil(60 / this.step)).fill(0).map((zero, index) => zero + index * this.step);
+ const minuteValues = minuteSteps.map((minutesToAdd) => moment(startDate).add(minutesToAdd, 'minutes').valueOf());
+ const activeValue = moment(minuteValues.filter((value) => value <= milliseconds).pop()).valueOf();
+
+ const nowValue = currentMilliseconds >= startDate.valueOf() && currentMilliseconds <= moment(startDate).endOf('hour').valueOf()
+ ? moment(minuteValues.filter((value) => value <= currentMilliseconds).pop()).valueOf()
+ : null;
+
+
+ const previousHour = moment(startDate).subtract(1, 'hour');
+ const nextHour = moment(startDate).add(1, 'hour');
+ const selectedValue = selectedMilliseconds === null || selectedMilliseconds === undefined
+ ? selectedMilliseconds
+ : moment(minuteValues.filter((value) => value <= selectedMilliseconds).pop()).valueOf();
+
+ const rows = new Array(Math.ceil(minuteSteps.length / 4))
+ .fill(0)
+ .map((zero, index) => zero + index)
+ .map((value) => {
+ return {cells: minuteSteps.slice((value * 4), (value * 4) + 4).map(rowOfMinutes)};
+ });
+
+ return {
+ viewName: 'minute',
+ viewLabel: startDate.format('lll'),
+ activeDate: activeValue,
+ leftButton: {
+ value: previousHour.valueOf(),
+ ariaLabel: `Go to ${previousHour.format('lll')}`,
+ classes: {},
+ },
+ upButton: {
+ value: startDate.valueOf(),
+ ariaLabel: `Go to ${startDate.format('ll')}`,
+ classes: {},
+ },
+ rightButton: {
+ value: nextHour.valueOf(),
+ ariaLabel: `Go to ${nextHour.format('lll')}`,
+ classes: {},
+ },
+ rows
+ };
+
+ function rowOfMinutes(stepMinutes): {
+ display: string;
+ ariaLabel: string;
+ value: number;
+ classes: {};
+ } {
+ const minuteMoment = moment(startDate).add(stepMinutes, 'minutes');
+ return {
+ display: minuteMoment.format('LT'),
+ ariaLabel: minuteMoment.format('LLL'),
+ value: minuteMoment.valueOf(),
+ classes: {
+ 'dl-abdtp-active': activeValue === minuteMoment.valueOf(),
+ 'dl-abdtp-selected': selectedValue === minuteMoment.valueOf(),
+ 'dl-abdtp-now': nowValue === minuteMoment.valueOf(),
+ }
+ };
+ }
+ }
+
+ /**
+ * Move the active `minute` one row `down` from the specified moment in time.
+ *
+ * Moving `down` can result in the `active` minute being part of a different hour than
+ * the specified `fromMilliseconds`, in this case the hour represented by the model
+ * will change to show the correct hour.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `minute` model `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `minute` one row `down` from the specified moment in time.
+ */
+ goDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(this.step * 4, 'minutes').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `minute` one row `down` from the specified moment in time.
+ *
+ * Moving `down` can result in the `active` minute being part of a different hour than
+ * the specified `fromMilliseconds`, in this case the hour represented by the model
+ * will change to show the correct hour.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `minute` model `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `minute` one row `down` from the specified moment in time.
+ */
+ goUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(this.step * 4, 'minutes').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` date one cell to `left` in the current `minute` view.
+ *
+ * Moving `left` can result in the `active` hour being part of a different hour than
+ * the specified `fromMilliseconds`, in this case the hour represented by the model
+ * will change to show the correct hour.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `minute` model to the `left` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `minute` one cell to the `left` of the specified moment in time.
+ */
+ goLeft(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(this.step, 'minutes').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move `active` minute one cell to `right` in the current `minute` view.
+ *
+ * Moving `right` can result in the `active` hour being part of a different hour than
+ * the specified `fromMilliseconds`, in this case the hour represented by the model
+ * will change to show the correct hour.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `minute` model to the `right` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `minute` one cell to the `right` of the specified moment in time.
+ */
+ goRight(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(this.step, 'minutes').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `minute` one hour `down` from the specified moment in time.
+ *
+ * The `active` minute will be `one (1) hour after` the specified milliseconds.
+ * This moves the `active` date one `page` `down` from the current `minute` view.
+ *
+ * The next cell `page-down` will be in a different hour than the currently
+ * displayed view and the model time range will include the new active cell.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `month` model page `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `month` one year `down` from the specified moment in time.
+ */
+ pageDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(1, 'hour').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `minute` one hour `up` from the specified moment in time.
+ *
+ * The `active` minute will be `one (1) hour before` the specified milliseconds.
+ * This moves the `active` date one `page` `down` from the current `minute` view.
+ *
+ * The next cell `page-up` will be in a different hour than the currently
+ * displayed view and the model time range will include the new active cell.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `month` model page `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `month` one year `down` from the specified moment in time.
+ */
+ pageUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(1, 'hour').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `minute` to the last cell of the current hour.
+ *
+ * The view or time range will not change unless the `fromMilliseconds` value
+ * is in a different hour than the displayed decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the last cell will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * a model with the last cell in the view as the active `minute`.
+ */
+ goEnd(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds)
+ .endOf('hour')
+ .valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `minute` to the first cell of the current hour.
+ *
+ * The view or time range will not change unless the `fromMilliseconds` value
+ * is in a different hour than the displayed decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the first cell will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * a model with the first cell in the view as the active `minute`.
+ */
+ goHome(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).startOf('hour').valueOf(), selectedMilliseconds);
+ }
+}
+
+ +
+ src/lib/dl-date-time-picker/dl-model-provider-month.ts
+
+
+
Default implementation for the month
view.
+
+ DlModelProvider
+
+ Methods+ |
+
+ + | +
+ + + getModel + + + | +||||||||||||
+getModel(milliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Returns the The The year always starts in January. +Each cell represents midnight on the 1st day of the month. +The the moment in time from which the month model will be created. + the current value of the date/time picker. + the model representing the specified moment in time. +
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ the model representing the specified moment in time. + + |
+
+ + + goDown + + + | +||||||||||||
+goDown(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Moving the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goEnd + + + | +||||||||||||
+goEnd(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The view or time range will not change unless the the moment in time from which
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ a model with the |
+
+ + + goHome + + + | +||||||||||||
+goHome(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The view or time range will not change unless the the moment in time from which
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ a model with the |
+
+ + + goLeft + + + | +||||||||||||
+goLeft(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the Moving the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goRight + + + | +||||||||||||
+goRight(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The Moving the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goUp + + + | +||||||||||||
+goUp(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Moving the moment in time from which the previous
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + onChanges + + + | +||||||
+onChanges(_changes: SimpleChanges)
+ |
+ ||||||
+ + | +||||||
+ Receives input changes detected by Angular. +the input changes detected by Angular. +
+ Parameters :
+
+
+
+ Returns :
+ void
+
+
+
+
+ |
+
+ + + pageDown + + + | +||||||||||||
+pageDown(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Paging the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + pageUp + + + | +||||||||||||
+pageUp(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active Paging the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
import {SimpleChanges} from '@angular/core';
+import moment from 'moment';
+import {DlDateTimePickerModel} from './dl-date-time-picker-model';
+import {DlModelProvider} from './dl-model-provider';
+
+/**
+ * Default implementation for the `month` view.
+ */
+export class DlMonthModelProvider implements DlModelProvider {
+
+ /**
+ * Receives input changes detected by Angular.
+ *
+ * @param changes
+ * the input changes detected by Angular.
+ */
+ onChanges(
+ _changes: SimpleChanges
+ ): void {}
+
+ /**
+ * Returns the `month` model for the specified moment in `local` time with the
+ * `active` month set to the first day of the specified month.
+ *
+ * The `month` model represents a year (12 months) as three rows with four columns.
+ *
+ * The year always starts in January.
+ *
+ * Each cell represents midnight on the 1st day of the month.
+ *
+ * The `active` month will be the January of year of the specified milliseconds.
+ *
+ * @param milliseconds
+ * the moment in time from which the month model will be created.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * the model representing the specified moment in time.
+ */
+ getModel(milliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ const startDate = moment(milliseconds).startOf('year');
+
+ const rowNumbers = [0, 1, 2];
+ const columnNumbers = [0, 1, 2, 3];
+
+ const previousYear = moment(startDate).subtract(1, 'year');
+ const nextYear = moment(startDate).add(1, 'year');
+ const activeValue = moment(milliseconds).startOf('month').valueOf();
+ const selectedValue = selectedMilliseconds === null || selectedMilliseconds === undefined
+ ? selectedMilliseconds
+ : moment(selectedMilliseconds).startOf('month').valueOf();
+
+ return {
+ viewName: 'month',
+ viewLabel: startDate.format('YYYY'),
+ activeDate: activeValue,
+ leftButton: {
+ value: previousYear.valueOf(),
+ ariaLabel: `Go to ${previousYear.format('YYYY')}`,
+ classes: {},
+ },
+ upButton: {
+ value: startDate.valueOf(),
+ ariaLabel: `Go to ${startDate.format('YYYY')}`,
+ classes: {},
+ },
+ rightButton: {
+ value: nextYear.valueOf(),
+ ariaLabel: `Go to ${nextYear.format('YYYY')}`,
+ classes: {},
+ },
+ rows: rowNumbers.map(rowOfMonths)
+ };
+
+ function rowOfMonths(rowNumber) {
+
+ const currentMoment = moment();
+ const cells = columnNumbers.map((columnNumber) => {
+ const monthMoment = moment(startDate).add((rowNumber * columnNumbers.length) + columnNumber, 'months');
+ return {
+ display: monthMoment.format('MMM'),
+ ariaLabel: monthMoment.format('MMM YYYY'),
+ value: monthMoment.valueOf(),
+ classes: {
+ 'dl-abdtp-active': activeValue === monthMoment.valueOf(),
+ 'dl-abdtp-selected': selectedValue === monthMoment.valueOf(),
+ 'dl-abdtp-now': monthMoment.isSame(currentMoment, 'month'),
+ }
+ };
+ });
+ return {cells};
+ }
+ }
+
+ /**
+ * Move the active `month` one row `down` from the specified moment in time.
+ *
+ * Moving `down` can result in the `active` month being part of a different year than
+ * the specified `fromMilliseconds`, in this case the year represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `month` model `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `month` one row `down` from the specified moment in time.
+ */
+ goDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(4, 'month').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `month` one row `up` from the specified moment in time.
+ *
+ * Moving `up` can result in the `active` month being part of a different year than
+ * the specified `fromMilliseconds`, in this case the year represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the previous `month` model `up` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `month` one row `up` from the specified moment in time.
+ */
+ goUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(4, 'month').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `month` one (1) month to the `left` of the specified moment in time.
+ *
+ * Moving `left` can result in the `active` month being part of a different year than
+ * the specified `fromMilliseconds`, in this case the year represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `month` model to the `left` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `month` one month to the `left` of the specified moment in time.
+ */
+ goLeft(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(1, 'month').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `month` one (1) month to the `right` of the specified moment in time.
+ *
+ * The `active` month will be `one (1) month after` the specified milliseconds.
+ * This moves the `active` date one month `right` in the current `month` view.
+ *
+ * Moving `right` can result in the `active` month being part of a different year than
+ * the specified `fromMilliseconds`, in this case the year represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `month` model to the `right` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `month` one year to the `right` of the specified moment in time.
+ */
+ goRight(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(1, 'month').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `month` one year `down` from the specified moment in time.
+ *
+ * Paging `down` will result in the `active` month being part of a different year than
+ * the specified `fromMilliseconds`. As a result, the year represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `month` model page `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `month` one year `down` from the specified moment in time.
+ */
+ pageDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(12, 'months').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `month` one year `down` from the specified moment in time.
+ *
+ * Paging `up` will result in the `active` month being part of a different year than
+ * the specified `fromMilliseconds`. As a result, the year represented by the model
+ * will change to show the correct year.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `month` model page `up` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `month` one year `up` from the specified moment in time.
+ */
+ pageUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(12, 'months').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `month` to `December` of the current year.
+ *
+ * The view or time range will not change unless the `fromMilliseconds` value
+ * is in a different year than the displayed decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which `December 1` will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * a model with the `December` cell in the view as the active `month`.
+ */
+ goEnd(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).endOf('year').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `month` to `January` of the current year.
+ *
+ * The view or time range will not change unless the `fromMilliseconds` value
+ * is in a different year than the displayed decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which `January 1` will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * a model with the `January` cell in the view as the active `month`.
+ */
+ goHome(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).startOf('year').valueOf(), selectedMilliseconds);
+ }
+}
+
+ +
+ src/lib/dl-date-time-picker/dl-model-provider-year.ts
+
+
+
Default implementation for the year
view.
+
+ DlModelProvider
+
+ Methods+ |
+
+ + | +
+ + + getModel + + + | +||||||||||||
+getModel(milliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Returns the The The decade always starts on a year ending with zero. +Each cell represents midnight January 1 of the indicated year. +The the moment in time from which the year model will be created. + the current value of the date/time picker. + the model representing the specified moment in time. +
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ the model representing the specified moment in time. + + |
+
+ + + goDown + + + | +||||||||||||
+goDown(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active The Moving the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goEnd + + + | +||||||||||||
+goEnd(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The view or time range will not change unless the the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ a model with the |
+
+ + + goHome + + + | +||||||||||||
+goHome(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The view or time range will not change unless the the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ a model with the |
+
+ + + goLeft + + + | +||||||||||||
+goLeft(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The Moving the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goRight + + + | +||||||||||||
+goRight(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The Moving the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + goUp + + + | +||||||||||||
+goUp(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active The Moving the moment in time from which the previous
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + onChanges + + + | +||||||
+onChanges(_changes: SimpleChanges)
+ |
+ ||||||
+ + | +||||||
+ Receives input changes detected by Angular. +the input changes detected by Angular. +
+ Parameters :
+
+
+
+ Returns :
+ void
+
+
+
+
+ |
+
+ + + pageDown + + + | +||||||||||||
+pageDown(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active The Paging the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
+ + + pageUp + + + | +||||||||||||
+pageUp(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the active The Paging the moment in time from which the next
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ model containing an |
+
import {SimpleChanges} from '@angular/core';
+import moment, {Moment} from 'moment';
+import {DlDateTimePickerModel} from './dl-date-time-picker-model';
+import {DlModelProvider} from './dl-model-provider';
+
+/**
+ * Default implementation for the `year` view.
+ */
+export class DlYearModelProvider implements DlModelProvider {
+
+ /**
+ * Create a moment at midnight january 1 at the start of the current decade.
+ * The start of the decade is always a year ending in zero.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the start of the decade will be determined.
+ * @returns
+ * moment at midnight january 1 at the start of the current decade.
+ * @internal
+ */
+ private static getStartOfDecade(fromMilliseconds: number): Moment {
+ // Truncate the last digit from the current year to get the start of the decade
+ const startDecade = (Math.trunc(moment(fromMilliseconds).year() / 10) * 10);
+ return moment({year: startDecade}).startOf('year');
+ }
+
+ /**
+ * Receives input changes detected by Angular.
+ *
+ * @param changes
+ * the input changes detected by Angular.
+ */
+ onChanges(
+ _changes: SimpleChanges
+ ): void {}
+
+ /**
+ * Returns the `year` model for the specified moment in `local` time with the
+ * `active` year set to January 1 of the specified year.
+ *
+ * The `year` model represents a decade (10 years) as two rows with five columns.
+ *
+ * The decade always starts on a year ending with zero.
+ *
+ * Each cell represents midnight January 1 of the indicated year.
+ *
+ * The `active` year will be the January 1 of year of the specified milliseconds.
+ *
+ * @param milliseconds
+ * the moment in time from which the year model will be created.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * the model representing the specified moment in time.
+ */
+ getModel(milliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ const rowNumbers = [0, 1];
+ const columnNumbers = [0, 1, 2, 3, 4];
+
+ const startYear = moment(milliseconds).startOf('year');
+ const startDate = DlYearModelProvider.getStartOfDecade(milliseconds);
+
+ const futureYear = startDate.year() + 9;
+ const pastYear = startDate.year();
+ const activeValue = startYear.valueOf();
+ const selectedValue = selectedMilliseconds === null || selectedMilliseconds === undefined
+ ? selectedMilliseconds
+ : moment(selectedMilliseconds).startOf('year').valueOf();
+
+ return {
+ viewName: 'year',
+ viewLabel: `${pastYear}-${futureYear}`,
+ activeDate: activeValue,
+ leftButton: {
+ value: moment(startDate).subtract(10, 'years').valueOf(),
+ ariaLabel: `Go to ${pastYear - 10}-${pastYear - 1}`,
+ classes: {},
+ },
+ rightButton: {
+ value: moment(startDate).add(10, 'years').valueOf(),
+ ariaLabel: `Go to ${futureYear + 1}-${futureYear + 10}`,
+ classes: {},
+ },
+ rows: rowNumbers.map(rowOfYears.bind(this))
+ };
+
+ function rowOfYears(rowNumber) {
+
+ const currentMoment = moment();
+ const cells = columnNumbers.map((columnNumber) => {
+ const yearMoment = moment(startDate).add((rowNumber * columnNumbers.length) + columnNumber, 'years');
+ return {
+ display: yearMoment.format('YYYY'),
+ value: yearMoment.valueOf(),
+ classes: {
+ 'dl-abdtp-active': activeValue === yearMoment.valueOf(),
+ 'dl-abdtp-selected': selectedValue === yearMoment.valueOf(),
+ 'dl-abdtp-now': yearMoment.isSame(currentMoment, 'year'),
+ }
+ };
+ });
+ return {cells};
+ }
+ }
+
+ /**
+ * Move the active `year` one row `down` from the specified moment in time.
+ *
+ * The `active` year will be the January 1 `five (5) years after` the specified milliseconds.
+ * This moves the `active` date one row `down` in the current `year` view.
+ *
+ * Moving `down` can result in the `active` year being part of a different decade than
+ * the specified `fromMilliseconds`, in this case the decade represented by the model
+ * will change to show the correct decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `year` model `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `year` one row `down` from the specified moment in time.
+ */
+ goDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(5, 'year').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `year` one row `up` from the specified moment in time.
+ *
+ * The `active` year will be the January 1 `five (5) years before` the specified milliseconds.
+ * This moves the `active` date one row `up` in the current `year` view.
+ *
+ * Moving `up` can result in the `active` year being part of a different decade than
+ * the specified `fromMilliseconds`, in this case the decade represented by the model
+ * will change to show the correct decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the previous `year` model `up` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `year` one row `up` from the specified moment in time.
+ */
+ goUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(5, 'year').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `year` one (1) year to the `left` of the specified moment in time.
+ *
+ * The `active` year will be the January 1 `one (1) year before` the specified milliseconds.
+ * This moves the `active` date one year `left` in the current `year` view.
+ *
+ * Moving `left` can result in the `active` year being part of a different decade than
+ * the specified `fromMilliseconds`, in this case the decade represented by the model
+ * will change to show the correct decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `year` model to the `left` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `year` one year to the `left` of the specified moment in time.
+ */
+ goLeft(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(1, 'year').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `year` one (1) year to the `right` of the specified moment in time.
+ *
+ * The `active` year will be the January 1 `one (1) year after` the specified milliseconds.
+ * This moves the `active` date one year `right` in the current `year` view.
+ *
+ * Moving `right` can result in the `active` year being part of a different decade than
+ * the specified `fromMilliseconds`, in this case the decade represented by the model
+ * will change to show the correct decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `year` model to the `right` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `year` one year to the `right` of the specified moment in time.
+ */
+ goRight(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(1, 'year').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `year` one decade `down` from the specified moment in time.
+ *
+ * The `active` year will be the January 1 `ten (10) years after` the specified milliseconds.
+ * This moves the `active` date one `page` `down` from the current `year` view.
+ *
+ * Paging `down` will result in the `active` year being part of a different decade than
+ * the specified `fromMilliseconds`. As a result, the decade represented by the model
+ * will change to show the correct decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `year` model page `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `year` one decade `down` from the specified moment in time.
+ */
+ pageDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(10, 'year').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `year` one decade `up` from the specified moment in time.
+ *
+ * The `active` year will be the January 1 `ten (10) years before` the specified milliseconds.
+ * This moves the `active` date one `page-up` from the current `year` view.
+ *
+ * Paging `up` will result in the `active` year being part of a different decade than
+ * the specified `fromMilliseconds`. As a result, the decade represented by the model
+ * will change to show the correct decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `year` model page `up` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `year` one decade `up` from the specified moment in time.
+ */
+ pageUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(10, 'year').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `year` to the `last` year in the decade.
+ *
+ * The view or time range will not change unless the `fromMilliseconds` value
+ * is in a different decade than the displayed decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `last` active `year` will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * a model with the `last` cell in the view as the active `year`.
+ */
+ goEnd(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(
+ DlYearModelProvider.getStartOfDecade(fromMilliseconds)
+ .add(9, 'years')
+ .endOf('year')
+ .valueOf(),
+ selectedMilliseconds
+ );
+ }
+
+ /**
+ * Move the `active` `year` to the `first` year in the decade.
+ *
+ * The view or time range will not change unless the `fromMilliseconds` value
+ * is in a different decade than the displayed decade.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `first` active `year` will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * a model with the `first` cell in the view as the active `year`.
+ */
+ goHome(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(
+ DlYearModelProvider.getStartOfDecade(fromMilliseconds)
+ .startOf('year')
+ .valueOf(),
+ selectedMilliseconds
+ );
+ }
+}
+
+ +
+ src/lib/dl-date-time-picker/dl-date-time-picker.component.ts
+
+
+
Component that provides all of the user facing functionality of the date/time picker.
+ + + + ++
+ OnChanges
+ OnInit
+ ControlValueAccessor
+
changeDetection | +ChangeDetectionStrategy.OnPush |
+
preserveWhitespaces | +false |
+
providers | +
+ {
+ provide: NG_VALUE_ACCESSOR, useExisting: DlDateTimePickerComponent, multi: true
+}
+ |
+
selector | +dl-date-time-picker |
+
styleUrls | +./dl-date-time-picker.component.scss |
+
templateUrl | +./dl-date-time-picker.component.html |
+
+ Inputs+ |
+
+
|
+
+ Outputs+ |
+
+
|
+
+ Accessors+ |
+
+
|
+
+constructor(_elementRef: ElementRef, _ngZone: NgZone, _dateAdapter: DlDateAdapter<D>, yearModelComponent: DlYearModelProvider, monthModelComponent: DlMonthModelProvider, dayModelComponent: DlDayModelProvider, hourModelComponent: DlHourModelProvider, minuteModelComponent: DlMinuteModelProvider)
+ |
+ ||||||||||||||||||||||||||||||||||||
+ + | +||||||||||||||||||||||||||||||||||||
+ Used to construct a new instance of a date/time picker. +reference to this element. + reference to an NgZone instance used to select the active element outside of angular. + date adapter for the date type in the model. + provider for the year view model. + provider for the month view model. + provider for the day view model. + provider for the hour view model. + provider for the minute view model. +
+ Parameters :
+
+
|
+
+ + leftIconClass + | +|
+ Type : string | string[] | Set<string> | literal type
+
+ |
+ |
+ Default value : [
+ 'oi',
+ 'oi-chevron-left'
+ ]
+ |
+ |
+ + | +|
+ Specifies the classes used to display the left icon. +This component uses OPENICONIC https://useiconic.com/open +by default but any icon library may be used. + |
+
+ + minuteStep + | +|
+ Type : number
+
+ |
+ |
+ Default value : 5
+ |
+ |
+ + | +|
+ The number of minutes between each Must be greater than |
+
+ + rightIconClass + | +|
+ Type : {}
+
+ |
+ |
+ Default value : [
+ 'oi',
+ 'oi-chevron-right'
+ ]
+ |
+ |
+ + | +|
+ Specifies the classes used to display the right icon. +This component uses OPENICONIC https://useiconic.com/open +by default but any icon library may be used. + |
+
+ + selectFilter + | +|
+ Type : function
+
+ |
+ |
+ Default value : () => true
+ |
+ |
+ + | +|
+ Determine whether or not the |
+
+ + startDate + | +|
+ Type : number
+
+ |
+ |
+ + | +|
+ Start at the view containing startDate when no value is selected. + |
+
+ + upIconClass + | +|
+ Type : {}
+
+ |
+ |
+ Default value : [
+ 'oi',
+ 'oi-chevron-top'
+ ]
+ |
+ |
+ + | +|
+ Specifies the classes used to display the up icon. +This component uses OPENICONIC https://useiconic.com/open +by default but any icon library may be used. + |
+
+ + change + | +|
+ Type : EventEmitter
+
+ |
+ |
+ + | +|
+ Emits when a |
+
+ + value + | +||||||
+ getvalue()
+ |
+ ||||||
+ + | +||||||
+ Returns
+ Returns :
+ D
+
+ |
+ ||||||
+ setvalue(value: D)
+ |
+ ||||||
+ + | +||||||
+ Sets value of the date/time picker and emits a change event if the +new value is different from the previous value. +
+ Parameters :
+
+
+
+
+ Returns :
+ void
+
+ |
+
This Component provides all of the user facing functionality of the date/time picker.
+The following keyboard shortcuts are supported in in all views:
+Shortcut | +Action | +
---|---|
LEFT_ARROW |
+Go to the cell to the left | +
RIGHT_ARROW |
+Go to the cell to the right | +
UP_ARROW |
+Go to the cell above | +
DOWN_ARROW |
+Go to the cell below | +
HOME |
+Go to the first cell in the view | +
END |
+Go to the last cell in the view | +
PAGE_UP |
+Go to the same cell in the previous time period | +
PAGE_DOWN |
+Go to the same cell in the next time period | +
ENTER or SPACE |
+Select current cell | +
Import the module corresponding to the desired data type of the date in the model.
+DlDateTimePickerDateModule
DlDateTimePickerMomentModule
DlDateTimePickerNumberModule
DlDateTimePickerStringModule
A DateAdapter
is used to adapt the data type in the model to the number
data type
+used internally by the date/time picker.
If you need a different data type than what is currently supported, you can extend
+DlDateAdapter<D>
to provide the data type you need then override the DlDateAdapter
+provider in app.module.ts
to use your new class.
providers: [{provide: DlDateAdapter, useClass: MyCustomDateAdapter}],
The input and output formats for dates are injected into the DlDateAdapterString
class
+using the DL_STRING_DATE_INPUT_FORMATS
and DL_STRING_DATE_OUTPUT_FORMAT
tokens.
DL_STRING_DATE_OUTPUT_FORMAT
defaults to moment
's lll
long date format.
DL_STRING_DATE_INPUT_FORMATS
defaults to the following:
[
+ moment.localeData().longDateFormat('lll'),
+ 'YYYY-MM-DDTHH:mm',
+ 'YYYY-MM-DDTHH:mm:ss',
+ 'YYYY-MM-DDTHH:mm:ss.SSS',
+ 'YYYY-MM-DD',
+ 'YYYY-MM-DDTHH:mm:ss.SSS[Z]' // ISO_8601
+]
If you want a different display (output) format, override the injection tokens in app.module.ts
+i.e {provide: DL_STRING_DATE_OUTPUT_FORMAT, useValue: '<what ever format you want goes here>'}
Nota bene For convenience DL_DATE_TIME_INPUT_FORMATS
defaults to support multiple formats,
+which can dramatically slow down parsing performance. It can also result in successfully parsing
+a date using a format that is not appropriate for your use case.
Consider overriding the DL_DATE_TIME_INPUT_FORMATS
token to only include the specific formats required by your project.
{provide: DL_DATE_TIME_INPUT_FORMATS, useValue: ['<input format zero>', ..., '<input format N>']}
See moment's parsing multiple formats +page for more information on how these date formats are used.
+ModelProvider
s are used to create the Model
for each of the views
in the date/time picker.
+If your project has special requirements for one or more of the views
, you may override
+one or more of the model providers to meet your needs.
DlYearModelProvider
to display 25 yearsFor example, imagine you want the year view to display 25 years
rather than the default of
+10 years
, you can override the the DlYearModelProvider
in your application so all date/time pickers
+display 25 years
by doing the following:
Test and implement QuarterCenturyYearModelProvider
It might look something like this:
+Example :/**
+ * @license
+ * Copyright 2013-present Dale Lotts All Rights Reserved.
+ * http://www.dalelotts.com
+ *
+ * Use of this source code is governed by an MIT-style license that can be
+ * found in the LICENSE file at https://github.com/dalelotts/angular-bootstrap-datetimepicker/blob/master/LICENSE
+ */
+
+import {DlDateTimePickerModel, DlModelProvider} from 'angular-bootstrap-datetimepicker';
+import {SimpleChanges} from '@angular/core';
+import moment, {Moment} from 'moment';
+
+/**
+ * Work around for moment namespace conflict when used with webpack and rollup.
+ * See https://github.com/dherges/ng-packagr/issues/163
+ *
+ * Depending on whether rollup is used, moment needs to be imported differently.
+ * Since Moment.js doesn't have a default export, we normally need to import using
+ * the `* as`syntax.
+ *
+ * rollup creates a synthetic default module and we thus need to import it using
+ * the `default as` syntax.
+ *
+ * @internal
+ **/
+const moment = _moment;
+
+/**
+ * Quarter century implementation for the `year` view.
+ */
+export class QuarterCenturyYearModelProvider implements DlModelProvider {
+
+ /**
+ * Create a moment at midnight january 1 at the start of the quarter-century.
+ * The start of the quarter-century is always a year ending in zero or five.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the start of the quarter-century will be determined.
+ * @returns
+ * moment at midnight january 1 at the start of the current quarter-century.
+ * @internal
+ */
+ private static getStartOfQuarterCentury(fromMilliseconds: number): Moment {
+ const currentYear = moment(fromMilliseconds).year();
+ const yearsToSubtract = currentYear % 25;
+ return moment({year: currentYear - yearsToSubtract}).startOf('year');
+ }
+
+ /**
+ * Receives input changes detected by Angular.
+ *
+ * @param changes
+ * the input changes detected by Angular.
+ */
+ onChanges(changes: SimpleChanges): void {
+ }
+
+ /**
+ * Returns the `year` model for the specified moment in `local` time with the
+ * `active` year set to January 1 of the specified year.
+ *
+ * The `year` model represents a quarter-century (25 years) as five rows with five columns.
+ *
+ * The quarter-century always starts on a year ending with zero or 5.
+ *
+ * Each cell represents midnight January 1 of the indicated year.
+ *
+ * The `active` year will be the January 1 of year of the specified milliseconds.
+ *
+ * @param milliseconds
+ * the moment in time from which the year model will be created.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * the model representing the specified moment in time.
+ */
+ getModel(milliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ const rowNumbers = [0, 1, 2, 3, 4];
+ const columnNumbers = [0, 1, 2, 3, 4];
+
+ const startYear = moment(milliseconds).startOf('year');
+ const startDate = QuarterCenturyYearModelProvider.getStartOfQuarterCentury(milliseconds);
+
+ const futureYear = startDate.year() + 24;
+ const pastYear = startDate.year();
+ const activeValue = startYear.valueOf();
+ const selectedValue = selectedMilliseconds === null || selectedMilliseconds === undefined
+ ? selectedMilliseconds
+ : moment(selectedMilliseconds).startOf('year').valueOf();
+
+ const result: DlDateTimePickerModel = {
+ viewName: 'year',
+ viewLabel: `${pastYear}-${futureYear}`,
+ activeDate: activeValue,
+ leftButton: {
+ value: moment(startDate).subtract(25, 'years').valueOf(),
+ ariaLabel: `Go to ${pastYear - 25}-${pastYear - 1}`,
+ classes: {},
+ },
+ rightButton: {
+ value: moment(startDate).add(25, 'years').valueOf(),
+ ariaLabel: `Go to ${futureYear + 1}-${futureYear + 25}`,
+ classes: {},
+ },
+ rows: rowNumbers.map(rowOfYears.bind(this))
+ };
+
+ result.leftButton.classes[`${result.leftButton.value}`] = true;
+ result.rightButton.classes[`${result.rightButton.value}`] = true;
+
+ return result;
+
+ function rowOfYears(rowNumber) {
+
+ const currentMoment = moment();
+ const cells = columnNumbers.map((columnNumber) => {
+ const yearMoment = moment(startDate).add((rowNumber * columnNumbers.length) + columnNumber, 'years');
+ return {
+ display: yearMoment.format('YYYY'),
+ value: yearMoment.valueOf(),
+ classes: {
+ 'dl-abdtp-active': activeValue === yearMoment.valueOf(),
+ 'dl-abdtp-selected': selectedValue === yearMoment.valueOf(),
+ 'dl-abdtp-now': yearMoment.isSame(currentMoment, 'year'),
+ }
+ };
+ });
+ return {cells};
+ }
+ }
+
+ /**
+ * Move the active `year` one row `down` from the specified moment in time.
+ *
+ * The `active` year will be the January 1 `five (5) years after` the specified milliseconds.
+ * This moves the `active` date one row `down` in the current `year` view.
+ *
+ * Moving `down` can result in the `active` year being part of a different quarter-century than
+ * the specified `fromMilliseconds`, in this case the quarter-century represented by the model
+ * will change to show the correct quarter-century.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `year` model `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `year` one row `down` from the specified moment in time.
+ */
+ goDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(5, 'year').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `year` one row `up` from the specified moment in time.
+ *
+ * The `active` year will be the January 1 `five (5) years before` the specified milliseconds.
+ * This moves the `active` date one row `up` in the current `year` view.
+ *
+ * Moving `up` can result in the `active` year being part of a different quarter-century than
+ * the specified `fromMilliseconds`, in this case the quarter-century represented by the model
+ * will change to show the correct quarter-century.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the previous `year` model `up` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `year` one row `up` from the specified moment in time.
+ */
+ goUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(5, 'year').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `year` one (1) year to the `left` of the specified moment in time.
+ *
+ * The `active` year will be the January 1 `one (1) year before` the specified milliseconds.
+ * This moves the `active` date one year `left` in the current `year` view.
+ *
+ * Moving `left` can result in the `active` year being part of a different quarter-century than
+ * the specified `fromMilliseconds`, in this case the quarter-century represented by the model
+ * will change to show the correct quarter-century.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `year` model to the `left` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `year` one year to the `left` of the specified moment in time.
+ */
+ goLeft(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(1, 'year').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `year` one (1) year to the `right` of the specified moment in time.
+ *
+ * The `active` year will be the January 1 `one (1) year after` the specified milliseconds.
+ * This moves the `active` date one year `right` in the current `year` view.
+ *
+ * Moving `right` can result in the `active` year being part of a different quarter-century than
+ * the specified `fromMilliseconds`, in this case the quarter-century represented by the model
+ * will change to show the correct quarter-century.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `year` model to the `right` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `year` one year to the `right` of the specified moment in time.
+ */
+ goRight(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(1, 'year').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `year` one quarter-century `down` from the specified moment in time.
+ *
+ * The `active` year will be the January 1 `ten (10) years after` the specified milliseconds.
+ * This moves the `active` date one `page` `down` from the current `year` view.
+ *
+ * Paging `down` will result in the `active` year being part of a different quarter-century than
+ * the specified `fromMilliseconds`. As a result, the quarter-century represented by the model
+ * will change to show the correct quarter-century.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `year` model page `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `year` one quarter-century `down` from the specified moment in time.
+ */
+ pageDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).add(25, 'year').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the active `year` one quarter-century `up` from the specified moment in time.
+ *
+ * The `active` year will be the January 1 `ten (10) years before` the specified milliseconds.
+ * This moves the `active` date one `page-up` from the current `year` view.
+ *
+ * Paging `up` will result in the `active` year being part of a different quarter-century than
+ * the specified `fromMilliseconds`. As a result, the quarter-century represented by the model
+ * will change to show the correct quarter-century.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next `year` model page `up` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * model containing an `active` `year` one quarter-century `up` from the specified moment in time.
+ */
+ pageUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(moment(fromMilliseconds).subtract(25, 'year').valueOf(), selectedMilliseconds);
+ }
+
+ /**
+ * Move the `active` `year` to the `last` year in the quarter-century.
+ *
+ * The view or time range will not change unless the `fromMilliseconds` value
+ * is in a different quarter-century than the displayed quarter-century.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `last` active `year` will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * a model with the `last` cell in the view as the active `year`.
+ */
+ goEnd(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(
+ QuarterCenturyYearModelProvider.getStartOfQuarterCentury(fromMilliseconds)
+ .add(24, 'years')
+ .endOf('year')
+ .valueOf(),
+ selectedMilliseconds
+ );
+ }
+
+ /**
+ * Move the `active` `year` to the `first` year in the quarter-century.
+ *
+ * The view or time range will not change unless the `fromMilliseconds` value
+ * is in a different quarter-century than the displayed quarter-century.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `first` active `year` will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * a model with the `first` cell in the view as the active `year`.
+ */
+ goHome(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel {
+ return this.getModel(
+ QuarterCenturyYearModelProvider.getStartOfQuarterCentury(fromMilliseconds)
+ .startOf('year')
+ .valueOf(),
+ selectedMilliseconds
+ );
+ }
+}
Override DlYearModelProvider
with QuarterCenturyYearModelProvider
in app.module.ts
providers: [
+ FormsModule,
+ {provide: DlYearModelProvider, useClass: QuarterCenturyYearModelProvider}
+ ]
This will result in QuarterCenturyYearModelProvider
being used in every instance of the date/time
+ picker in your application.
This approach can be extended to any of the ModelProvider
's for a view.
For example, imagine you need a time picker that only displays certain hours of the day. You can implement
+an HourModelProvider
that has the exact functionality you need without having the write the entire
+component yourself.
import {
+ ChangeDetectionStrategy,
+ Component,
+ ElementRef,
+ EventEmitter,
+ Input,
+ NgZone,
+ OnChanges,
+ OnInit,
+ Output,
+ SimpleChanges
+} from '@angular/core';
+
+import {ControlValueAccessor, NG_VALUE_ACCESSOR} from '@angular/forms';
+import moment from 'moment';
+import {take} from 'rxjs/operators';
+import {DlDateAdapter} from '../core/public-api';
+import {DlDateTimePickerChange} from './dl-date-time-picker-change';
+import {DateButton} from './dl-date-time-picker-date-button';
+import {DlDateTimePickerModel} from './dl-date-time-picker-model';
+import {DlModelProvider} from './dl-model-provider';
+import {DlDayModelProvider} from './dl-model-provider-day';
+import {DlHourModelProvider} from './dl-model-provider-hour';
+import {DlMinuteModelProvider} from './dl-model-provider-minute';
+import {DlMonthModelProvider} from './dl-model-provider-month';
+import {DlYearModelProvider} from './dl-model-provider-year';
+
+/**
+ * Maps key codes to the model provider function name
+ * that should be called to perform the action.
+ *
+ * @internal
+ **/
+
+const keyCodeToModelProviderMethod = {
+ 'ArrowDown': 'goDown',
+ 'ArrowLeft': 'goLeft',
+ 'ArrowRight': 'goRight',
+ 'ArrowUp': 'goUp',
+ 'Down': 'goDown',
+ 'End': 'goEnd',
+ 'Home': 'goHome',
+ 'Left': 'goLeft',
+ 'PageDown': 'pageDown',
+ 'PageUp': 'pageUp',
+ 'Right': 'goRight',
+ 'Up': 'goUp',
+ 33: 'pageUp',
+ 34: 'pageDown',
+ 35: 'goEnd',
+ 36: 'goHome',
+ 37: 'goLeft',
+ 38: 'goUp',
+ 39: 'goRight',
+ 40: 'goDown',
+};
+
+
+/**
+ * List of view names for the calendar.
+ *
+ * This list must be in order from
+ * smallest increment of time to largest increment of time.
+ *
+ * @internal
+ **/
+const VIEWS = [
+ 'minute',
+ 'hour',
+ 'day',
+ 'month',
+ 'year'
+];
+
+/**
+ * Component that provides all of the user facing functionality of the date/time picker.
+ */
+
+@Component({
+ changeDetection: ChangeDetectionStrategy.OnPush,
+ preserveWhitespaces: false,
+ providers: [
+ {
+ provide: NG_VALUE_ACCESSOR,
+ useExisting: DlDateTimePickerComponent,
+ multi: true
+ }
+ ],
+ selector: 'dl-date-time-picker',
+ styleUrls: ['./dl-date-time-picker.component.scss'],
+ templateUrl: './dl-date-time-picker.component.html',
+})
+export class DlDateTimePickerComponent<D> implements OnChanges, OnInit, ControlValueAccessor {
+
+ /**
+ * Change listener callback functions registered
+ * via `registerOnChange`
+ * @internal
+ **/
+ private _changed: ((value: D) => void)[] = [];
+ /**
+ * Model for the current view.
+ *
+ * @internal
+ **/
+ _model: DlDateTimePickerModel;
+ /**
+ * Maps view name to the next view (the view for the next smallest increment of time).
+ * @internal
+ **/
+ private _nextView = {
+ 'year': 'month',
+ 'month': 'day',
+ 'day': 'hour',
+ 'hour': 'minute'
+ };
+ /**
+ * Maps view name to the previous view (the view for the next largest increment of time).
+ * @internal
+ **/
+ private _previousView = {
+ 'minute': 'hour',
+ 'hour': 'day',
+ 'day': 'month',
+ 'month': 'year'
+ };
+ /**
+ * Touch listener callback functions registered
+ * via `registerOnChange`
+ * @internal
+ **/
+ private _touched: (() => void)[] = [];
+ /**
+ * Stores the selected value for this picker.
+ * @internal
+ **/
+ private _value: D;
+ /**
+ * Maps view name to the model provider for that view.
+ * @internal
+ **/
+ private readonly _viewToModelProvider: {
+ year: DlModelProvider;
+ month: DlModelProvider;
+ day: DlModelProvider;
+ hour: DlModelProvider;
+ minute: DlModelProvider;
+ };
+ /**
+ * Emits when a `change` event when date/time is selected or
+ * the value of the date/time picker changes.
+ **/
+ @Output() /* eslint-disable-next-line @angular-eslint/no-output-native */
+ readonly change = new EventEmitter<DlDateTimePickerChange<D>>();
+ /**
+ * Specifies the classes used to display the left icon.
+ *
+ * This component uses OPENICONIC https://useiconic.com/open
+ * by default but any icon library may be used.
+ */
+ @Input()
+ leftIconClass: string | string[] | Set<string> | {} = [
+ 'oi',
+ 'oi-chevron-left'
+ ];
+ /**
+ * The highest view that the date/time picker can show.
+ * Setting this to a view less than year could make it more
+ * difficult for the end-user to navigate to certain dates.
+ */
+ @Input()
+ maxView: 'year' | 'month' | 'day' | 'hour' | 'minute' = 'year';
+ /**
+ * The view that will be used for date/time selection.
+ *
+ * The default of `minute means that selection will not happen
+ * until the end-user clicks on a cell in the minute view.
+ *
+ * for example, if you want the end-user to select a only day (date),
+ * setting `minView` to `day` will cause selection to happen when the
+ * end-user selects a cell in the day view.
+ *
+ * NOTE: This must be set lower than or equal to `startView'
+ */
+ @Input()
+ minView: 'year' | 'month' | 'day' | 'hour' | 'minute' = 'minute';
+ /**
+ * The number of minutes between each `.dl-abdtp-minute` button.
+ *
+ * Must be greater than `0` and less than `60`.
+ */
+ @Input()
+ minuteStep = 5;
+ /**
+ * Specifies the classes used to display the right icon.
+ *
+ * This component uses OPENICONIC https://useiconic.com/open
+ * by default but any icon library may be used.
+ */
+ @Input()
+ rightIconClass = [
+ 'oi',
+ 'oi-chevron-right'
+ ];
+
+ /* tslint:disable:member-ordering */
+ /**
+ * Determine whether or not the `DateButton` is selectable by the end user.
+ */
+ @Input()
+ selectFilter: (dateButton: DateButton, viewName: string) => boolean = () => true
+
+ /**
+ * Start at the view containing startDate when no value is selected.
+ */
+ @Input()
+ startDate: number;
+
+ /**
+ * The initial view that the date/time picker will show.
+ * The picker will also return to this view after a date/time
+ * is selected.
+ *
+ * NOTE: This must be set lower than or equal to `maxView'
+ */
+ @Input()
+ startView: 'year' | 'month' | 'day' | 'hour' | 'minute' = 'day';
+
+ /**
+ * Specifies the classes used to display the up icon.
+ *
+ * This component uses OPENICONIC https://useiconic.com/open
+ * by default but any icon library may be used.
+ */
+ @Input()
+ upIconClass = [
+ 'oi',
+ 'oi-chevron-top'
+ ];
+
+ /**
+ * Used to construct a new instance of a date/time picker.
+ *
+ * @param _elementRef
+ * reference to this element.
+ * @param _ngZone
+ * reference to an NgZone instance used to select the active element outside of angular.
+ * @param _dateAdapter
+ * date adapter for the date type in the model.
+ * @param yearModelComponent
+ * provider for the year view model.
+ * @param monthModelComponent
+ * provider for the month view model.
+ * @param dayModelComponent
+ * provider for the day view model.
+ * @param hourModelComponent
+ * provider for the hour view model.
+ * @param minuteModelComponent
+ * provider for the minute view model.
+ */
+ constructor(private _elementRef: ElementRef,
+ private _ngZone: NgZone,
+ private _dateAdapter: DlDateAdapter<D>,
+ private yearModelComponent: DlYearModelProvider,
+ private monthModelComponent: DlMonthModelProvider,
+ private dayModelComponent: DlDayModelProvider,
+ private hourModelComponent: DlHourModelProvider,
+ private minuteModelComponent: DlMinuteModelProvider) {
+
+ this._viewToModelProvider = {
+ year: yearModelComponent,
+ month: monthModelComponent,
+ day: dayModelComponent,
+ hour: hourModelComponent,
+ minute: minuteModelComponent,
+ };
+ }
+
+ /* tslint:enable:member-ordering */
+ /**
+ * Set's the model for the current view after applying the selection filter.
+ *
+ * @internal
+ **/
+ private set model(model: DlDateTimePickerModel) {
+ this._model = this.applySelectFilter(model);
+ }
+
+ /**
+ * Returns `D` value of the date/time picker or undefined/null if no value is set.
+ **/
+ get value(): D {
+ return this._value;
+ }
+
+ /**
+ * Sets value of the date/time picker and emits a change event if the
+ * new value is different from the previous value.
+ **/
+ set value(value: D) {
+ if (this._value !== value) {
+ this._value = value;
+ this.model = this._viewToModelProvider[this._model.viewName].getModel(this.getStartDate(), this.valueOf);
+ this._changed.forEach(f => f(value));
+ this.change.emit(new DlDateTimePickerChange<D>(value));
+ }
+ }
+
+ /**
+ * Returns `milliseconds` value of the date/time picker or undefined/null if no value is set.
+ **/
+ get valueOf(): number | null {
+ return this._dateAdapter.toMilliseconds(this._value);
+ }
+
+ /**
+ * Applies the `selectionFilter` by adding the `dl-abdtp-disabled`
+ * class to any `DateButton` where `selectFilter` returned false.
+ *
+ * @param model
+ * the new model
+ *
+ * @returns
+ * the supplied model with zero or more `DateButton`'s
+ * having the `dl-abdtp-disabled` class set to `true` if the
+ * selection for that date should be disabled.
+ *
+ * @internal
+ */
+ private applySelectFilter(model: DlDateTimePickerModel): DlDateTimePickerModel {
+ if (this.selectFilter) {
+ model.rows = model.rows.map((row) => {
+ row.cells.map((dateButton: DateButton) => {
+ const disabled = !this.selectFilter(dateButton, model.viewName);
+ dateButton.classes['dl-abdtp-disabled'] = disabled;
+ if (disabled) {
+ dateButton.classes['aria-disabled'] = true;
+ }
+ return dateButton;
+ });
+ return row;
+ });
+ }
+
+ return model;
+ }
+
+ /**
+ * Focuses the `.dl-abdtp-active` cell after the microtask queue is empty.
+ * @internal
+ **/
+ private focusActiveCell() {
+ this._ngZone.runOutsideAngular(() => {
+ this._ngZone.onStable.asObservable().pipe(take(1)).subscribe(() => {
+ this._elementRef.nativeElement.querySelector('.dl-abdtp-active').focus();
+ });
+ });
+ }
+
+ /**
+ * Determines the start date for the picker.
+ * @internal
+ **/
+ private getStartDate() {
+ if (hasValue(this._value)) {
+ return this._dateAdapter.toMilliseconds(this._value);
+ }
+ if (hasValue(this.startDate)) {
+ return this.startDate;
+ }
+ return moment().valueOf();
+ }
+
+ /**
+ * Determine the start view for the picker
+ * @returns
+ * the largest time increment view between the `minView` or `minute` view and the `startView` or `day` view.
+ */
+ private getStartView(): string {
+ const startIndex = Math.max(VIEWS.indexOf(this.minView || 'minute'), VIEWS.indexOf(this.startView || 'day'));
+ return VIEWS[startIndex];
+ }
+
+ /**
+ * Calls all registered `touch` callback functions.
+ * @internal
+ **/
+ private onTouch() {
+ this._touched.forEach((onTouched) => onTouched());
+ }
+
+ /**
+ * Receives configuration changes detected by Angular and passes the changes on
+ * to the model providers so the provider is aware of any necessary configuration
+ * changes (i.e. minuteStep)
+ *
+ * @param changes
+ * the input changes detected by Angular.
+ */
+ ngOnChanges(changes: SimpleChanges): void {
+ Object.values(this._viewToModelProvider).forEach((provider: DlModelProvider) => provider.onChanges(changes));
+
+ if (this._model) { // only update the model after ngOnInit has set it the first time.
+ this.model = this._viewToModelProvider[this._model.viewName].getModel(this._model.activeDate, this.valueOf);
+ }
+ }
+
+ /**
+ * Sets the initial model.
+ *
+ * @internal
+ **/
+ ngOnInit(): void {
+ this.model = this._viewToModelProvider[this.getStartView()].getModel(this.getStartDate(), this.valueOf);
+ }
+
+ /**
+ * Handles click (and enter & space key down) events on the date elements.
+ *
+ * If the current view is the minimum view then the date value is selected
+ * and the picker returns to the start view.
+ *
+ * Otherwise the picker displays the next view with the next
+ * smallest time increment.
+ *
+ * @internal
+ **/
+ _onDateClick(dateButton: DateButton) {
+ if (dateButton.classes['dl-abdtp-disabled']) {
+ return;
+ }
+
+ let nextView = this._nextView[this._model.viewName];
+
+ if ((this.minView || 'minute') === this._model.viewName) {
+ this.value = this._dateAdapter.fromMilliseconds(dateButton.value);
+ nextView = this.startView;
+ }
+
+ this.model = this._viewToModelProvider[nextView].getModel(dateButton.value, this.valueOf);
+
+ this.onTouch();
+ }
+
+ /**
+ * Handles click (and enter & space key down) events on the left button.
+ *
+ * Changes the displayed time range of the picker to the previous time range.
+ * For example, in year view, the previous decade is displayed.
+ *
+ * @internal
+ **/
+ _onLeftClick() {
+ this.model = this._viewToModelProvider[this._model.viewName].getModel(this._model.leftButton.value, this.valueOf);
+ this.onTouch();
+ }
+
+ /**
+ * Handles click (and enter & space key down) events on the up button.
+ *
+ * Changes the view of the picker to the next largest time increment.
+ * For example, in day view, the next view displayed will be month view.
+ *
+ * @internal
+ **/
+ _onUpClick() {
+ this.model = this._viewToModelProvider[this._previousView[this._model.viewName]].getModel(this._model.upButton.value, this.valueOf);
+ }
+
+ /**
+ * Handles click (and enter & space key down) events on the right button.
+ *
+ * Changes the displayed time range of the picker to the next time range.
+ * For example, in year view, the next decade is displayed.
+ *
+ * @internal
+ **/
+ _onRightClick() {
+ this.model = this._viewToModelProvider[this._model.viewName].getModel(this._model.rightButton.value, this.valueOf);
+ this.onTouch();
+ }
+
+ /**
+ * Handles various key down events to move the `active date` around the calendar.
+ *
+ * @internal
+ **/
+ _handleKeyDown($event: KeyboardEvent): void {
+ const functionName = keyCodeToModelProviderMethod[$event.key];
+
+ if (functionName) {
+ const modelProvider = this._viewToModelProvider[this._model.viewName];
+ this.model = modelProvider[functionName](this._model.activeDate, this.valueOf);
+
+ this.focusActiveCell();
+ // Prevent unexpected default actions such as form submission.
+ $event.preventDefault();
+ }
+ }
+
+ /**
+ * Implements ControlValueAccessor.registerOnChange to register change listeners.
+ * @internal
+ **/
+ registerOnChange(fn: (value: D) => void) {
+ this._changed.push(fn);
+ }
+
+ /**
+ * Implements ControlValueAccessor.registerOnTouched to register touch listeners.
+ * @internal
+ **/
+ registerOnTouched(fn: () => void) {
+ this._touched.push(fn);
+ }
+
+ /**
+ * Implements ControlValueAccessor.writeValue to store the value from the model.
+ * @internal
+ **/
+ writeValue(value: D) {
+ this.value = value;
+ }
+
+}
+
+/** @internal */
+function hasValue(value: any): boolean {
+ return (typeof value !== 'undefined') && (value !== null);
+}
+
+ <div class="text-center dl-abdtp-{{_model.viewName}}-view" [attr.data-dl-abdtp-view]="_model.viewName">
+ <div class="row align-items-center no-gutters">
+ <button class="col dl-abdtp-left-button align-items-center"
+ type="button"
+ [attr.aria-label]="_model.leftButton.ariaLabel"
+ [attr.dl-abdtp-value]="_model.leftButton.value"
+ [attr.title]="_model.leftButton.ariaLabel"
+ (click)="_onLeftClick()"
+ ><span class="left-icon" [ngClass]="leftIconClass"></span>
+ </button>
+
+ <div *ngIf="_model.viewName === (this.maxView || 'year'); then maxViewLabel else defaultViewLabel;"></div>
+
+ <button class="col dl-abdtp-right-button"
+ type="button"
+ [attr.aria-label]="_model.rightButton.ariaLabel"
+ [attr.dl-abdtp-value]="_model.rightButton.value"
+ [attr.title]="_model.rightButton.ariaLabel"
+ (click)="_onRightClick()"
+ ><span class="right-icon" [ngClass]="rightIconClass"></span>
+ </button>
+ </div>
+ <div (keydown)="_handleKeyDown($event)">
+ <div *ngIf="_model.rowLabels?.length" class="row no-gutters">
+ <div *ngFor="let label of _model.rowLabels"
+ class="col align-items-center no-gutters dl-abdtp-col-label">{{label}}</div>
+ </div>
+ <div *ngFor="let row of _model.rows" class="row align-items-center no-gutters">
+ <div *ngFor="let cell of row.cells"
+ role="gridcell"
+ class="col dl-abdtp-date-button dl-abdtp-{{_model.viewName}}"
+ [ngClass]="cell.classes"
+ [attr.aria-label]="cell.ariaLabel"
+ [attr.aria-disabled]="cell.classes['dl-abdtp-disabled']"
+ [attr.dl-abdtp-value]="cell.value"
+ [attr.tabindex]="cell.classes['dl-abdtp-active'] ? 0 : -1"
+ (click)="_onDateClick(cell)"
+ (keydown.space)="_onDateClick(cell)"
+ (keydown.enter)="_onDateClick(cell)"
+ >{{cell.display}}</div>
+ </div>
+ </div>
+</div>
+
+<ng-template #maxViewLabel>
+ <div class="col-10 dl-abdtp-view-label">{{_model.viewLabel}}</div>
+</ng-template>
+<ng-template #defaultViewLabel>
+ <button class="col-10 dl-abdtp-view-label dl-abdtp-up-button"
+ type="button"
+ [attr.aria-label]="_model.upButton.ariaLabel"
+ [attr.dl-abdtp-value]="_model.upButton.value"
+ [attr.title]="_model.upButton.ariaLabel"
+ (click)="_onUpClick()"
+ [ngClass]="_model.upButton.classes"
+ >{{_model.viewLabel}} <span class="up-icon" [ngClass]="upIconClass"></span>
+ </button>
+</ng-template>
+
+
+ ./dl-date-time-picker.component.scss
+
@import '../../scss/variables';
+
+:host {
+ user-select: none;
+}
+
+.dl-abdtp-col-label,
+.dl-abdtp-view-label {
+ font-weight: bold;
+}
+
+.dl-abdtp-view-label,
+.dl-abdtp-left-button,
+.dl-abdtp-right-button,
+.dl-abdtp-date-button {
+ padding: 5px;
+ border-radius: $dl-abdtp-date-button-border-radius;
+ cursor: pointer;
+ color: $dl-abdtp-date-button-color;
+ outline: 0;
+}
+
+.dl-abdtp-left-button,
+.dl-abdtp-up-button,
+.dl-abdtp-right-button,
+.dl-abdtp-date-button {
+ border-width: 0;
+}
+
+.dl-abdtp-active:focus,
+.dl-abdtp-date-button:focus,
+.dl-abdtp-date-button:hover,
+.dl-abdtp-left-button:focus,
+.dl-abdtp-left-button:hover,
+.dl-abdtp-right-button:focus,
+.dl-abdtp-right-button:hover,
+.dl-abdtp-up-button:focus,
+.dl-abdtp-up-button:hover,
+.dl-abdtp-view-label:focus {
+ background: $dl-abdtp-hover-background;
+}
+
+.dl-abdtp-past,
+.dl-abdtp-future {
+ color: $dl-abdtp-past-future-color;
+}
+
+.dl-abdtp-now,
+.dl-abdtp-now:hover,
+.dl-abdtp-now.disabled,
+.dl-abdtp-now.disabled:hover {
+ border-width: 1px;
+ border-style: solid;
+ border-radius: $dl-abdtp-date-button-border-radius;
+ border-color: $dl-abdtp-now-border-color;
+}
+
+.dl-abdtp-selected {
+ color: $dl-abdtp-selected-color;
+ background: $dl-abdtp-selected-background;
+}
+
+.dl-abdtp-selected:focus,
+.dl-abdtp-selected:hover {
+ background: $dl-abdtp-selected-hover-background;
+}
+
+.dl-abdtp-disabled {
+ cursor: default;
+ color: $dl-abdtp-disabled;
+}
+
+ File | +Type | +Identifier | +Statements | +
---|---|---|---|
+ + src/lib/core/dl-date-adapter-moment.ts + | +class | +DlDateAdapterMoment | ++ 100 % + (3/3) + | +
+ + src/lib/core/dl-date-adapter-native.ts + | +class | +DlDateAdapterNative | ++ 100 % + (3/3) + | +
+ + src/lib/core/dl-date-adapter-number.ts + | +class | +DlDateAdapterNumber | ++ 100 % + (3/3) + | +
+ + src/lib/core/dl-date-adapter-string.ts + | +injectable | +DlDateAdapterString | ++ 100 % + (4/4) + | +
+ + src/lib/core/dl-date-adapter.ts + | +class | +DlDateAdapter | ++ 100 % + (3/3) + | +
+ + src/lib/core/dl-date-time-string-format.ts + | +variable | +DL_DATE_TIME_DISPLAY_FORMAT | ++ 100 % + (1/1) + | +
+ + src/lib/core/dl-date-time-string-format.ts + | +variable | +DL_DATE_TIME_DISPLAY_FORMAT_DEFAULT | ++ 100 % + (1/1) + | +
+ + src/lib/core/dl-date-time-string-format.ts + | +variable | +DL_DATE_TIME_INPUT_FORMATS | ++ 100 % + (1/1) + | +
+ + src/lib/core/dl-date-time-string-format.ts + | +variable | +DL_DATE_TIME_INPUT_FORMATS_DEFAULT | ++ 100 % + (1/1) + | +
+ + src/lib/core/dl-date-time-string-format.ts + | +variable | +DL_DATE_TIME_MODEL_FORMAT | ++ 100 % + (1/1) + | +
+ + src/lib/core/dl-date-time-string-format.ts + | +variable | +DL_DATE_TIME_MODEL_FORMAT_DEFAULT | ++ 100 % + (1/1) + | +
+ + src/lib/dl-date-time-input/dl-date-time-input-change.ts + | +class | +DlDateTimeInputChange | ++ 100 % + (2/2) + | +
+ + src/lib/dl-date-time-input/dl-date-time-input.directive.ts + | +directive | +DlDateTimeInputDirective | ++ 100 % + (10/10) + | +
+ + src/lib/dl-date-time-picker/dl-date-time-picker-change.ts + | +class | +DlDateTimePickerChange | ++ 100 % + (2/2) + | +
+ + src/lib/dl-date-time-picker/dl-date-time-picker-date-button.ts + | +interface | +DateButton | ++ 100 % + (5/5) + | +
+ + src/lib/dl-date-time-picker/dl-date-time-picker-model.ts + | +interface | +DlDateTimePickerModel | ++ 100 % + (9/9) + | +
+ + src/lib/dl-date-time-picker/dl-date-time-picker.component.ts + | +component | +DlDateTimePickerComponent | ++ 100 % + (12/12) + | +
+ + src/lib/dl-date-time-picker/dl-model-provider-day.ts + | +class | +DlDayModelProvider | ++ 100 % + (11/11) + | +
+ + src/lib/dl-date-time-picker/dl-model-provider-hour.ts + | +class | +DlHourModelProvider | ++ 100 % + (11/11) + | +
+ + src/lib/dl-date-time-picker/dl-model-provider-minute.ts + | +class | +DlMinuteModelProvider | ++ 100 % + (11/11) + | +
+ + src/lib/dl-date-time-picker/dl-model-provider-month.ts + | +class | +DlMonthModelProvider | ++ 100 % + (11/11) + | +
+ + src/lib/dl-date-time-picker/dl-model-provider-year.ts + | +class | +DlYearModelProvider | ++ 100 % + (11/11) + | +
+ + src/lib/dl-date-time-picker/dl-model-provider.ts + | +interface | +DlModelProvider | ++ 100 % + (11/11) + | +
+
+ src/lib/dl-date-time-input/dl-date-time-input.directive.ts
+
+
+
This directive allows the user to enter dates, using the keyboard, into an input box and + angular will then store a date value in the model.
+The input format(s), display format, and model format are independent and fully customizable.
+ + + + ++
+ ControlValueAccessor
+ Validator
+
Providers | +
+
+ { provide: NG_VALUE_ACCESSOR, useExisting: DlDateTimeInputDirective, multi: true }
+ { provide: NG_VALIDATORS, useExisting: DlDateTimeInputDirective, multi: true }
+
+ |
+
Selector | +input[dlDateTimeInput] |
+
+ Methods+ |
+
+ + | +
+ Inputs+ |
+
+
|
+
+ Outputs+ |
+
+
|
+
+ HostListeners+ |
+
+ + | +
+ Accessors+ |
+
+
|
+
+constructor(_renderer: Renderer2, _elementRef: ElementRef, _dateAdapter: DlDateAdapter<D>, _displayFormat: string, _inputFormats: string[])
+ |
+ ||||||||||||||||||||||||
+ + | +||||||||||||||||||||||||
+ Constructs a new instance of this directive.
+ reference to the renderer.
+ reference to this element.
+ date adapter for the date type in the model.
+ from
+ Parameters :
+
+
|
+
+ + dlDateTimeInputFilter + | +|
+ Type : boolean
+
+ |
+ |
+ + | +|
+ Set a function used to determine whether or not the |
+
+ + dateChange + | +|
+ Type : EventEmitter
+
+ |
+ |
+ + | +|
+ Emits when a |
+
+ + + + blur + + + + | +
+ + | +
+ Format the input text using DL_DATE_TIME_DISPLAY_FORMAT and mark the control as touched. + |
+
+ + + + change + + + + | +
+ + | +
+ Emit a |
+
+ + + + input + + + + | +||||||
+ Arguments : '$event.target.value'
+ |
+ ||||||
+ + | +||||||
+ Parse the user input into a possibly valid date. +The model value is not set if the input is NOT one of the DL_DATE_TIME_INPUT_FORMATS. + Value of the input control. +
+ Parameters :
+
+
+
+ |
+
+ + + + _onBlur + + + | +
+
+ _onBlur()
+ |
+
+ Decorators :
+ + @HostListener('blur')
+ |
+
+ + | +
+ Format the input text using DL_DATE_TIME_DISPLAY_FORMAT and mark the control as touched. +
+ Returns :
+ void
+
+ |
+
+ + + + _onChange + + + | +
+
+ _onChange()
+ |
+
+ Decorators :
+ + @HostListener('change')
+ |
+
+ + | +
+ Emit a
+ Returns :
+ void
+
+ |
+
+ + + + _onInput + + + | +||||||||
+
+ _onInput(value: string | null | undefined)
+ |
+ ||||||||
+ Decorators :
+ + @HostListener('input', ['$event.target.value'])
+ |
+ ||||||||
+ + | +||||||||
+ Parse the user input into a possibly valid date. +The model value is not set if the input is NOT one of the DL_DATE_TIME_INPUT_FORMATS. + Value of the input control. +
+ Parameters :
+
+
+
+ Returns :
+ void
+
+
+
+
+ |
+
+ + dlDateTimeInputFilter + | +||||||||
+ setdlDateTimeInputFilter(inputFilterFunction: (value: D | null) => void)
+ |
+ ||||||||
+ + | +||||||||
+ Set a function used to determine whether or not the
+ Parameters :
+
+
+
+
+ Returns :
+ void
+
+ |
+
+ + value + | +||||||||
+ getvalue()
+ |
+ ||||||||
+ + | +||||||||
+ Returns
+ Returns :
+ D
+
+ |
+ ||||||||
+ setvalue(newValue: D | null | undefined)
+ |
+ ||||||||
+ + | +||||||||
+ Set the value of the date/time input to a value of
+ Parameters :
+
+
+
+
+ Returns :
+ void
+
+ |
+
This directive provides all of the user facing functionality to input a date and/or time using the keyboard. |
+Import the module corresponding to the desired data type of the date in the model.
+DlDateTimePickerDateModule
DlDateTimePickerMomentModule
DlDateTimePickerNumberModule
DlDateTimePickerStringModule
A DateAdapter
is used to adapt the data type in the model to the number
data type
+used internally by the date/time picker.
If you need a different data type than what is currently supported, you can extend
+DlDateAdapter<D>
to provide the data type you need then override the DlDateAdapter
+provider in app.module.ts
to use your new class.
providers: [{provide: DlDateAdapter, useClass: MyCustomDateAdapter}],
The display format is defined in the DL_DATE_TIME_DISPLAY_FORMAT
token and is injected into this component
+to control the display format.
DL_DATE_TIME_DISPLAY_FORMAT
defaults to moment
's lll
long date format.
+Override DL_DATE_TIME_DISPLAY_FORMAT
if you do not like the default format.
{provide: DL_DATE_TIME_DISPLAY_FORMAT, useValue: '<what ever format you want goes here>'}
This directive supports multiple input formats, as defined in the DL_DATE_TIME_INPUT_FORMATS
token.
+When the user inputs a string value into a text box, this directive attempts to parse the input
+using one of the specified formats, in the order the format occur in the array.
Once one of the formats is able to parse the user input, the date is set in the model.
+Nota bene For convenience DL_DATE_TIME_INPUT_FORMATS
defaults to support multiple formats,
+which can dramatically slow down parsing performance. It can also result in successfully parsing
+a date using a format that is not appropriate for your use case.
Consider overriding the DL_DATE_TIME_INPUT_FORMATS
token to only include the specific formats required by your project.
{provide: DL_DATE_TIME_INPUT_FORMATS, useValue: ['<input format zero>', ..., '<input format N>']}
See moment's parsing multiple formats +page for more information on how these date formats are used.
+ +import {Directive, ElementRef, EventEmitter, HostListener, Inject, Input, Output, Renderer2} from '@angular/core';
+import {
+ AbstractControl,
+ ControlValueAccessor,
+ NG_VALIDATORS,
+ NG_VALUE_ACCESSOR,
+ ValidationErrors,
+ Validator,
+ ValidatorFn,
+ Validators,
+} from '@angular/forms';
+import moment from 'moment';
+import {DL_DATE_TIME_DISPLAY_FORMAT, DL_DATE_TIME_INPUT_FORMATS, DlDateAdapter} from '../core/public-api';
+import {DlDateTimeInputChange} from './dl-date-time-input-change';
+
+/**
+ * This directive allows the user to enter dates, using the keyboard, into an input box and
+ * angular will then store a date value in the model.
+ *
+ * The input format(s), display format, and model format are independent and fully customizable.
+ */
+@Directive({
+ selector: 'input[dlDateTimeInput]',
+ providers: [
+ {provide: NG_VALUE_ACCESSOR, useExisting: DlDateTimeInputDirective, multi: true},
+ {provide: NG_VALIDATORS, useExisting: DlDateTimeInputDirective, multi: true}
+ ]
+})
+export class DlDateTimeInputDirective<D> implements ControlValueAccessor, Validator {
+
+ /* tslint:disable:member-ordering */
+ private _filterValidator: ValidatorFn = (control: AbstractControl): ValidationErrors | null => {
+ return (this._inputFilter || (() => true))(this._value) ?
+ null : {'dlDateTimeInputFilter': {'value': control.value}};
+ }
+ private _inputFilter: (value: (D | null)) => boolean = () => true;
+ private _isValid = true;
+ private _parseValidator: ValidatorFn = (): ValidationErrors | null => {
+ return this._isValid ?
+ null : {'dlDateTimeInputParse': {'text': this._elementRef.nativeElement.value}};
+ }
+ private _changed: ((value: D) => void)[] = [];
+ private _touched: (() => void)[] = [];
+ private _validator = Validators.compose([this._parseValidator, this._filterValidator]);
+ private _onValidatorChange: () => void = () => {};
+ private _value: D | undefined = undefined;
+
+ /**
+ * Emits when a `change` event when date/time is selected or
+ * the value of the date/time picker changes.
+ **/
+ @Output()
+ readonly dateChange = new EventEmitter<DlDateTimeInputChange<D>>();
+
+ /**
+ * Constructs a new instance of this directive.
+ * @param _renderer
+ * reference to the renderer.
+ * @param _elementRef
+ * reference to this element.
+ * @param _dateAdapter
+ * date adapter for the date type in the model.
+ * @param _displayFormat
+ * from `DL_DATE_TIME_DISPLAY_FORMAT`, which defines the format to use for a valid date/time value.
+ * @param _inputFormats
+ * from `DL_DATE_TIME_INPUT_FORMATS`, which defines the input formats that allowed as valid date/time values.
+ * NB: moment is always in strict parse mode for this directive.
+ */
+ constructor(
+ private _renderer: Renderer2,
+ private _elementRef: ElementRef,
+ private _dateAdapter: DlDateAdapter<D>,
+ @Inject(DL_DATE_TIME_DISPLAY_FORMAT) private readonly _displayFormat: string,
+ @Inject(DL_DATE_TIME_INPUT_FORMATS) private readonly _inputFormats: string[]
+ ) {}
+
+ /**
+ * Set a function used to determine whether or not the `value` entered by the user is allowed.
+ * @param inputFilterFunction
+ * a function that returns `true` if the `value` entered by the user is allowed, otherwise `false`.
+ */
+ @Input()
+ set dlDateTimeInputFilter(inputFilterFunction: (value: D | null) => boolean) {
+ this._inputFilter = inputFilterFunction || (() => true);
+ this._onValidatorChange();
+ }
+
+ /* tslint:enable:member-ordering */
+
+ /**
+ * Returns `D` value of the date/time input or `undefined` | `null` if no value is set.
+ **/
+ get value(): D {
+ return this._value;
+ }
+
+ /**
+ * Set the value of the date/time input to a value of `D` | `undefined` | `null`;
+ * @param newValue
+ * the new value of the date/time input
+ */
+
+ set value(newValue: D | null | undefined) {
+ if (newValue !== this._value) {
+ this._value = newValue;
+ this._changed.forEach(onChanged => onChanged(this._value));
+ }
+ }
+
+ /**
+ * Emit a `change` event when the value of the input changes.
+ */
+ @HostListener('change') _onChange() {
+ this.dateChange.emit(new DlDateTimeInputChange(this._value));
+ }
+
+ /**
+ * Format the input text using {@link DL_DATE_TIME_DISPLAY_FORMAT} and mark the control as touched.
+ */
+ @HostListener('blur') _onBlur() {
+ if (this._value) {
+ this._setElementValue(this._value);
+ }
+ this._touched.forEach(onTouched => onTouched());
+ }
+
+ /**
+ * Parse the user input into a possibly valid date.
+ * The model value is not set if the input is NOT one of the {@link DL_DATE_TIME_INPUT_FORMATS}.
+ * @param value
+ * Value of the input control.
+ */
+ @HostListener('input', ['$event.target.value']) _onInput(value: string | null | undefined): void {
+ const testDate = value === null || value === undefined || value === ''
+ ? undefined
+ : moment(value, this._inputFormats, true);
+
+ this._isValid = testDate && testDate.isValid();
+ this.value = this._isValid ? this._dateAdapter.fromMilliseconds(testDate.valueOf()) : undefined;
+ }
+
+ /**
+ * @internal
+ */
+ private _setElementValue(value: D) {
+ if (value !== null && value !== undefined) {
+ this._renderer.setProperty(this._elementRef.nativeElement, 'value', moment(value).format(this._displayFormat));
+ }
+ }
+
+ /**
+ * @internal
+ */
+ registerOnChange(onChange: (value: any) => void): void {
+ this._changed.push(onChange);
+ }
+
+ /**
+ * @internal
+ */
+ registerOnTouched(onTouched: () => void): void {
+ this._touched.push(onTouched);
+ }
+
+ /**
+ * @internal
+ */
+ registerOnValidatorChange(validatorOnChange: () => void): void {
+ this._onValidatorChange = validatorOnChange;
+ }
+
+ /**
+ * @internal
+ */
+ setDisabledState(isDisabled: boolean): void {
+ this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
+ }
+
+ /**
+ * @internal
+ */
+ validate(control: AbstractControl): ValidationErrors | null {
+ return this._validator(control);
+ }
+
+ /**
+ * @internal
+ */
+ writeValue(value: D): void {
+ this._isValid = true;
+ this.value = value;
+ this._setElementValue(value);
+ }
+}
+
+ Native Angular (8+) datetime picker component styled by Twitter Bootstrap 4.
+ + + + + +Read this in other languages: Spanish
+Use install version 3.1.0
+npm install angular-bootstrap-datetimepicker@3.1.0
See angularjs-bootstrap-datetimepicker
+I know this is a tiny component but many people use it in production (high 5 to all of us) - if you happen to use this component please click the star button (at the top of the page) - it means a lot to all the contributors.
+ +Peer dependencies:
+jQuery is NOT required.
+If you are using the Angular CLI there are a few simple steps to +add this component to your project.
+First, install this module and it's peer dependencies.
+Example :npm install --save angular-bootstrap-datetimepicker bootstrap moment open-iconic
Then update ./src/app/app.module.ts
to include the following:
import { AppComponent } from './app.component';
+import { BrowserModule } from '@angular/platform-browser';
+import { FormsModule } from '@angular/forms';
+import { NgModule } from '@angular/core';
+import { DlDateTimeDateModule, DlDateTimePickerModule } from 'angular-bootstrap-datetimepicker';
+
+@NgModule({
+ declarations: [
+ AppComponent
+ ],
+ imports: [
+ BrowserModule,
+ FormsModule,
+ DlDateTimeDateModule, // <--- Determines the data type of the model
+ DlDateTimePickerModule,
+ ],
+ providers: [FormsModule],
+ bootstrap: [AppComponent]
+})
+export class AppModule { }
Next, add the following to ./src/app/app.component.html
<dl-date-time-picker
+ startView="day"
+ maxView="year"
+ minView="minute"
+ minuteStep="5"
+ [(ngModel)]="selectedDate"
+>
+</dl-date-time-picker>
Next, add the following to ./src/styles.css
@import '~bootstrap/dist/css/bootstrap.min.css';
+@import '~open-iconic/font/css/open-iconic-bootstrap.css';
Note: This component uses open-iconic
icons by default, but you can use any icon library
+that supports styling with classes
.
Finally, run npm start
and you should see the date/time picker on http://localhost:4200/
By default, the date/time picker is as wide as it's container { width:100% }
.
+It uses bootstrap's flex row
and col
classes to layout the date/time picker into rows and columns.
+If the parent container is too narrow (less than 340px in english), the row and column layout may wrap in ways that are not attractive.
+Other languages/locals may require a wider container to fit the contents.
Use the automated configuration generator (please let me know if it does not work for your use case!), +or see https://dalelotts.github.io/angular-bootstrap-datetimepicker/ +for the automatically generated documentation.
+The first day of the week is determined by moment's i18n settings.
+For example, setting the locale to 'fr'
will cause Monday to be the first day of the week.
The format of hours and minutes is also determined by moment's i18n settings.
+hours are displayed using ll
as the format.
+minutes are displayed using lll
as the format.
I recommend you use the default locale settings from Moment (if they are incorrect, submit a PR to moment to correct the settings) +If for some reason the default Moment settings will not work, you can customize the existing locale or create a custom locale with the desired formats.
+You can generate the documentation by running npm run documentation
+or see https://dalelotts.github.io/angular-bootstrap-datetimepicker/
The DlDateTimePickerComponent
component adds aria-label
attributes to the left, right, and up buttons
+in addition to all calendar cells where the text of the cell may not fully describe the value.
The DlDateTimePickerComponent
component supports the following keyboard shortcuts in all views:
Shortcut | +Action | +
---|---|
LEFT_ARROW |
+Go to the cell to the left | +
RIGHT_ARROW |
+Go to the cell to the right | +
UP_ARROW |
+Go to the cell above | +
DOWN_ARROW |
+Go to the cell below | +
HOME |
+Go to the first cell in the view | +
END |
+Go to the last cell in the view | +
PAGE_UP |
+Go to the same cell in the previous time period | +
PAGE_DOWN |
+Go to the same cell in the next time period | +
ENTER or SPACE |
+Select current cell | +
This view allows the user to select the year for the target date. +If the year view is the minView, the date will be set to midnight on the first day of the year
+This view allows the user to select the month in the selected year. +If the month view is the minView, the date will be set to midnight on the first day of the month.
+This view allows the user to select the the day of the month, in the selected month. +If the day view is the minView, the date will be set to midnight on the day selected.
+This view allows the user to select the hour of the day, on the selected day. +If the hour view is the minView, the date will be set to the beginning of the hour on the day selected.
+This view allows the user to select a specific time of day, in the selected hour.
+By default, the time is displayed in 5 minute increments. The minuteStep
property controls the increments of time displayed.
+If the minute view is the minView, which is is by default, the date will be set to the beginning of the hour on the day selected.
See Contributing.md
+This component was written using TDD and all enhancements and changes have related tests.
+We use karma and jshint to ensure the quality of the code. The easiest way to run these checks is to use gulp:
+Example :npm install
+npm test
The karma task will try to open Chrome as a browser in which to run the tests. +Make sure Chrome is available or change the browsers setting in karma.config.js
+angular-bootstrap-datetimepicker is released under the MIT license and is copyright 2015 Knight Rider Consulting, Inc.. Boiled down to smaller chunks, it can be described with the following conditions.
+The full angular-bootstrap-datetimepicker license is located in the project repository for more information.
+ + + + + + + + + + + + + + + + + + + + + ++
+ src/lib/core/dl-date-adapter-string.ts
+
+
+
Adapts string
to be usable as a date by date/time components that work with dates.
+
+ DlDateAdapter
+
+ Methods+ |
+
+
|
+
+constructor(inputFormats: string[], modelFormat: string)
+ |
+ ||||||||||||
+ Defined in src/lib/core/dl-date-adapter-string.ts:15
+ |
+ ||||||||||||
+ Constructs a new instance of this class. +see DL_DATE_TIME_INPUT_FORMATS + see DL_DATE_TIME_MODEL_FORMAT +
+ Parameters :
+
+
|
+
+ + + fromMilliseconds + + + | +||||||||
+fromMilliseconds(milliseconds: number)
+ |
+ ||||||||
+ Inherited from
+ DlDateAdapter
+ |
+ ||||||||
+ Defined in
+ DlDateAdapter:39
+ |
+ ||||||||
+ Returns the specified number. + a moment time time. + the specified moment in time. +
+ Parameters :
+
+
+
+ Returns :
+ string
+
+
+
+ the specified moment in time. + + |
+
+ + + toMilliseconds + + + | +||||||||
+toMilliseconds(value: string | null)
+ |
+ ||||||||
+ Inherited from
+ DlDateAdapter
+ |
+ ||||||||
+ Defined in
+ DlDateAdapter:51
+ |
+ ||||||||
+ Returns the specified number.
+ a moment time time or
+ Parameters :
+
+
+
+ Returns :
+ number | null
+
+
+
+ the milliseconds for the specified value or |
+
import {Inject, Injectable} from '@angular/core';
+import moment from 'moment';
+import {DlDateAdapter} from './dl-date-adapter';
+import {DL_DATE_TIME_INPUT_FORMATS, DL_DATE_TIME_MODEL_FORMAT} from './dl-date-time-string-format';
+
+/**
+ * Adapts `string` to be usable as a date by date/time components that work with dates.
+ **/
+@Injectable({
+ providedIn: 'root'
+})
+export class DlDateAdapterString extends DlDateAdapter<string> {
+
+ private readonly inputFormats: string[];
+ private readonly modelFormat: string;
+
+ /**
+ * Constructs a new instance of this class.
+ *
+ * @param inputFormats
+ * see {@link DL_DATE_TIME_INPUT_FORMATS}
+ * @param modelFormat
+ * see {@link DL_DATE_TIME_MODEL_FORMAT}
+ */
+ constructor(@Inject(DL_DATE_TIME_INPUT_FORMATS) inputFormats: string[],
+ @Inject(DL_DATE_TIME_MODEL_FORMAT) modelFormat: string) {
+ super();
+ this.inputFormats = inputFormats;
+ this.modelFormat = modelFormat;
+ }
+
+ /**
+ * Returns the specified number.
+ * @param milliseconds
+ * a moment time time.
+ * @returns
+ * the specified moment in time.
+ */
+ fromMilliseconds(milliseconds: number): string {
+ return moment(milliseconds).format(this.modelFormat);
+ }
+
+ /**
+ * Returns the specified number.
+ * @param value
+ * a moment time time or `null`
+ * @returns
+ * the milliseconds for the specified value or `null`
+ * `null` is returned when value is not a valid input date string
+ */
+ toMilliseconds(value: string | null): number | null {
+ if (value !== undefined && value !== null) {
+ const newMoment = moment(value, this.inputFormats, true);
+ return newMoment.isValid() ? newMoment.valueOf() : undefined;
+ }
+ }
+}
+
+ +
+ src/lib/dl-date-time-picker/dl-date-time-picker-date-button.ts
+
+
+
Represents the configuration for a cell in the picker.
+ + + + +
+ Properties+ |
+
+
|
+
+ + ariaLabel + + + + + | +
+ ariaLabel:
+ |
+
+ Type : string
+
+ |
+
+ The accessible label for the cell. +Used by screen readers. + |
+
+ + classes + + + + + | +
+ classes:
+ |
+
+ Type : literal type
+
+ |
+
+ The classes to add to the cell button + |
+
+ + display + + + + + | +
+ display:
+ |
+
+ Type : string
+
+ |
+
+ The text to display in the button. + |
+
+ + value + + + + + | +
+ value:
+ |
+
+ Type : number
+
+ |
+
+ The date/time value for the button. + |
+
export interface DateButton {
+
+ /**
+ * The accessible label for the cell.
+ * Used by screen readers.
+ */
+ ariaLabel: string;
+ /**
+ * The classes to add to the cell button
+ */
+ classes: {};
+ /**
+ * The text to display in the button.
+ */
+ display: string;
+ /**
+ * The date/time value for the button.
+ */
+ value: number;
+}
+
+ +
+ src/lib/dl-date-time-picker/dl-date-time-picker-model.ts
+
+
+
Interface that represents the model for every view in a date/time picker.
+ + + + +
+ Properties+ |
+
+
|
+
+ + activeDate + + + + + | +
+ activeDate:
+ |
+
+ Type : number
+
+ |
+
+ The date value of the currently active cell in the model. + |
+
+ + leftButton + + + + + | +
+ leftButton:
+ |
+
+ Type : literal type
+
+ |
+
+ Represent the configuration for the left button. + |
+
+ + rightButton + + + + + | +
+ rightButton:
+ |
+
+ Type : literal type
+
+ |
+
+ Represents the configuration for the right button. + |
+
+ + rowLabels + + + + + | +
+ rowLabels:
+ |
+
+ Type : string[]
+
+ |
+
+ Optional + | +
+ Optional row labels.
+Used to include the weekday labels in the |
+
+ + rows + + + + + | +
+ rows:
+ |
+
+ Type : Array<literal type>
+
+ |
+
+ The rows in the current view. + |
+
+ + upButton + + + + + | +
+ upButton:
+ |
+
+ Type : literal type
+
+ |
+
+ Optional + | +
+ Represent the configuration for the up button. + |
+
+ + viewLabel + + + + + | +
+ viewLabel:
+ |
+
+ Type : string
+
+ |
+
+ The label displayed in the top-center of the date/time picker + |
+
+ + viewName + + + + + | +
+ viewName:
+ |
+
+ Type : string
+
+ |
+
+ The name of the view represented by this model. + |
+
import {DateButton} from './dl-date-time-picker-date-button';
+
+/**
+ * Interface that represents the model for every view in a date/time picker.
+ */
+export interface DlDateTimePickerModel {
+ /**
+ * The date value of the currently active cell in the model.
+ */
+ activeDate: number;
+ /**
+ * Represent the configuration for the left button.
+ */
+ leftButton: {
+ /**
+ * The value for the model to the left of this model.
+ */
+ value: number;
+
+ /**
+ * The accessible label for the left button.
+ * Used by screen readers.
+ */
+ ariaLabel: string;
+
+ /**
+ * The classes to add to the left button
+ */
+ classes: {};
+ };
+ /**
+ * Represents the configuration for the right button.
+ */
+ rightButton: {
+
+ /**
+ * The value for the model to the right this model.
+ */
+ value: number;
+
+ /**
+ * The accessible label for the right button.
+ * Used by screen readers.
+ */
+ ariaLabel: string;
+
+ /**
+ * The classes to add to the up button
+ */
+ classes: {};
+ };
+ /**
+ * Optional row labels.
+ * Used to include the weekday labels in the `day` view
+ */
+ rowLabels?: string[];
+ /**
+ * The rows in the current view.
+ */
+ rows: Array<{
+ /**
+ * The cells in the current row.
+ */
+ cells: Array<DateButton>
+ }>;
+ /**
+ * Represent the configuration for the up button.
+ */
+ upButton?: {
+
+ /**
+ * The value for the model above this model.
+ */
+ value: number;
+
+ /**
+ * The accessible label for the up button.
+ * Used by screen readers.
+ */
+ ariaLabel: string;
+
+ /**
+ * The classes to add to the up button
+ */
+ classes: {};
+ };
+ /**
+ * The label displayed in the top-center of the date/time picker
+ */
+ viewLabel: string;
+ /**
+ * The name of the view represented by this model.
+ */
+ viewName: string;
+}
+
+ +
+ src/lib/dl-date-time-picker/dl-model-provider.ts
+
+
+
Implemented by classes that provide models for the date/time picker.
+The terms left
, right
, up
, and down
are used in place of
+previous
, next
, etc so that the model provider is UI centric
+rather than time direction centric.
For example, another calendar implementation may render future
dates to the left
.
Having the api method goLeft
may move the active
cell to a
+future or past value depending on the calendar implementation,
+but both operations are performed with the left-arrow
key.
+ Methods+ |
+
+
|
+
+ + + getModel + + + | +||||||||||||
+getModel(milliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Returns the model for the specified moment in time. + the moment in time the model should represent. + the current value of the date/time picker. + the model representing the specified moment in time. +
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ the model representing the specified moment in time. + + |
+
+ + + goDown + + + | +||||||||||||
+goDown(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The next cell What happens is determined entirely by the implementation and it +varies from view-to-view. +This is used for keyboard navigation. + the moment in time from which the next model
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ the model representing the next model |
+
+ + + goEnd + + + | +||||||||||||
+goEnd(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the Typically the view or time range will not change. However, changes to the view +or time rage are not specifically prohibited. +What happens is determined entirely by the implementation and it +varies from view-to-view. +This is used for keyboard navigation. + the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ a model with the |
+
+ + + goHome + + + | +||||||||||||
+goHome(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the Typically the view or time range will not change. However, changes to the view +or time rage are not specifically prohibited. +What happens is determined entirely by the implementation and it +varies from view-to-view. +This is used for keyboard navigation. + the moment in time from which the
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ a model with the |
+
+ + + goLeft + + + | +||||||||||||
+goLeft(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The next cell What happens is determined entirely by the implementation and it +varies from view-to-view. +This is used for keyboard navigation. + the moment in time from which the next model
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ the model representing the next model |
+
+ + + goRight + + + | +||||||||||||
+goRight(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The next cell What happens is determined entirely by the implementation and it +varies from view-to-view. +This is used for keyboard navigation. + the moment in time from which the next model
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ the model representing the next model |
+
+ + + goUp + + + | +||||||||||||
+goUp(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The next cell What happens is determined entirely by the implementation and it +varies from view-to-view. +This is used for keyboard navigation. + the moment in time from which the next model
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ the model representing the next model |
+
+ + + onChanges + + + | +||||||||
+onChanges(changes: SimpleChanges)
+ |
+ ||||||||
+ + | +||||||||
+ Receives configuration changes detected by Angular. (i.e. minuteStep) +the changes detected by Angular. +
+ Parameters :
+
+
+
+ Returns :
+ void
+
+
+
+
+ |
+
+ + + pageDown + + + | +||||||||||||
+pageDown(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The next cell What happens is determined entirely by the implementation and it +varies from view-to-view. +This is used for keyboard navigation. + the moment in time from which the next model
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ the model representing the next model |
+
+ + + pageUp + + + | +||||||||||||
+pageUp(fromMilliseconds: number, selectedMilliseconds: number)
+ |
+ ||||||||||||
+ + | +||||||||||||
+ Move the The next cell What happens is determined entirely by the implementation and it +varies from view-to-view. +This is used for keyboard navigation. + the moment in time from which the next model
+ Parameters :
+
+
+
+ Returns :
+ DlDateTimePickerModel
+
+
+
+ the model representing the next model |
+
import {SimpleChanges} from '@angular/core';
+import {DlDateTimePickerModel} from './dl-date-time-picker-model';
+
+/**
+ * Implemented by classes that provide models for the date/time picker.
+ *
+ * The terms `left`, `right`, `up`, and `down` are used in place of
+ * `previous`, `next`, etc so that the model provider is UI centric
+ * rather than time direction centric.
+ *
+ * For example, another calendar implementation may render `future` dates to the `left`.
+ *
+ * Having the api method `goLeft` may move the `active` cell to a
+ * future or past value depending on the calendar implementation,
+ * but both operations are performed with the `left-arrow` key.
+ */
+export interface DlModelProvider {
+
+ /**
+ * Receives configuration changes detected by Angular. (i.e. minuteStep)
+ *
+ * @param changes
+ * the changes detected by Angular.
+ */
+ onChanges(changes: SimpleChanges): void;
+
+ /**
+ * Returns the model for the specified moment in time.
+ * @param milliseconds
+ * the moment in time the model should represent.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker.
+ * @returns
+ * the model representing the specified moment in time.
+ */
+ getModel(milliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel;
+
+ /**
+ * Move the `active` cell one cell down from the specified moment in time.
+ *
+ * The next cell `down` might be in a different time range than the currently
+ * displayed view. In this case, the model time range will include the new active cell.
+ *
+ * What happens is determined entirely by the implementation and it
+ * varies from view-to-view.
+ *
+ * This is used for keyboard navigation.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next model `down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker
+ * @returns
+ * the model representing the next model `down` from the specified moment in time.
+ */
+ goDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel;
+
+ /**
+ * Move the `active` cell to the `last` cell from the specified moment in time.
+ *
+ * Typically the view or time range will not change. However, changes to the view
+ * or time rage are not specifically prohibited.
+ *
+ * What happens is determined entirely by the implementation and it
+ * varies from view-to-view.
+ *
+ * This is used for keyboard navigation.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `last` active cell will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker
+ * @returns
+ * a model with the `last` cell in the view as the active cell.
+ */
+ goEnd(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel;
+
+ /**
+ * Move the `active` cell to the `first` cell from the specified moment in time.
+ *
+ * Typically the view or time range will not change. However, changes to the view
+ * or time rage are not specifically prohibited.
+ *
+ * What happens is determined entirely by the implementation and it
+ * varies from view-to-view.
+ *
+ * This is used for keyboard navigation.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the `first` active cell will be calculated.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker
+ * @returns
+ * a model with the `first` cell in the view as the active cell.
+ */
+ goHome(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel;
+
+ /**
+ * Move the `active` cell one cell to the `left` from the specified moment in time.
+ *
+ * The next cell `left` might be in a different time range than the currently
+ * displayed view. In this case, the model time range will include the new active cell.
+ *
+ * What happens is determined entirely by the implementation and it
+ * varies from view-to-view.
+ *
+ * This is used for keyboard navigation.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next model `left` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker
+ * @returns
+ * the model representing the next model `left` from the specified moment in time.
+ */
+ goLeft(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel;
+
+ /**
+ * Move the `active` cell one cell to the `right` from the specified moment in time.
+ *
+ * The next cell `right` might be in a different time range than the currently
+ * displayed view. In this case, the model time range will include the new active cell.
+ *
+ * What happens is determined entirely by the implementation and it
+ * varies from view-to-view.
+ *
+ * This is used for keyboard navigation.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next model `right` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker
+ * @returns
+ * the model representing the next model `right` from the specified moment in time.
+ */
+ goRight(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel;
+
+ /**
+ * Move the `active` cell one cell `up` from the specified moment in time.
+ *
+ * The next cell `up` might be in a different time range than the currently
+ * displayed view. In this case, the model time range will include the new active cell.
+ *
+ * What happens is determined entirely by the implementation and it
+ * varies from view-to-view.
+ *
+ * This is used for keyboard navigation.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next model `up` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker
+ * @returns
+ * the model representing the next model `up` from the specified moment in time.
+ */
+ goUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel;
+
+ /**
+ * Move the `active` cell one `page-down` from the specified moment in time.
+ *
+ * The next cell `page-down` will be in a different time range than the currently
+ * displayed view and the model time range will include the new active cell.
+ *
+ * What happens is determined entirely by the implementation and it
+ * varies from view-to-view.
+ *
+ * This is used for keyboard navigation.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next model `page-down` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker
+ * @returns
+ * the model representing the next model `page-down` from the specified moment in time.
+ */
+ pageDown(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel;
+
+ /**
+ * Move the `active` cell one `page-up` from the specified moment in time.
+ *
+ * The next cell `page-up` will be in a different time range than the currently
+ * displayed view and the model time range will include the new active cell.
+ *
+ * What happens is determined entirely by the implementation and it
+ * varies from view-to-view.
+ *
+ * This is used for keyboard navigation.
+ *
+ * @param fromMilliseconds
+ * the moment in time from which the next model `page-up` will be constructed.
+ * @param selectedMilliseconds
+ * the current value of the date/time picker
+ * @returns
+ * the model representing the next model `page-up` from the specified moment in time.
+ */
+ pageUp(fromMilliseconds: number, selectedMilliseconds: number): DlDateTimePickerModel;
+}
+
+ Copyright (c) 2013-present Dale Lotts
+Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of +the Software, and to permit persons to whom the Software is furnished to do so, +subject to the following conditions:
+The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS +FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR +COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER +IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN +CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ + + + + + + + + + + + + + + + + + + + + +