73static String translateTimeField (
int n,
const char*
singular,
const char*
plural)
78static String describeYears (
int n) {
return translateTimeField (n,
NEEDS_TRANS (
"1 year"),
NEEDS_TRANS (
"2 years")); }
79static String describeMonths (
int n) {
return translateTimeField (n,
NEEDS_TRANS (
"1 month"),
NEEDS_TRANS (
"2 months")); }
80static String describeWeeks (
int n) {
return translateTimeField (n,
NEEDS_TRANS (
"1 week"),
NEEDS_TRANS (
"2 weeks")); }
81static String describeDays (
int n) {
return translateTimeField (n,
NEEDS_TRANS (
"1 day"),
NEEDS_TRANS (
"2 days")); }
82static String describeHours (
int n) {
return translateTimeField (n,
NEEDS_TRANS (
"1 hr"),
NEEDS_TRANS (
"2 hrs")); }
83static String describeMinutes (
int n) {
return translateTimeField (n,
NEEDS_TRANS (
"1 min"),
NEEDS_TRANS (
"2 mins")); }
84static String describeSeconds (
int n) {
return translateTimeField (n,
NEEDS_TRANS (
"1 sec"),
NEEDS_TRANS (
"2 secs")); }
88 if (numSeconds <= 1.0)
93 if (
weeks > 52)
return describeYears (
weeks / 52);
94 if (
weeks > 8)
return describeMonths ((
weeks * 12) / 52);
100 return describeDays (
days);
105 return describeHours (
hours);
110 return describeMinutes (
minutes);
112 return describeSeconds ((
int) numSeconds);
117 if (std::abs (numSeconds) < 0.001)
133 fields.add (describeDays (n));
140 fields.add (describeHours (n));
147 fields.add (describeMinutes (n));
154 fields.add (describeSeconds (n));
162 return fields.joinIntoString (
" ");
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.
void add(String stringToAdd)
Appends a string at the end of the array.
#define TRANS(stringLiteral)
Uses the LocalisedStrings class to translate the given string literal.
#define NEEDS_TRANS(stringLiteral)
A dummy version of the TRANS macro, used to indicate a string literal that should be added to the tra...
bool operator>(const var &v1, const var &v2)
Compares the values of two var objects, using the var::equals() comparison.
bool operator<=(const var &v1, const var &v2)
Compares the values of two var objects, using the var::equals() comparison.
constexpr bool exactlyEqual(Type a, Type b)
Equivalent to operator==, but suppresses float-equality warnings.
bool operator>=(const var &v1, const var &v2)
Compares the values of two var objects, using the var::equals() comparison.
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...
JUCE_API RelativeTime JUCE_CALLTYPE operator-(RelativeTime t1, RelativeTime t2) noexcept
Subtracts two RelativeTimes.
long long int64
A platform-independent 64-bit integer type.