Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Author: TheOriginalBIT
- Version: 1.1
- Created: 03 Feb 2013
- Last Update: 10 Mar 2013
- License:
- COPYRIGHT NOTICE
- Copyright © 2013 Joshua Asbury a.k.a TheOriginalBIT [theoriginalbit@gmail.com]
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
- associated documentation files (the "Software"), to deal in the Software without restriction,
- including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
- copies of the Software, and to permit persons to whom the Software is furnished to do so,
- subject to the following conditions:
- -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
- -Visible credit is given to the original author.
- -The software is distributed in a non-profit way.
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
- COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
- ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- ]]--
- if not os.day then
- print("Sorry but you don't seem to be running the version of ComputerCraft that this program requires (1.48+)")
- return
- end
- local useShorthand = false
- local useAmPm = false
- local refreshRate = 0.05
- -- argument override
- local argv = {...}
- local ignoreNext = false
- for i = 1, #argv do
- local v = argv[i]
- if v == '-ds' then
- useShorthand = true
- elseif v == '-ts' then
- useAmPm = true
- elseif v == '-rr' then
- refreshRate = tonumber(argv[i+1])
- ignoreNext = true
- elseif not ignoreNext then
- printError("Error: Invalid runtime parameter, "..v)
- error()
- elseif ignoreNext then
- ignoreNext = false
- end
- end
- -- initialise variables
- local currentYear = 1
- local currentMonth = 1
- local currentDay = 1
- local isLeapYear = (currentYear % 4 == 0 and (currentYear % 100 > 0 or currentYear % 400 == 0))
- local yearPrefix = "AS (After Spawn)"
- local monthsTable = {
- {month="January", days=31, shorthand="JAN"},
- {month="February", days=28, shorthand="FEB"},
- {month="March", days=31, shorthand="MAR"},
- {month="April", days=30, shorthand="APR"},
- {month="May", days=31, shorthand="MAY"},
- {month="June", days=30, shorthand="JUNE"},
- {month="July", days=31, shorthand="JULY"},
- {month="August", days=31, shorthand="AUG"},
- {month="September", days=30, shorthand="SEPT"},
- {month="October", days=31, shorthand="OCT"},
- {month="November", days=30, shorthand="NOV"},
- {month="December", days=31, shorthand="DEC"},
- }
- local daysTable = {
- {day="Monday", shorthand="MON"},
- {day="Tuesday", shorthand="TUE"},
- {day="Wednesday", shorthand="WED"},
- {day="Thursday", shorthand="THU"},
- {day="Friday", shorthand="FRI"},
- {day="Saturday", shorthand="SAT"},
- {day="Sunday", shorthand="SUN"},
- }
- local function updateLeapYear(year)
- isLeapYear = (currentYear % 4 == 0 and (currentYear % 100 > 0 or currentYear % 400 == 0))
- end
- local function updateYear(days)
- currentYear = math.floor(days/(isLeapYear and 366 or 365)+1)
- updateLeapYear(year)
- end
- local function updateMonth(days)
- local shiftedDays = days%366
- local d = 0
- for i = 1, #monthsTable do
- local before = d
- if i == 2 and isLeapYear then
- d = d + 29
- else
- d = d + monthsTable[i].days
- end
- if shiftedDays >= before and shiftedDays <= d then
- currentMonth = i
- return
- end
- end
- end
- local function updateDay(days)
- local shiftedDays = days%366
- for i = 1, currentMonth - 1 do
- shiftedDays = shiftedDays - monthsTable[i].days
- end
- currentDay = shiftedDays
- end
- local function hexToCol(hex)
- local num = tonumber(hex, 16)
- return num ~= nil and 2^num or nil
- end
- local function cwrite(msg, y, offset)
- local sw,sh=term.getSize()
- term.setCursorPos(sw/2-#msg/2, y or sh/2 + offset or 0)
- write(msg)
- end
- while true do
- term.clear()
- local dayCount = os.day()
- updateYear(dayCount)
- updateMonth(dayCount)
- updateDay(dayCount)
- cwrite("The time is: "..textutils.formatTime(os.time(), not useAmPm),nil,-2)
- cwrite("The date is: "..currentDay.." "..(useShorthand and monthsTable[currentMonth].shorthand or monthsTable[currentMonth].month).." "..string.format("%.4d",currentYear),nil,2)
- os.startTimer(refreshRate)
- os.pullEvent("timer")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement