Class: Time
- Inherits:
-
Object
- Object
- Time
- Includes:
- Date_locale
- Defined in:
- lib/date_tools/date_time_compare.rb,
lib/date_tools/date_locale.rb
Overview
Adaption to allow comparison of time and date
Constant Summary
Constants included from Date_locale
Class Method Summary collapse
-
.sec2time(sec) ⇒ Object
Build a string with number of days, hours …
Instance Method Summary collapse
-
#cwday ⇒ Object
Simulate Date#cwday.
- #cweek ⇒ Object
-
#cwyear ⇒ Object
Simulate Date#cwyear.
-
#strftime(format = '%F', lang = nil) ⇒ Object
Redefine strftime for locale versions.
- #strftime_orig ⇒ Object
-
#timediff(time2) ⇒ Object
Calculate the difference (no negative times) and build the diff-string.
-
#to_date ⇒ Object
Convert Time object to a Date object.
Methods included from Date_locale
get_language_key, locale?, set_target_encoding, #strftime_locale
Class Method Details
.sec2time(sec) ⇒ Object
Build a string with number of days, hours … for the given seconds. Only positive seconds allowed.
37 38 39 40 41 42 43 |
# File 'lib/date_tools/date_time_compare.rb', line 37 def self.sec2time( sec ) raise "No negative time" if sec < 0 days, sec = sec.divmod(86400) # 60*60*24 hours, sec = sec.divmod(3600) # 60*60 min, sec = sec.divmod(60) # 60*60 return "#{days}d #{hours}h #{min}m #{sec}s" end |
Instance Method Details
#cwday ⇒ Object
Simulate Date#cwday
13 14 15 |
# File 'lib/date_tools/date_time_compare.rb', line 13 def cwday() return self.to_date.cwday end |
#cweek ⇒ Object
20 21 22 23 24 |
# File 'lib/date_tools/date_time_compare.rb', line 20 def cweek() #~ return [1,self.strftime_d('%W').to_i].max #~ return self.strftime_d('%W').to_i #Wrong, not ISO 8601 return self.to_date.cweek end |
#cwyear ⇒ Object
Simulate Date#cwyear
26 27 28 |
# File 'lib/date_tools/date_time_compare.rb', line 26 def cwyear() return self.to_date.cwyear end |
#strftime(format = '%F', lang = nil) ⇒ Object
Redefine strftime for locale versions.
276 277 278 |
# File 'lib/date_tools/date_locale.rb', line 276 def strftime(format='%F', lang = nil ) return strftime_locale(format, lang ) end |
#strftime_orig ⇒ Object
274 |
# File 'lib/date_tools/date_locale.rb', line 274 alias :strftime_orig :strftime |
#timediff(time2) ⇒ Object
Calculate the difference (no negative times) and build the diff-string.
31 32 33 |
# File 'lib/date_tools/date_time_compare.rb', line 31 def timediff( time2 ) return Time.sec2time( ( self - time2 ).abs ) end |
#to_date ⇒ Object
Convert Time object to a Date object.
9 10 11 |
# File 'lib/date_tools/date_time_compare.rb', line 9 def to_date() return Date.new( self.year, self.month, self.day ) end |