mmamaev / timeboard

Calendar calculations over business days and work shifts
Other
145 stars 20 forks source link

Working hours #5

Closed kamalkarki closed 5 years ago

kamalkarki commented 5 years ago

Suppose I am making a calendar for a machine in my company and I want to give the working hours for that to a calender say from morning 6am to evening 6pm how can i do that?

mmamaev commented 5 years ago

It depends on your business definition of workshift. If you care only about days (i.e. each calendar day is considered as a 12-hour shift) than the calendar is:

>>> clnd = tb.Timeboard('D', '15 Jan 2019', '31 Jan 2019',
...                     layout=[12],
...                     worktime_source = 'labels')

To count working hours in a period of days, you create an interval and call worktime() on it:

>>> ivl = clnd.get_interval(('15 Jan 2019', '17 Jan 2019'))
>>> ivl.worktime()
36

This is not an interesting calendar though, as you don't need timeboard package to just count calendar days and multiply them by 12. Timeboard will be useful if there are patterns of days on alternating with days off.

If, in your workshift accounting, you care about the hours of the day when shifts start or end, than the calendar will be:

>>> clnd = tb.Timeboard('12H', '15 Jan 2019 6:00', '31 Jan 2019 17:59',
...                     layout=[12, 0],
...                     worktime_source = 'labels')
>>> ivl = clnd.get_interval(('15 Jan 2019 6:00', '17 Jan 2019 18:00'))
>>> ivl.worktime()
36

Again, this is not awfully exciting, as there is one shift per day that starts and ends on the same hour every day. Timeboard will be useful if you have many shifts per day, or shifts of varying lengths, or shifts starting/ending on varying hours.