I'm working on a script that calculates my salary, for each of my work days, since we don't get the plan send out electronic. We do earn extra withing some time periods.
every hour i earn 61.86 DKK
, but at within some time periods i earn extra money, as seen below.
(For simplicity i have calculated the time in 24h cycle, since that what i am used to)
Weekdays (18:00 - 06:00) 12.20 DKK
Saturday (15:00 - 24:00) 21.65 DKK
Sunday (whole day) 24.50 DKK
So fare i have worked out, how to calculate the extra money and the hourly rate fine. Although my problem is, if i have a work guard that starts 20:00 and ends next day 4:00 then it will give me and error. I have an IF statement that activates if the hour is above 18(which is when i get extra in the weekdays) then i subtract the hour count with 18 to get, how many hours that's i need to earn extra.
if d2.isoweekday() <= 5: #If its a weekday
if d2.hour >= 18:
extra += ((d2.hour - 18) * weekdaySalary) + ((d2.minute / 60) * weekdaySalary)
How do i detect, exact how many hours that's between a specific period?
like if i have to dates
26-12-2014 17:00
27-12-2014 08:00
i need a way to see how many of those work hours is within the time period(18:00-06:00). how can this be done? it's like having 2 diffrent date ranges. 1st - for when i get extra. 2rd - for when i actually work.
26-12-2014 17:00
18:00 - extra money period start here
|
|how do i get the time between these to points?
|
06:00 - extra money period ends here
27-12-2014 08:00
it could also be like this
26-12-2014 17:00
18:00 - extra money period start here
|
|how do i get the time between these to points?
|
27-12-2014 04:00
06:00 - extra money period ends here
Every answer is highly appreciated, spent so much time trying to figure out with no really result.