Changeset 5f9d3a09ef35ffe149aa080e6377d811a1994291
- Timestamp:
- 03/07/10 21:17:47 (5 months ago)
- Author:
- Giuseppe Bilotta <giuseppe.bilotta@…>
- Children:
- 8893bf66c0aa6f2bbf2e2941f7be82486fecdb46
- Parents:
- 38c076622c020e509c8f1dca4e3168ea38f5999e
- git-committer:
- Giuseppe Bilotta <giuseppe.bilotta@gmail.com> 1267985867 +0100
- Message:
-
Time parsing: also parse months and years
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r0cad272
|
r5f9d3a0
|
|
| 78 | 78 | FRACTION_RX = Regexp.new FRACTIONS.keys.join('|') |
| 79 | 79 | |
| 80 | | UNITSPEC_RX = /(s(?:ec(?:ond)?s?)?|m(?:in(?:ute)?s?)?|h(?:(?:ou)?rs?)?|d(?:ays?)?|weeks?)/ |
| | 80 | UNITSPEC_RX = /(years?|months?|s(?:ec(?:ond)?s?)?|m(?:in(?:ute)?s?)?|h(?:(?:ou)?rs?)?|d(?:ays?)?|weeks?)/ |
| 81 | 81 | |
| 82 | 82 | # str must much UNITSPEC_RX |
| … |
… |
|
| 86 | 86 | 1 |
| 87 | 87 | when :m |
| 88 | | 60 |
| | 88 | if str[1,1] == 'o' |
| | 89 | # months |
| | 90 | 3600*24*30 |
| | 91 | else |
| | 92 | #minutes |
| | 93 | 60 |
| | 94 | end |
| 89 | 95 | when :h |
| 90 | 96 | 3600 |
| … |
… |
|
| 93 | 99 | when :w |
| 94 | 100 | 3600*24*7 |
| | 101 | when :y |
| | 102 | 3600*24*365 |
| 95 | 103 | end |
| 96 | 104 | end |
| … |
… |
|
| 129 | 137 | end |
| 130 | 138 | end |
| 131 | | frac = $5 |
| 132 | | unit = ParseTime.time_unit($6) |
| 133 | | clean.strip! |
| 134 | | if frac.nil? and clean.sub!(/^and\s+(#{FRACTION_RX})/, '') |
| 135 | | frac = $1 |
| 136 | | end |
| 137 | | if frac |
| 138 | | num += FRACTIONS[frac.intern] |
| 139 | | end |
| | 139 | frac = $5 |
| | 140 | unit = ParseTime.time_unit($6) |
| | 141 | clean.strip! |
| | 142 | if frac.nil? and clean.sub!(/^and\s+(#{FRACTION_RX})/, '') |
| | 143 | frac = $1 |
| | 144 | end |
| | 145 | if frac |
| | 146 | num += FRACTIONS[frac.intern] |
| | 147 | end |
| 140 | 148 | else |
| 141 | 149 | raise "invalid time string: #{clean} (parsed #{sofar} so far)" |