mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-31 14:33:54 -04:00
Merge branch 'master' of https://github.com/cbhaley/calibre
This commit is contained in:
commit
5889505d92
@ -3489,19 +3489,16 @@ This can be useful to truncate a value.
|
|||||||
pat = re.compile(r'\[(.)(:(.*?))?\]')
|
pat = re.compile(r'\[(.)(:(.*?))?\]')
|
||||||
|
|
||||||
if not largest_unit:
|
if not largest_unit:
|
||||||
|
highest_index = 0
|
||||||
for m in pat.finditer(template):
|
for m in pat.finditer(template):
|
||||||
fmt_char = m.group(1)
|
try:
|
||||||
match fmt_char.lower():
|
# We know that m.group(1) is a single character so the only
|
||||||
case 'w' if largest_unit in 'dhms':
|
# exception possible is that the character is not in the string
|
||||||
largest_unit = 'w'
|
dex = 'smhdw'.index(m.group(1).lower())
|
||||||
case 'd' if largest_unit in 'hms':
|
highest_index = dex if dex > highest_index else highest_index
|
||||||
largest_unit = 'd'
|
except Exception:
|
||||||
case 'h' if largest_unit in 'ms':
|
raise ValueError(_('The {} format specifier is not valid').format(m.group()))
|
||||||
largest_unit = 'h'
|
largest_unit = 'smhdw'[highest_index]
|
||||||
case 'm' if largest_unit in 's':
|
|
||||||
largest_unit = 'm'
|
|
||||||
case 's' if not largest_unit:
|
|
||||||
largest_unit = 's'
|
|
||||||
|
|
||||||
int_val = remainder = round(float(value)) if value else 0
|
int_val = remainder = round(float(value)) if value else 0
|
||||||
weeks,remainder = divmod(remainder, 60*60*24*7) if largest_unit == 'w' else (-1,remainder)
|
weeks,remainder = divmod(remainder, 60*60*24*7) if largest_unit == 'w' else (-1,remainder)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user