Class: L43::Time::Wrapper

Inherits:
Object
  • Object
show all
Defined in:
lib/l43/time/wrapper.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#time ⇒ Object (readonly)

Returns the value of attribute time.



6
7
8
# File 'lib/l43/time/wrapper.rb', line 6

def time
  @time
end

Class Method Details

.from_ts(ts) ⇒ Object



9
# File 'lib/l43/time/wrapper.rb', line 9

def from_ts(ts) = new(::Time.at(ts))

Instance Method Details

#+(ts) ⇒ Object



23
24
25
# File 'lib/l43/time/wrapper.rb', line 23

def +(ts)
  self.class.from_ts(time + ts)
end

#-(ts) ⇒ Object



27
28
29
# File 'lib/l43/time/wrapper.rb', line 27

def -(ts)
  self.class.from_ts(time - ts)
end

#==(other) ⇒ Object



18
19
20
21
# File 'lib/l43/time/wrapper.rb', line 18

def ==(other) 
  return false unless self.class === other 
  other.time == time
end

#deconstruct ⇒ Object



12
13
14
15
16
# File 'lib/l43/time/wrapper.rb', line 12

def deconstruct(*)
  [
    time.year, time.month, time.day, time.hour, time.min, time.sec, seconds_since_epoch, microseconds
  ]
end

#microseconds ⇒ Object



35
# File 'lib/l43/time/wrapper.rb', line 35

def microseconds =  @__microseconds__ ||= ((time.to_f - seconds_since_epoch) * 1_000_000).to_i

#seconds_since_epoch ⇒ Object



36
# File 'lib/l43/time/wrapper.rb', line 36

def seconds_since_epoch =  @__seconds_since_epoch__ ||= time.to_i

#to_f ⇒ Object



31
# File 'lib/l43/time/wrapper.rb', line 31

def to_f = time.to_f

#to_i ⇒ Object



33
# File 'lib/l43/time/wrapper.rb', line 33

def to_i = time.to_i

#with_day(day, hour = 0, min = 0, sec = 0) ⇒ Object



38
39
40
41
# File 'lib/l43/time/wrapper.rb', line 38

def with_day(day, hour=0, min=0, sec=0)
  self => [y, m, *]
  self.class.new(y, m, day, hour, min, sec)
end

#with_month(month, day = 1, hour = 0, min = 0, sec = 0) ⇒ Object



43
44
45
# File 'lib/l43/time/wrapper.rb', line 43

def with_month(month, day=1, hour=0, min=0, sec=0)
  self.class.new(time.year, month, day, hour, min, sec)
end

#with_time(hour = 0, min = 0, sec = 0) ⇒ Object



47
48
49
50
# File 'lib/l43/time/wrapper.rb', line 47

def with_time(hour=0, min=0, sec=0)
  self => [year, month, day, *]
  self.class.new(year, month, day, hour, min, sec)
end

#with_year(year, month, day = 1, hour = 0, min = 0, sec = 0) ⇒ Object



52
53
54
55
56
# File 'lib/l43/time/wrapper.rb', line 52

def with_year(year, month, day=1, hour=0, min=0, sec=0)
  year = Integer(year)
  year += 2000 if year < 1000
  self.class.new(year, month, day, hour, min, sec)
end