Module: ByStar::Kernel::Date

Defined in:
lib/by_star/kernel/date.rb

Instance Method Summary collapse

Instance Method Details

#beginning_of_calendar_month(*args) ⇒ Object

A “Calendar Month” is defined as a month as it appears on a calendar, including days form previous/following months which are part of the first/last weeks of the given month.

[View source]

30
31
32
# File 'lib/by_star/kernel/date.rb', line 30

def beginning_of_calendar_month(*args)
  beginning_of_month.beginning_of_week(*args)
end

#beginning_of_fortnightObject

A “Fortnight” is defined as a two week period, with the first fortnight of the year beginning on 1st January.

[View source]

20
21
22
# File 'lib/by_star/kernel/date.rb', line 20

def beginning_of_fortnight
  beginning_of_year + 14 * ((self - beginning_of_year) / 14).to_i
end

#beginning_of_weekendObject

A “Weekend” is defined as beginning of Saturday to end of Sunday. The weekend for a given date will be the the next weekend if the day Mon-Thurs, otherwise the current weekend if the day is Fri-Sun.

[View source]

10
11
12
# File 'lib/by_star/kernel/date.rb', line 10

def beginning_of_weekend
  beginning_of_week(:monday).advance(days: 5)
end

#end_of_calendar_month(*args) ⇒ Object

[View source]

34
35
36
# File 'lib/by_star/kernel/date.rb', line 34

def end_of_calendar_month(*args)
  end_of_month.end_of_week(*args)
end

#end_of_fortnightObject

[View source]

24
25
26
# File 'lib/by_star/kernel/date.rb', line 24

def end_of_fortnight
  beginning_of_fortnight + 13
end

#end_of_weekendObject

[View source]

14
15
16
# File 'lib/by_star/kernel/date.rb', line 14

def end_of_weekend
  beginning_of_weekend + 1
end