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
- #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.
45 46 47 48 49 50 51 |
# File 'lib/zoneless_time/time_without_zone.rb', line 45 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
136 137 138 139 140 141 142 143 144 145 146 |
# File 'lib/zoneless_time/time_without_zone.rb', line 136 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
24 25 26 |
# File 'lib/zoneless_time/time_without_zone.rb', line 24 def +(amount) (to_time + amount).without_zone end |
#-(amount) ⇒ Object
28 29 30 31 32 33 34 35 |
# File 'lib/zoneless_time/time_without_zone.rb', line 28 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
20 21 22 |
# File 'lib/zoneless_time/time_without_zone.rb', line 20 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
118 119 120 |
# File 'lib/zoneless_time/time_without_zone.rb', line 118 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 |
#acts_like?(sym) ⇒ Boolean
126 127 128 |
# File 'lib/zoneless_time/time_without_zone.rb', line 126 def acts_like?(sym) [:date, :time].include? sym end |
#day ⇒ Object
59 60 61 |
# File 'lib/zoneless_time/time_without_zone.rb', line 59 def day date.day end |
#eql?(other) ⇒ Boolean
122 123 124 |
# File 'lib/zoneless_time/time_without_zone.rb', line 122 def eql?(other) self == other end |
#hash ⇒ Object
86 87 88 |
# File 'lib/zoneless_time/time_without_zone.rb', line 86 def hash self.class.hash ^ to_i end |
#in_time_zone(*args) ⇒ Object
94 95 96 |
# File 'lib/zoneless_time/time_without_zone.rb', line 94 def in_time_zone(*args) dup end |
#inspect ⇒ Object
78 79 80 |
# File 'lib/zoneless_time/time_without_zone.rb', line 78 def inspect to_s end |
#local ⇒ Object
98 99 100 |
# File 'lib/zoneless_time/time_without_zone.rb', line 98 def local dup end |
#matches?(other) ⇒ Boolean
106 107 108 |
# File 'lib/zoneless_time/time_without_zone.rb', line 106 def matches?(other) [:year, :month, :day, :hour, :min, :sec].all? { |sym| other.send(sym) == self.send(sym) } end |
#month ⇒ Object
56 57 58 |
# File 'lib/zoneless_time/time_without_zone.rb', line 56 def month date.month end |
#seconds_since_midnight ⇒ Object
66 67 68 |
# File 'lib/zoneless_time/time_without_zone.rb', line 66 def seconds_since_midnight ((60 * hour) + min) * 60 + sec end |
#since(amount) ⇒ Object
37 38 39 |
# File 'lib/zoneless_time/time_without_zone.rb', line 37 def since(amount) self + amount end |
#strftime(*args) ⇒ Object
102 103 104 |
# File 'lib/zoneless_time/time_without_zone.rb', line 102 def strftime(*args) to_time.strftime *args end |
#to_date ⇒ Object
114 115 116 |
# File 'lib/zoneless_time/time_without_zone.rb', line 114 def to_date Date.new(year, month, day) end |
#to_i ⇒ Object
82 83 84 |
# File 'lib/zoneless_time/time_without_zone.rb', line 82 def to_i to_time.to_i end |
#to_s(type = nil) ⇒ Object
70 71 72 73 74 75 76 |
# File 'lib/zoneless_time/time_without_zone.rb', line 70 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
110 111 112 |
# File 'lib/zoneless_time/time_without_zone.rb', line 110 def to_time Time.local(year, month, day, hour, min, sec, usec) end |
#until(amount) ⇒ Object
41 42 43 |
# File 'lib/zoneless_time/time_without_zone.rb', line 41 def until(amount) self - amount end |
#wday ⇒ Object
62 63 64 |
# File 'lib/zoneless_time/time_without_zone.rb', line 62 def wday date.wday end |
#without_zone ⇒ Object
90 91 92 |
# File 'lib/zoneless_time/time_without_zone.rb', line 90 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
53 54 55 |
# File 'lib/zoneless_time/time_without_zone.rb', line 53 def year date.year end |