Skip to content

Commit

Permalink
Fix previous_summary from summary timer
Browse files Browse the repository at this point in the history
  • Loading branch information
Samuel committed Jun 2, 2022
1 parent 3225f27 commit 20de227
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions lib/archethic/beacon_chain/summary_timer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,20 @@ defmodule Archethic.BeaconChain.SummaryTimer do
Returns the list of previous summaries times from the given date
"""
@spec previous_summary(DateTime.t()) :: DateTime.t()
def previous_summary(date_from = %DateTime{microsecond: {0, 0}}) do
get_interval()
|> CronParser.parse!(true)
|> CronScheduler.get_previous_run_dates(DateTime.to_naive(date_from))
|> Enum.at(1)
|> DateTime.from_naive!("Etc/UTC")
end

def previous_summary(date_from = %DateTime{}) do
get_interval()
|> CronParser.parse!(true)
|> CronScheduler.get_previous_run_date!(DateTime.to_naive(date_from))
|> DateTime.from_naive!("Etc/UTC")
cron_expression = CronParser.parse!(get_interval(), true)
naive_date_from = DateTime.to_naive(date_from)

if Crontab.DateChecker.matches_date?(cron_expression, naive_date_from) do
cron_expression
|> CronScheduler.get_previous_run_dates(naive_date_from)
|> Enum.at(1)
|> DateTime.from_naive!("Etc/UTC")
else
cron_expression
|> CronScheduler.get_previous_run_date!(naive_date_from)
|> DateTime.from_naive!("Etc/UTC")
end
end

@doc """
Expand Down

0 comments on commit 20de227

Please sign in to comment.