Sha256: ba416ebc354a429b91e09ddbedce657445b37c41ff89280cbe94353ea3914f44

Contents?: true

Size: 841 Bytes

Versions: 124

Compression:

Stored size: 841 Bytes

Contents

# frozen_string_literal: true

class ReeDatetime::BeginningOfWeek
  include Ree::FnDSL

  fn :beginning_of_week do
    link :now
    link :change
    link :beginning_of_day    
    link :beginning_of_week, from: :ree_date
  end

  doc(<<~DOC)
    Returns a new date/time at the start of the week.
    If no date_time passed returns date/time at the start of the current week.
    
      date_time(optional) => Wed, 25 May 2022 13:00:00
      beginning_of_week(date_time, :monday) # => Mon, 23 May 2022 00:00:00
      beginning_of_week(date_time, :sunday) # => Sun, 22 May 2022 00:00:00
    Week is assumed to start on +week_start+ (monday or sunday).
  DOC
  contract(Nilor[DateTime], Or[:sunday, :monday] => DateTime)
  def call(date_time = nil, week_start)
    beginning_of_day(beginning_of_week((date_time || now), week_start)) 
  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/beginning_of_week.rb
ree_lib-1.0.123 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.122 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.121 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.120 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.119 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.118 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.117 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.116 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.115 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.114 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.113 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.112 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.111 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.110 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.109 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.108 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.107 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.106 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.105 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb