Skip to content

Commit

Permalink
fix: loosen input date type
Browse files Browse the repository at this point in the history
  • Loading branch information
ihym committed Feb 3, 2020
1 parent ed9fd1b commit 0fd67e6
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 27 deletions.
4 changes: 2 additions & 2 deletions lib/src/timeago.clock.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import { Injectable } from '@angular/core';
import { Observable, of, empty, timer } from 'rxjs';
import { expand, skip } from 'rxjs/operators';
import { MINUTE, HOUR, DAY, WEEK, MONTH, YEAR } from './util';
import { MINUTE, HOUR, DAY } from './util';

export abstract class TimeagoClock {
abstract tick(then: number): Observable<any>;
}

@Injectable()
export class TimeagoDefaultClock extends TimeagoClock {
tick(then: number): Observable<number> {
tick(then: number): Observable<any> {
return of(0)
.pipe(
expand(() => {
Expand Down
17 changes: 4 additions & 13 deletions lib/src/timeago.directive.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,4 @@
import {
Directive,
Input,
ElementRef,
Optional,
SimpleChanges,
OnChanges,
OnDestroy,
ChangeDetectorRef
} from '@angular/core';
import { Directive, Input, ElementRef, Optional, OnChanges, OnDestroy, ChangeDetectorRef } from '@angular/core';
import { Subscription, Subject } from 'rxjs';
import { filter } from 'rxjs/operators';
import { TimeagoClock } from './timeago.clock';
Expand All @@ -33,10 +24,10 @@ export class TimeagoDirective implements OnChanges, OnDestroy {

/** The Date to display. An actual Date object or something that can be fed to new Date. */
@Input()
get date(): number {
get date(): any {
return this._date;
}
set date(date: number) {
set date(date: any) {
this._date = dateParser(date).valueOf();
if (this._date) {
if (this.clockSubscription) {
Expand Down Expand Up @@ -76,7 +67,7 @@ export class TimeagoDirective implements OnChanges, OnDestroy {
});
}

ngOnChanges(changes: SimpleChanges) {
ngOnChanges() {
this.stateChanges.next();
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/timeago.formatter.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Injectable, Optional } from '@angular/core';
import { Injectable } from '@angular/core';
import { TimeagoIntl } from './timeago.intl';
import { MINUTE, HOUR, DAY, WEEK, MONTH, YEAR } from './util';

Expand Down
1 change: 0 additions & 1 deletion lib/src/timeago.module.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { NgModule, ModuleWithProviders, Provider } from '@angular/core';
import { TimeagoDirective } from './timeago.directive';
import { TimeagoPipe } from './timeago.pipe';
import { TimeagoIntl } from './timeago.intl';
import { TimeagoClock, TimeagoDefaultClock } from './timeago.clock';
import { TimeagoFormatter, TimeagoDefaultFormatter } from './timeago.formatter';

Expand Down
13 changes: 3 additions & 10 deletions lib/src/timeago.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
import {
Injectable,
OnDestroy,
Pipe,
PipeTransform,
Optional,
ChangeDetectorRef
} from '@angular/core';
import { Injectable, OnDestroy, Pipe, PipeTransform, Optional, ChangeDetectorRef } from '@angular/core';
import { Subscription, Subject } from 'rxjs';
import { TimeagoClock } from './timeago.clock';
import { TimeagoFormatter } from './timeago.formatter';
Expand Down Expand Up @@ -36,7 +29,7 @@ export class TimeagoPipe implements PipeTransform, OnDestroy {

constructor(@Optional() intl: TimeagoIntl,
cd: ChangeDetectorRef,
private formatter: TimeagoFormatter,
formatter: TimeagoFormatter,
private clock: TimeagoClock) {
if (intl) {
this.intlSubscription = intl.changes.subscribe(() => this.stateChanges.next());
Expand All @@ -47,7 +40,7 @@ export class TimeagoPipe implements PipeTransform, OnDestroy {
});
}

transform(date: number, ...args: any[]) {
transform(date: any, ...args: any[]) {
const _date = dateParser(date).valueOf();
let _live: boolean;

Expand Down

0 comments on commit 0fd67e6

Please sign in to comment.