summaryrefslogtreecommitdiff
path: root/Data/BuiltIn/Libraries/lua-addons/addons/Clock
diff options
context:
space:
mode:
Diffstat (limited to 'Data/BuiltIn/Libraries/lua-addons/addons/Clock')
-rw-r--r--Data/BuiltIn/Libraries/lua-addons/addons/Clock/Clock.lua189
-rw-r--r--Data/BuiltIn/Libraries/lua-addons/addons/Clock/ReadMe.md48
-rw-r--r--Data/BuiltIn/Libraries/lua-addons/addons/Clock/time_zones.lua215
3 files changed, 452 insertions, 0 deletions
diff --git a/Data/BuiltIn/Libraries/lua-addons/addons/Clock/Clock.lua b/Data/BuiltIn/Libraries/lua-addons/addons/Clock/Clock.lua
new file mode 100644
index 0000000..9a66f68
--- /dev/null
+++ b/Data/BuiltIn/Libraries/lua-addons/addons/Clock/Clock.lua
@@ -0,0 +1,189 @@
+_addon.name = 'Clock'
+_addon.author = 'StarHawk'
+_addon.version = '1.0.1.1'
+_addon.command = 'clock'
+
+require('tables')
+require('lists')
+require('strings')
+require('logger')
+config = require('config')
+texts = require('texts')
+
+time_zones = T(require('time_zones'))
+
+for key, val in pairs(time_zones) do
+ time_zones[key] = val * 3600
+end
+
+local tz_format = {}
+for tz in time_zones:keyset():it() do
+ tz_format[tz:upper()] = tz:gsub('%d', '')
+end
+
+defaults = {}
+defaults.Format = '%H:%M:%S'
+defaults.TimeZones = L{'UTC', 'JST'}
+defaults.Display = T{}
+defaults.ShowTimeZones = true
+defaults.Separator = '\\n'
+defaults.Sort = 'None'
+defaults.Clock = {}
+
+settings = config.load(defaults)
+
+clock = texts.new('', settings.Clock, settings)
+
+sort = T{
+ time = function(t1, t2)
+ return time_zones[t1] < time_zones[t2]
+ end,
+ alphabetical = function(t1, t2)
+ return t1 < t2
+ end,
+}
+
+redraw = function()
+ local sorted = settings.Sort ~= 'None' and settings.TimeZones:sort(sort[settings.Sort:lower()]) or settings.TimeZones
+ local width = settings.TimeZones:reduce(function(acc, tz)
+ return math.max(acc, #(settings.Display[tz] or tz_format[tz]))
+ end, 0)
+ local format_string = settings.ShowTimeZones and '%s%s: ${%s}' or '${%s}'
+ local strings = sorted:map(function(tz)
+ local display = settings.Display[tz] or tz_format[tz]
+ return format_string:format(display, ' ':rep(width - #display), tz)
+ end)
+
+ -- Use loadstring to let Lua interpret things like \n for us
+ clock:text(strings:concat(loadstring('return \'%s\'':format(settings.Separator))()))
+end
+
+config.register(settings, redraw)
+
+clock:show()
+
+utc_diff = os.difftime(os.time(), os.time(os.date('!*t', os.time())))
+
+windower.register_event('prerender', function()
+ local utc_now = os.time() - utc_diff
+ for var in clock:it() do
+ if tz_format[var] then
+ clock[var] = os.date(settings.Format, utc_now + time_zones[var])
+ end
+ end
+end)
+
+windower.register_event('addon command', function(command, ...)
+ command = command and command:lower() or 'help'
+ local args = L{...}
+
+ if command == 'help' or command == 'h' then
+ print(_addon.name .. ' v.' .. _addon.version)
+ print(' \\cs(51, 153, 255)f\\cs(153, 204, 255)ormat\\cr - Displays the current or sets a new format to use')
+ print(' \\cs(51, 153, 255)a\\cs(153, 204, 255)dd\\cr - Adds a new time zone to the list')
+ print(' \\cs(51, 153, 255)r\\cs(153, 204, 255)emove\\cr - Removes a time zone to the current list')
+
+ elseif command == 'format' or command == 'f' then
+ if args[1] then
+ settings.Format = args:concat(' ')
+ config.save(settings)
+ end
+
+ log('Format set to: %s':format(settings.Format))
+
+ elseif command == 'add' or command == 'a' then
+ if not args[1] then
+ error('Invalid syntax: //clock add <timezones...>')
+ return
+ end
+
+ while args[1] do
+ local arg = args:remove(1):upper()
+ local tz = tz_format[arg]
+ if not tz then
+ error('Unknown time zone identifier: %s':format(args[1]))
+ return
+ end
+
+ if settings.TimeZones:contains(arg) then
+ notice('Time zone "%s" is already being displayed.':format(tz))
+ return
+ end
+
+ settings.TimeZones:append(arg)
+ end
+
+ config.save(settings)
+ redraw()
+
+ elseif command == 'remove' or command == 'r' then
+ if not args[1] then
+ error('Invalid syntax: //clock add <timezones...>')
+ return
+ end
+
+ while args[1] do
+ local arg = args:remove(1):upper()
+ local tz = tz_format[arg]
+ if not tz then
+ error('Unknown time zone identifier: %s':format(args[1]))
+ return
+ end
+
+ if not settings.TimeZones:contains(arg) then
+ notice('Time zone "%s" is not being displayed.':format(tz))
+ return
+ end
+
+ settings.TimeZones:remove(settings.TimeZones:find(arg))
+ end
+
+ config.save(settings)
+ redraw()
+
+ elseif command == 'sort' or command == 's' then
+ if args[1] and not sort[args[1]:lower()] then
+ error('Invalid sorting specified. Choose one of: %s':format((L{'None'} + sort:keyset():sort()):map(string.capitalize):format('or')))
+ return
+ end
+
+ if args[1] then
+ settings.Sort = args[1]:capitalize()
+ config.save(settings)
+ end
+
+ log('Sorting set to: %s':format(settings.Sort:capitalize()))
+ redraw()
+
+ elseif command == 'display' or command == 'd' then
+ if not args[1] or not args[2] then
+ error('Invalid syntax: //clock display <timezone> <name>')
+ return
+ end
+
+ local arg = args:remove(1):upper()
+ local tz = tz_format[arg]
+ if not tz then
+ error('Unknown time zone identifier: %s':format(args[1]))
+ return
+ end
+
+ settings.Display[arg] = args:concat(' ')
+ config.save(settings)
+ redraw()
+
+ end
+end)
+
+--[[
+Copyright � 2015, Windower
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ * Neither the name of Windower nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Windower BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+]]
diff --git a/Data/BuiltIn/Libraries/lua-addons/addons/Clock/ReadMe.md b/Data/BuiltIn/Libraries/lua-addons/addons/Clock/ReadMe.md
new file mode 100644
index 0000000..72237d3
--- /dev/null
+++ b/Data/BuiltIn/Libraries/lua-addons/addons/Clock/ReadMe.md
@@ -0,0 +1,48 @@
+# Clock
+
+Displays the current time in various time zones around the world in a customizable format on the screen.
+
+### Commands
+
+#### Time format
+
+```
+clock format [new]
+```
+
+If `new` is provided, will set that as the new format, according to [these rules](http://www.cplusplus.com/reference/ctime/strftime/). If omitted, will print out the current format.
+
+#### Sorting
+
+```
+clock sort [order]
+```
+
+If `order` is provided, will set that as the new sorting order. If omitted, will print out the current sorting order. Valid values are:
+* `None`: Leaves the order as it is defined in the file
+* `Alphabetical`: Sorts them alphabetically by their time zone abbreviation
+* `Time`: Sorts them according to the time they display in ascending order
+
+#### Add time zone
+
+```
+clock add <timezones...>
+```
+
+Appends a time zone to the list of currently displayed time zones. The `timezone` parameter needs to be one of [these abbreviations](https://github.com/Windower/Lua/blob/4.1-dev/addons/Clock/time_zones.lua).
+
+#### Remove time zone
+
+```
+clock remove <timezones...>
+```
+
+Removes a time zone from the list of currently displayed time zones. The `timezone` parameter needs to be one of [these abbreviations](https://github.com/Windower/Lua/blob/4.1-dev/addons/Clock/time_zones.lua).
+
+#### Set up time zone display
+
+```
+clock display <timezone> <name>
+```
+
+Sets the display name for a time zone, instead of displaying the time zone identifier. So `clock display jst JP clock` would display `JP clock` before the time instead of `JST`.
diff --git a/Data/BuiltIn/Libraries/lua-addons/addons/Clock/time_zones.lua b/Data/BuiltIn/Libraries/lua-addons/addons/Clock/time_zones.lua
new file mode 100644
index 0000000..9895072
--- /dev/null
+++ b/Data/BuiltIn/Libraries/lua-addons/addons/Clock/time_zones.lua
@@ -0,0 +1,215 @@
+return {
+ UTC = +00.00, -- Coordinated Universal Time
+
+ ACDT = +10.50, -- Australian Central Daylight Savings Time
+ ACST = +09.50, -- Australian Central Standard Time
+ ACT = +08.00, -- ASEAN Common Time
+ ADT = -03.00, -- Atlantic Daylight Time
+ AEDT = +11.00, -- Australian Eastern Daylight Savings Time
+ AEST = +10.00, -- Australian Eastern Standard Time
+ AFT = +04.50, -- Afghanistan Time
+ AKDT = -08.00, -- Alaska Daylight Time
+ AKST = -09.00, -- Alaska Standard Time
+ AMST = -03.00, -- Amazon Summer Time (Brazil)[1]
+ AMST2 = +05.00, -- Armenia Summer Time
+ AMT = -04.00, -- Amazon Time (Brazil)[2]
+ AMT2 = +04.00, -- Armenia Time
+ ART = -03.00, -- Argentina Time
+ AST = -04.00, -- Atlantic Standard Time
+ AST2 = +03.00, -- Arabia Standard Time
+ AWDT = +09.00, -- Australian Western Daylight Time
+ AWST = +08.00, -- Australian Western Standard Time
+ AZOST = -01.00, -- Azores Standard Time
+ AZT = +04.00, -- Azerbaijan Time
+ BDT = +08.00, -- Brunei Time
+ BIOT = +06.00, -- British Indian Ocean Time
+ BIT = -12.00, -- Baker Island Time
+ BOT = -04.00, -- Bolivia Time
+ BRT = -03.00, -- Brasilia Time
+ BST = +01.00, -- British Summer Time (British Standard Time from Feb 1968 to Oct 1971)
+ BST2 = +06.00, -- Bangladesh Standard Time
+ BTT = +06.00, -- Bhutan Time
+ CAT = +02.00, -- Central Africa Time
+ CCT = +06.50, -- Cocos Islands Time
+ CDT = -05.00, -- Central Daylight Time (North America)
+ CDT2 = -04.00, -- Cuba Daylight Time[3]
+ CEDT = +02.00, -- Central European Daylight Time
+ CEST = +02.00, -- Central European Summer Time (Cf. HAEC)
+ CET = +01.00, -- Central European Time
+ CHADT = +13.75, -- Chatham Daylight Time
+ CHAST = +12.75, -- Chatham Standard Time
+ CHOT = +08.00, -- Choibalsan
+ ChST = +10.00, -- Chamorro Standard Time
+ CHUT = +10.00, -- Chuuk Time
+ CIST = -08.00, -- Clipperton Island Standard Time
+ CIT = +08.00, -- Central Indonesia Time
+ CKT = -10.00, -- Cook Island Time
+ CLST = -03.00, -- Chile Summer Time
+ CLT = -04.00, -- Chile Standard Time
+ COST = -04.00, -- Colombia Summer Time
+ COT = -05.00, -- Colombia Time
+ CST = -06.00, -- Central Standard Time (North America)
+ CST2 = -05.00, -- Cuba Standard Time
+ CST3 = +08.00, -- China Standard Time
+ CST4 = +09.50, -- Central Standard Time (Australia)
+ CST5 = +10.50, -- Central Summer Time (Australia)
+ CT = +08.00, -- China time
+ CVT = -01.00, -- Cape Verde Time
+ CWST = +08.75, -- Central Western Standard Time (Australia) unofficial
+ CXT = +07.00, -- Christmas Island Time
+ DAVT = +07.00, -- Davis Time
+ DDUT = +10.00, -- Dumont d'Urville Time
+ DFT = +01.00, -- AIX specific equivalent of Central European Time[4]
+ EASST = -05.00, -- Easter Island Standard Summer Time
+ EAST = -06.00, -- Easter Island Standard Time
+ EAT = +03.00, -- East Africa Time
+ ECT = -04.00, -- Eastern Caribbean Time (does not recognise DST)
+ ECT = -05.00, -- Ecuador Time
+ EDT = -04.00, -- Eastern Daylight Time (North America)
+ EEDT = +03.00, -- Eastern European Daylight Time
+ EEST = +03.00, -- Eastern European Summer Time
+ EET = +02.00, -- Eastern European Time
+ EGST = +00.00, -- Eastern Greenland Summer Time
+ EGT = -01.00, -- Eastern Greenland Time
+ EIT = +09.00, -- Eastern Indonesian Time
+ EST = -05.00, -- Eastern Standard Time (North America)
+ EST2 = +10.00, -- Eastern Standard Time (Australia)
+ FET = +03.00, -- Further-eastern European Time
+ FJT = +12.00, -- Fiji Time
+ FKST = -03.00, -- Falkland Islands Standard Time
+ FKST = -03.00, -- Falkland Islands Summer Time
+ FKT = -04.00, -- Falkland Islands Time
+ FNT = -02.00, -- Fernando de Noronha Time
+ GALT = -06.00, -- Galapagos Time
+ GAMT = -09.00, -- Gambier Islands
+ GET = +04.00, -- Georgia Standard Time
+ GFT = -03.00, -- French Guiana Time
+ GILT = +12.00, -- Gilbert Island Time
+ GIT = -09.00, -- Gambier Island Time
+ GMT = +00.00, -- Greenwich Mean Time
+ GST = -02.00, -- South Georgia and the South Sandwich Islands
+ GST2 = +04.00, -- Gulf Standard Time
+ GYT = -04.00, -- Guyana Time
+ HADT = -09.00, -- Hawaii-Aleutian Daylight Time
+ HAEC = +02.00, -- Heure Avanc�e d'Europe Centrale francised name for CEST
+ HAST = -10.00, -- Hawaii-Aleutian Standard Time
+ HKT = +08.00, -- Hong Kong Time
+ HMT = +05.00, -- Heard and McDonald Islands Time
+ HOVT = +07.00, -- Khovd Time
+ HST = -10.00, -- Hawaii Standard Time
+ ICT = +07.00, -- Indochina Time
+ IDT = +03.00, -- Israel Daylight Time
+ IOT = +03.00, -- Indian Ocean Time
+ IRDT = +04.50, -- Iran Daylight Time
+ IRKT = +08.00, -- Irkutsk Time
+ IRST = +03.50, -- Iran Standard Time
+ IST = +01.00, -- Irish Standard Time[5]
+ IST2 = +02.00, -- Israel Standard Time
+ IST3 = +05.50, -- Indian Standard Time
+ JST = +09.00, -- Japan Standard Time
+ KGT = +06.00, -- Kyrgyzstan time
+ KOST = +11.00, -- Kosrae Time
+ KRAT = +07.00, -- Krasnoyarsk Time
+ KST = +09.00, -- Korea Standard Time
+ LHST = +10.50, -- Lord Howe Standard Time
+ LHST2 = +11.00, -- Lord Howe Summer Time
+ LINT = +14.00, -- Line Islands Time
+ MAGT = +12.00, -- Magadan Time
+ MART = -09.50, -- Marquesas Islands Time
+ MAWT = +05.00, -- Mawson Station Time
+ MDT = -06.00, -- Mountain Daylight Time (North America)
+ MET = +01.00, -- Middle European Time Same zone as CET
+ MEST = +02.00, -- Middle European Saving Time Same zone as CEST
+ MHT = +12.00, -- Marshall Islands
+ MIST = +11.00, -- Macquarie Island Station Time
+ MIT = -09.50, -- Marquesas Islands Time
+ MMT = +06.50, -- Myanmar Time
+ MSK = +03.00, -- Moscow Time
+ MST = -07.00, -- Mountain Standard Time (North America)
+ MST2 = +06.50, -- Myanmar Standard Time
+ MST3 = +08.00, -- Malaysia Standard Time
+ MUT = +04.00, -- Mauritius Time
+ MVT = +05.00, -- Maldives Time
+ MYT = +08.00, -- Malaysia Time
+ NCT = +11.00, -- New Caledonia Time
+ NDT = -02.50, -- Newfoundland Daylight Time
+ NFT = +11.50, -- Norfolk Time
+ NPT = +05.75, -- Nepal Time
+ NST = -03.50, -- Newfoundland Standard Time
+ NT = -03.50, -- Newfoundland Time
+ NUT = -11.00, -- Niue Time
+ NZDT = +13.00, -- New Zealand Daylight Time
+ NZST = +12.00, -- New Zealand Standard Time
+ OMST = +06.00, -- Omsk Time
+ ORAT = +05.00, -- Oral Time
+ PDT = -07.00, -- Pacific Daylight Time (North America)
+ PET = -05.00, -- Peru Time
+ PETT = +12.00, -- Kamchatka Time
+ PGT = +10.00, -- Papua New Guinea Time
+ PHOT = +13.00, -- Phoenix Island Time
+ PKT = +05.00, -- Pakistan Standard Time
+ PMDT = -02.00, -- Saint Pierre and Miquelon Daylight time
+ PMST = -03.00, -- Saint Pierre and Miquelon Standard Time
+ PONT = +11.00, -- Pohnpei Standard Time
+ PST = -08.00, -- Pacific Standard Time (North America)
+ PST2 = +08.00, -- Philippine Standard Time
+ PYST = -03.00, -- Paraguay Summer Time (South America)[6]
+ PYT = -04.00, -- Paraguay Time (South America)[7]
+ RET = +04.00, -- R�union Time
+ ROTT = -03.00, -- Rothera Research Station Time
+ SAKT = +11.00, -- Sakhalin Island time
+ SAMT = +04.00, -- Samara Time
+ SAST = +02.00, -- South African Standard Time
+ SBT = +11.00, -- Solomon Islands Time
+ SCT = +04.00, -- Seychelles Time
+ SGT = +08.00, -- Singapore Time
+ SLST = +05.50, -- Sri Lanka Time
+ SRET = +11.00, -- Srednekolymsk Time
+ SRT = -03.00, -- Suriname Time
+ SST = -11.00, -- Samoa Standard Time
+ SST2 = +08.00, -- Singapore Standard Time
+ SYOT = +03.00, -- Showa Station Time
+ TAHT = -10.00, -- Tahiti Time
+ THA = +07.00, -- Thailand Standard Time
+ TFT = +05.00, -- Indian/Kerguelen
+ TJT = +05.00, -- Tajikistan Time
+ TKT = +13.00, -- Tokelau Time
+ TLT = +09.00, -- Timor Leste Time
+ TMT = +05.00, -- Turkmenistan Time
+ TOT = +13.00, -- Tonga Time
+ TVT = +12.00, -- Tuvalu Time
+ ULAT = +08.00, -- Ulaanbaatar Time
+ USZ1 = +02.00, -- Kaliningrad Time
+ UYST = -02.00, -- Uruguay Summer Time
+ UYT = -03.00, -- Uruguay Standard Time
+ UZT = +05.00, -- Uzbekistan Time
+ VET = -04.50, -- Venezuelan Standard Time
+ VLAT = +10.00, -- Vladivostok Time
+ VOLT = +04.00, -- Volgograd Time
+ VOST = +06.00, -- Vostok Station Time
+ VUT = +11.00, -- Vanuatu Time
+ WAKT = +12.00, -- Wake Island Time
+ WAST = +02.00, -- West Africa Summer Time
+ WAT = +01.00, -- West Africa Time
+ WEDT = +01.00, -- Western European Daylight Time
+ WEST = +01.00, -- Western European Summer Time
+ WET = +00.00, -- Western European Time
+ WIT = +07.00, -- Western Indonesian Time
+ WST = +08.00, -- Western Standard Time
+ YAKT = +09.00, -- Yakutsk Time
+ YEKT = +05.00, -- Yekaterinburg Time
+ Z = +00.00, -- Zulu Time (Coordinated Universal Time)
+}
+
+--[[
+Copyright � 2015, Windower
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ * Neither the name of Windower nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL Windower BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+]]