55JUCE_API RelativeTime JUCE_CALLTYPE operator- (RelativeTime t1, RelativeTime t2)
noexcept {
return t1 -= t2; }
57JUCE_API bool JUCE_CALLTYPE operator== (RelativeTime t1, RelativeTime t2)
noexcept {
return t1.inSeconds() == t2.inSeconds(); }
58JUCE_API bool JUCE_CALLTYPE operator!= (RelativeTime t1, RelativeTime t2)
noexcept {
return t1.inSeconds() != t2.inSeconds(); }
59JUCE_API bool JUCE_CALLTYPE operator> (RelativeTime t1, RelativeTime t2)
noexcept {
return t1.inSeconds() > t2.inSeconds(); }
60JUCE_API bool JUCE_CALLTYPE operator< (RelativeTime t1, RelativeTime t2)
noexcept {
return t1.inSeconds() < t2.inSeconds(); }
61JUCE_API bool JUCE_CALLTYPE operator>= (RelativeTime t1, RelativeTime t2)
noexcept {
return t1.inSeconds() >= t2.inSeconds(); }
62JUCE_API bool JUCE_CALLTYPE operator<= (RelativeTime t1, RelativeTime t2)
noexcept {
return t1.inSeconds() <= t2.inSeconds(); }
65static String translateTimeField (
int n,
const char* singular,
const char* plural)
67 return TRANS (n == 1 ? singular : plural).replace (n == 1 ?
"1" :
"2", String (n));
70static String describeYears (
int n) {
return translateTimeField (n, NEEDS_TRANS(
"1 year"), NEEDS_TRANS(
"2 years")); }
71static String describeMonths (
int n) {
return translateTimeField (n, NEEDS_TRANS(
"1 month"), NEEDS_TRANS(
"2 months")); }
72static String describeWeeks (
int n) {
return translateTimeField (n, NEEDS_TRANS(
"1 week"), NEEDS_TRANS(
"2 weeks")); }
73static String describeDays (
int n) {
return translateTimeField (n, NEEDS_TRANS(
"1 day"), NEEDS_TRANS(
"2 days")); }
74static String describeHours (
int n) {
return translateTimeField (n, NEEDS_TRANS(
"1 hr"), NEEDS_TRANS(
"2 hrs")); }
75static String describeMinutes (
int n) {
return translateTimeField (n, NEEDS_TRANS(
"1 min"), NEEDS_TRANS(
"2 mins")); }
76static 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));
A relative measure of time.
int64 inMilliseconds() const noexcept
Returns the number of milliseconds this time represents.
static RelativeTime minutes(double numberOfMinutes) noexcept
Creates a new RelativeTime object representing a number of minutes.
double inWeeks() const noexcept
Returns the number of weeks this time represents.
String getDescription(const String &returnValueForZeroTime="0") const
Returns a readable textual description of the time.
double inDays() const noexcept
Returns the number of days this time represents.
double inHours() const noexcept
Returns the number of hours this time represents.
static RelativeTime milliseconds(int milliseconds) noexcept
Creates a new RelativeTime object representing a number of milliseconds.
double inSeconds() const noexcept
Returns the number of seconds this time represents.
~RelativeTime() noexcept
Destructor.
static RelativeTime hours(double numberOfHours) noexcept
Creates a new RelativeTime object representing a number of hours.
static RelativeTime days(double numberOfDays) noexcept
Creates a new RelativeTime object representing a number of days.
RelativeTime & operator=(const RelativeTime &other) noexcept
Copies another relative time.
RelativeTime operator+=(RelativeTime timeToAdd) noexcept
Adds another RelativeTime to this one.
RelativeTime operator-=(RelativeTime timeToSubtract) noexcept
Subtracts another RelativeTime from this one.
String getApproximateDescription() const
This returns a string that roughly describes how long ago this time was, which can be handy for showi...
static RelativeTime weeks(double numberOfWeeks) noexcept
Creates a new RelativeTime object representing a number of weeks.
static RelativeTime seconds(double seconds) noexcept
Creates a new RelativeTime object representing a number of seconds.
RelativeTime(double seconds=0.0) noexcept
Creates a RelativeTime.
double inMinutes() const noexcept
Returns the number of minutes this time represents.
A special array for holding a list of strings.
String joinIntoString(StringRef separatorString, int startIndex=0, int numberOfElements=-1) const
Joins the strings in the array together into one string.
int size() const noexcept
Returns the number of strings in the array.
void add(String stringToAdd)
Appends a string at the end of the array.
bool isEmpty() const noexcept
Returns true if the array is empty, false otherwise.
#define JUCE_API
This macro is added to all JUCE public class declarations.