aboutsummaryrefslogtreecommitdiff
path: root/challenge-100/stuart-little/lua/ch-1.lua
diff options
context:
space:
mode:
authorchirvasitua <chirvasitua@gmail.com>2021-07-15 14:30:05 -0400
committerchirvasitua <chirvasitua@gmail.com>2021-07-15 14:30:05 -0400
commit81465123f99e4ef5f088a4fb8fab6678723c8d49 (patch)
tree2bc6455857f345a77c4ce4c03314684258947989 /challenge-100/stuart-little/lua/ch-1.lua
parent3cf2f377eb630f019d81293e81885a8a3a1ba187 (diff)
downloadperlweeklychallenge-club-81465123f99e4ef5f088a4fb8fab6678723c8d49.tar.gz
perlweeklychallenge-club-81465123f99e4ef5f088a4fb8fab6678723c8d49.tar.bz2
perlweeklychallenge-club-81465123f99e4ef5f088a4fb8fab6678723c8d49.zip
1st commit on 100_lua
Diffstat (limited to 'challenge-100/stuart-little/lua/ch-1.lua')
-rwxr-xr-xchallenge-100/stuart-little/lua/ch-1.lua16
1 files changed, 16 insertions, 0 deletions
diff --git a/challenge-100/stuart-little/lua/ch-1.lua b/challenge-100/stuart-little/lua/ch-1.lua
new file mode 100755
index 0000000000..29f1bc624f
--- /dev/null
+++ b/challenge-100/stuart-little/lua/ch-1.lua
@@ -0,0 +1,16 @@
+#!/usr/bin/env lua
+
+-- run <script> <time, formatted as hh:mm [am/pm]>
+
+function cvrt(h,m,ap)
+ if ap:len() > 0 then
+ local hap = (ap:lower()=="am") and (("%02d"):format(tonumber(h)%12)) or (("%02d"):format(12+(tonumber(h)%12)))
+ return hap..":"..("%02d"):format(m)
+ end
+ ap=(tonumber(h)>=12) and " pm" or " am"
+ h=((tonumber(h)>12) and h-12) or (tonumber(h)==0 and 12) or h
+ return ("%02d"):format(h)..":"..("%02d"):format(m)..ap
+end
+
+local h,m,ap=table.concat(arg,""):match("(%d+):(%d+)%s*([a-zA-Z]*)")
+print(cvrt(h,m,ap))