File

core/common/relative-time.pipe.ts

Metadata

Methods

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 :
                  A positive number indicates a future time relative to now, and a negative number indicates a past time.
                    If `false`, the output will include these based on whether the time is in the future or past.
               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
Parameters :
Name Type Optional Description
differenceMs number No
  • The time difference in milliseconds. A positive number indicates a future time relative to now, and a negative number indicates a past time.
noPrefixOrSuffix boolean No
  • 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 : 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 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.

Example :
           A positive number indicates a future time relative to now, and a negative number indicates a past time.
                    If `false`, the output will include these based on whether the time is in the future or past.
Parameters :
Name Type Optional Default value Description
input Date | number No
  • 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.
noPrefixOrSuffix No false
  • 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 : string

The formatted and translated time difference string.

results matching ""

    No results matching ""