lib/edtf/date.rb
def edtf
    return "y#{year}" if long_year?

    v = values
    s = FORMATS.take(v.length).zip(v).map { |f,d| f % d.abs }
    s[0] = "-#{s[0]}" if year < 0
    s = unspecified.mask(s)

    unless (h = ua_hash).zero?
      #
      # To efficiently calculate the uncertain/approximate state we use
      # the bitmask. The primary flags are:
      #
      # Uncertain:    1 - year,  2 - month,  4 - day
      # Approximate:  8 - year, 16 - month, 32 - day
      #
      # Invariant: assumes that uncertain/approximate are not set for values
      # not covered by precision!
      #
      y, m, d = s

      # ?/~ if true-false or true-true and other false-true
      y << SYMBOLS[:uncertain]   if  3&h==1 || 27&h==19
      y << SYMBOLS[:approximate] if 24&h==8 || 27&h==26


      # combine if false-true-true and other m == d
      if 7&h==6 && (48&h==48 || 48&h==0)  || 56&h==48 && (6&h==6 || 6&h==0)
        m[0,0] = '('
        d << ')'
      else
        case
        # false-true
        when 3&h==2 || 24&h==16
          m[0,0] = '('
          m << ')'

        # *-false-true
        when 6&h==4 || 48&h==32
          d[0,0] = '('
          d << ')'
        end

        # ?/~ if *-true-false or *-true-true and other m != d
        m << SYMBOLS[:uncertain]   if h!=31 && (6&h==2  ||  6&h==6  && (48&h==16 || 48&h==32))
        m << SYMBOLS[:approximate] if h!=59 && (48&h==16 || 48&h==48 && (6&h==2 || 6&h==4))
      end

      # ?/~ if *-*-true
      d << SYMBOLS[:uncertain]   if  4&h==4
      d << SYMBOLS[:approximate] if 32&h==32
    end

    s = s.join('-')
    s << SYMBOLS[:calendar] << calendar if calendar?
    s
  end
# Returns the Date's EDTF string.
Returns the Date's EDTF string.
Returns the Date ' s EDTF string .
def edtf
    return "y{year}" if long_year?
    v = values
    s = FORMATS.take(v.length).zip(v).map { |f,d| f % d.abs }
    s[0] = "-{s[0]}" if year < 0
    s = unspecified.mask(s)
    unless (h = ua_hash).zero?
       To efficiently calculate the uncertain/approximate state we use
       the bitmask. The primary flags are:
       Uncertain:    1 - year,  2 - month,  4 - day
       Approximate:  8 - year, 16 - month, 32 - day
       Invariant: assumes that uncertain/approximate are not set for values
       not covered by precision!
      y, m, d = s
       ?/~ if true-false or true-true and other false-true
      y << SYMBOLS[:uncertain]   if  3&h==1 || 27&h==19
      y << SYMBOLS[:approximate] if 24&h==8 || 27&h==26
       combine if false-true-true and other m == d
      if 7&h==6 && (48&h==48 || 48&h==0)  || 56&h==48 && (6&h==6 || 6&h==0)
        m[0,0] = '('
        d << ')'
      else
        case
         false-true
        when 3&h==2 || 24&h==16
          m[0,0] = '('
          m << ')'
         *-false-true
        when 6&h==4 || 48&h==32
          d[0,0] = '('
          d << ')'
        end
         ?/~ if *-true-false or *-true-true and other m != d
        m << SYMBOLS[:uncertain]   if h!=31 && (6&h==2  ||  6&h==6  && (48&h==16 || 48&h==32))
        m << SYMBOLS[:approximate] if h!=59 && (48&h==16 || 48&h==48 && (6&h==2 || 6&h==4))
      end
       ?/~ if *-*-true
      d << SYMBOLS[:uncertain]   if  4&h==4
      d << SYMBOLS[:approximate] if 32&h==32
    end
    s = s.join('-')
    s << SYMBOLS[:calendar] << calendar if calendar?
    s
  end
def edtf return "y#{year}" if long_year? v = values s = FORMATS . take ( v . length ) . zip ( v ) . map { | f , d | f % d . abs } s [ 0 ] = "-#{s[0]}" if year < 0 s = unspecified . mask ( s ) unless ( h = ua_hash ) . zero? y , m , d = s y << SYMBOLS [ :uncertain ] if 3 & h == 1 || 27 & h == 19 y << SYMBOLS [ :approximate ] if 24 & h == 8 || 27 & h == 26 if 7 & h == 6 && ( 48 & h == 48 || 48 & h == 0 ) || 56 & h == 48 && ( 6 & h == 6 || 6 & h == 0 ) m [ 0 , 0 ] = '(' d << ')' else case when 3 & h == 2 || 24 & h == 16 m [ 0 , 0 ] = '(' m << ')' when 6 & h == 4 || 48 & h == 32 d [ 0 , 0 ] = '(' d << ')' end m << SYMBOLS [ :uncertain ] if h != 31 && ( 6 & h == 2 || 6 & h == 6 && ( 48 & h == 16 || 48 & h == 32 ) ) m << SYMBOLS [ :approximate ] if h != 59 && ( 48 & h == 16 || 48 & h == 48 && ( 6 & h == 2 || 6 & h == 4 ) ) end d << SYMBOLS [ :uncertain ] if 4 & h == 4 d << SYMBOLS [ :approximate ] if 32 & h == 32 end s = s . join ( '-' ) s << SYMBOLS [ :calendar ] << calendar if calendar? s end
Returns the Date's EDTF string.
Returns the Date ' s EDTF string .
# # To efficiently calculate the uncertain/approximate state we use # the bitmask. The primary flags are: # # Uncertain:    1 - year,  2 - month,  4 - day # Approximate:  8 - year, 16 - month, 32 - day # # Invariant: assumes that uncertain/approximate are not set for values # not covered by precision! # # ?/~ if true-false or true-true and other false-true # combine if false-true-true and other m == d # false-true # *-false-true # ?/~ if *-true-false or *-true-true and other m != d # ?/~ if *-*-true