UNPKG

@angular/material-moment-adapter

Version:
10 lines (9 loc) 5.25 kB
/** * @license * Copyright Google LLC All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://angular.io/license */ !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/core"),require("@angular/material/core"),require("moment")):"function"==typeof define&&define.amd?define("@angular/material-moment-adapter",["exports","@angular/core","@angular/material/core","moment"],e):e((t.ng=t.ng||{},t.ng.materialMomentAdapter={}),t.ng.core,t.ng.material.core,t.moment)}(this,function(t,e,o,r){"use strict";function n(t,e){function o(){this.constructor=t}l(t,e),t.prototype=null===e?Object.create(e):(o.prototype=e.prototype,new o)}function a(){return{useUtc:!1}}function i(t,e){for(var o=Array(t),r=0;r<t;r++)o[r]=e(r);return o}var s=r.default,l=function(t,e){return(l=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var o in e)e.hasOwnProperty(o)&&(t[o]=e[o])})(t,e)},c=s||r,p=new e.InjectionToken("MAT_MOMENT_DATE_ADAPTER_OPTIONS",{providedIn:"root",factory:a}),u=function(t){function r(e,o){var r=t.call(this)||this;return r._options=o,r.setLocale(e||c.locale()),r}return n(r,t),r.prototype.setLocale=function(e){var o=this;t.prototype.setLocale.call(this,e);var r=c.localeData(e);this._localeData={firstDayOfWeek:r.firstDayOfWeek(),longMonths:r.months(),shortMonths:r.monthsShort(),dates:i(31,function(t){return o.createDate(2017,0,t+1).format("D")}),longDaysOfWeek:r.weekdays(),shortDaysOfWeek:r.weekdaysShort(),narrowDaysOfWeek:r.weekdaysMin()}},r.prototype.getYear=function(t){return this.clone(t).year()},r.prototype.getMonth=function(t){return this.clone(t).month()},r.prototype.getDate=function(t){return this.clone(t).date()},r.prototype.getDayOfWeek=function(t){return this.clone(t).day()},r.prototype.getMonthNames=function(t){return"long"==t?this._localeData.longMonths:this._localeData.shortMonths},r.prototype.getDateNames=function(){return this._localeData.dates},r.prototype.getDayOfWeekNames=function(t){return"long"==t?this._localeData.longDaysOfWeek:"short"==t?this._localeData.shortDaysOfWeek:this._localeData.narrowDaysOfWeek},r.prototype.getYearName=function(t){return this.clone(t).format("YYYY")},r.prototype.getFirstDayOfWeek=function(){return this._localeData.firstDayOfWeek},r.prototype.getNumDaysInMonth=function(t){return this.clone(t).daysInMonth()},r.prototype.clone=function(t){return t.clone().locale(this.locale)},r.prototype.createDate=function(t,e,o){if(e<0||e>11)throw Error('Invalid month index "'+e+'". Month index has to be between 0 and 11.');if(o<1)throw Error('Invalid date "'+o+'". Date has to be greater than 0.');var r=this._createMoment({year:t,month:e,date:o}).locale(this.locale);if(!r.isValid())throw Error('Invalid date "'+o+'" for month with index "'+e+'".');return r},r.prototype.today=function(){return this._createMoment().locale(this.locale)},r.prototype.parse=function(t,e){return t&&"string"==typeof t?this._createMoment(t,e,this.locale):t?this._createMoment(t).locale(this.locale):null},r.prototype.format=function(t,e){if(t=this.clone(t),!this.isValid(t))throw Error("MomentDateAdapter: Cannot format invalid date.");return t.format(e)},r.prototype.addCalendarYears=function(t,e){return this.clone(t).add({years:e})},r.prototype.addCalendarMonths=function(t,e){return this.clone(t).add({months:e})},r.prototype.addCalendarDays=function(t,e){return this.clone(t).add({days:e})},r.prototype.toIso8601=function(t){return this.clone(t).format()},r.prototype.deserialize=function(e){var o;if(e instanceof Date)o=this._createMoment(e).locale(this.locale);else if(this.isDateInstance(e))return this.clone(e);if("string"==typeof e){if(!e)return null;o=this._createMoment(e,c.ISO_8601).locale(this.locale)}return o&&this.isValid(o)?this._createMoment(o).locale(this.locale):t.prototype.deserialize.call(this,e)},r.prototype.isDateInstance=function(t){return c.isMoment(t)},r.prototype.isValid=function(t){return this.clone(t).isValid()},r.prototype.invalid=function(){return c.invalid()},r.prototype._createMoment=function(){for(var t=[],e=0;e<arguments.length;e++)t[e]=arguments[e];return this._options&&this._options.useUtc?c.utc.apply(c,t):c.apply(void 0,t)},r.decorators=[{type:e.Injectable}],r.ctorParameters=function(){return[{type:String,decorators:[{type:e.Optional},{type:e.Inject,args:[o.MAT_DATE_LOCALE]}]},{type:void 0,decorators:[{type:e.Optional},{type:e.Inject,args:[p]}]}]},r}(o.DateAdapter),f={parse:{dateInput:"l"},display:{dateInput:"l",monthYearLabel:"MMM YYYY",dateA11yLabel:"LL",monthYearA11yLabel:"MMMM YYYY"}},d=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{providers:[{provide:o.DateAdapter,useClass:u,deps:[o.MAT_DATE_LOCALE,p]}]}]}],t}(),h=f,y=function(){function t(){}return t.decorators=[{type:e.NgModule,args:[{imports:[d],providers:[{provide:o.MAT_DATE_FORMATS,useValue:h}]}]}],t}();t.MomentDateModule=d,t.MatMomentDateModule=y,t.MAT_MOMENT_DATE_ADAPTER_OPTIONS_FACTORY=a,t.MAT_MOMENT_DATE_ADAPTER_OPTIONS=p,t.MomentDateAdapter=u,t.MAT_MOMENT_DATE_FORMATS=f,Object.defineProperty(t,"__esModule",{value:!0})}); //# sourceMappingURL=material-moment-adapter.umd.min.js.map