ceil time entry to nearest quarter hour

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
    def getHours(self):
        """returns floating point hours rounded up to the nearest quarter hour"""
        td = self.end_time - self.start_time
        hours = td.seconds // 3600
        minutes = (td.seconds % 3600) // 60
        dec = (float(minutes) / 60)
        quarter = dec // 0.25
        if ((dec % 0.25) > 0):
            quarter += 0.25
        return hours + quarter

More like this

  1. SplitTimeField by theju 5 years, 3 months ago
  2. Custom model field for mysql time type. by xuqingkuang 3 years, 7 months ago
  3. Querying datetime aware objects in your local timezone by jayliew 12 months ago
  4. Quantize decimal template filter by bl4th3rsk1t3 4 years ago
  5. Time ranges like 7-9 p.m. by sgb 5 years, 4 months ago

Comments

(Forgotten your password?)