Class: Date
- Inherits:
-
Object
- Object
- Date
- Includes:
- Date_locale
- Defined in:
- lib/date_tools/date_locale.rb,
lib/date_tools/date_creator.rb,
lib/date_tools/date_time_compare.rb
Overview
Adaption to allow comparison of time and date
Constant Summary
Constants included from Date_locale
Class Method Summary collapse
-
.new_by_mday(year, month, weekday, nr) ⇒ Object
Get the third monday in march 2008: new_by_mday( 2008, 3, 1, 3).
Instance Method Summary collapse
-
#strftime(format = '%F', lang = nil) ⇒ Object
Redefine strftime with flexible daynames.
- #strftime_orig ⇒ Object
-
#to_date ⇒ Object
Returns ‘me’.
Methods included from Date_locale
get_language_key, locale?, set_target_encoding, #strftime_locale
Class Method Details
.new_by_mday(year, month, weekday, nr) ⇒ Object
Get the third monday in march 2008: new_by_mday( 2008, 3, 1, 3)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/date_tools/date_creator.rb', line 16 def self.new_by_mday(year, month, weekday, nr) raise( ArgumentError, "No number for weekday/nr") unless weekday.respond_to?(:between?) and nr.respond_to?(:between?) raise( ArgumentError, "Number not in Range 1..5: #{nr}") unless nr.between?(1,5) raise( ArgumentError, "Weekday not between 0 (Sunday)and 6 (Saturday): #{nr}") unless weekday.between?(0,6) day = (weekday-Date.new(year, month, 1).wday)%7 + (nr-1)*7 + 1 if nr == 5 lastday = (Date.new(year, (month)%12+1, 1)-1).day # each december has the same no. of days raise "There are not 5 weekdays with number #{weekday} in month #{month}" if day > lastday end Date.new(year, month, day) end |
Instance Method Details
#strftime(format = '%F', lang = nil) ⇒ Object
Redefine strftime with flexible daynames.
251 252 253 |
# File 'lib/date_tools/date_locale.rb', line 251 def strftime(format = '%F', lang = nil ) return strftime_locale(format, lang ) end |
#strftime_orig ⇒ Object
247 |
# File 'lib/date_tools/date_locale.rb', line 247 alias :strftime_orig :strftime |
#to_date ⇒ Object
Returns ‘me’.
Needed like Time#to_date() if you don’t know, if you have a date or a time-object.
51 52 53 |
# File 'lib/date_tools/date_time_compare.rb', line 51 def to_date() self end |