This commit is contained in:
BoHung Chiu 2022-08-02 21:48:24 +08:00
parent 48c4948946
commit a6e9c31222
1 changed files with 9 additions and 2 deletions

View File

@ -119,6 +119,7 @@ class PHire
if date_only if date_only
@recurring_events = @recurring_events.where(:date.ne=>nil) @recurring_events = @recurring_events.where(:date.ne=>nil)
end end
start_date_utc_mjd = start_date.to_datetime.utc.mjd
@recurring_events.each do |re| @recurring_events.each do |re|
datet = re.date datet = re.date
interval = 1.send(re.recurring_interval) rescue 0 interval = 1.send(re.recurring_interval) rescue 0
@ -133,10 +134,16 @@ class PHire
period_str = nil period_str = nil
if re.recurring_interval == "week" if re.recurring_interval == "week"
period_str = 'week' period_str = 'week'
add_interval = ((start_date - @start_date - 1.day).to_i / 7.day) add_interval = (start_date_utc_mjd - @start_date.utc.mjd)
days = 7.day
if add_interval < 0
add_interval = -(-add_interval / days)
else
add_interval = add_interval / days
end
else else
period_str = 'month' period_str = 'month'
add_interval = ((start_date.year * 12 + start_date.month) - (@start_date.year * 12 + @start_date.month) - 1) add_interval = ((start_date.year * 12 + start_date.month) - (@start_date.year * 12 + @start_date.month))
end end
add_interval = 0 if add_interval < 0 add_interval = 0 if add_interval < 0
add_interval = add_interval.send(period_str) add_interval = add_interval.send(period_str)