Module: Nexpose::ISO8601

Defined in:
lib/nexpose/util.rb

Overview

Function module for converting to ISO 8601 and UTC dates expected by 2.0 API.

Class Method Summary collapse

Class Method Details

.to_string(time = Time.now) ⇒ String

Convert a time object into a UTC ISO 8601 basic date-time format.

Parameters:

  • time (Time|Date|DateTime) (defaults to: Time.now)

    Time to convert.

Returns:

  • (String)

    ISO 8601 basic representation.



104
105
106
# File 'lib/nexpose/util.rb', line 104

def to_string(time = Time.now)
  time.to_time.utc.strftime('%Y%m%dT%H%M%S.%LZ')
end

.to_time(time_string) ⇒ Time

Convert a string representation into a Time object.

Parameters:

  • time_string (String)

    String representation in basic format. For example: ā€˜20141210T165822.412Zā€™

Returns:

  • (Time)

    Time, if it can be converted.



95
96
97
# File 'lib/nexpose/util.rb', line 95

def to_time(time_string)
  Time.strptime(time_string.to_s, '%Y%m%dT%H%M%S.%L%Z')
end