11
12
13
14
15
16
17
18
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
45
46
47
48
49
50
51
52
|
# File 'lib/dr/parse/time_parse.rb', line 11
def parse(s, **opt)
return s if Date===s or Time===s
!opt[:norange] and s.match(/(.*)\.\.(.*)/) do |m|
first=m[1]
second=m[2]
opt[:norange]=true
return Chronic::Span.new(self.parse(first, opt),self.parse(second,opt))
end
if s.match(/\A[[:space:]]*\z/) t=Time.now
elsif s[0] =~ /[+-]/
begin
t=eval(s)
rescue SyntaxError
t=ChronicDuration.parse(s[1...s.length])
t=-t if s[0]=='-'
end
case t
when Time
else
t=Time.now+t
end
return t
else
chronicopts=[:context,:now,:guess,:ambiguous_time_range,:endian_precedence,:ambiguous_year_future_bias]
chronicopt={hours24: true, ambiguous_time_range: 0, endian_precedence: [:little,:middle]}
chronicopt[:guess]=false if opt[:range]
chronicopt.update(opt.reject {|k,v| not chronicopts.include?(k)})
t=Chronic.parse(s, chronicopt)
t=Time.parse(s) if not t
end
if opt[:range] && !opt[:norange] then
return time_to_day_range(t) unless Range === t
end
return t
end
|