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
static RelativeTime days(double numberOfDays) noexcept
RelativeTime & operator=(const RelativeTime &other) noexcept
double inHours() const noexcept
String getApproximateDescription() const
static RelativeTime milliseconds(int milliseconds) noexcept
double inDays() const noexcept
double inWeeks() const noexcept
int64 inMilliseconds() const noexcept
static RelativeTime seconds(double seconds) noexcept
static RelativeTime hours(double numberOfHours) noexcept
static RelativeTime minutes(double numberOfMinutes) noexcept
RelativeTime operator+=(RelativeTime timeToAdd) noexcept
static RelativeTime weeks(double numberOfWeeks) noexcept
RelativeTime(double seconds=0.0) noexcept
String getDescription(const String &returnValueForZeroTime="0") const
String joinIntoString(StringRef separatorString, int startIndex=0, int numberOfElements=-1) const
double inSeconds() const noexcept
RelativeTime operator-=(RelativeTime timeToSubtract) noexcept
int size() const noexcept
double inMinutes() const noexcept
void add(String stringToAdd)