From 593a9f72703ecc537cba2880ff3c3ff031bd8325 Mon Sep 17 00:00:00 2001 From: SisMaker <1713699517@qq.com> Date: Tue, 9 Mar 2021 21:00:30 +0800 Subject: [PATCH] =?UTF-8?q?ft:=20=E4=BB=A3=E7=A0=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/rumUtil.erl | 138 +++++++++++++++++------------------------- 1 file changed, 55 insertions(+), 83 deletions(-) diff --git a/src/utils/rumUtil.erl b/src/utils/rumUtil.erl index c29a414..b318d6b 100644 --- a/src/utils/rumUtil.erl +++ b/src/utils/rumUtil.erl @@ -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) ->