Class: Date

Inherits:
Object
  • Object
show all
Defined in:
lib/sinatra/extensions/date.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.year(year = Date.today.year) ⇒ Object



4
5
6
# File 'lib/sinatra/extensions/date.rb', line 4

def self.year(year=Date.today.year)
  Date.new(year)
end

Instance Method Details

#add_working_days(days = 1) ⇒ Object



36
37
38
39
40
41
42
# File 'lib/sinatra/extensions/date.rb', line 36

def add_working_days(days=1)
  new_date = self + days
  while (new_date.wday % 7 == 0) or (new_date.wday % 7 == 6) do
    new_date += 1
  end
  new_date
end

#december(day = nil) ⇒ Object



16
17
18
# File 'lib/sinatra/extensions/date.rb', line 16

def december(day=nil)
  day.nil?? self.change(month: 12) : self.change(month: 12, day: day)
end

#displayObject



28
29
30
# File 'lib/sinatra/extensions/date.rb', line 28

def display
  "#{Configuration::DAYS[self.wday]} #{self.day} de #{Configuration::MONTHS[self.month-1]}, #{self.year}"
end

#first_monday_beforeObject



52
53
54
55
# File 'lib/sinatra/extensions/date.rb', line 52

def first_monday_before
  return self if self.monday?
  (self - 1).first_monday_before
end

#january(day = nil) ⇒ Object



8
9
10
# File 'lib/sinatra/extensions/date.rb', line 8

def january(day=nil)
  day.nil?? self.change(month: 1) : self.change(month: 1, day: day)
end

#mondayObject



20
21
22
# File 'lib/sinatra/extensions/date.rb', line 20

def monday
  self - (self.wday - 1) % 7
end

#next_working_dateObject



44
45
46
# File 'lib/sinatra/extensions/date.rb', line 44

def next_working_date
  add_working_days(1)
end

#october(day = nil) ⇒ Object



12
13
14
# File 'lib/sinatra/extensions/date.rb', line 12

def october(day=nil)
  day.nil?? self.change(month: 10) : self.change(month: 10, day: day)
end

#prev_working_dateObject



48
49
50
# File 'lib/sinatra/extensions/date.rb', line 48

def prev_working_date
  add_working_days(-1)
end

#short_displayObject



32
33
34
# File 'lib/sinatra/extensions/date.rb', line 32

def short_display
  self.strftime('%-d/%-m/%Y')
end

#weekend?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/sinatra/extensions/date.rb', line 24

def weekend?
  self.wday == 0 || self.wday == 6
end