[READ-ONLY] Mirror of https://github.com/thoda-dev/DualUniverse. DualUniverse scripts
0

Configure Feed

Select the types of activity you want to include in your feed.

Update TimeScript.lua

authored by

Thomas and committed by
GitHub
(Jan 1, 2021, 6:19 PM +0100) 95fe3ff4 85389a86

+94 -236
+94 -236
TimeScript/TimeScript.lua
··· 1 + 1 2 --[[ 2 - Jericho's time script -- https://github.com/Jericho1060 3 - Display IRL date and time in game 4 - https://github.com/Jericho1060/DualUniverse/tree/master/TimeScript 5 - 6 - Clock script from Leodr, modified and updated by Jericho 7 - original script: https://github.com/leodr99/DU-quick_n_dirty-scripts/blob/main/clock/clock.lua 8 - ]] 3 + Jericho's time script -- https://github.com/Jericho1060 4 + Display IRL date and time in game 5 + https://github.com/Jericho1060/DualUniverse/edit/master/TimeScript/TimeScript.lua 6 + ]]-- 9 7 10 - --Globals 11 - local outputTime = false --for debug 12 - local summertime = false --export: summer time enabled 13 - -- 14 - --//functions 15 - function epochTime() 16 - function rZ(data) 17 - if string.len(data) <= 1 then 18 - return "0" .. data 19 - else 20 - return data 21 - end 22 - end 23 - function dPoint(value) 24 - if not(value == math.floor(value)) then 25 - return true 26 - else 27 - return false 28 - end 29 - end 30 - function lYear(year) 31 - if(not dPoint(year / 4)) then 32 - if(dPoint(year / 100)) then 33 - return true 34 - else 35 - if(not dPoint(year / 400)) then 36 - return true 37 - else 38 - return false 39 - end 40 - end 41 - else 42 - return false 43 - end 44 - end 45 - 46 - local timeStampDayOfWeak = 5 47 - local secondsInHour = 3600 48 - local secondsInDay = 86400 49 - local secondsInYear = 31536000 50 - local secondsInLeapYear = 31622400 51 - local monthWith28 = 2419200 52 - local monthWith29 = 2505600 53 - local monthWith30 = 2592000 54 - local monthWith31 = 2678400 8 + summer_time = false --export 9 + 10 + function DUCurrentDateTime() 11 + local time = system.getTime() 12 + local additionnal_hour = 0 13 + local seconds_to_2018 = 7948800 --from 01-10-2017 (arkship time) 14 + local secondsInMinute = 60 15 + local secondsInHour = secondsInMinute * 60 16 + local secondsInDay = secondsInHour * 24 17 + local secondsInYear = secondsInDay * 365 55 18 local monthsWith30 = {4, 6, 9, 11} 56 19 local monthsWith31 = {1, 3, 5, 7, 8, 10, 12} 57 - local daysSinceEpoch = 0 58 - local duEpochOffset = 1506816000 --(Oct. 1, 2017, at 00:00) //1506729600 59 - local DOWAssociates = {"Tur,", "Fri,", "Sat,", "Sun,", "Mon,", "Tue,", "Wed,"} 60 - local getTime = system.getTime() 61 - if summertime == true then getTime = getTime + 3600 end 62 - 63 - now = math.floor(getTime + duEpochOffset) 64 - year = 1970 --the original epoch time (1/1/1970), in order to match DU's epoch offset. 65 - secs = 0 66 - daysSinceEpoch = 0 67 - while((secs + secondsInLeapYear) < now or (secs + secondsInYear) < now) do 68 - if(lYear(year+1)) then 69 - if((secs + secondsInLeapYear) < now) then 70 - secs = secs + secondsInLeapYear 71 - year = year + 1 72 - daysSinceEpoch = daysSinceEpoch + 366 73 - end 20 + if summer_time then time = time + 1 end 21 + time = time - seconds_to_2018 22 + local year = 2018 23 + local month = 1 24 + local day = 1 25 + local daysInFebuary = 28 26 + while time >= secondsInYear do 27 + if (year % 4) == 0 then --leap year 28 + if time >= (secondsInYear - secondsInDay) then 29 + year = year + 1 30 + time = time - secondsInYear - secondsInDay 74 31 else 75 - if((secs + secondsInYear) < now) then 76 - secs = secs + secondsInYear 77 - year = year + 1 78 - daysSinceEpoch = daysSinceEpoch + 365 79 - end 80 - end 81 - end 82 - secondsRemaining = now - secs 83 - monthSecs = 0 84 - yearlYear = lYear(year) 85 - month = 1 -- January 86 - while((monthSecs + monthWith28) < secondsRemaining or (monthSecs + monthWith30) < secondsRemaining or (monthSecs + monthWith31) < secondsRemaining) do 87 - if(month == 1) then 88 - if((monthSecs + monthWith31) < secondsRemaining) then 89 - month = 2 90 - monthSecs = monthSecs + monthWith31 91 - daysSinceEpoch = daysSinceEpoch + 31 92 - else 93 - break 94 - end 95 - end 96 - if(month == 2) then 97 - if(not yearlYear) then 98 - if((monthSecs + monthWith28) < secondsRemaining) then 99 - month = 3 100 - monthSecs = monthSecs + monthWith28 101 - daysSinceEpoch = daysSinceEpoch + 28 102 - else 103 - break 104 - end 105 - else 106 - if((monthSecs + monthWith29) < secondsRemaining) then 107 - month = 3 108 - monthSecs = monthSecs + monthWith29 109 - daysSinceEpoch = daysSinceEpoch + 29 110 - else 111 - break 112 - end 113 - end 114 - end 115 - if(month == 3) then 116 - if((monthSecs + monthWith31) < secondsRemaining) then 117 - month = 4 118 - monthSecs = monthSecs + monthWith31 119 - daysSinceEpoch = daysSinceEpoch + 31 120 - else 121 - break 122 - end 123 - end 124 - if(month == 4) then 125 - if((monthSecs + monthWith30) < secondsRemaining) then 126 - month = 5 127 - monthSecs = monthSecs + monthWith30 128 - daysSinceEpoch = daysSinceEpoch + 30 129 - else 130 - break 131 - end 132 - end 133 - if(month == 5) then 134 - if((monthSecs + monthWith31) < secondsRemaining) then 135 - month = 6 136 - monthSecs = monthSecs + monthWith31 137 - daysSinceEpoch = daysSinceEpoch + 31 138 - else 139 - break 140 - end 141 - end 142 - if(month == 6) then 143 - if((monthSecs + monthWith30) < secondsRemaining) then 144 - month = 7 145 - monthSecs = monthSecs + monthWith30 146 - daysSinceEpoch = daysSinceEpoch + 30 147 - else 148 - break 149 - end 150 - end 151 - if(month == 7) then 152 - if((monthSecs + monthWith31) < secondsRemaining) then 153 - month = 8 154 - monthSecs = monthSecs + monthWith31 155 - daysSinceEpoch = daysSinceEpoch + 31 156 - else 157 - break 158 - end 159 - end 160 - if(month == 8) then 161 - if((monthSecs + monthWith31) < secondsRemaining) then 162 - month = 9 163 - monthSecs = monthSecs + monthWith31 164 - daysSinceEpoch = daysSinceEpoch + 31 165 - else 166 - break 167 - end 32 + local daysInFebuary = 29 33 + break 168 34 end 169 - if(month == 9) then 170 - if((monthSecs + monthWith30) < secondsRemaining) then 171 - month = 10 172 - monthSecs = monthSecs + monthWith30 173 - daysSinceEpoch = daysSinceEpoch + 30 174 - else 175 - break 176 - end 177 - end 178 - if(month == 10) then 179 - if((monthSecs + monthWith31) < secondsRemaining) then 180 - month = 11 181 - monthSecs = monthSecs + monthWith31 182 - daysSinceEpoch = daysSinceEpoch + 31 183 - else 184 - break 185 - end 186 - end 187 - if(month == 11) then 188 - if((monthSecs + monthWith30) < secondsRemaining) then 189 - month = 12 190 - monthSecs = monthSecs + monthWith30 191 - daysSinceEpoch = daysSinceEpoch + 30 192 - else 193 - break 194 - end 195 - end 35 + else 36 + year = year + 1 37 + time = time - secondsInYear 196 38 end 197 - day = 1 -- 1st 198 - daySecs = 0 199 - daySecsRemaining = secondsRemaining - monthSecs 200 - while((daySecs + secondsInDay) < daySecsRemaining) do 201 - day = day + 1 202 - daySecs = daySecs + secondsInDay 203 - daysSinceEpoch = daysSinceEpoch + 1 204 - end 205 - hour = 0 -- Midnight 206 - hourSecs = 0 207 - hourSecsRemaining = daySecsRemaining - daySecs 208 - while((hourSecs + secondsInHour) < hourSecsRemaining) do 209 - hour = hour + 1 210 - hourSecs = hourSecs + secondsInHour 211 - end 212 - minute = 0 -- Midnight 213 - minuteSecs = 0 214 - minuteSecsRemaining = hourSecsRemaining - hourSecs 215 - while((minuteSecs + 60) < minuteSecsRemaining) do 216 - minute = minute + 1 217 - minuteSecs = minuteSecs + 60 218 - end 219 - second = math.floor(now % 60) 220 - year = rZ(year) 221 - month = rZ(month) 222 - day = rZ(day) 223 - hour = rZ(hour) 224 - minute = rZ(minute) 225 - second = rZ(second) 226 - remanderForDOW = daysSinceEpoch % 7 227 - DOW = DOWAssociates[remanderForDOW] 228 - 229 - if(outputTime) then 230 - str = "Year: " .. year .. ", Month: " .. month .. ", Day: " .. day .. ", Hour: " .. hour .. ", Minute: " .. minute .. ", Second: ".. second .. ", Day of Week: " .. DOW 231 - system.print(str) 232 - end 233 - return year, month, day, hour, minute, second, DOW 39 + end 40 + local daysFromYearStart = math.floor(time/secondsInDay) 41 + --febuary 42 + if daysFromYearStart >= 31 then 43 + month = 2 44 + daysFromYearStart = daysFromYearStart - 31 45 + end 46 + --march 47 + if daysFromYearStart >= daysInFebuary then 48 + month = 3 49 + daysFromYearStart = daysFromYearStart - daysInFebuary 50 + end 51 + --april 52 + if daysFromYearStart >= 31 then 53 + month = 4 54 + daysFromYearStart = daysFromYearStart - 31 55 + end 56 + --may 57 + if daysFromYearStart >= 30 then 58 + month = 5 59 + daysFromYearStart = daysFromYearStart - 30 60 + end 61 + --juin 62 + if daysFromYearStart >= 31 then 63 + month = 6 64 + daysFromYearStart = daysFromYearStart - 31 65 + end 66 + --july 67 + if daysFromYearStart >= 30 then 68 + month = 7 69 + daysFromYearStart = daysFromYearStart - 30 70 + end 71 + --august 72 + if daysFromYearStart >= 31 then 73 + month = 8 74 + daysFromYearStart = daysFromYearStart - 31 75 + end 76 + --september 77 + if daysFromYearStart >= 31 then 78 + month = 9 79 + daysFromYearStart = daysFromYearStart - 31 80 + end 81 + --october 82 + if daysFromYearStart >= 30 then 83 + month = 10 84 + daysFromYearStart = daysFromYearStart - 30 85 + end 86 + --november 87 + if daysFromYearStart >= 31 then 88 + month = 11 89 + daysFromYearStart = daysFromYearStart - 31 90 + end 91 + --december 92 + if daysFromYearStart >= 30 then 93 + month = 12 94 + daysFromYearStart = daysFromYearStart - 30 95 + end 96 + day = daysFromYearStart 97 + time = time % secondsInDay 98 + local h = math.floor(time/secondsInHour)%24 99 + local m = math.floor(time%secondsInHour/60) 100 + local s = math.floor(time%60) 101 + return year, month, day, h, m, s 234 102 end 235 - 236 - 237 - --[[ 238 - USAGE 239 - Copy the full script in Library > Start 240 - 241 - local year, month, day, hour, minute, second, dow = epochTime() 242 - 243 - you can add a timer every seconds to display the time 244 - ]]