for emp in employee:
contract_id = contract_pool.search(cr, uid, [('employee_id','=',emp.employee_id.id)], context=context)
for contract in contract_pool.browse(cr, uid, contract_id, context=context):
for attendance in contract.working_hours.attendance_ids:
if day == attendance.dayofweek:
planned_time_in = attendance.hour_from
planned_time_out = attendance.hour_to
planned_wrkng_hrs = planned_time_out - planned_time_in
print planned_wrkng_hrs
actual_time_in = emp.time_in
actual_time_out = emp.time_out
actual_wrkd_hrs = actual_time_out - actual_time_in
print actual_wrkd_hrs
hrs_short = planned_wrkng_hrs - actual_wrkd_hrs
print hrs_short
这给出了输出为:
9.00
8.57
0.43
我怎样才能得到:
9:00
8:57
00:03
浮动值在这里被减去而不是时间。
答案 0 :(得分:0)
假设时间值的格式与您的示例类似,您可以通过执行类似
的操作将其转换为分钟 - 午夜time_in_mins = int(original_time) * 60 + (original_time - int(original(time)) * 100
然后使用新的"标准化"进行所有计算。值,然后将其转换回您首选的格式以供显示或存储。
答案 1 :(得分:0)
希望这能帮到你^^:
from datetime import time
from datetime import datetime, date
import math
# on thing hour part cannot be more that 23 and
first_time = 23.5
secend_time = 23.0
# convert float to hour and minute
f_hour, f_time = int(math.floor(first_time)), int(round((first_time % 1) * 60))
s_hour, s_time = int(math.floor(secend_time)), int(round((secend_time % 1) * 60))
# create datetime object to perform substraction
duration = datetime.combine(date.min,time(f_hour,f_time))- datetime.combine(date.min,time(s_hour,s_time))
print "total minute between this two time is %s minutes " % (duration.total_seconds() / 60)
结果:
total minute between this two time is 30.0 minutes