Class: Date

Inherits:
Object
  • Object
show all
Extended by:
MonthValue
Defined in:
lib/zones.rb

Class Method Summary collapse

Methods included from MonthValue

month_value

Class Method Details

.parse_str(str) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/zones.rb', line 19

def self.parse_str(str)
  case str
  when %r!^((?:19|20)\d\d)(\d\d)(\d\d)!
    ymd = [$1.to_i, $2.to_i, $3.to_i]
  when %r!^
    (?:(0[1-9]|[12]\d|3[01]|[1-9](?=\D))[-/\s]?          #  $1: day
       (                          (?>[a-z]{3,9}))[-/\s]? #  $2: month (no digits allowed here)
       ((?>19|20)\d\d)                                   #  $3: year
    | # or...
       ((?>19|20)\d\d)[-/\s]?                            #  $4: year
       (0[1-9]|1[012]|[1-9](?=\D)|(?>[a-z]{3,9}))[-/\s]? #  $5: month
       (0[1-9]|[12]\d|3[01]|[1-9]\b)                     #  $6: day
    | # or...
       (0[1-9]|1[012]|[1-9](?=\D)|(?>[a-z]{3,9}))[-/\s]? #  $7: month
       (0[1-9]|[12]\d|3[01]|[1-9](?=\D)),?[-/\s]?        #  $8: day
       ((?>19|20)\d\d)                                   #  $9: year
    )
  !iox
    ymd =   $1 ? [ $3.to_i, month_value($2), $1.to_i] : \
            $4 ? [ $4.to_i, month_value($5), $6.to_i] : \
                 [ $9.to_i, month_value($7), $8.to_i]
  else
    raise "can't parse: #{str}"
  end
  ymd
end

.to_day(str) ⇒ Object

parse date



47
48
49
50
# File 'lib/zones.rb', line 47

def self.to_day(str)
  ymd = parse_str(str)
  out = Date.new(*ymd)
end