Class: TimeInterval

Inherits:
Object
  • Object
show all
Defined in:
lib/rubko/plugins/db.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mon, day, usec) ⇒ TimeInterval

this class directly adheres to Postgres’s internal INTERVAL representation



358
359
360
361
362
# File 'lib/rubko/plugins/db.rb', line 358

def initialize(mon, day, usec)
	@mon = mon
	@day = day
	@usec = usec
end

Instance Attribute Details

#dayObject

Returns the value of attribute day.



364
365
366
# File 'lib/rubko/plugins/db.rb', line 364

def day
  @day
end

#monObject

Returns the value of attribute mon.



364
365
366
# File 'lib/rubko/plugins/db.rb', line 364

def mon
  @mon
end

#usecObject

Returns the value of attribute usec.



364
365
366
# File 'lib/rubko/plugins/db.rb', line 364

def usec
  @usec
end

Instance Method Details

#+(time) ⇒ Object



370
371
372
# File 'lib/rubko/plugins/db.rb', line 370

def +(time)
	( (time >> mon) + day ).to_time + usec/1_000_000.0
end

#to_fObject



378
379
380
# File 'lib/rubko/plugins/db.rb', line 378

def to_f
	to_time.to_f
end

#to_iObject



382
383
384
# File 'lib/rubko/plugins/db.rb', line 382

def to_i
	to_time.to_i
end

#to_jsonObject



386
387
388
# File 'lib/rubko/plugins/db.rb', line 386

def to_json(*)
	to_f.to_s
end

#to_sObject



366
367
368
# File 'lib/rubko/plugins/db.rb', line 366

def to_s
	"#{mon}mon #{day}day #{usec}usec"
end

#to_timeObject



374
375
376
# File 'lib/rubko/plugins/db.rb', line 374

def to_time
	self + DateTime.new(1970)
end