Class: Jirarest2Field::DateTimeField

Inherits:
DateField show all
Defined in:
lib/jirarest2/field.rb

Overview

A field resembling a DateTime

Instance Attribute Summary

Attributes inherited from Field

#allowed_values, #id, #name, #raw_value, #readonly, #required

Instance Method Summary collapse

Methods inherited from DateField

#to_j_inner, #value

Methods inherited from Field

#createmeta, #initialize, #value, #value_allowed?

Constructor Details

This class inherits a constructor from Jirarest2Field::Field

Instance Method Details

#parse_value(jvalue) ⇒ Object

Parse the value of this field as sent by the server



227
228
229
230
# File 'lib/jirarest2/field.rb', line 227

def parse_value(jvalue)
  super
  @value = DateTime.parse(jvalue)
end

#to_j(value = @value) ⇒ Hash

Representation to be used for json and JIRA(tm) JIRA(tm) expects certain format which we try to accomodate here

Returns:

  • (Hash)


235
236
237
238
239
240
241
242
# File 'lib/jirarest2/field.rb', line 235

def to_j(value = @value)
  if value.nil? then
    super(nil)
  else
    strvalue = value.strftime("%FT%T.%L%z")
    super(strvalue)
  end
end

#value=(content) ⇒ Object

Set the value

Parameters:

  • content (String)

    The DateTime in a string representation (Use “YYYY-MM-DD HH:MM:SS” although others like “HH:MM:SS YYYY-MM-DD” or “HH:MM:SS DD.MM.YYYY” work too. See DateTime.parse )



220
221
222
223
# File 'lib/jirarest2/field.rb', line 220

def value=(content)
  value = DateTime.parse(content)
  @value = value if value_allowed?(value)
end