sumtimes.py

Created by mobluse

Created on April 27, 2024

514 Bytes

This program sums the times in the list with end times (positive) and start times (negative) for work days in a week. The times are given in the sexagesimal format h.mmss i.e. 14:50:00 is 14.5000 and -07:45:06.18 is -7.450618. The result is also in sexagesimal. It could be used to compute working hours for jobs with flexible hours per day. NO WARRANTY.


# Sum times in list
from math import *
# Sexagesimal: hh.mmss
ts=[17.00,-7.45,17.00,-8.50,
    15.50,-8.45,14.50,-8.50,
    15.50,-8.50]
def sumtimes(ts):
  sum_s=0
  for t in ts:
    ta=abs(t)
    s=3600*int(ta)
    s+=60*int(100*(ta%1))
    s+=60*((100*ta)%1)
    sum_s+=copysign(s,t)
  sum_sa=abs(sum_s)
  hh_mmss=sum_sa//3600
  temp=round(sum_sa%3600,10)
  minu=temp//60
  temp=temp%60
  hh_mmss+=minu/100+temp/10000
  hh_mmss=copysign(hh_mmss,sum_s)
  return hh_mmss
print("%.6f"%sumtimes(ts))

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.