@c8y/ngx-components
Version:
Angular modules for Cumulocity IoT applications
64 lines • 3.73 kB
TypeScript
import { PipeTransform } from '@angular/core';
import { TranslateService } from '@ngx-translate/core';
import * as i0 from "@angular/core";
export declare const NULL_VALUE_PLACEHOLDER = "--";
export declare class RelativeTimePipe implements PipeTransform {
private translateService;
constructor(translateService: TranslateService);
/**
* Transforms the given input into a formatted time difference string.
*
* This method calculates the time difference between the current date and the input.
* If the input is a `Date` object, the difference in milliseconds is calculated from the current date.
* If the input is a number, it is treated as the difference in milliseconds.
*
* The method returns a string representing the time difference, optionally prefixed with
* "in " for future dates or suffixed with " ago" for past dates, based on the `noPrefixOrSuffix` flag.
*
* @param input - The date or the time difference in milliseconds to be transformed.
* A positive number indicates a future time relative to now, and a negative number indicates a past time.
* @param noPrefixOrSuffix - If `true`, the output will not include "in" or "ago" prefixes/suffixes.
* If `false`, the output will include these based on whether the time is in the future or past.
* @returns The formatted and translated time difference string.
*/
transform(input: Date | number, noPrefixOrSuffix?: boolean): string;
/**
* Calculates a human-readable representation of a time difference.
*
* Time ranges are same as moment.js timeFromNow function counterpart:
* https://momentjscom.readthedocs.io/en/latest/moment/04-displaying/02-fromnow/
*
* @param differenceMs - The time difference in milliseconds.
* A positive number indicates a future time relative to now, and a negative number indicates a past time.
* @param noPrefixOrSuffix - If `true`, the output will not include "in" or "ago" prefixes/suffixes.
* If `false`, the output will include these based on whether the time is in the future or past.
* @returns A string representing the time difference in a human-readable format.
* The format depends on the duration of the difference:
* - Less than 45 seconds: returns 'a few seconds'
* - 45 to 89 seconds: returns 'a minute'
* - 90 seconds to 44 minutes: returns the number of minutes
* - 45 to 89 minutes: returns 'an hour'
* - 90 minutes to 21 hours: returns the number of hours
* - 22 to 35 hours: returns 'a day'
* - 36 hours to 25 days: returns the number of days
* - 26 to 45 days: returns 'a month'
* - 45 to 319 days: returns the number of months
* - 320 days to 1.5 years: returns 'a year'
* - More than 1.5 years: returns the number of years
*/
getHumanReadableTimeDiffString(differenceMs: number, noPrefixOrSuffix: boolean): string;
private withinFewSeconds;
private withinMinute;
private withinMinutes;
private withinHour;
private withinHours;
private withinDay;
private withinDays;
private withinMonth;
private withinMonths;
private withinYear;
private withinYears;
static ɵfac: i0.ɵɵFactoryDeclaration<RelativeTimePipe, never>;
static ɵpipe: i0.ɵɵPipeDeclaration<RelativeTimePipe, "relativeTime", true>;
}
//# sourceMappingURL=relative-time.pipe.d.ts.map