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.44 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.43 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.42 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.41 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.40 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.39 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.38 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.37 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.36 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.35 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.34 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.33 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.32 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.31 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.30 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.29 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.28 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.27 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.26 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb
ree_lib-1.0.24 lib/ree_lib/packages/ree_datetime/package/ree_datetime/functions/beginning_of_week.rb