Skip to content

Commit

Permalink
[units]Add millimeter support (input only)
Browse files Browse the repository at this point in the history
  • Loading branch information
tyrope committed May 1, 2014
1 parent 1dbf9fe commit 19ea5ca
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion units.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import re

find_temp = re.compile('(-?[0-9]*\.?[0-9]*)[ °]*(K|C|F)', re.IGNORECASE)
find_length = re.compile('([0-9]*\.?[0-9]*)[ ]*(mile[s]?|mi|inch|in|foot|feet|ft|yard[s]?|yd|(?:centi|kilo|)meter[s]?|[kc]?m)', re.IGNORECASE)
find_length = re.compile('([0-9]*\.?[0-9]*)[ ]*(mile[s]?|mi|inch|in|foot|feet|ft|yard[s]?|yd|(?:milli|centi|kilo|)meter[s]?|[mkc]?m)', re.IGNORECASE)
find_mass = re.compile('([0-9]*\.?[0-9]*)[ ]*(lb|lbm|pound[s]?|ounce|oz|(?:kilo|)gram(?:me|)[s]?|[k]?g)', re.IGNORECASE)


Expand Down Expand Up @@ -81,6 +81,8 @@ def distance(bot, trigger):
meter = 0
if unit in ("meters", "meter", "m"):
meter = numeric
elif unit in ("millimeters", "millimeter", "mm"):
meter = numeric / 1000
elif unit in ("kilometers", "kilometer", "km"):
meter = numeric * 1000
elif unit in ("miles", "mile", "mi"):
Expand All @@ -96,6 +98,7 @@ def distance(bot, trigger):

if meter >= 1000:
metric_part = '{:.2f}km'.format(meter / 1000)
#TODO, Maybe: elif meter < 0.01, display in millimeters?
elif meter < 1:
metric_part = '{:.2f}cm'.format(meter * 100)
else:
Expand Down

0 comments on commit 19ea5ca

Please sign in to comment.