Skip to content

Commit

Permalink
EndOf#expiration_of(...) always returns #final_date
Browse files Browse the repository at this point in the history
#final_date is when it will (or already has) expire(d)
  • Loading branch information
jdowd committed Sep 1, 2024
1 parent 870b24c commit 7d15ffc
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
12 changes: 4 additions & 8 deletions lib/sof/cycles/end_of.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,17 @@ def to_s
"#{volume}x by #{final_date.to_fs(:american)}"
end

# Returns the expiration date for the cycle, based on the given anchor date
# Returns the expiration date for the cycle
#
# @param [nil] _ Unused parameter, maintained for compatibility
# @param anchor [Date] The date to check against (default: current date)
# @return [Date, nil] The final date of the cycle if satisfied, nil otherwise
# @param anchor [nil] _ Unused parameter, maintained for compatibility
# @return [Date] The final date of the cycle
#
# @example
# Cycle.for("V1E18MF2020-01-09")
# .expiration_of(anchor: "2020-06-04".to_date)
# # => #<Date: 2021-06-30>
def expiration_of(_ = nil, anchor: Date.current)
return unless satisfied_by?(anchor:)

final_date
end
def expiration_of(_ = nil, anchor: nil) = final_date

# Is the supplied anchor date prior to the final date?
#
Expand Down
4 changes: 2 additions & 2 deletions spec/sof/cycles/end_of_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ module SOF
context "when the anchor date > the final date" do
let(:anchor) { "2021-07-31".to_date }

it "returns nil" do
expect(cycle.expiration_of(anchor:)).to be_nil
it "returns the final date" do
expect(cycle.expiration_of(anchor:)).to eq "2021-06-30".to_date
end
end
end
Expand Down

0 comments on commit 7d15ffc

Please sign in to comment.