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AAE,cAAY,CAAC,CAAC;gBACnB,CAAC,CAAC,CAAC;YACL,CAAC;QACH,CAAC;IACH,CAAC;IAEc,wBAAW,GAA1B;QACE,EAAE,CAAC,CAAC,cAAY,CAAC,KAAK,CAAC,CAAC,CAAC;YACvB,MAAM,CAAC,YAAY,CAAC,cAAY,CAAC,KAAK,CAAC,CAAC;YACxC,cAAY,CAAC,KAAK,GAAG,IAAI,CAAC;YAC1B,cAAY,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC/B,CAAC;IACH,CAAC;IAEc,wCAA2B,GAA1C;QACE,IAAI,GAAG,GAAG,iBAAiB,EAAE,CAAC;QAC9B,IAAI,QAAQ,GAAG,iBAAiB,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;QACjE,IAAI,cAAc,GAAG,QAAQ,CAAC,OAAO,EAAE,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;QACxD,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,CAAC,0BAA0B;IAC1D,CAAC;IAtFD;;;OAGG;IACY,iBAAI,GAAW,CAAC,CAAC;IANrB,YAAY;QADxB,WAAI,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;yCAcb,wBAAiB,EAAkB,aAAM;OAbzD,YAAY,CAyFxB;IAAD,mBAAC;;CAAA,AAzFD,IAyFC;AAzFY,oCAAY","sourcesContent":["/* angular2-moment (c) 2015, 2016 Uri Shaked / MIT Licence */\r\n\r\nimport { Pipe, ChangeDetectorRef, PipeTransform, EventEmitter, OnDestroy, NgZone } from '@angular/core';\r\nimport * as moment from 'moment';\r\nimport { Subscription } from 'rxjs/Subscription';\r\n\r\n// under systemjs, moment is actually exported as the default export, so we account for that\r\nconst momentConstructor: (value?: any) => moment.Moment = (<any>moment).default || moment;\r\n\r\n@Pipe({ name: 'amCalendar', pure: false })\r\nexport class CalendarPipe implements PipeTransform, OnDestroy {\r\n\r\n /**\r\n * @private Internal reference counter, so we can clean up when no instances are in use\r\n * @type {number}\r\n */\r\n private static refs: number = 0;\r\n\r\n private static timer: number;\r\n private static midnight: EventEmitter<Date>;\r\n\r\n private midnightSub: Subscription;\r\n\r\n constructor(private cdRef: ChangeDetectorRef, private ngZone: NgZone) {\r\n // using a single static timer for all instances of this pipe for performance reasons\r\n CalendarPipe.initTimer(ngZone);\r\n\r\n CalendarPipe.refs++;\r\n\r\n // values such as Today will need to be replaced with Yesterday after midnight,\r\n // so make sure we subscribe to an EventEmitter that we set up to emit at midnight\r\n this.midnightSub = CalendarPipe.midnight.subscribe(() => {\r\n this.ngZone.run(() => this.cdRef.markForCheck());\r\n });\r\n }\r\n\r\n transform(value: Date | moment.Moment, ...args: any[]): any {\r\n let formats: any = null;\r\n let referenceTime: any = null;\r\n\r\n for (let i = 0, len = args.length; i < len; i++) {\r\n if (args[i] !== null) {\r\n if (typeof args[i] === 'object' && !moment.isMoment(args[i])) {\r\n formats = args[i];\r\n } else {\r\n referenceTime = momentConstructor(args[i]);\r\n }\r\n }\r\n }\r\n\r\n return momentConstructor(value).calendar(referenceTime, formats);\r\n }\r\n\r\n ngOnDestroy(): void {\r\n if (CalendarPipe.refs > 0) {\r\n CalendarPipe.refs--;\r\n }\r\n\r\n if (CalendarPipe.refs === 0) {\r\n CalendarPipe.removeTimer();\r\n }\r\n\r\n this.midnightSub.unsubscribe();\r\n }\r\n\r\n private static initTimer(ngZone: NgZone) {\r\n // initialize the timer\r\n if (!CalendarPipe.midnight) {\r\n CalendarPipe.midnight = new EventEmitter<Date>();\r\n if (typeof window !== 'undefined') {\r\n let timeToUpdate = CalendarPipe._getMillisecondsUntilUpdate();\r\n CalendarPipe.timer = ngZone.runOutsideAngular(() => {\r\n return window.setTimeout(() => {\r\n // emit the current date\r\n CalendarPipe.midnight.emit(new Date());\r\n\r\n // refresh the timer\r\n CalendarPipe.removeTimer();\r\n CalendarPipe.initTimer(ngZone);\r\n }, timeToUpdate);\r\n });\r\n }\r\n }\r\n }\r\n\r\n private static removeTimer() {\r\n if (CalendarPipe.timer) {\r\n window.clearTimeout(CalendarPipe.timer);\r\n CalendarPipe.timer = null;\r\n CalendarPipe.midnight = null;\r\n }\r\n }\r\n\r\n private static _getMillisecondsUntilUpdate() {\r\n var now = momentConstructor();\r\n var tomorrow = momentConstructor().startOf('day').add(1, 'days');\r\n var timeToMidnight = tomorrow.valueOf() - now.valueOf();\r\n return timeToMidnight + 1000; // 1 second after midnight\r\n }\r\n}\r\n\ninterface DecoratorInvocation {\n type: Function;\n args?: any[];\n}\n"]} |