Class: ZonelessTime::TimeWithoutZone
- Inherits:
-
Object
- Object
- ZonelessTime::TimeWithoutZone
- Defined in:
- lib/zoneless_time/time_without_zone.rb
Constant Summary collapse
- RFC2822_DAY_NAME =
Time::RFC2822_DAY_NAME
- RFC2822_MONTH_NAME =
Time::RFC2822_MONTH_NAME
Instance Attribute Summary collapse
-
#date ⇒ Object
Returns the value of attribute date.
-
#hour ⇒ Object
Returns the value of attribute hour.
-
#min ⇒ Object
Returns the value of attribute min.
-
#sec ⇒ Object
Returns the value of attribute sec.
-
#usec ⇒ Object
Returns the value of attribute usec.
Class Method Summary collapse
Instance Method Summary collapse
- #+(amount) ⇒ Object
- #-(amount) ⇒ Object
- #<(other) ⇒ Object
- #<=(other) ⇒ Object
- #<=>(other) ⇒ Object
- #==(other) ⇒ Object
- #>(other) ⇒ Object
- #>=(other) ⇒ Object
- #acts_like?(sym) ⇒ Boolean
- #day ⇒ Object
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
- #in_time_zone(*args) ⇒ Object
-
#initialize(year, month, day, hour, min, sec, usec = 0) ⇒ TimeWithoutZone
constructor
A new instance of TimeWithoutZone.
- #inspect ⇒ Object
- #local ⇒ Object
- #matches?(other) ⇒ Boolean
- #month ⇒ Object
- #seconds_since_midnight ⇒ Object
- #since(amount) ⇒ Object
- #strftime(*args) ⇒ Object
- #to_date ⇒ Object
- #to_i ⇒ Object
- #to_s(type = nil) ⇒ Object
- #to_time ⇒ Object
- #until(amount) ⇒ Object
- #wday ⇒ Object
- #without_zone ⇒ Object
- #xmlschema ⇒ Object
- #year ⇒ Object
Constructor Details
#initialize(year, month, day, hour, min, sec, usec = 0) ⇒ TimeWithoutZone
Returns a new instance of TimeWithoutZone.
53 54 55 56 57 58 59 |
# File 'lib/zoneless_time/time_without_zone.rb', line 53 def initialize(year,month,day,hour,min,sec,usec=0) @date = Date.new(year,month,day) @hour = hour @min = min @sec = sec @usec = usec end |
Instance Attribute Details
#date ⇒ Object
Returns the value of attribute date.
3 4 5 |
# File 'lib/zoneless_time/time_without_zone.rb', line 3 def date @date end |
#hour ⇒ Object
Returns the value of attribute hour.
3 4 5 |
# File 'lib/zoneless_time/time_without_zone.rb', line 3 def hour @hour end |
#min ⇒ Object
Returns the value of attribute min.
3 4 5 |
# File 'lib/zoneless_time/time_without_zone.rb', line 3 def min @min end |
#sec ⇒ Object
Returns the value of attribute sec.
3 4 5 |
# File 'lib/zoneless_time/time_without_zone.rb', line 3 def sec @sec end |
#usec ⇒ Object
Returns the value of attribute usec.
3 4 5 |
# File 'lib/zoneless_time/time_without_zone.rb', line 3 def usec @usec end |
Class Method Details
.at(time) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/zoneless_time/time_without_zone.rb', line 144 def at(time) if time.nil? nil elsif time.is_a? self time elsif time.acts_like? :time from_time time else from_time Time.at(time) end end |
Instance Method Details
#+(amount) ⇒ Object
32 33 34 |
# File 'lib/zoneless_time/time_without_zone.rb', line 32 def +(amount) (to_time + amount).without_zone end |
#-(amount) ⇒ Object
36 37 38 39 40 41 42 43 |
# File 'lib/zoneless_time/time_without_zone.rb', line 36 def -(amount) result = if amount.is_a? Fixnum to_time - amount else to_time - amount.to_time end (result.is_a? Time) ? result.without_zone : result end |
#<(other) ⇒ Object
24 25 26 |
# File 'lib/zoneless_time/time_without_zone.rb', line 24 def <(other) to_i < other.to_time.to_i end |
#<=(other) ⇒ Object
28 29 30 |
# File 'lib/zoneless_time/time_without_zone.rb', line 28 def <=(other) to_i <= other.to_time.to_i end |
#<=>(other) ⇒ Object
12 13 14 |
# File 'lib/zoneless_time/time_without_zone.rb', line 12 def <=>(other) to_i <=> other.to_time.to_i end |
#==(other) ⇒ Object
126 127 128 |
# File 'lib/zoneless_time/time_without_zone.rb', line 126 def ==(other) matches? other end |
#>(other) ⇒ Object
16 17 18 |
# File 'lib/zoneless_time/time_without_zone.rb', line 16 def >(other) to_i > other.to_time.to_i end |
#>=(other) ⇒ Object
20 21 22 |
# File 'lib/zoneless_time/time_without_zone.rb', line 20 def >=(other) to_i >= other.to_time.to_i end |
#acts_like?(sym) ⇒ Boolean
134 135 136 |
# File 'lib/zoneless_time/time_without_zone.rb', line 134 def acts_like?(sym) [:date, :time].include? sym end |
#day ⇒ Object
67 68 69 |
# File 'lib/zoneless_time/time_without_zone.rb', line 67 def day date.day end |
#eql?(other) ⇒ Boolean
130 131 132 |
# File 'lib/zoneless_time/time_without_zone.rb', line 130 def eql?(other) self == other end |
#hash ⇒ Object
94 95 96 |
# File 'lib/zoneless_time/time_without_zone.rb', line 94 def hash self.class.hash ^ to_i end |
#in_time_zone(*args) ⇒ Object
102 103 104 |
# File 'lib/zoneless_time/time_without_zone.rb', line 102 def in_time_zone(*args) dup end |
#inspect ⇒ Object
86 87 88 |
# File 'lib/zoneless_time/time_without_zone.rb', line 86 def inspect to_s end |
#local ⇒ Object
106 107 108 |
# File 'lib/zoneless_time/time_without_zone.rb', line 106 def local dup end |
#matches?(other) ⇒ Boolean
114 115 116 |
# File 'lib/zoneless_time/time_without_zone.rb', line 114 def matches?(other) [:year, :month, :day, :hour, :min, :sec].all? { |sym| other.send(sym) == self.send(sym) } end |
#month ⇒ Object
64 65 66 |
# File 'lib/zoneless_time/time_without_zone.rb', line 64 def month date.month end |
#seconds_since_midnight ⇒ Object
74 75 76 |
# File 'lib/zoneless_time/time_without_zone.rb', line 74 def seconds_since_midnight ((60 * hour) + min) * 60 + sec end |
#since(amount) ⇒ Object
45 46 47 |
# File 'lib/zoneless_time/time_without_zone.rb', line 45 def since(amount) self + amount end |
#strftime(*args) ⇒ Object
110 111 112 |
# File 'lib/zoneless_time/time_without_zone.rb', line 110 def strftime(*args) to_time.strftime *args end |
#to_date ⇒ Object
122 123 124 |
# File 'lib/zoneless_time/time_without_zone.rb', line 122 def to_date Date.new(year, month, day) end |
#to_i ⇒ Object
90 91 92 |
# File 'lib/zoneless_time/time_without_zone.rb', line 90 def to_i to_time.to_i end |
#to_s(type = nil) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/zoneless_time/time_without_zone.rb', line 78 def to_s(type=nil) if type == :db "#{year}-#{two_char month}-#{two_char day} #{two_char hour}:#{two_char min}:#{two_char sec}" else "#{RFC2822_DAY_NAME[wday]} #{RFC2822_MONTH_NAME[month-1]} #{day} #{two_char hour}:#{two_char min}:#{two_char sec} #{year}" end end |
#to_time ⇒ Object
118 119 120 |
# File 'lib/zoneless_time/time_without_zone.rb', line 118 def to_time Time.local(year, month, day, hour, min, sec, usec) end |
#until(amount) ⇒ Object
49 50 51 |
# File 'lib/zoneless_time/time_without_zone.rb', line 49 def until(amount) self - amount end |
#wday ⇒ Object
70 71 72 |
# File 'lib/zoneless_time/time_without_zone.rb', line 70 def wday date.wday end |
#without_zone ⇒ Object
98 99 100 |
# File 'lib/zoneless_time/time_without_zone.rb', line 98 def without_zone dup end |
#xmlschema ⇒ Object
8 9 10 |
# File 'lib/zoneless_time/time_without_zone.rb', line 8 def xmlschema to_time.xmlschema.gsub(/\+.*\Z/, '') end |
#year ⇒ Object
61 62 63 |
# File 'lib/zoneless_time/time_without_zone.rb', line 61 def year date.year end |