ORE Studio 0.0.4
Loading...
Searching...
No Matches
Public Member Functions | List of all members
relative_time_formatter Class Referencefinal

Formats time points as relative time strings. More...

#include <relative_time_formatter.hpp>

Collaboration diagram for relative_time_formatter:
Collaboration graph

Public Member Functions

 relative_time_formatter (numeric_style style=numeric_style::automatic)
 Constructs a formatter with the specified numeric style.
 
std::string format (const std::chrono::system_clock::time_point &tp) const
 Formats a time point relative to now.
 
std::string format (const std::chrono::system_clock::time_point &tp, const std::chrono::system_clock::time_point &reference) const
 Formats a time point relative to a reference time.
 
std::string format (long long value, time_unit unit) const
 Formats a numeric value and unit as a relative time string.
 

Detailed Description

Formats time points as relative time strings.

Inspired by ECMAScript Intl.RelativeTimeFormat, this class provides human-readable relative time strings like "just now", "5 minutes ago", "in 3 days", etc.

See also
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/RelativeTimeFormat

Constructor & Destructor Documentation

◆ relative_time_formatter()

relative_time_formatter ( numeric_style  style = numeric_style::automatic)
explicit

Constructs a formatter with the specified numeric style.

Parameters
styleThe numeric style to use for formatting.

Member Function Documentation

◆ format() [1/3]

std::string format ( const std::chrono::system_clock::time_point &  tp) const

Formats a time point relative to now.

Parameters
tpThe time point to format.
Returns
Human-readable relative time string.
Here is the caller graph for this function:

◆ format() [2/3]

std::string format ( const std::chrono::system_clock::time_point &  tp,
const std::chrono::system_clock::time_point &  reference 
) const

Formats a time point relative to a reference time.

Parameters
tpThe time point to format.
referenceThe reference time point to compare against.
Returns
Human-readable relative time string.

◆ format() [3/3]

std::string format ( long long  value,
time_unit  unit 
) const

Formats a numeric value and unit as a relative time string.

Based on ECMAScript Intl.RelativeTimeFormat.format().

Parameters
valueThe numeric value (positive for future, negative for past).
unitThe time unit.
Returns
Human-readable relative time string.