Class: RDF::N3::Algebra::Time::Timezone

Inherits:
ResourceOperator
  • Object
show all
Defined in:
lib/rdf/n3/algebra/time/timezone.rb

Overview

For a date-time, its time:timeZone is the trailing timezone offset part, e.g. “-05:00”.

Constant Summary collapse

NAME =
:timeTimezone
URI =
RDF::N3::Time.timeZone

Instance Attribute Summary

Attributes included from Enumerable

#existentials, #universals

Instance Method Summary collapse

Methods inherited from ResourceOperator

#as_literal, #execute, #input_operand

Methods included from Builtin

#each, #evaluate, #hash, #input_operand, #rank, #to_uri

Instance Method Details

#resolve(resource, position:) ⇒ RDF::Term

The time:timeZone operator takes string or dateTime and extracts the timeZone component.

Parameters:

  • resource (RDF::Term)
  • position (:subject, :object)

Returns:

See Also:

  • ResourceOperator#evaluate


17
18
19
20
21
22
23
24
25
26
# File 'lib/rdf/n3/algebra/time/timezone.rb', line 17

def resolve(resource, position:)
  case position
  when :subject
    return nil unless resource.literal?
    resource.as_datetime.tz
  when :object
    return nil unless resource.literal? || resource.variable?
    resource
  end
end

#valid?(subject, object) ⇒ Boolean

There is no timezone unless it was specified in the lexical form and is not “Z”

Returns:

  • (Boolean)


30
31
32
33
# File 'lib/rdf/n3/algebra/time/timezone.rb', line 30

def valid?(subject, object)
  md = subject.value.match(%r(^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(Z|[\+-][\d-]+)))
  md && md[1].to_s != 'Z'
end