You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Apr 30, 2020. It is now read-only.
I am looking at the source code of Bitter and had a question about it.
in the function bitDateRange in Bitter.php (line 137+) it looks like you get two different DatePeriods, then do two array_diffs, and it looks like this sometimes will result in bitOfOr being performed twice for the $hoursTo array.
What is the purpose of doing two different calls to DatePeriod::createForHour ?
Here is my analysis of what you are doing (in words):
IF the date period is within the same day
With $hoursFrom, get all hours within the day
With $hoursTo, get just the hours between the start of this day and the $to hour value
ELSE // the date period overlaps more than one day
With both $hoursFrom and $hoursTo, get actual hours between $from and $to
Is this meaningful? Why do you do anything other than return the actual hour span in all cases? Why do the bitOfOr twice?
Code below
// Hours
$hoursFrom = DatePeriod::createForHour($from, $to, DatePeriod::CREATE_FROM);
foreach ($hoursFrom as $date) {
$this->bitOpOr($destKey, new Hour($key, $date), $destKey);
}
$hoursTo = DatePeriod::createForHour($from, $to, DatePeriod::CREATE_TO);
if (array_diff($hoursTo->toArray(true), $hoursFrom->toArray(true)) !== array_diff($hoursFrom->toArray(true), $hoursTo->toArray(true))) {
foreach ($hoursTo as $date) {
$this->bitOpOr($destKey, new Hour($key, $date), $destKey);
}
}
The text was updated successfully, but these errors were encountered:
So I guess it seems that the idea is to capture only for granular time units where the next-level-up unit is not 100% covered, ie. hours that are not a full day, days that are not a full month, months that do not cover a full year, etc.
Yes, that the point. We could get all the data with the smallest part (hours) but that not really good. Remember that bit works as: does something happened on that day? on that hour? on that year? If something happened this hour, it happened this day so this month so this year.
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
I am looking at the source code of Bitter and had a question about it.
in the function bitDateRange in Bitter.php (line 137+) it looks like you get two different DatePeriods, then do two array_diffs, and it looks like this sometimes will result in bitOfOr being performed twice for the $hoursTo array.
What is the purpose of doing two different calls to DatePeriod::createForHour ?
Here is my analysis of what you are doing (in words):
Is this meaningful? Why do you do anything other than return the actual hour span in all cases? Why do the bitOfOr twice?
Code below
// Hours
$hoursFrom = DatePeriod::createForHour($from, $to, DatePeriod::CREATE_FROM);
foreach ($hoursFrom as $date) {
$this->bitOpOr($destKey, new Hour($key, $date), $destKey);
}
$hoursTo = DatePeriod::createForHour($from, $to, DatePeriod::CREATE_TO);
if (array_diff($hoursTo->toArray(true), $hoursFrom->toArray(true)) !== array_diff($hoursFrom->toArray(true), $hoursTo->toArray(true))) {
foreach ($hoursTo as $date) {
$this->bitOpOr($destKey, new Hour($key, $date), $destKey);
}
}
The text was updated successfully, but these errors were encountered: