Ejemplo n.º 1
0
def _duration_string_short(duration):
    """
    Format a "short" duration string without seconds precision. This is
    intended to fit better in smaller spaces on a graph.
    :returns: a string of the form XhXm.
    """
    h, m, s = duration_parts(duration)
    return '{}h{}m'.format(h, m)
Ejemplo n.º 2
0
def _duration_string_ms(duration):
    """
    Format a "short" duration string with only minutes and seconds. This is
    intended to fit better in smaller spaces on a graph.
    :returns: a string of the form Xm.
    """
    h, m, s = duration_parts(duration)
    return '{}m{}s'.format(m, s)
Ejemplo n.º 3
0
def seconds(duration):
    """
    Return the "seconds" portion of a duration.
    :param duration: a timedetla instance.
    :returns: an integer representing the number of seconds in duration.
    """
    if not duration:
        return 0
    try:
        h, m, s = utils.duration_parts(duration)
        return s
    except (ValueError, TypeError):
        return 0
Ejemplo n.º 4
0
def minutes(duration):
    """
    Return the "minutes" portion of a duration.
    :param duration: a timedetla instance.
    :returns: an integer representing the number of minutes in duration.
    """
    if not duration:
        return 0
    try:
        h, m, s = duration_parts(duration)
        return m
    except (ValueError, TypeError):
        return 0
Ejemplo n.º 5
0
 def test_duration_parts(self):
     duration = timezone.timedelta(hours=1, minutes=30, seconds=45)
     self.assertEqual(duration_parts(duration), (1, 30, 45))
     self.assertRaises(TypeError, lambda: duration_parts('1 hour'))