~ubuntu-branches/ubuntu/saucy/gaupol/saucy-proposed

« back to all changes in this revision

Viewing changes to aeidon/calculator.py

  • Committer: Bazaar Package Importer
  • Author(s): Piotr Ożarowski
  • Date: 2011-05-30 23:34:55 UTC
  • mfrom: (1.2.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20110530233455-dbhjajtn3tnz2r2e
Tags: 0.18-1
New upstream release

Show diffs side-by-side

added added

removed removed

Lines of Context:
121
121
                0 <= seconds <= 59 and
122
122
                0 <= mseconds <= 999)
123
123
 
 
124
    def parse_time(self, time):
 
125
        """Parse syntactically sloppy `time` to valid format.
 
126
 
 
127
        >>> calc = aeidon.Calculator()
 
128
        >>> calc.parse_time("1:2:3,4")
 
129
        '01:02:03.400'
 
130
        """
 
131
        time = time.strip()
 
132
        sign = ("-" if time.startswith("-") else "")
 
133
        time = time.replace("-", "")
 
134
        time = time.replace(",", ".")
 
135
        hours, minutes, seconds = map(float, time.split(":"))
 
136
        return "%s%02.0f:%02.0f:%02.0f.%03.0f" % (sign,
 
137
                                                  hours,
 
138
                                                  minutes,
 
139
                                                  int(seconds),
 
140
                                                  (seconds % 1) * 1000)
 
141
 
124
142
    def round_time(self, time, decimals):
125
143
        """Round `time` to amount of `decimals` in seconds."""
126
144
        seconds = self.time_to_seconds(time)