core/common/relative-time.pipe.ts
Name | relativeTime |
Standalone | true |
getHumanReadableTimeDiffString | ||||||||||||
getHumanReadableTimeDiffString(differenceMs: number, noPrefixOrSuffix: boolean)
|
||||||||||||
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/ Example :
Parameters :
Returns :
string
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 |
transform | |||||||||||||||
transform(input: Date | number, noPrefixOrSuffix)
|
|||||||||||||||
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 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
Parameters :
Returns :
string
The formatted and translated time difference string. |