|
|
@ -272,6 +272,7 @@ calcNextRotate([], Data, Time, NowDataTime) -> |
|
|
|
calendar:datetime_to_gregorian_seconds(Later) - calendar:datetime_to_gregorian_seconds(NowDataTime); |
|
|
|
calcNextRotate([OneSpec | Spec], NDate, NTime, NowDataTime) -> |
|
|
|
{NHour, NMinute, _} = NTime, |
|
|
|
{NYear, NMonth, NDay} = NDate, |
|
|
|
case OneSpec of |
|
|
|
{minute, SMinute} -> |
|
|
|
case NMinute < SMinute of |
|
|
@ -298,98 +299,69 @@ calcNextRotate([OneSpec | Spec], NDate, NTime, NowDataTime) -> |
|
|
|
end; |
|
|
|
{day, SDay} -> |
|
|
|
CurDay = rumTime:weekDay(NDate), |
|
|
|
AdjustedDay = |
|
|
|
case SDay of |
|
|
|
0 -> 7; |
|
|
|
_ -> SDay |
|
|
|
end, |
|
|
|
case AdjustedDay of |
|
|
|
CurDay -> %% rotation is today |
|
|
|
case calcNextRotate(T, Now) of |
|
|
|
AdjustedDay = ?IIF(SDay == 0, 7, SDay), |
|
|
|
if |
|
|
|
AdjustedDay > CurDay -> |
|
|
|
PlusDays = AdjustedDay - CurDay, |
|
|
|
NexSec = rumTime:lDateTimeToSec(NowDataTime) + (86400 * PlusDays), |
|
|
|
{NewDate, _} = rumTime:secToLDateTime(NexSec), |
|
|
|
NewNow = {NewDate, {0, 0, 0}}, |
|
|
|
calcNextRotate(Spec, NewNow); |
|
|
|
AdjustedDay < CurDay -> |
|
|
|
PlusDays = ((7 - CurDay) + AdjustedDay), |
|
|
|
NexSec = rumTime:lDateTimeToSec(NowDataTime) + (86400 * PlusDays), |
|
|
|
{NewDate, _} = rumTime:secToLDateTime(NexSec), |
|
|
|
NewNow = {NewDate, {0, 0, 0}}, |
|
|
|
calcNextRotate(Spec, NewNow); |
|
|
|
true -> |
|
|
|
case calcNextRotate(Spec, Now) of |
|
|
|
{Date, _} = NewNow -> NewNow; |
|
|
|
{NewDate, _} -> |
|
|
|
%% rotation *isn't* today! rerun the calculation |
|
|
|
NewNow = {NewDate, {0, 0, 0}}, |
|
|
|
calcNextRotate([{day, SDay} | T], NewNow) |
|
|
|
calcNextRotate([{day, SDay} | Spec], NewNow) |
|
|
|
end |
|
|
|
end; |
|
|
|
{date, last} -> |
|
|
|
Last = rumTime:monthDay(NYear, NMonth), |
|
|
|
case Last == Day of |
|
|
|
true -> %% doing rotation today |
|
|
|
case calcNextRotate(T, Now) of |
|
|
|
{{Year, Month, Day}, _} = NewNow -> NewNow; |
|
|
|
{NewDate, _} -> |
|
|
|
%% rotation *isn't* today! rerun the calculation |
|
|
|
NewNow = {NewDate, {0, 0, 0}}, |
|
|
|
calcNextRotate([{date, last} | T], NewNow) |
|
|
|
end; |
|
|
|
Y when Y > CurDay -> %% rotation is later this week |
|
|
|
PlusDays = Y - CurDay, |
|
|
|
false -> |
|
|
|
NewNow = setelement(1, Now, {Year, Month, Last}), |
|
|
|
calcNextRotate(T, NewNow) |
|
|
|
end; |
|
|
|
{date, SDate} -> |
|
|
|
if |
|
|
|
SDate < NDay -> |
|
|
|
Last = calendar:last_day_of_the_month(Year, Month), |
|
|
|
(Last - Day), |
|
|
|
Seconds = calendar:datetime_to_gregorian_seconds(Now) + (86400 * PlusDays), |
|
|
|
{NewDate, _} = calendar:gregorian_seconds_to_datetime(Seconds), |
|
|
|
NewNow = {NewDate, {0, 0, 0}}, |
|
|
|
NewNow = calendar:gregorian_seconds_to_datetime(Seconds), |
|
|
|
calcNextRotate(T, NewNow); |
|
|
|
Y when Y < CurDay -> %% rotation is next week |
|
|
|
PlusDays = ((7 - CurDay) + Y), |
|
|
|
SDate > NDay -> |
|
|
|
X - Day, |
|
|
|
Seconds = calendar:datetime_to_gregorian_seconds(Now) + (86400 * PlusDays), |
|
|
|
{NewDate, _} = calendar:gregorian_seconds_to_datetime(Seconds), |
|
|
|
NewNow = {NewDate, {0, 0, 0}}, |
|
|
|
calcNextRotate(T, NewNow) |
|
|
|
end; |
|
|
|
NewNow = calendar:gregorian_seconds_to_datetime(Seconds), |
|
|
|
calcNextRotate(T, NewNow); |
|
|
|
true -> |
|
|
|
%% rotation is today |
|
|
|
case calcNextRotate(T, Now) of |
|
|
|
{{Year, Month, Date}, _} = NewNow -> NewNow; |
|
|
|
{NewDate, _} -> |
|
|
|
%% rotation *isn't* today! rerun the calculation |
|
|
|
NewNow = setelement(1, Now, NewDate), |
|
|
|
calcNextRotate([{date, Date} | T], NewNow) |
|
|
|
end |
|
|
|
end |
|
|
|
|
|
|
|
end; |
|
|
|
calcNextRotate([{day, SDay} | T], {Date, _Time} = Now) -> |
|
|
|
CurDay = calendar:day_of_the_week(Date), |
|
|
|
AdjustedDay = case SDay of |
|
|
|
0 -> 7; |
|
|
|
X -> X |
|
|
|
end, |
|
|
|
case AdjustedDay of |
|
|
|
CurDay -> %% rotation is today |
|
|
|
case calcNextRotate(T, Now) of |
|
|
|
{Date, _} = NewNow -> NewNow; |
|
|
|
{NewDate, _} -> |
|
|
|
%% rotation *isn't* today! rerun the calculation |
|
|
|
NewNow = {NewDate, {0, 0, 0}}, |
|
|
|
calcNextRotate([{day, SDay} | T], NewNow) |
|
|
|
end; |
|
|
|
Y when Y > CurDay -> %% rotation is later this week |
|
|
|
PlusDays = Y - CurDay, |
|
|
|
Seconds = calendar:datetime_to_gregorian_seconds(Now) + (86400 * PlusDays), |
|
|
|
{NewDate, _} = calendar:gregorian_seconds_to_datetime(Seconds), |
|
|
|
NewNow = {NewDate, {0, 0, 0}}, |
|
|
|
calcNextRotate(T, NewNow); |
|
|
|
Y when Y < CurDay -> %% rotation is next week |
|
|
|
PlusDays = ((7 - CurDay) + Y), |
|
|
|
Seconds = calendar:datetime_to_gregorian_seconds(Now) + (86400 * PlusDays), |
|
|
|
{NewDate, _} = calendar:gregorian_seconds_to_datetime(Seconds), |
|
|
|
NewNow = {NewDate, {0, 0, 0}}, |
|
|
|
calcNextRotate(T, NewNow) |
|
|
|
end; |
|
|
|
calcNextRotate([{date, last} | T], {{Year, Month, Day}, _} = Now) -> |
|
|
|
Last = calendar:last_day_of_the_month(Year, Month), |
|
|
|
case Last == Day of |
|
|
|
true -> %% doing rotation today |
|
|
|
case calcNextRotate(T, Now) of |
|
|
|
{{Year, Month, Day}, _} = NewNow -> NewNow; |
|
|
|
{NewDate, _} -> |
|
|
|
%% rotation *isn't* today! rerun the calculation |
|
|
|
NewNow = {NewDate, {0, 0, 0}}, |
|
|
|
calcNextRotate([{date, last} | T], NewNow) |
|
|
|
end; |
|
|
|
false -> |
|
|
|
NewNow = setelement(1, Now, {Year, Month, Last}), |
|
|
|
calcNextRotate(T, NewNow) |
|
|
|
end; |
|
|
|
calcNextRotate([{date, Date} | T], {{Year, Month, Date}, _} = Now) -> |
|
|
|
%% rotation is today |
|
|
|
case calcNextRotate(T, Now) of |
|
|
|
{{Year, Month, Date}, _} = NewNow -> NewNow; |
|
|
|
{NewDate, _} -> |
|
|
|
%% rotation *isn't* today! rerun the calculation |
|
|
|
NewNow = setelement(1, Now, NewDate), |
|
|
|
calcNextRotate([{date, Date} | T], NewNow) |
|
|
|
end; |
|
|
|
calcNextRotate([{date, Date} | T], {{Year, Month, Day}, _} = Now) -> |
|
|
|
PlusDays = case Date of |
|
|
|
X when X < Day -> %% rotation is next month |
|
|
|
Last = calendar:last_day_of_the_month(Year, Month), |
|
|
|
(Last - Day); |
|
|
|
X when X > Day -> %% rotation is later this month |
|
|
|
X - Day |
|
|
|
end, |
|
|
|
Seconds = calendar:datetime_to_gregorian_seconds(Now) + (86400 * PlusDays), |
|
|
|
NewNow = calendar:gregorian_seconds_to_datetime(Seconds), |
|
|
|
calcNextRotate(T, NewNow). |
|
|
|
end. |
|
|
|
|
|
|
|
-spec trace_filter(Query :: 'none' | [tuple()]) -> {ok, any()}. |
|
|
|
trace_filter(Query) -> |
|
|
|