Sha256: 656ee5bed58669f1bd77872eb0f6038253b29f7e518bddf2bf8ede4d26d94700

Contents?: true

Size: 1002 Bytes

Versions: 8

Compression:

Stored size: 1002 Bytes

Contents

require 'chronic'
require 'ndr_support/daterange'

module Tnql #:nodoc: all
  module Nodes
    module FuzzyDateNode
      def to_daterange
        date.to_daterange
      end
    end

    module SpecificDateNode
      def to_daterange
        date_fragment.to_daterange
      end
    end

    module FragmentedDateRangeNode
      def to_daterange
        d1 = start.to_daterange.date1
        d2 = finish.to_daterange.date2

        Daterange.new(d1, d2)
      end
    end

    module DateFragmentNode
      def to_daterange
        fragment.to_daterange
      end
    end

    module DateRangeNode
      def to_daterange
        Daterange.new(text_value.to_s)
      end
    end

    module ChronicDateNode
      def to_daterange
        chronic = Chronic.parse(text_value.to_s, context: :past, guess: false)
        if chronic.instance_of?(Chronic::Span)
          Daterange.new(chronic.begin, chronic.end - 1.day)
        else
          Daterange.new(chronic)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
tnql-1.1.2 lib/tnql/nodes/dates.rb
tnql-1.1.1 lib/tnql/nodes/dates.rb
tnql-1.1.0 lib/tnql/nodes/dates.rb
tnql-1.0.4 lib/tnql/nodes/dates.rb
tnql-1.0.3 lib/tnql/nodes/dates.rb
tnql-1.0.2 lib/tnql/nodes/dates.rb
tnql-1.0.1 lib/tnql/nodes/dates.rb
tnql-1.0.0 lib/tnql/nodes/dates.rb