Sha256: 908b35e65be30ad4abf581046d6ca25c405e0a0c999d2f9745f6a4716f0363fb
Contents?: true
Size: 958 Bytes
Versions: 1
Compression:
Stored size: 958 Bytes
Contents
# typed: strict module Repeatable module Expression class Biweekly < Date sig { params(weekday: Integer, start_after: Object).void } def initialize(weekday:, start_after: ::Date.today) @weekday = weekday @start_after = T.let(Conversions::Date(start_after), ::Date) @_first_occurrence = T.let(find_first_occurrence, ::Date) end sig { override.params(date: ::Date).returns(T::Boolean) } def include?(date) date >= start_after && (date - _first_occurrence) % 14 == 0 end private sig { returns(Integer) } attr_reader :weekday sig { returns(::Date) } attr_reader :start_after sig { returns(::Date) } attr_reader :_first_occurrence sig { returns(::Date) } def find_first_occurrence days_away = weekday - start_after.wday days_away += 7 if days_away <= 0 start_after + days_away end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
repeatable-1.1.0 | lib/repeatable/expression/biweekly.rb |