angular-bootstrap-datetimepicker
Version:
Native Angular (8+) datetime picker component styled by Twitter Bootstrap 4.
1,155 lines (1,115 loc) • 125 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('moment'), require('@angular/core'), require('@angular/forms'), require('@angular/common'), require('rxjs/operators')) :
typeof define === 'function' && define.amd ? define('angular-bootstrap-datetimepicker', ['exports', 'moment', '@angular/core', '@angular/forms', '@angular/common', 'rxjs/operators'], factory) :
(global = global || self, factory(global['angular-bootstrap-datetimepicker'] = {}, global.moment, global.ng.core, global.ng.forms, global.ng.common, global.rxjs.operators));
}(this, (function (exports, _moment, core, forms, common, operators) { 'use strict';
var _moment__default = 'default' in _moment ? _moment['default'] : _moment;
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
function __values(o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
/**
* Determines the model type of the Date/Time picker another type.
*/
var DlDateAdapter = /** @class */ (function () {
function DlDateAdapter() {
}
return DlDateAdapter;
}());
/**
* 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
**/
var moment = _moment;
/**
* Adapts `moment` to be usable as a date by date/time components that work with dates.
**/
var DlDateAdapterMoment = /** @class */ (function (_super) {
__extends(DlDateAdapterMoment, _super);
function DlDateAdapterMoment() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* 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.
*/
DlDateAdapterMoment.prototype.fromMilliseconds = function (milliseconds) {
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`
*/
DlDateAdapterMoment.prototype.toMilliseconds = function (value) {
return (value) ? value.valueOf() : undefined;
};
return DlDateAdapterMoment;
}(DlDateAdapter));
/**
* Adapts `Date` to be usable as a date by date/time components that work with dates.
**/
var DlDateAdapterNative = /** @class */ (function (_super) {
__extends(DlDateAdapterNative, _super);
function DlDateAdapterNative() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* 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.
*/
DlDateAdapterNative.prototype.fromMilliseconds = function (milliseconds) {
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`.
*/
DlDateAdapterNative.prototype.toMilliseconds = function (value) {
return (value) ? value.getTime() : undefined;
};
return DlDateAdapterNative;
}(DlDateAdapter));
/**
* Adapts `number` to be usable as a date by date/time components that work with dates.
* No op adapter.
**/
var DlDateAdapterNumber = /** @class */ (function (_super) {
__extends(DlDateAdapterNumber, _super);
function DlDateAdapterNumber() {
return _super !== null && _super.apply(this, arguments) || this;
}
/**
* Returns the specified number.
* @param milliseconds
* a moment time time.
* @returns
* the specified moment in time.
*/
DlDateAdapterNumber.prototype.fromMilliseconds = function (milliseconds) {
return milliseconds;
};
/**
* Returns the specified number.
* @param value
* a moment time time or `null`
* @returns
* the specified moment in time or `null`
*/
DlDateAdapterNumber.prototype.toMilliseconds = function (value) {
return value;
};
return DlDateAdapterNumber;
}(DlDateAdapter));
/**
* @internal
*/
var moment$1 = _moment;
/* istanbul ignore if */
if ('default' in _moment) {
moment$1 = _moment__default;
}
/**
* InjectionToken for string dates that can be used to override default model format.
**/
var DL_DATE_TIME_DISPLAY_FORMAT = new core.InjectionToken('DL_DATE_TIME_DISPLAY_FORMAT');
/**
* `Moment`'s long date format `lll` used as the default output format
* for string date's
*/
var DL_DATE_TIME_DISPLAY_FORMAT_DEFAULT = moment$1.localeData().longDateFormat('lll');
/**
* InjectionToken for string dates that can be used to override default input formats.
**/
var DL_DATE_TIME_INPUT_FORMATS = new core.InjectionToken('DL_DATE__TIME_INPUT_FORMATS');
/**
* Default input format's used by `DlDateAdapterString`
*/
var DL_DATE_TIME_INPUT_FORMATS_DEFAULT = [
'YYYY-MM-DDTHH:mm',
'YYYY-MM-DDTHH:mm:ss',
'YYYY-MM-DDTHH:mm:ss.SSS',
'YYYY-MM-DD',
'M/D/YYYY h:m:s A',
'M/D/YYYY h:m A',
'M/D/YYYY h:m A',
'M/D/YYYY',
'M/D/YY h:m:s A',
'M/D/YY h:m A',
'M/D/YY h A',
'M/D/YY',
DL_DATE_TIME_DISPLAY_FORMAT_DEFAULT,
moment$1.ISO_8601,
];
/**
* InjectionToken for string dates that can be used to override default model format.
**/
var DL_DATE_TIME_MODEL_FORMAT = new core.InjectionToken('DL_DATE_TIME_MODEL_FORMAT');
/**
* Default model format (ISO 8601)`
*/
var DL_DATE_TIME_MODEL_FORMAT_DEFAULT = 'YYYY-MM-DDTHH:mm:ss.SSSZ';
/**
* 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
*
**/
var moment$2 = _moment;
/**
* Adapts `string` to be usable as a date by date/time components that work with dates.
**/
var DlDateAdapterString = /** @class */ (function (_super) {
__extends(DlDateAdapterString, _super);
/**
* 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}
*/
function DlDateAdapterString(inputFormats, modelFormat) {
var _this = _super.call(this) || this;
_this.inputFormats = inputFormats;
_this.modelFormat = modelFormat;
return _this;
}
/**
* Returns the specified number.
* @param milliseconds
* a moment time time.
* @returns
* the specified moment in time.
*/
DlDateAdapterString.prototype.fromMilliseconds = function (milliseconds) {
return moment$2(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
*/
DlDateAdapterString.prototype.toMilliseconds = function (value) {
if (value !== undefined && value !== null) {
var newMoment = moment$2(value, this.inputFormats, true);
return newMoment.isValid() ? newMoment.valueOf() : undefined;
}
};
DlDateAdapterString = __decorate([
__param(0, core.Inject(DL_DATE_TIME_INPUT_FORMATS)),
__param(1, core.Inject(DL_DATE_TIME_MODEL_FORMAT))
], DlDateAdapterString);
return DlDateAdapterString;
}(DlDateAdapter));
var ɵ0 = DL_DATE_TIME_DISPLAY_FORMAT_DEFAULT, ɵ1 = DL_DATE_TIME_INPUT_FORMATS_DEFAULT, ɵ2 = DL_DATE_TIME_MODEL_FORMAT_DEFAULT;
/**
* Import this module to supply your own `DateAdapter` provider.
* @internal
**/
var DlDateTimeCoreModule = /** @class */ (function () {
function DlDateTimeCoreModule() {
}
DlDateTimeCoreModule = __decorate([
core.NgModule({
providers: [
{ provide: DL_DATE_TIME_DISPLAY_FORMAT, useValue: ɵ0 },
{ provide: DL_DATE_TIME_INPUT_FORMATS, useValue: ɵ1 },
{ provide: DL_DATE_TIME_MODEL_FORMAT, useValue: ɵ2 }
]
})
], DlDateTimeCoreModule);
return DlDateTimeCoreModule;
}());
/**
* Import this module to store `milliseconds` in the model.
* @internal
*/
var DlDateTimeNumberModule = /** @class */ (function () {
function DlDateTimeNumberModule() {
}
DlDateTimeNumberModule = __decorate([
core.NgModule({
imports: [DlDateTimeCoreModule],
providers: [
{ provide: DlDateAdapter, useClass: DlDateAdapterNumber }
],
exports: [DlDateTimeCoreModule]
})
], DlDateTimeNumberModule);
return DlDateTimeNumberModule;
}());
/**
* Import this module to store a native JavaScript `Date` in the model.
* @internal
*/
var DlDateTimeDateModule = /** @class */ (function () {
function DlDateTimeDateModule() {
}
DlDateTimeDateModule = __decorate([
core.NgModule({
imports: [DlDateTimeCoreModule],
providers: [
{ provide: DlDateAdapter, useClass: DlDateAdapterNative }
],
})
], DlDateTimeDateModule);
return DlDateTimeDateModule;
}());
/**
* Import this module to store a `moment` in the model.
* @internal
*/
var DlDateTimeMomentModule = /** @class */ (function () {
function DlDateTimeMomentModule() {
}
DlDateTimeMomentModule = __decorate([
core.NgModule({
imports: [DlDateTimeCoreModule],
providers: [
{ provide: DlDateAdapter, useClass: DlDateAdapterMoment }
],
})
], DlDateTimeMomentModule);
return DlDateTimeMomentModule;
}());
var ɵ3 = DL_DATE_TIME_INPUT_FORMATS_DEFAULT, ɵ4 = DL_DATE_TIME_DISPLAY_FORMAT_DEFAULT;
/**
* Import this module to store a `string` in the model.
* @internal
*/
var DlDateTimeStringModule = /** @class */ (function () {
function DlDateTimeStringModule() {
}
DlDateTimeStringModule = __decorate([
core.NgModule({
imports: [DlDateTimeCoreModule],
providers: [
{ provide: DL_DATE_TIME_INPUT_FORMATS, useValue: ɵ3 },
{ provide: DL_DATE_TIME_MODEL_FORMAT, useValue: ɵ4 },
{ provide: DlDateAdapter, useClass: DlDateAdapterString }
],
})
], DlDateTimeStringModule);
return DlDateTimeStringModule;
}());
/**
* @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
*/
/**
* @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
*/
/**
* Emitted when the value of a date/time input changes.
*/
var DlDateTimeInputChange = /** @class */ (function () {
/**
* Constructs a new instance.
* @param newValue
* the new value of the date/time picker.
*/
function DlDateTimeInputChange(newValue) {
this._value = newValue;
}
Object.defineProperty(DlDateTimeInputChange.prototype, "value", {
/**
* Get the new value of the date/time picker.
* @returns the new value or null.
*/
get: function () {
return this._value;
},
enumerable: true,
configurable: true
});
return DlDateTimeInputChange;
}());
/**
* @internal
*/
var moment$3 = _moment;
/**
* 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.
*/
var DlDateTimeInputDirective = /** @class */ (function () {
/**
* 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.
*/
function DlDateTimeInputDirective(_renderer, _elementRef, _dateAdapter, _displayFormat, _inputFormats) {
var _this = this;
this._renderer = _renderer;
this._elementRef = _elementRef;
this._dateAdapter = _dateAdapter;
this._displayFormat = _displayFormat;
this._inputFormats = _inputFormats;
/* tslint:disable:member-ordering */
this._filterValidator = function (control) {
// @ts-ignore
return (_this._inputFilter || (function () { return true; }))(_this._value) ?
null : { 'dlDateTimeInputFilter': { 'value': control.value } };
};
this._inputFilter = function () { return true; };
this._isValid = true;
this._parseValidator = function () {
return _this._isValid ?
null : { 'dlDateTimeInputParse': { 'text': _this._elementRef.nativeElement.value } };
};
this._changed = [];
this._touched = [];
this._validator = forms.Validators.compose([this._parseValidator, this._filterValidator]);
this._onValidatorChange = function () { };
this._value = undefined;
/**
* Emits when a `change` event when date/time is selected or
* the value of the date/time picker changes.
**/
this.dateChange = new core.EventEmitter();
}
DlDateTimeInputDirective_1 = DlDateTimeInputDirective;
Object.defineProperty(DlDateTimeInputDirective.prototype, "dlDateTimeInputFilter", {
/**
* 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`.
*/
set: function (inputFilterFunction) {
this._inputFilter = inputFilterFunction || (function () { return true; });
this._onValidatorChange();
},
enumerable: true,
configurable: true
});
Object.defineProperty(DlDateTimeInputDirective.prototype, "value", {
/* tslint:enable:member-ordering */
/**
* Returns `D` value of the date/time input or `undefined` | `null` if no value is set.
**/
get: function () {
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: function (newValue) {
var _this = this;
if (newValue !== this._value) {
this._value = newValue;
this._changed.forEach(function (onChanged) { return onChanged(_this._value); });
}
},
enumerable: true,
configurable: true
});
/**
* Emit a `change` event when the value of the input changes.
*/
DlDateTimeInputDirective.prototype._onChange = function () {
this.dateChange.emit(new DlDateTimeInputChange(this._value));
};
/**
* Format the input text using {@link DL_DATE_TIME_DISPLAY_FORMAT} and mark the control as touched.
*/
DlDateTimeInputDirective.prototype._onBlur = function () {
if (this._value) {
this._setElementValue(this._value);
}
this._touched.forEach(function (onTouched) { return 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.
*/
DlDateTimeInputDirective.prototype._onInput = function (value) {
var testDate = value === null || value === undefined || value === ''
? undefined
: moment$3(value, this._inputFormats, true);
this._isValid = testDate && testDate.isValid();
this.value = this._isValid ? this._dateAdapter.fromMilliseconds(testDate.valueOf()) : undefined;
};
/**
* @internal
*/
DlDateTimeInputDirective.prototype._setElementValue = function (value) {
if (value !== null && value !== undefined) {
this._renderer.setProperty(this._elementRef.nativeElement, 'value', moment$3(value).format(this._displayFormat));
}
};
/**
* @internal
*/
DlDateTimeInputDirective.prototype.registerOnChange = function (onChange) {
this._changed.push(onChange);
};
/**
* @internal
*/
DlDateTimeInputDirective.prototype.registerOnTouched = function (onTouched) {
this._touched.push(onTouched);
};
/**
* @internal
*/
DlDateTimeInputDirective.prototype.registerOnValidatorChange = function (validatorOnChange) {
this._onValidatorChange = validatorOnChange;
};
/**
* @internal
*/
DlDateTimeInputDirective.prototype.setDisabledState = function (isDisabled) {
this._renderer.setProperty(this._elementRef.nativeElement, 'disabled', isDisabled);
};
/**
* @internal
*/
DlDateTimeInputDirective.prototype.validate = function (control) {
return this._validator(control);
};
/**
* @internal
*/
DlDateTimeInputDirective.prototype.writeValue = function (value) {
this._isValid = true;
this.value = value;
this._setElementValue(value);
};
var DlDateTimeInputDirective_1;
DlDateTimeInputDirective.ctorParameters = function () { return [
{ type: core.Renderer2 },
{ type: core.ElementRef },
{ type: DlDateAdapter },
{ type: String, decorators: [{ type: core.Inject, args: [DL_DATE_TIME_DISPLAY_FORMAT,] }] },
{ type: Array, decorators: [{ type: core.Inject, args: [DL_DATE_TIME_INPUT_FORMATS,] }] }
]; };
__decorate([
core.Output()
], DlDateTimeInputDirective.prototype, "dateChange", void 0);
__decorate([
core.Input()
], DlDateTimeInputDirective.prototype, "dlDateTimeInputFilter", null);
__decorate([
core.HostListener('change')
], DlDateTimeInputDirective.prototype, "_onChange", null);
__decorate([
core.HostListener('blur')
], DlDateTimeInputDirective.prototype, "_onBlur", null);
__decorate([
core.HostListener('input', ['$event.target.value'])
], DlDateTimeInputDirective.prototype, "_onInput", null);
DlDateTimeInputDirective = DlDateTimeInputDirective_1 = __decorate([
core.Directive({
selector: 'input[dlDateTimeInput]',
providers: [
{ provide: forms.NG_VALUE_ACCESSOR, useExisting: DlDateTimeInputDirective_1, multi: true },
{ provide: forms.NG_VALIDATORS, useExisting: DlDateTimeInputDirective_1, multi: true }
]
}),
__param(3, core.Inject(DL_DATE_TIME_DISPLAY_FORMAT)),
__param(4, core.Inject(DL_DATE_TIME_INPUT_FORMATS))
], DlDateTimeInputDirective);
return DlDateTimeInputDirective;
}());
/**
* @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 this module to allow date/time input.
* @internal
**/
var DlDateTimeInputModule = /** @class */ (function () {
function DlDateTimeInputModule() {
}
DlDateTimeInputModule = __decorate([
core.NgModule({
declarations: [DlDateTimeInputDirective],
imports: [common.CommonModule],
exports: [DlDateTimeInputDirective],
})
], DlDateTimeInputModule);
return DlDateTimeInputModule;
}());
/**
* @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
*/
/**
* @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
*/
/**
* Emitted when the value of a date/time picker changes.
*/
var DlDateTimePickerChange = /** @class */ (function () {
/**
* Constructs a new instance.
* @param newValue
* the new value of the date/time picker.
*/
function DlDateTimePickerChange(newValue) {
this._value = newValue;
}
Object.defineProperty(DlDateTimePickerChange.prototype, "value", {
/**
* Get the new value of the date/time picker.
* @returns the new value or null.
*/
get: function () {
return this._value;
},
enumerable: true,
configurable: true
});
return DlDateTimePickerChange;
}());
/**
* @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
*/
/**
* 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
**/
var moment$4 = _moment;
/**
* Default implementation for the `day` view.
*/
var DlDayModelProvider = /** @class */ (function () {
function DlDayModelProvider() {
}
/**
* Receives input changes detected by Angular.
*
* @param changes
* the input changes detected by Angular.
*/
DlDayModelProvider.prototype.onChanges = function (
// @ts-ignore
changes) { };
/**
* 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.
*/
DlDayModelProvider.prototype.getModel = function (milliseconds, selectedMilliseconds) {
var startOfMonth = moment$4(milliseconds).startOf('month');
var endOfMonth = moment$4(milliseconds).endOf('month');
var startOfView = moment$4(startOfMonth).subtract(Math.abs(startOfMonth.weekday()), 'days');
var rowNumbers = [0, 1, 2, 3, 4, 5];
var columnNumbers = [0, 1, 2, 3, 4, 5, 6];
var previousMonth = moment$4(startOfMonth).subtract(1, 'month');
var nextMonth = moment$4(startOfMonth).add(1, 'month');
var activeValue = moment$4(milliseconds).startOf('day').valueOf();
var selectedValue = selectedMilliseconds === null || selectedMilliseconds === undefined
? selectedMilliseconds
: moment$4(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(function (column) { return moment$4().weekday(column).format('dd'); }),
rows: rowNumbers.map(rowOfDays)
};
function rowOfDays(rowNumber) {
var currentMoment = moment$4();
var cells = columnNumbers.map(function (columnNumber) {
var dayMoment = moment$4(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: 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.
*/
DlDayModelProvider.prototype.goDown = function (fromMilliseconds, selectedMilliseconds) {
return this.getModel(moment$4(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.
*/
DlDayModelProvider.prototype.goUp = function (fromMilliseconds, selectedMilliseconds) {
return this.getModel(moment$4(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.
*/
DlDayModelProvider.prototype.goLeft = function (fromMilliseconds, selectedMilliseconds) {
return this.getModel(moment$4(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.
*/
DlDayModelProvider.prototype.goRight = function (fromMilliseconds, selectedMilliseconds) {
return this.getModel(moment$4(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.
*/
DlDayModelProvider.prototype.pageDown = function (fromMilliseconds, selectedMilliseconds) {
return this.getModel(moment$4(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.
*/
DlDayModelProvider.prototype.pageUp = function (fromMilliseconds, selectedMilliseconds) {
return this.getModel(moment$4(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`.
*/
DlDayModelProvider.prototype.goEnd = function (fromMilliseconds, selectedMilliseconds) {
return this.getModel(moment$4(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`.
*/
DlDayModelProvider.prototype.goHome = function (fromMilliseconds, selectedMilliseconds) {
return this.getModel(moment$4(fromMilliseconds).startOf('month').valueOf(), selectedMilliseconds);
};
return DlDayModelProvider;
}());
/**
* @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
*/
/**
* 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
**/
var moment$5 = _moment;
/**
* Default implementation for the `hour` view.
*/
var DlHourModelProvider = /** @class */ (function () {
function DlHourModelProvider() {
}
/**
* Receives input changes detected by Angular.
*
* @param changes
* the input changes detected by Angular.
*/
DlHourModelProvider.prototype.onChanges = function (
// @ts-ignore
changes) { };
/**
* 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.
*/
DlHourModelProvider.prototype.getModel = function (milliseconds, selectedMilliseconds) {
var startDate = moment$5(milliseconds).startOf('day');
var rowNumbers = [0, 1, 2, 3, 4, 5];
var columnNumbers = [0, 1, 2, 3];
var previousDay = moment$5(startDate).subtract(1, 'day');
var nextDay = moment$5(startDate).add(1, 'day');
var activeValue = moment$5(milliseconds).startOf('hour').valueOf();
var selectedValue = selectedMilliseconds === null || selectedMilliseconds === undefined
? selectedMilliseconds
: moment$5(selectedMilliseconds).startOf('hour').valueOf();
return