Class: BellyWash::Nocturnal
- Inherits:
-
Object
- Object
- BellyWash::Nocturnal
- Defined in:
- lib/belly_wash/nocturnal.rb
Constant Summary collapse
- DAYS_INTO_WEEK =
{ sunday: 0, monday: 1, tuesday: 2, wednesday: 3, thursday: 4, friday: 5, saturday: 6 }.freeze
Class Method Summary collapse
Instance Method Summary collapse
- #beginning_of_day ⇒ Object
- #beginning_of_hour ⇒ Object
- #beginning_of_minute ⇒ Object
- #beginning_of_month ⇒ Object
- #beginning_of_quarter ⇒ Object
- #beginning_of_week ⇒ Object
- #beginning_of_year ⇒ Object
- #change(**fractions) ⇒ Object
- #days_to_week_start ⇒ Object
-
#initialize(at) ⇒ Nocturnal
constructor
A new instance of Nocturnal.
- #next_day ⇒ Object
- #next_hour ⇒ Object
- #next_minute ⇒ Object
- #next_month ⇒ Object
- #next_quarter ⇒ Object
- #next_week ⇒ Object
- #next_year ⇒ Object
Constructor Details
Class Method Details
.timeline(from:, to:, range:) ⇒ Object
10 11 12 13 14 15 16 17 18 |
# File 'lib/belly_wash/nocturnal.rb', line 10 def self.timeline(from:, to:, range:) list = [] item = new(from).send("beginning_of_#{range}") while item < to list << item item = BellyWash::Nocturnal.new(list.last).send("next_#{range}") end list end |
Instance Method Details
#beginning_of_day ⇒ Object
57 58 59 |
# File 'lib/belly_wash/nocturnal.rb', line 57 def beginning_of_day change(hour: 0, minute: 0) end |
#beginning_of_hour ⇒ Object
47 48 49 |
# File 'lib/belly_wash/nocturnal.rb', line 47 def beginning_of_hour change(minute: 0) end |
#beginning_of_minute ⇒ Object
37 38 39 |
# File 'lib/belly_wash/nocturnal.rb', line 37 def beginning_of_minute change end |
#beginning_of_month ⇒ Object
87 88 89 |
# File 'lib/belly_wash/nocturnal.rb', line 87 def beginning_of_month change(day: 1, hour: 0, minute: 0) end |
#beginning_of_quarter ⇒ Object
97 98 99 100 101 102 103 104 105 106 |
# File 'lib/belly_wash/nocturnal.rb', line 97 def beginning_of_quarter first_quarter_month = @at.month - (2 + @at.month) % 3 change( month: first_quarter_month, day: 1, hour: 0, minute: 0 ) end |
#beginning_of_week ⇒ Object
67 68 69 70 71 |
# File 'lib/belly_wash/nocturnal.rb', line 67 def beginning_of_week today = beginning_of_day (today.to_date - days_to_week_start).to_time end |
#beginning_of_year ⇒ Object
114 115 116 |
# File 'lib/belly_wash/nocturnal.rb', line 114 def beginning_of_year change(month: 1, day: 1, hour: 0, minute: 0) end |
#change(**fractions) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/belly_wash/nocturnal.rb', line 25 def change(**fractions) Time.new( fractions.fetch(:year, @at.year), fractions.fetch(:month, @at.month), fractions.fetch(:day, @at.day), fractions.fetch(:hour, @at.hour), fractions.fetch(:minute, @at.min), 0, # second @tz.utc_offset ) end |
#days_to_week_start ⇒ Object
79 80 81 82 83 84 85 |
# File 'lib/belly_wash/nocturnal.rb', line 79 def days_to_week_start start_day_number = DAYS_INTO_WEEK.fetch( BellyWash.config.beginning_of_week ) (@at.wday - start_day_number) % 7 end |
#next_day ⇒ Object
61 62 63 64 65 |
# File 'lib/belly_wash/nocturnal.rb', line 61 def next_day Nocturnal.new( beginning_of_day + 60 * 60 * 24 ).beginning_of_day end |
#next_hour ⇒ Object
51 52 53 54 55 |
# File 'lib/belly_wash/nocturnal.rb', line 51 def next_hour Nocturnal.new( beginning_of_hour + 60 * 60 ).beginning_of_hour end |
#next_minute ⇒ Object
41 42 43 44 45 |
# File 'lib/belly_wash/nocturnal.rb', line 41 def next_minute Nocturnal.new( beginning_of_minute + 60 ).beginning_of_minute end |
#next_month ⇒ Object
91 92 93 94 95 |
# File 'lib/belly_wash/nocturnal.rb', line 91 def next_month Nocturnal.new( beginning_of_month + 60 * 60 * 24 * 31 ).beginning_of_month end |
#next_quarter ⇒ Object
108 109 110 111 112 |
# File 'lib/belly_wash/nocturnal.rb', line 108 def next_quarter Nocturnal.new( beginning_of_quarter + 60 * 60 * 24 * 31 * 3 ).beginning_of_quarter end |
#next_week ⇒ Object
73 74 75 76 77 |
# File 'lib/belly_wash/nocturnal.rb', line 73 def next_week Nocturnal.new( beginning_of_week + 60 * 60 * 24 * 7 ).beginning_of_week end |
#next_year ⇒ Object
118 119 120 121 122 |
# File 'lib/belly_wash/nocturnal.rb', line 118 def next_year Nocturnal.new( beginning_of_year + 60 * 60 * 24 * 31 * 12 ).beginning_of_year end |