UNPKG

ng-pick-datetime

Version:
80 lines (79 loc) 2.59 kB
import { Subject } from 'rxjs'; import { inject, InjectionToken, LOCALE_ID } from '@angular/core'; export var OWL_DATE_TIME_LOCALE = new InjectionToken('OWL_DATE_TIME_LOCALE', { providedIn: 'root', factory: OWL_DATE_TIME_LOCALE_FACTORY, }); export function OWL_DATE_TIME_LOCALE_FACTORY() { return inject(LOCALE_ID); } export var OWL_DATE_TIME_LOCALE_PROVIDER = { provide: OWL_DATE_TIME_LOCALE, useExisting: LOCALE_ID }; var DateTimeAdapter = (function () { function DateTimeAdapter() { this._localeChanges = new Subject(); this.millisecondsInDay = 86400000; this.milliseondsInMinute = 60000; } Object.defineProperty(DateTimeAdapter.prototype, "localeChanges", { get: function () { return this._localeChanges; }, enumerable: true, configurable: true }); DateTimeAdapter.prototype.compare = function (first, second) { if (!this.isValid(first) || !this.isValid(second)) { throw Error('JSNativeDate: Cannot compare invalid dates.'); } var dateFirst = this.clone(first); var dateSecond = this.clone(second); var diff = this.getTime(dateFirst) - this.getTime(dateSecond); if (diff < 0) { return -1; } else if (diff > 0) { return 1; } else { return diff; } }; DateTimeAdapter.prototype.compareYear = function (first, second) { if (!this.isValid(first) || !this.isValid(second)) { throw Error('JSNativeDate: Cannot compare invalid dates.'); } var yearLeft = this.getYear(first); var yearRight = this.getYear(second); var diff = yearLeft - yearRight; if (diff < 0) { return -1; } else if (diff > 0) { return 1; } else { return 0; } }; DateTimeAdapter.prototype.deserialize = function (value) { if (value == null || this.isDateInstance(value) && this.isValid(value)) { return value; } return this.invalid(); }; DateTimeAdapter.prototype.setLocale = function (locale) { this.locale = locale; this._localeChanges.next(); }; DateTimeAdapter.prototype.clampDate = function (date, min, max) { if (min && this.compare(date, min) < 0) { return min; } if (max && this.compare(date, max) > 0) { return max; } return date; }; return DateTimeAdapter; }()); export { DateTimeAdapter };