From c891d8b2d3b1dabbca5aee54358f9b1599af4a46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Thu, 21 Nov 2019 11:13:42 +0200 Subject: [PATCH] add deg.py --- misc/deg.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 misc/deg.py diff --git a/misc/deg.py b/misc/deg.py new file mode 100644 index 0000000..8012f1d --- /dev/null +++ b/misc/deg.py @@ -0,0 +1,22 @@ +from decimal import Decimal as Dec + +Deg = namedtuple('Deg', ['hh', 'mm', 'ss']) + +def guess(inp): + if isinstance(inp, Dec): + return inp + + if '-' in instr: + deg, mm, ss = instr.split('-') + ddeg, dmm, dss = Dec(deg), Dec(mm), Dec(ss) + return deg + dmm/60 + dss/3600 + else: + return Dec(instr) + +def hms(deg): + assert isinstance(deg, Dec) + pdeg, pmm = divmod(deg, 1) + pmm = pmm * Dec(60) + pmm, pss = divmod(pmm, 1) + pss = pss * Dec(60) + return Deg(pdeg, pmm, pss)