65 static String translateTimeField (
int n,
const char* singular,
const char* plural)
67 return TRANS (n == 1 ? singular : plural).replace (n == 1 ?
"1" :
"2",
String (n));
70 static String describeYears (
int n) {
return translateTimeField (n, NEEDS_TRANS(
"1 year"), NEEDS_TRANS(
"2 years")); }
71 static String describeMonths (
int n) {
return translateTimeField (n, NEEDS_TRANS(
"1 month"), NEEDS_TRANS(
"2 months")); }
72 static String describeWeeks (
int n) {
return translateTimeField (n, NEEDS_TRANS(
"1 week"), NEEDS_TRANS(
"2 weeks")); }
73 static String describeDays (
int n) {
return translateTimeField (n, NEEDS_TRANS(
"1 day"), NEEDS_TRANS(
"2 days")); }
74 static String describeHours (
int n) {
return translateTimeField (n, NEEDS_TRANS(
"1 hr"), NEEDS_TRANS(
"2 hrs")); }
75 static String describeMinutes (
int n) {
return translateTimeField (n, NEEDS_TRANS(
"1 min"), NEEDS_TRANS(
"2 mins")); }
76 static String describeSeconds (
int n) {
return translateTimeField (n, NEEDS_TRANS(
"1 sec"), NEEDS_TRANS(
"2 secs")); }
80 if (numSeconds <= 1.0)
85 if (
weeks > 52)
return describeYears (
weeks / 52);
86 if (
weeks > 8)
return describeMonths ((
weeks * 12) / 52);
92 return describeDays (
days);
97 return describeHours (
hours);
102 return describeMinutes (
minutes);
104 return describeSeconds ((
int) numSeconds);
109 if (std::abs (numSeconds) < 0.001)
110 return returnValueForZeroTime;
113 return "-" +
RelativeTime (-numSeconds).getDescription();
120 fields.
add (describeWeeks (n));
125 fields.
add (describeDays (n));
127 if (fields.
size() < 2)
132 fields.
add (describeHours (n));
134 if (fields.
size() < 2)
139 fields.
add (describeMinutes (n));
141 if (fields.
size() < 2)
146 fields.
add (describeSeconds (n));
bool isEmpty() const noexcept
Returns true if the array is empty, false otherwise.
static RelativeTime days(double numberOfDays) noexcept
Creates a new RelativeTime object representing a number of days.
#define JUCE_API
This macro is added to all JUCE public class declarations.
RelativeTime & operator=(const RelativeTime &other) noexcept
Copies another relative time.
double inHours() const noexcept
Returns the number of hours this time represents.
String getApproximateDescription() const
This returns a string that roughly describes how long ago this time was, which can be handy for showi...
static RelativeTime milliseconds(int milliseconds) noexcept
Creates a new RelativeTime object representing a number of milliseconds.
A special array for holding a list of strings.
double inDays() const noexcept
Returns the number of days this time represents.
A relative measure of time.
double inWeeks() const noexcept
Returns the number of weeks this time represents.
int64 inMilliseconds() const noexcept
Returns the number of milliseconds this time represents.
static RelativeTime seconds(double seconds) noexcept
Creates a new RelativeTime object representing a number of seconds.
static RelativeTime hours(double numberOfHours) noexcept
Creates a new RelativeTime object representing a number of hours.
static RelativeTime minutes(double numberOfMinutes) noexcept
Creates a new RelativeTime object representing a number of minutes.
RelativeTime operator+=(RelativeTime timeToAdd) noexcept
Adds another RelativeTime to this one.
static RelativeTime weeks(double numberOfWeeks) noexcept
Creates a new RelativeTime object representing a number of weeks.
RelativeTime(double seconds=0.0) noexcept
Creates a RelativeTime.
String getDescription(const String &returnValueForZeroTime="0") const
Returns a readable textual description of the time.
String joinIntoString(StringRef separatorString, int startIndex=0, int numberOfElements=-1) const
Joins the strings in the array together into one string.
double inSeconds() const noexcept
Returns the number of seconds this time represents.
~RelativeTime() noexcept
Destructor.
RelativeTime operator-=(RelativeTime timeToSubtract) noexcept
Subtracts another RelativeTime from this one.
int size() const noexcept
Returns the number of strings in the array.
double inMinutes() const noexcept
Returns the number of minutes this time represents.
void add(String stringToAdd)
Appends a string at the end of the array.