Module: UU::AppLog::ApplicationLog::TimeConversions

Included in:
ApplicationLogAddRecord, ApplicationLogGetRecordList, ApplicationLogRecordAttributes
Defined in:
uu_applog-0.27.16/lib/uu/applog/application_log/time_conversions.rb

Overview

Time conversion helper.

Examples:

Intended use

class UU::AppLog::SystemLog::Foo
  include TimeConversions

  def bar(val)
    time = parse_time(val)
  end
end

Constant Summary

Instance Method Summary (collapse)

Instance Method Details

- (Time) parse_time(val)

Parses the given value into an instance of Time representing time in local time.

Parameters:

  • val (String, Fixnum, Float)

    The input value. Either a String in ISO8601 format or a number representing one of values supported by Time.at method.

Returns:

  • (Time)

    Time object corresponding to the input value.

See Also:



25
26
27
28
29
30
31
32
33
34
35
# File 'uu_applog-0.27.16/lib/uu/applog/application_log/time_conversions.rb', line 25

def parse_time(val)
  result = nil
  if val
    if val.kind_of?String
      result = Time.parse(val).getlocal
    elsif (val.kind_of?Fixnum) || (val.kind_of?Float)
      result = Time.at(val / 1000.0).getlocal
    end
  end
  result
end

- (String) to_iso8601(val)

Converts the given value to a String in ISO8601 format.

Parameters:

  • val (String, DateTime, Time)

    The input value.

Returns:

  • (String)

    String representing time in ISO8601 format.



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'uu_applog-0.27.16/lib/uu/applog/application_log/time_conversions.rb', line 40

def to_iso8601(val)
  result = nil
  if val
    if val.kind_of?String
      result = Time.parse(val).iso8601(FRACTION_DIGITS)
    elsif val.kind_of?Time
      result = val.iso8601(FRACTION_DIGITS)
    elsif val.kind_of?DateTime
      result = val.to_time.iso8601(FRACTION_DIGITS)
    end
  end
  result
end