72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/active_record/connection_adapters/cockroachdb/oid/interval.rb', line 72
def self.parse(string)
matches = REGEX.match(string)
raise(ParseError) unless matches
duration = 0
parts = {}
if matches[1]
val = matches[1].to_i
duration += val * PARTS_IN_SECONDS[:years]
parts[:years] = val
end
if matches[2]
val = matches[2].to_i
duration += val * PARTS_IN_SECONDS[:months]
parts[:months] = val
end
if matches[3]
val = matches[3].to_i
duration += val * PARTS_IN_SECONDS[:days]
parts[:days] = val
end
if matches[5]
val = matches[5].to_i
duration += val * PARTS_IN_SECONDS[:hours]
parts[:hours] = val
end
if matches[6]
val = matches[6].to_i
duration += val * PARTS_IN_SECONDS[:minutes]
parts[:minutes] = val
end
if matches[7]
val = matches[7].to_f
duration += val * PARTS_IN_SECONDS[:seconds]
parts[:seconds] = val
end
ActiveSupport::Duration.new(duration, parts)
end
|