Sha256: 6b6ee70be535243845f5c793d423f6e270c9cef9e3f941b2e1603cdb763a6299

Contents?: true

Size: 1.02 KB

Versions: 124

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

class ReeDatetime::NextOccurring
  include Ree::FnDSL

  fn :next_occurring do
    link :now
    link :change
    link :next_occurring, from: :ree_date
  end

  doc(<<~DOC)
  # Returns a new date/time representing the next occurrence of the specified day of week.
  # 
  #   now                              # => Tue, 24 May 2022 13:15:20
  #   date_time (optional)                  # => Thu, 14 Dec 2017 13:15:20
  #   next_occurring(date_time, :monday)    # => Mon, 18 Dec 2017 13:15:20
  #   next_occurring(date_time, :thursday)  # => Thu, 21 Dec 2017 13:15:20
  #   next_occurring(:thursday)        # => Thu, 2  Jun 2022 13:15:20
  DOC
  contract(
    Nilor[DateTime], 
    Or[
      :monday,
      :tuesday, 
      :wednesday, 
      :thursday, 
      :friday, 
      :saturday, 
      :sunday
    ] => DateTime
  )
  def call(date_time = nil, week_day)
    date_time = date_time || now
    change(next_occurring(date_time, week_day), hour: date_time.hour, min: date_time.min, sec: date_time.sec)
  end
end

Version data entries

124 entries across 124 versions & 1 rubygems

Version Path
ree_lib-1.0.124 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.123 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.122 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.121 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.120 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.119 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.118 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.117 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.116 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.115 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.114 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.113 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.112 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.111 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.110 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.109 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.108 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.107 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.106 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb
ree_lib-1.0.105 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/next_occurring.rb