Would appreciate any pointers to how I could solve the following problem in Go…
I’m building an application to prepare data prior to being ingested into an analytics cluster. Part of that process requires me to calculate in minutes, hours and days the elapsed time between the event being created and then later closed. I have these values as strings as part of each line, or event.
So it’s trivial to parse each value into a time.Time object then use sub to get a duration which gives me access to mins and hours. So far so easy…
I now need to subtract from this duration the following operational factors:
Minutes elapsing over weekends, as that does not count. So how to work out how many, or if at all, Saturdays and Sundays exist inside this duration?
A full working day (mon-fri) is between set hours, let’s say 08:00 and 17:00 so any minutes out with those hours must also be subtracted.
I’m veering toward trying to create a slice of time.Time for every day between the start and end time stamps (inclusive) then I could range over them applying the test conditionals and accumulate minutes from each test. Does anyone know how to create a slice of time.Time dates between two time stamps?
I can’t help feel that this is the kind of datetime calculation that there may be a helper package for that I’m missing?
Would be extremely grateful for any suggestions, thanks.