Exemplo n.º 1
0
def test_format_timedelta():
    assert dates.format_timedelta(timedelta(weeks=12), locale="en_US") == u"3 months"
    assert dates.format_timedelta(timedelta(seconds=1), locale="es") == u"1 segundo"

    assert dates.format_timedelta(timedelta(hours=3), granularity="day", locale="en_US") == u"1 day"

    assert dates.format_timedelta(timedelta(hours=23), threshold=0.9, locale="en_US") == u"1 day"
    assert dates.format_timedelta(timedelta(hours=23), threshold=1.1, locale="en_US") == u"23 hours"
Exemplo n.º 2
0
 def test_zero_seconds(self):
     string = dates.format_timedelta(timedelta(seconds=0), locale="en")
     self.assertEqual("0 seconds", string)
     string = dates.format_timedelta(timedelta(seconds=0), locale="en", format="short")
     self.assertEqual("0 secs", string)
     string = dates.format_timedelta(timedelta(seconds=0), granularity="hour", locale="en")
     self.assertEqual("0 hours", string)
     string = dates.format_timedelta(timedelta(seconds=0), granularity="hour", locale="en", format="short")
     self.assertEqual("0 hrs", string)
Exemplo n.º 3
0
    def timedelta(self, delta, granularity='second', threshold=.85,
                  format='medium', add_direction=False):
        """Return a time delta according to the rules of the given locale.

        >>> from datetime import timedelta
        >>> fmt = Format('en_US')
        >>> fmt.timedelta(timedelta(weeks=11))
        u'3 months'
        """
        return format_timedelta(delta, granularity=granularity,
                                threshold=threshold,
                                format=format, add_direction=add_direction,
                                locale=self.locale)
Exemplo n.º 4
0
 def test_direction_adding(self):
     string = dates.format_timedelta(timedelta(hours=1), locale="en", add_direction=True)
     self.assertEqual("In 1 hour", string)
     string = dates.format_timedelta(timedelta(hours=-1), locale="en", add_direction=True)
     self.assertEqual("1 hour ago", string)
Exemplo n.º 5
0
 def test_small_value_with_granularity(self):
     string = dates.format_timedelta(timedelta(seconds=42), granularity="hour", locale="en")
     self.assertEqual("1 hour", string)
     string = dates.format_timedelta(timedelta(seconds=42), granularity="hour", locale="en", format="short")
     self.assertEqual("1 hr", string)