Class: FuzzyTime

FuzzyTime

new FuzzyTime()

Constructs a new FuzzyTime instance.

Author:
  • Robert Bost <bostrt at gmail dot com>
License:
  • MIT
Source:

Members

<static, readonly> Unit :number

Enumeration of time units supported by FuzzyTimeJS.

Type:
  • number
Properties:
Name Type Default Description
YEAR number 6
MONTH number 5
WEEK number 4
DAY number 3
HOUR number 2
MINUTE number 1
SECOND number 0
Source:

Methods

after(format, delta)

Configures this FuzzyTime instance to return the given string format (with values plugged in) any time that FuzzyTime#build is called and after the given time delta has passed

Parameters:
Name Type Description
format string

The string format

delta string | list

The time delta at which to display. This can be either an ISO 8601 Duration (string) or a list of maps like:

[
  {time: 1, unit: FuzzyTime.Unit.MINUTE},
  {time: 30, unit: FuzzyTime.Unit.SECOND},
  ...
]
Source:

at(format, delta)

Configure this FuzzyTime to return the given string format (with values plugged in) when FuzzyTime#build is called and the given time delta has been reached.

Parameters:
Name Type Description
format string

The string format

delta string | list

The time delta at which to display. This can be either an ISO 8601 Duration (string) or a list of maps like:

[
  {time: 1, unit: FuzzyTime.Unit.MINUTE},
  {time: 30, unit: FuzzyTime.Unit.SECOND},
  ...
]
Source:

before(format, delta)

Configures this FuzzyTime instance to return the given string format (with values plugged in) any time FuzzyTime#build is called and before the given time delta has passed.

Parameters:
Name Type Description
format string

The string format

delta string | list

The time delta at which to display. This can be either an ISO 8601 Duration (string) or a list of maps like:

[
  {time: 1, unit: FuzzyTime.Unit.MINUTE},
  {time: 30, unit: FuzzyTime.Unit.SECOND},
  ...
]
Source:

build(date, referenceDate) → {string}

Build a "fuzzy" interpretation of the difference between the provided dates based on previous configurations (using FuzzyTime#at, FuzzyTime#before, and FuzzyTime#after).

Parameters:
Name Type Argument Description
date date

The starting date

referenceDate date <optional>

The ending date. If nothing is provided for this parameter, it defaults to now (i.e. new Date()).

Source:
Returns:

The "fuzzy" timestamp for the differene between the two provided dates (if only one date is provided, now is used for second date). If there is no "at", "before", or "after" configuration that applies to the difference between the dates provided, the locale string of the date parameter is provided.

Type
string