177
Return a pretty string representation of the `TimeDelta` like '12 hours'
178
or '1 second'. Because a string like '1 hour' is not precise enough,
179
it will also include the number of minutes in that case:
180
'1 hour and 23 minutes'.
177
Return a pretty, localized string representation of the `TimeDelta` like
178
'12 hours' or '1 second'.
180
Because a string like '1 hour' is not precise enough, it must also
181
include information about the value of the next smaller time scale, in
184
Because such values will often be imprecise (especially if they're
185
estimations), the value of the next smaller time scale will be rounded
188
This means that instead of '1 hour and 43 minutes', the returned string
189
will be '1 hour and 40 minutes'. For estimations that are likely to
190
change over time, this causes the return values to be changed less
193
Consider the following example return values:
195
>>> TimeDelta(seconds=46).short
197
>>> TimeDelta(minutes=2, seconds=3).short
199
>>> TimeDelta(minutes=2, seconds=33).short
200
'2 minutes and 30 seconds'.
201
>>> TimeDelta(hours=2, minutes=3).short
203
>>> TimeDelta(hours=2, minutes=33).short
204
'2 hours and 30 minutes'.
205
>>> TimeDelta(days=2, minutes=57)
207
>>> TimeDelta(days=1, hours=18)
183
211
# Use 'seconds' as the default major time scale so that if the
199
227
if minor_scale is None:
228
# `minor_scale' is None because `major_scale' is 'seconds'.
200
229
return self._get_simple_string(major_scale)
231
minor_scale_value = self._get_partitioned_value(minor_scale)
233
if minor_scale in ("minutes", "seconds"):
234
# Only round minutes and seconds.
235
minor_scale_value = minor_scale_value / 10 * 10
237
if not minor_scale_value:
238
# Don't return something like '1 minute and 0 seconds', but
240
return self._get_simple_string(major_scale)
242
rounded_time_delta = TimeDelta(**{
243
major_scale: self._get_partitioned_value(major_scale),
244
minor_scale: minor_scale_value
202
247
return _("%(major_time_scale)s and %(minor_time_scale)s") % {
203
"major_time_scale": self._get_simple_string(major_scale),
204
"minor_time_scale": self._get_simple_string(minor_scale)
249
rounded_time_delta._get_simple_string(major_scale),
251
rounded_time_delta._get_simple_string(minor_scale)
207
254
def _get_partitioned_value(self, scale):