Sha256: 338d28c9e9a6d5e287e0de731d92a85716d326ff50dda73aefab1bdb5ba61df5

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

module RDF::N3::Algebra::Time
  ##
  # For a date-time, its time:timeZone is the trailing timezone offset part, e.g.  "-05:00".
  #
  # @see https://www.w3.org/TR/xpath-functions/#func-timezone-from-dateTime
  class Timezone < RDF::N3::Algebra::ResourceOperator
    NAME = :timeTimezone
    URI = RDF::N3::Time.timeZone

    ##
    # The time:timeZone operator takes string or dateTime and extracts the timeZone component.
    #
    # @param [RDF::Term] resource
    # @param [:subject, :object] position
    # @return [RDF::Term]
    # @see RDF::N3::ResourceOperator#evaluate
    def resolve(resource, position:)
      case position
      when :subject
        return nil unless resource.literal?
        resource = resource.as_datetime
        RDF::Literal(resource.object.strftime("%Z"))
      when :object
        return nil unless resource.literal? || resource.variable?
        resource
      end
    end

    ##
    # There is no timezone unless it was specified in the lexical form and is not "Z"
    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
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rdf-n3-3.2.1 lib/rdf/n3/algebra/time/timezone.rb
rdf-n3-3.2.0 lib/rdf/n3/algebra/time/timezone.rb
rdf-n3-3.1.2 lib/rdf/n3/algebra/time/timezone.rb