Advertisement
Guest User

Clock

a guest
Nov 25th, 2014
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.01 KB | None | 0 0
  1. --Alias
  2. --Pattern: ^setTime (\d+):(\d+) (\w+)$
  3. set_time(matches[2], matches[3], matches[4])
  4.  
  5. --Timer
  6. if min == nil then
  7.     min = 0;
  8. end
  9. if hr == nil then
  10.     hr = 0;
  11. end
  12.  
  13. min = min + 1;
  14. if min == 60 then
  15.     min = 0;
  16.     hr = hr + 1;
  17.     if hr == 24 then
  18.         hr = 0;
  19.     end
  20. end
  21.  
  22. --Script
  23. function set_time(shr, smin, sdot)
  24.     local h = tonumber(shr);
  25.     if sdot == "AM" and h == 12 then
  26.         h = 0;
  27.     elseif sdot == "PM" and h ~= 12 then
  28.         h = h + 12;
  29.     end
  30.     hr = h;
  31.     min = tonumber(smin);
  32. end
  33.  
  34. function write_time()
  35.     local s;
  36.     local shr;
  37.     local smin;
  38.     local sdot;
  39.  
  40.     if hr < 12 then
  41.         sdot = "am";
  42.     else
  43.         sdot = "pm";
  44.     end
  45.  
  46.     if hr == 0 then
  47.         shr = "12"
  48.     elseif hr > 12 then
  49.         shr = hr - 12
  50.     else
  51.         shr = hr
  52.     end
  53.  
  54.     if min < 10 then
  55.         smin = "0" .. min;
  56.     else
  57.         smin = min;
  58.     end
  59.    
  60.     s = "Time is " .. shr .. ":" .. smin .. " " .. sdot;
  61.     return s;
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement