Class: Chronic::MiniDate
- Inherits:
-
Object
- Object
- Chronic::MiniDate
- Defined in:
- lib/chronic/mini_date.rb
Instance Attribute Summary collapse
-
#day ⇒ Object
Returns the value of attribute day.
-
#month ⇒ Object
Returns the value of attribute month.
Class Method Summary collapse
Instance Method Summary collapse
- #equals?(other) ⇒ Boolean
-
#initialize(month, day) ⇒ MiniDate
constructor
A new instance of MiniDate.
- #is_between?(md_start, md_end) ⇒ Boolean
Constructor Details
#initialize(month, day) ⇒ MiniDate
Returns a new instance of MiniDate.
9 10 11 12 13 14 15 16 |
# File 'lib/chronic/mini_date.rb', line 9 def initialize(month, day) unless (1..12).include?(month) raise ArgumentError, "1..12 are valid months" end @month = month @day = day end |
Instance Attribute Details
#day ⇒ Object
Returns the value of attribute day.
3 4 5 |
# File 'lib/chronic/mini_date.rb', line 3 def day @day end |
#month ⇒ Object
Returns the value of attribute month.
3 4 5 |
# File 'lib/chronic/mini_date.rb', line 3 def month @month end |
Class Method Details
.from_time(time) ⇒ Object
5 6 7 |
# File 'lib/chronic/mini_date.rb', line 5 def self.from_time(time) new(time.month, time.day) end |
Instance Method Details
#equals?(other) ⇒ Boolean
34 35 36 |
# File 'lib/chronic/mini_date.rb', line 34 def equals?(other) @month == other.month and @day == other.day end |
#is_between?(md_start, md_end) ⇒ Boolean
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/chronic/mini_date.rb', line 18 def is_between?(md_start, md_end) return false if (@month == md_start.month && @month == md_end.month) && (@day < md_start.day || @day > md_end.day) return true if (@month == md_start.month && @day >= md_start.day) || (@month == md_end.month && @day <= md_end.day) i = (md_start.month % 12) + 1 until i == md_end.month return true if @month == i i = (i % 12) + 1 end return false end |