Skip to content

Commit

Permalink
#55 days optional
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Aug 7, 2024
1 parent 039c3b9 commit 4e478ce
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
14 changes: 8 additions & 6 deletions lib/fbe/regularly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,9 @@
require_relative '../fbe'
require_relative 'fb'

def Fbe.regularly(area, days, interval, fb: Fbe.fb, judge: $judge, loog: $loog, &)
pmp = fb.query("(and (eq what 'pmp') (eq area '#{area}') (exists #{days}))").each.to_a.first
days = pmp.nil? ? 28 : pmp[days].first
since = Time.now - (days * 24 * 60 * 60)
interval = pmp.nil? ? 7 : pmp[interval].first
def Fbe.regularly(area, p_every_days, p_since_days = nil, fb: Fbe.fb, judge: $judge, loog: $loog, &)
pmp = fb.query("(and (eq what 'pmp') (eq area '#{area}') (exists #{p_every_days}))").each.to_a.first
interval = pmp.nil? ? 7 : pmp[p_every_days].first
unless fb.query(
"(and
(eq what '#{judge}')
Expand All @@ -41,6 +39,10 @@ def Fbe.regularly(area, days, interval, fb: Fbe.fb, judge: $judge, loog: $loog,
f = fb.insert
f.what = judge
f.when = Time.now
f.since = since
unless p_since_days.nil?
days = pmp.nil? ? 28 : pmp[p_since_days].first
since = Time.now - (days * 24 * 60 * 60)
f.since = since
end
yield f
end
4 changes: 3 additions & 1 deletion test/fbe/test_award.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
# SOFTWARE.

require 'minitest/autorun'
require 'loog'
require_relative '../test__helper'
require_relative '../../lib/fbe/award'

Expand Down Expand Up @@ -58,7 +59,8 @@ def test_simple
(set b2 (if (lt b2 at_least) b2 0))
(set b2 (between b2 3 120))
(give b2 "for holding the bug open for too long (${days} days)"))
'
',
judge: '', global: {}, loog: Loog::NULL, options: nil
)
b = a.bill(hours: 10)
assert(b.points <= 100)
Expand Down
2 changes: 1 addition & 1 deletion test/fbe/test_regularly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def test_simple
loog = Loog::NULL
judge = 'test'
2.times do
Fbe.regularly('pmp', 'days', 'interval', fb:, loog:, judge:) do |f|
Fbe.regularly('pmp', 'interval', 'days', fb:, loog:, judge:) do |f|
f.foo = 42
end
end
Expand Down

0 comments on commit 4e478ce

Please sign in to comment.