Class: OAI::Provider::Response::Base

Inherits:
Object
  • Object
show all
Defined in:
backend/app/lib/oai/oai_gem_patches/date_parse_timezone_fix.rb

Direct Known Subclasses

Identify, ListSets, RecordResponse

Instance Method Summary collapse

Instance Method Details

#parse_date(value) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'backend/app/lib/oai/oai_gem_patches/date_parse_timezone_fix.rb', line 3

def parse_date(value)
  return value if value.respond_to?(:strftime)

  Date.parse(value) # This will raise an exception for badly formatted dates

  # ArchivesSpace fix: don't parse a simple date into the wrong timezone!
  #
  # The OAI gem helpfully parses the incoming time string, but appears to
  # incorrectly adjust it relative to the local timezone.  For example, I
  # give a date of '2017-05-28' meaning "the 28th of May, 2017 UTC", and it
  # parses that into the 27th of May, 1pm UTC (my timezone is +11:00).
  #
  parsed = Time.parse(value)

  if parsed.utc_offset != 0
    # We want our timestamp as UTC!
    offset = parsed.utc_offset
    parsed.utc + offset
  else
    parsed
  end
rescue
  raise OAI::ArgumentException.new, "unparsable date: '#{value}'"
end