Sha256: 24410ac298e74886b5bf7c8222d35bd2a4d88ea0059d2d2173f38e10925bbe2c
Contents?: true
Size: 631 Bytes
Versions: 2
Compression:
Stored size: 631 Bytes
Contents
module Repeatable module Expression class Biweekly < Date def initialize(weekday:, start_after: ::Date.today) @weekday = weekday @start_after = Date(start_after) end def include?(date) date >= start_after && (date - first_occurrence) % 14 == 0 end private attr_reader :weekday, :start_after def first_occurrence @first_occurrence ||= find_first_occurrence end 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
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
repeatable-0.6.0 | lib/repeatable/expression/biweekly.rb |
repeatable-0.5.0 | lib/repeatable/expression/biweekly.rb |