Class: ICalPal::RDT
- Inherits:
-
DateTime
- Object
- DateTime
- ICalPal::RDT
- Defined in:
- lib/rdt.rb
Overview
Child class of DateTime that adds support for relative dates (RelativeDateTime).
Class Method Summary collapse
-
.conv(str) ⇒ RDT
Convert a String to an RDT.
Instance Method Summary collapse
- #==(obj) ⇒ Boolean
-
#to_a ⇒ Array
Self as an array.
-
#to_i ⇒ Integer
Seconds since epoch.
-
#to_s ⇒ String
(also: #inspect)
Values can be day before yesterday,
yesterday
,today
,tomorrow
, day after tomorrow, or the result from strftime.
Class Method Details
.conv(str) ⇒ RDT
Convert a String to an RDT
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rdt.rb', line 12 def self.conv(str) case str when 'yesterday' then $today - 1 when 'today' then $today when 'tomorrow' then $today + 1 when /^\+([0-9]+)/ then $today + $1.to_i when /^\-([0-9]+)/ then $today - $1.to_i else parse(str) end end |
Instance Method Details
#==(obj) ⇒ Boolean
59 60 61 |
# File 'lib/rdt.rb', line 59 def ==(obj) self.to_s == obj.to_s end |
#to_a ⇒ Array
Returns Self as an array.
47 48 49 |
# File 'lib/rdt.rb', line 47 def to_a [ year, month, day, hour, min, sec ] end |
#to_i ⇒ Integer
Returns Seconds since epoch.
52 53 54 |
# File 'lib/rdt.rb', line 52 def to_i to_time.to_i end |
#to_s ⇒ String Also known as: inspect
Values can be day before yesterday, yesterday
, today
, tomorrow
, day after tomorrow, or the result from strftime
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/rdt.rb', line 29 def to_s return strftime($opts[:df]) if $opts[:nrd] && $opts[:df] case Integer(RDT.new(year, month, day) - $today) when -2 then 'day before yesterday' when -1 then 'yesterday' when 0 then 'today' when 1 then 'tomorrow' when 2 then 'day after tomorrow' else strftime($opts[:df]) if $opts[:df] end end |