Currently first archiving after midnight in site timezone will create definite archive for previous period. However this logic contains slight error - it is possible that single visit will have visit_last_action_time set to 23:59:00 at the moment of archiving. However after archiving will complete incorporating this single visit, user can still make new action that will change visit_last_action_time to 00:15:00. This way this visit will be counted for the second time on next archiving for this second day.
Solution for this problem could be to only allow creating definite archives after midnight + standard_visit_length (i.e. 00:30:00 AM) in timezone of site.
Thanks @mgazdzik for the suggestion.
Basically this bug means that we get different metrics from the API depending on the time that the website was archived.
(implementation note: we should
min(standard_visit_length, 3600) as some users set very high
standard_visit_length values (so the visit never expires) and we wouldn't want to break archiving for this case)