Software / code / prosody
Comparison
util/human/io.lua @ 13199:278920294dfe
util.human.io: Fix pattern in parse_duration() to cover all used letters
Notably 'h' was missing. Awkwardly, 'hour' would result in 'ho' which
was missing from table.
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 16 Jul 2023 19:27:18 +0200 |
| parent | 13068:7a75cbc4d87c |
| child | 13210:8dbe693ded6b |
comparison
equal
deleted
inserted
replaced
| 13198:313c49c7566a | 13199:278920294dfe |
|---|---|
| 195 end | 195 end |
| 196 | 196 |
| 197 local day = 86400; | 197 local day = 86400; |
| 198 local multipliers = { | 198 local multipliers = { |
| 199 d = day, w = day * 7, m = 31 * day, mo = 31 * day, y = 365.2425 * day; | 199 d = day, w = day * 7, m = 31 * day, mo = 31 * day, y = 365.2425 * day; |
| 200 s = 1, mi = 60, h = 3600 | 200 s = 1, mi = 60, h = 3600, ho = 3600 |
| 201 }; | 201 }; |
| 202 local function parse_duration(duration_string) | 202 local function parse_duration(duration_string) |
| 203 local n, m = duration_string:lower():match("(%d+)%s*([dwmy]?.?)"); | 203 local n, m = duration_string:lower():match("(%d+)%s*([smhdwy]?[io]?)"); |
| 204 if not n then return nil; end | 204 if not n then return nil; end |
| 205 return tonumber(n) * ( multipliers[m] or 1 ); | 205 return tonumber(n) * ( multipliers[m] or 1 ); |
| 206 end | 206 end |
| 207 | 207 |
| 208 return { | 208 return { |