Jump to content

Module:Sandbox/DixonD/Datetime/Julian

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Verdy p (talk | contribs) at 04:11, 19 April 2013. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
local z = {}

function z.julianDay(year, month, day, hour, minute, second)
    -- set defaults 
    if month == nil then month = 1; end;
    if day == nil then day = 1; end;
    if hour == nil then hour = 12; end;
    if minute == nil then minute = 0; end;
    if second == nil then second = 0; end;
    -- http://www.tondering.dk/claus/cal/julperiod.php#formula
    local y = year + 4799;
    local m = y * 12 + month + 9;
    local d = day - 1;
    y = math.floor(m / 12);
    m = m - y * 12;
    return
          math.floor(y * 1461 / 4)
        + math.floor((m + 4) * 153 / 5) - 122
        + d
        + (hour - 12) / 24
        + minute / 1440
        + second / 86400
        - 32082;
end
 
return z