ng-time-past-pipe
Version:
Reactive textual representation of the time that has been passed between a given date and now in your Angular App.
130 lines (123 loc) • 4.01 kB
TypeScript
import * as i0 from '@angular/core';
import { PipeTransform, OnDestroy, InjectionToken } from '@angular/core';
/**
* Accessor Input Type
*/
type TAInput = number | string | Date;
declare class TimePastPipe implements PipeTransform, OnDestroy {
private readonly changeDetectorRef;
private readonly ticker;
private readonly timeDiffGenerator;
private readonly updateIntervalGenerator;
private initialSeconds;
private lastInput;
private lastSeconds?;
private lastResult?;
private currentPeriod;
private readonly intervalTimer;
private readonly intervalSubscription;
/**
* Transform anything that can be parsed to a Date in the past, to a string that represent the relative
* time that has been passed between now and this point of time.
*
* @param value A value that can be parsed to a Date in the past or future
* @param overflow Overflow to time in past when initial date was in future
* @return The textual representation of the time that has been passed between the given Date
* and the current.
*/
transform<T extends TAInput>(value: T, overflow?: boolean): undefined | string | T;
/**
* Validate the Input Value and log a warning per value when it fails
*
* @param value
* @private
*/
private isValidInput;
/**
* Clear interval ticker subscription
*/
ngOnDestroy(): void;
static ɵfac: i0.ɵɵFactoryDeclaration<TimePastPipe, never>;
static ɵpipe: i0.ɵɵPipeDeclaration<TimePastPipe, "timePast", true>;
}
/**
* @deprecated Use TimePastPipe instead
*/
declare const NgTimePastPipePipe: typeof TimePastPipe;
/**
* Represents the Time Difference in the different time units
*
* @public
* @api
*/
interface TimeDiff {
seconds: number;
minutes: number;
hours: number;
months: number;
days: number;
years: number;
isFuture?: boolean;
}
/**
* Function Type for the `TimeDiffGenerator`
*
* @public
* @api
*/
type TimeDiffGenerator = (diff: TimeDiff) => string;
/**
* Custom `TimeDiffGenerator` Injection Token
*
* @public
* @api
*/
declare const CUSTOM_TIME_DIFF_GENERATOR: InjectionToken<TimeDiffGenerator>;
/**
* Return a respective textual representation of the input, as the input is a timespan that has been passed.
*
* @param diff The time diff object
* @public
* @api
*/
declare const defaultTimeDiffGenerator: TimeDiffGenerator;
/**
* Function Type for the `UpdateIntervalGenerator`
*
* @public
* @api
*/
type UpdateIntervalGenerator = (diff: TimeDiff) => number;
/**
* Custom `UpdateIntervalGenerator` Injection Token
*
* @public
* @api
*/
declare const CUSTOM_UPDATE_INTERVAL_GENERATOR: InjectionToken<UpdateIntervalGenerator>;
/**
* Determinate the point of time on when the output should be checked for a update
*
* @param diff The time diff object
* @return A point of time in future in seconds
* @public
* @api
*/
declare const defaultUpdateIntervalGenerator: UpdateIntervalGenerator;
declare class TimePastService {
private readonly timeDiffGenerator;
constructor(timeDiffGenerator: TimeDiffGenerator);
/**
* Transform anything that can be parsed to a Date in the past, to a string that represent the relative
* time that has been passed between now and this point of time.
*
* @param value A value that can be parsed to a Date in the past
* @return The textual representation of the time that has been passed between the given Date
* and the current.
*/
timePast(value: TAInput): undefined | string;
static ɵfac: i0.ɵɵFactoryDeclaration<TimePastService, [{ optional: true; }]>;
static ɵprov: i0.ɵɵInjectableDeclaration<TimePastService>;
}
export { CUSTOM_TIME_DIFF_GENERATOR, CUSTOM_UPDATE_INTERVAL_GENERATOR, NgTimePastPipePipe, TimePastPipe, TimePastService, defaultTimeDiffGenerator, defaultUpdateIntervalGenerator };
export type { TAInput, TimeDiff, TimeDiffGenerator, UpdateIntervalGenerator };