Class: Date

Inherits:
Object show all
Defined in:
lib/dohutil/to_display.rb,
lib/dohutil/move_weekday.rb,
lib/dohutil/core_ext/date.rb,
lib/dohutil/core_ext/inspect.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.days_in_month(year, month) ⇒ Object



5
6
7
# File 'lib/dohutil/core_ext/date.rb', line 5

def self.days_in_month(year, month)
  civil(year, month, -1).mday
end

Instance Method Details

#inspectObject



6
7
8
# File 'lib/dohutil/core_ext/inspect.rb', line 6

def inspect
  "#<Date:#{strftime('%F')}>"
end

#make_datetime(hour = 0, minute = 0, second = 0, offset = 0) ⇒ Object



13
14
15
# File 'lib/dohutil/core_ext/date.rb', line 13

def make_datetime(hour = 0, minute = 0, second = 0, offset = 0)
  DateTime.new(year, month, mday, hour, minute, second, offset)
end

#make_local_datetime(hour = 0, minute = 0, second = 0) ⇒ Object



17
18
19
# File 'lib/dohutil/core_ext/date.rb', line 17

def make_local_datetime(hour = 0, minute = 0, second = 0)
  DateTime.local(year, month, mday, hour, minute, second)
end

#next_weekdayObject



4
5
6
7
8
9
10
# File 'lib/dohutil/move_weekday.rb', line 4

def next_weekday
  retval = self + 1
  until retval.weekday?
    retval += 1
  end
  retval
end

#previous_weekdayObject



12
13
14
15
16
17
18
# File 'lib/dohutil/move_weekday.rb', line 12

def previous_weekday
  retval = self - 1
  until retval.weekday?
    retval -= 1
  end
  retval
end

#to_displayObject



22
23
24
# File 'lib/dohutil/to_display.rb', line 22

def to_display
  strftime('%m/%d/%Y')
end

#weekday?Boolean

Returns:

  • (Boolean)


9
10
11
# File 'lib/dohutil/core_ext/date.rb', line 9

def weekday?
  (wday > 0) && (wday < 6)
end