Module: Utilities

Extended by:
Utilities
Included in:
Utilities
Defined in:
lib/splitclient-rb_utilitites.rb

Instance Method Summary collapse

Instance Method Details

#to_epoch(value) ⇒ Object

Convert String with Time info to its epoch FixNum previously setting to zero the seconds



5
6
7
8
9
# File 'lib/splitclient-rb_utilitites.rb', line 5

def to_epoch value
  parsed = Time.parse(value)
  zeroed = Time.new(parsed.year, parsed.month, parsed.day, parsed.hour, parsed.min, 0, 0)
  zeroed.to_i
end

#to_epoch_milis(value) ⇒ Object



11
12
13
# File 'lib/splitclient-rb_utilitites.rb', line 11

def to_epoch_milis value
  (to_epoch (value)) * 1000
end

#to_milis_zero_out_from_hour(value) ⇒ Object



25
26
27
28
29
30
31
32
33
# File 'lib/splitclient-rb_utilitites.rb', line 25

def to_milis_zero_out_from_hour value
  begin
    parsed_value = Time.strptime(value.to_s,'%s').utc
    zeroed = Time.new(parsed_value.year, parsed_value.month, parsed_value.day, 0, 0, 0, 0)
    return zeroed.to_i*1000
  rescue
    return :non_valid_date_info
  end
end

#to_milis_zero_out_from_seconds(value) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/splitclient-rb_utilitites.rb', line 15

def to_milis_zero_out_from_seconds value
  begin
    parsed_value = Time.strptime(value.to_s,'%s').utc
    zeroed = Time.new(parsed_value.year, parsed_value.month, parsed_value.day, parsed_value.hour, parsed_value.min, 0, 0)
    return zeroed.to_i*1000
  rescue
    return :non_valid_date_info
  end
end