Created
May 17, 2016 20:42
-
-
Save Validark/943b451d8de7baf452459a4695f95519 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Unix must be the current timestamp in seconds since January 1st, 1970 | |
-- Get days, month and year | |
local days = floor(unix / 86400) + 719468 | |
local wday = (days + 3) % 7 | |
local year = floor((days >= 0 and days or days - 146096) / 146097) -- 400 Year bracket | |
days = (days - year * 146097) -- Days into 400 year bracket [0, 146096] | |
local years = floor((days - floor(days/1460) + floor(days/36524) - floor(days/146096))/365) -- Years into 400 Year bracket[0, 399] | |
days = days - (365*years + floor(years/4) - floor(years/100)) -- Days into year (March 1st is first day) [0, 365] | |
local month = floor((5*days + 2)/153) -- Month of year (March is month 0) [0, 11] | |
local yDay = days -- Hi readers :) | |
days = days - floor((153*month + 2)/5) + 1 -- Days into month [1, 31] | |
month = month + (month < 10 and 3 or -9) -- Real life month [1, 12] | |
year = years + year*400 + (month < 3 and 1 or 0) -- Actual year (Shift 1st month from March to January) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment