Class: Mediaflux::Time

Inherits:
Object
  • Object
show all
Defined in:
app/models/mediaflux/time.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.format_date_for_mediaflux(iso8601_date) ⇒ Object

Transform iso8601 dates to MediaFlux expected format

Examples:

Mediaflux::Time.format_date_for_mediaflux("2024-02-26T10:33:11-05:00") => "22-FEB-2024 13:57:19"


28
29
30
31
# File 'app/models/mediaflux/time.rb', line 28

def self.format_date_for_mediaflux(iso8601_date)
  return if iso8601_date.nil?
  Object::Time.zone.parse(iso8601_date).strftime("%e-%b-%Y %H:%M:%S").upcase
end

Instance Method Details

#convert(xml_snip:) ⇒ String

Converts the givin time snippet into local princeton time while accounting for potential time zone of the asset.

Parameters:

  • xml_snip (:nokigiri)

    , response_xml from a mediaflux request

Returns:

  • (String)

    returns a iso8601 Princeton time value.



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/mediaflux/time.rb', line 8

def convert(xml_snip:)
  xml = xml_snip
  time = xml.text.to_time
  gmt = xml.xpath("./@gmt-offset").text.to_f

  if gmt.zero?
    return time.in_time_zone("America/New_York").iso8601
  elsif gmt.positive?
    time -= gmt.hours
  else
    time += gmt.hours
  end

  princeton_time = time.in_time_zone("America/New_York").iso8601
  princeton_time
end