@biancadevera
The sample Time Tracker app you are following was only intended to track daily times, not times that would cross the day boundary (i.e. 12 AM)
You could implement an offset time on all of your calculations, to account for the day boundary, but it is a challenge to do.
So, in other words, the architecture of that app was very specific to just a day. It would need to be adjusted completely for different periods of time.
As for the hour calculations, some years ago I replied to someone on this forum with an app that does summing of all the people and hours from the app. I'd hunt it down, but I feel it might not be worth it in this case since you really need to address non-day boundaries for check in/out.