Difference between revisions of "Module:Age/sandbox"

From blackwiki
Jump to navigation Jump to search
blackwiki>Steel1943
(Create sandbox version of Module:Age)
 
blackwiki>Johnuniq
(plans for having Module:Age use Module:Date; more to do)
Line 1: Line 1:
--[[ Code for some date functions, including implementations of:
+
-- Implement various "age of" and other date-related templates.
        {{Age in days}}                age_days
 
        {{Age in years and months}}    age_ym
 
        {{Gregorian serial date}}      gsd_ymd
 
Calendar functions will be needed in many areas, so this may be superseded
 
by some other system, perhaps using PHP functions accessed via mw.
 
]]
 
  
 +
local datemod = require('Module:Date')
 +
local current = datemod._current
 +
local Date = datemod._Date
 
local MINUS = '−'  -- Unicode U+2212 MINUS SIGN
 
local MINUS = '−'  -- Unicode U+2212 MINUS SIGN
 
local function number_name(number, singular, plural, sep)
 
    -- Return the given number, converted to a string, with the
 
    -- separator (default space) and singular or plural name appended.
 
    plural = plural or (singular .. 's')
 
    sep = sep or ' '
 
    return tostring(number) .. sep .. ((number == 1) and singular or plural)
 
    -- this uses an interesting trick of Lua:
 
    --  * and reurns false if the first argument is false, and the second otherwise, so (number==1) and singular returns singular if its 1, returns false if it is only 1
 
    --  * or returns the first argument if it is not false, and the second argument if the first is false
 
    --  * so, if number is 1, and evaluates (true and singular) returning (singular); or evaluates (singular or plural), finds singular non-false, and returns singular
 
    --  * but, if number is not 1, and evaluates (false and singular) returning (false); or evaluates (false or plural), and is forced to return plural
 
end
 
  
 
local function strip_to_nil(text)
 
local function strip_to_nil(text)
    -- If text is a non-blank string, return its content with no leading
+
-- If text is a string, return its trimmed content, or nil if empty.
    -- or trailing whitespace.
+
-- Otherwise return text (which may, for example, be nil).
    -- Otherwise return nil (a nil or empty string argument gives a nil
+
if type(text) == 'string' then
    -- result, as does a string argument of only whitespace).
+
text = text:match('(%S.-)%s*$')
    if type(text) == 'string' then
+
end
        local result = text:match("^%s*(.-)%s*$")
+
return text
        if result ~= '' then
 
            return result
 
        end
 
    end
 
    return nil
 
 
end
 
end
  
local function is_leap_year(year)
+
local function number_name(number, singular, plural, sep)
    -- Return true if year is a leap year, assuming Gregorian calendar.
+
-- Return the given number, converted to a string, with the
    return year % 4 == 0 and (year % 100 ~= 0 or year % 400 == 0)
+
-- separator (default space) and singular or plural name appended.
 +
plural = plural or (singular .. 's')
 +
sep = sep or ' '
 +
return tostring(number) .. sep .. ((number == 1) and singular or plural)
 
end
 
end
  
local function days_in_month(year, month)
+
local function message(msg, nocat)
    -- Return number of days (1..31) in given month (1..12).
+
-- Return formatted message text for an error.
    local month_days = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
+
-- Can append "#FormattingError" to URL of a page with a problem to find it.
    if month == 2 and is_leap_year(year) then
+
local anchor = '<span id="FormattingError" />'
        return 29
+
local category
    end
+
if not nocat and mw.title.getCurrentTitle():inNamespaces(0, 10) then
    return month_days[month]
+
-- Category only in namespaces: 0=article, 10=template.
 +
category = '[[Category:Age error]]'
 +
else
 +
category = ''
 +
end
 +
return anchor ..
 +
'<strong class="error">Error: ' ..
 +
msg ..
 +
'</strong>' ..
 +
category .. '\n'
 
end
 
end
 
-- A table to get current year/month/day (UTC), but only if needed.
 
local current = setmetatable({}, {
 
        __index = function (self, key)
 
            local d = os.date('!*t')
 
            self.year = d.year
 
            self.month = d.month
 
            self.day = d.day
 
            return rawget(self, key)
 
        end
 
    })
 
  
 
local function date_component(named, positional, component)
 
local function date_component(named, positional, component)
    -- Return the first of the two arguments that is not nil and is not empty.
+
-- Return the first of the two arguments (named like {{example|year=2001}}
    -- If both are nil, return the current date component, if specified.
+
-- or positional like {{example|2001}}) that is not nil and is not empty.
    -- The returned value is nil or is a number.
+
-- If both are nil, return the current date component, if specified.
    -- This translates empty arguments passed to the template to nil, and
+
-- This translates empty arguments passed to the template to nil, and
    -- optionally replaces a nil argument with a value from the current date.
+
-- optionally replaces a nil argument with a value from the current date.
    named = strip_to_nil(named)
+
named = strip_to_nil(named)
    if named then
+
if named then
        return tonumber(named)
+
return named
    end
+
end
    positional = strip_to_nil(positional)
+
positional = strip_to_nil(positional)
    if positional then
+
if positional then
        return tonumber(positional)
+
return positional
    end
+
end
    if component then
+
if component then
        return current[component]
+
return current[component]
    end
+
end
    return nil
+
return nil
 
end
 
end
  
local function gsd(year, month, day)
+
local function get_dates(frame, want_mixture)
    -- Return the Gregorian serial day (an integer >= 1) for the given date,
+
-- Return date1, date2 from template parameters.
    -- or return nil if the date is invalid (only check that year >= 1).
+
-- Either may be nil if given arguments are invalid.
    -- This is the number of days from the start of 1 AD (there is no year 0).
+
-- If want_mixture is true, a missing date component is replaced
    -- This code implements the logic in [[Template:Gregorian serial date]].
+
-- from the current date, so can get a bizarre mixture of
    if year < 1 then
+
-- specified/current y/m/d as has been done by some "age" templates.
        return nil
+
-- TODO Accept a date as a string like "1 April 2016".
    end
+
local date1, date2
    local floor = math.floor
+
local args = frame:getParent().args
    local days_this_year = (month - 1) * 30.5 + day
+
if want_mixture then
    if month > 2 then
+
date1 = Date(
        if is_leap_year(year) then
+
date_component(args.year1 , args[1], 'year' ),
            days_this_year = days_this_year - 1
+
date_component(args.month1, args[2], 'month'),
        else
+
date_component(args.day1  , args[3], 'day'  )
            days_this_year = days_this_year - 2
+
)
        end
+
date2 = Date(
        if month > 8 then
+
date_component(args.year2 , args[4], 'year' ),
            days_this_year = days_this_year + 0.9
+
date_component(args.month2, args[5], 'month'),
        end
+
date_component(args.day2  , args[6], 'day'  )
    end
+
)
    days_this_year = floor(days_this_year + 0.5)
+
else
    year = year - 1
+
local fields = {}
    local days_from_past_years = year * 365
+
for i = 1, 6 do
        + floor(year / 4)
+
fields[i] = strip_to_nil(args[i])
        - floor(year / 100)
+
end
        + floor(year / 400)
+
date1 = Date(fields[1], fields[2], fields[3])
    return days_from_past_years + days_this_year
+
if fields[4] and fields[5] and fields[6] then
 +
date2 = Date(fields[4], fields[5], fields[6])
 +
else
 +
date2 = Date('currentdate')
 +
end
 +
end
 +
return date1, date2
 
end
 
end
  
local Date = {
+
local function age_days(frame)
    -- A naive date that assumes the Gregorian calendar always applied.
+
-- Return age in days between two given dates, or
    year = 0,  -- 1 to 9999 (0 if never set)
+
-- between given date and current date.
    month = 1,  -- 1 to 12
+
-- This code implements the logic in [[Template:Age in days]].
    day = 1,    -- 1 to 31
+
-- Like {{Age in days}}, a missing argument is replaced from the current
    isvalid = false,
+
-- date, so can get a bizarre mixture of specified/current y/m/d.
    new = function (self, o)
+
local date1, date2 = get_dates(frame, true)
        o = o or {}
+
if not (date1 and date2) then
        setmetatable(o, self)
+
return message('Need valid year, month, day')
        self.__index = self
+
end
        return o
+
local sign = ''
    end
+
local result = date2.jd - date1.jd
}
+
if result < 0 then
 +
sign = '−'
 +
result = -result
 +
end
 +
return sign .. tostring(result)
 +
end
  
function Date:__lt(rhs)
+
local function _age_ym(diff)
    -- Return true if self < rhs.
+
-- Return text specifying date difference in years, months.
    if self.year < rhs.year then
+
local sign = diff.isnegative and MINUS or ''
        return true
+
local years, months = diff:age('ym')
    elseif self.year == rhs.year then
+
local mtext = number_name(months, 'month')
        if self.month < rhs.month then
+
local result
            return true
+
if years > 0 then
        elseif self.month == rhs.month then
+
local ytext = number_name(years, 'year')
            return self.day < rhs.day
+
if months == 0 then
        end
+
result = ytext
    end
+
else
    return false
+
result = ytext .. ',&nbsp;' .. mtext
    -- probably simplify to return (self.year < rhs.year) or ((self.year == rhs.year) and ((self.month < rhs.month) or ((self.month == rhs.month) and (self.day < rhs.day))))
+
end
    -- would be just as efficient, as lua does not evaluate second argument of (true or second_argument)
+
else
    -- or similarly return self.year < rhs.year ? true : self.year > rhs.year ? false : self.month < rhs.month ? true : self.month > rhs.month ? false : self.day < rhs.day
+
if months == 0 then
 +
sign = ''
 +
end
 +
result = mtext
 +
end
 +
return sign .. result
 
end
 
end
  
function Date:set_current()
+
local function age_ym(frame)
    -- Set date from current time (UTC) and return self.
+
-- Return age in years and months between two given dates, or
    self.year = current.year
+
-- between given date and current date.
    self.month = current.month
+
-- The older date is usually first; result is negative if the first is newer.
    self.day = current.day
+
local date1, date2 = get_dates(frame, false)
    self.isvalid = true
+
if not date1 then
    return self
+
return message('Need valid year, month, day')
 +
end
 +
if not date2 then
 +
return message('Second date should be year, month, day')
 +
end
 +
return _age_ym(date2 - date1)
 
end
 
end
  
function Date:set_ymd(y, m, d)
+
--[[ TODO
    -- Set date from year, month, day (strings or numbers) and return self.
+
All these templates usually have the older date first (otherwise result is negative).
    -- LATER: If m is a name like "March" or "mar", translate it to a month.
+
                    * = date1, date2 positional; date2 defaults to current
    y = tonumber(y)
+
age_days(frame) * also accepts named y,m,d and text dates
    m = tonumber(m)
+
age_years(frame) *
    d = tonumber(d)
+
age_yd(frame) * also accepts text dates
    if type(y) == 'number' and type(m) == 'number' and type(d) == 'number' then
+
age_ym(frame) *
        self.year = y
+
age_ymd(frame) * also accepts named y,m,d; can omit d for "or"
        self.month = m
+
age_ymwd(frame) . named only; defaults to current
        self.day = d
+
]]
        self.isvalid = (1 <= y and y <= 9999 and 1 <= m and m <= 12 and
+
local function age_years(frame)
                        1 <= d and d <= days_in_month(y, m))
+
-- TODO d1, d2 positional; d2 defaults to current; usually d1 < d2
    end
 
    return self
 
 
end
 
end
 
+
local function age_yd(frame)
local DateDiff = {
+
-- TODO
    -- Simple difference between two dates, assuming Gregorian calendar.
 
    isnegative = false,  -- true if second date is before first
 
    years = 0,
 
    months = 0,
 
    days = 0,
 
    new = function (self, o)
 
        o = o or {}
 
        setmetatable(o, self)
 
        self.__index = self
 
        return o
 
    end
 
}
 
 
 
function DateDiff:set(date1, date2)
 
    -- Set difference between the two dates, and return self.
 
    -- Difference is negative if the second date is older than the first.
 
    local isnegative
 
    if date2 < date1 then
 
        isnegative = true
 
        date1, date2 = date2, date1
 
    else
 
        isnegative = false
 
    end
 
    -- It is known that date1 <= date2.
 
    local y1, m1, d1 = date1.year, date1.month, date1.day
 
    local y2, m2, d2 = date2.year, date2.month, date2.day
 
    local years, months, days = y2 - y1, m2 - m1, d2 - d1
 
    if days < 0 then
 
        days = days + days_in_month(y1, m1)
 
        months = months - 1
 
    end
 
    if months < 0 then
 
        months = months + 12
 
        years = years - 1
 
    end
 
    self.years, self.months, self.days, self.isnegative = years, months, days, isnegative
 
    return self
 
 
end
 
end
 
+
local function age_ymd(frame)
function DateDiff:age_ym()
+
-- TODO
    -- Return text specifying difference in years, months.
 
    local sign = self.isnegative and MINUS or ''
 
    local mtext = number_name(self.months, 'month')
 
    local result
 
    if self.years > 0 then
 
        local ytext = number_name(self.years, 'year')
 
        if self.months == 0 then
 
            result = ytext
 
        else
 
            result = ytext .. ',&nbsp;' .. mtext
 
        end
 
    else
 
        if self.months == 0 then
 
            sign = ''
 
        end
 
        result = mtext
 
    end
 
    return sign .. result
 
 
end
 
end
 
+
local function age_ymwd(frame)
local function error_wikitext(text)
+
-- TODO
    -- Return message for display when template parameters are invalid.
 
    local prefix = '[[Module talk:Age|Module error]]:'
 
    local cat = '[[Category:Age error]]'
 
    return '<span style="color:black; background-color:pink;">' ..
 
            prefix .. ' ' .. text .. cat .. '</span>'
 
 
end
 
end
  
local function age_days(frame)
+
local function gsd_ymd(frame)
    -- Return age in days between two given dates, or
+
-- Return Gregorian serial date of the given date, or the current date.
    -- between given date and current date.
+
-- Like {{Gregorian serial date}}, a missing argument is replaced from the
    -- This code implements the logic in [[Template:Age in days]].
+
-- current date, so can get a bizarre mixture of specified/current y/m/d.
    -- Like {{Age in days}}, a missing argument is replaced from the current
+
-- This also accepts positional arguments, although the original template does not.
    -- date, so can get a bizarre mixture of specified/current y/m/d.
+
-- The returned value is negative for dates before 1 January 1 AD despite
    local args = frame:getParent().args
+
-- the fact that GSD is not defined for earlier dates.
    local year1  = date_component(args.year1 , args[1], 'year' )
+
local args = frame:getParent().args
    local month1 = date_component(args.month1, args[2], 'month')
+
local date = Date(
    local day1  = date_component(args.day1 , args[3], 'day'  )
+
date_component(args.year , args[1], 'year' ),
    local year2  = date_component(args.year2 , args[4], 'year' )
+
date_component(args.month, args[2], 'month'),
    local month2 = date_component(args.month2, args[5], 'month')
+
date_component(args.day , args[3], 'day'  )
    local day2  = date_component(args.day2  , args[6], 'day'  )
+
)
    local gsd1 = gsd(year1, month1, day1)
+
if date then
    local gsd2 = gsd(year2, month2, day2)
+
return tostring(date.gsd)
    if gsd1 and gsd2 then
+
end
        local sign = ''
+
return message('Need valid year, month, day')
        local result = gsd2 - gsd1
 
        if result < 0 then
 
            sign = MINUS
 
            result = -result
 
        end
 
        return sign .. tostring(result)
 
    end
 
    return error_wikitext('Cannot handle dates before the year 1 AD')
 
 
end
 
end
  
local function age_ym(frame)
+
local function ymd_from_jd(frame)
    -- Return age in years and months between two given dates, or
+
-- Return formatted date from a Julian date.
    -- between given date and current date.
+
-- The result is y-m-d or y-m-d H:M:S if input includes a fraction.
    local args = frame:getParent().args
+
-- The word 'Julian' is accepted for the Julian calendar.
    local fields = {}
+
local args = frame:getParent().args
    for i = 1, 6 do
+
local date = Date('juliandate', args[1], args[2])
        fields[i] = strip_to_nil(args[i])
+
if date then
    end
+
return date:text()
    local date1, date2
+
end
    if fields[1] and fields[2] and fields[3] then
+
return message('Need valid Julian date number')
        date1 = Date:new():set_ymd(fields[1], fields[2], fields[3])
 
    end
 
    if not (date1 and date1.isvalid) then
 
        return error_wikitext('Need date: year, month, day')
 
    end
 
    if fields[4] and fields[5] and fields[6] then
 
        date2 = Date:new():set_ymd(fields[4], fields[5], fields[6])
 
        if not date2.isvalid then
 
            return error_wikitext('Second date should be year, month, day')
 
        end
 
    else
 
        date2 = Date:new():set_current()
 
    end
 
    return DateDiff:new():set(date1, date2):age_ym()
 
 
end
 
end
  
local function gsd_ymd(frame)
+
local function ymd_to_jd(frame)
    -- Return Gregorian serial day of the given date, or the current date.
+
-- Return Julian date (a number) from a date (y-m-d), or datetime (y-m-d H:M:S),
    -- Like {{Gregorian serial date}}, a missing argument is replaced from the
+
-- or the current date ('currentdate') or current datetime ('currentdatetime').
    -- current date, so can get a bizarre mixture of specified/current y/m/d.
+
-- The word 'Julian' is accepted for the Julian calendar.
    -- This accepts positional arguments, although the original template does not.
+
local args = frame:getParent().args
    local args = frame:getParent().args
+
local date = Date(args[1], args[2], args[3], args[4], args[5], args[6], args[7])
    local year  = date_component(args.year , args[1], 'year' )
+
if date then
    local month = date_component(args.month, args[2], 'month')
+
return tostring(date.jd)
    local day  = date_component(args.day  , args[3], 'day'  )
+
end
    local result = gsd(year, month, day)
+
return message('Need valid year/month/day or "currentdate"')
    if result then
 
        return tostring(result)
 
    end
 
    return error_wikitext('Cannot handle dates before the year 1 AD')
 
 
end
 
end
  
return { age_days = age_days, age_ym = age_ym, gsd = gsd_ymd }
+
return {
 +
age_days = age_days,
 +
age_years = age_years,
 +
age_yd = age_yd,
 +
age_ym = age_ym,
 +
age_ymd = age_ymd,
 +
age_ymwd = age_ymwd,
 +
gsd = gsd_ymd,
 +
JULIANDAY = ymd_to_jd,
 +
ymd_from_jd = ymd_from_jd,
 +
ymd_to_jd = ymd_to_jd,
 +
}

Revision as of 00:48, 14 May 2016

Documentation for this module may be created at Module:Age/sandbox/doc

-- Implement various "age of" and other date-related templates.

local datemod = require('Module:Date')
local current = datemod._current
local Date = datemod._Date
local MINUS = '−'  -- Unicode U+2212 MINUS SIGN

local function strip_to_nil(text)
	-- If text is a string, return its trimmed content, or nil if empty.
	-- Otherwise return text (which may, for example, be nil).
	if type(text) == 'string' then
		text = text:match('(%S.-)%s*$')
	end
	return text
end

local function number_name(number, singular, plural, sep)
	-- Return the given number, converted to a string, with the
	-- separator (default space) and singular or plural name appended.
	plural = plural or (singular .. 's')
	sep = sep or ' '
	return tostring(number) .. sep .. ((number == 1) and singular or plural)
end

local function message(msg, nocat)
	-- Return formatted message text for an error.
	-- Can append "#FormattingError" to URL of a page with a problem to find it.
	local anchor = '<span id="FormattingError" />'
	local category
	if not nocat and mw.title.getCurrentTitle():inNamespaces(0, 10) then
		-- Category only in namespaces: 0=article, 10=template.
		category = '[[Category:Age error]]'
	else
		category = ''
	end
	return anchor ..
		'<strong class="error">Error: ' ..
		msg ..
		'</strong>' ..
		category .. '\n'
end

local function date_component(named, positional, component)
	-- Return the first of the two arguments (named like {{example|year=2001}}
	-- or positional like {{example|2001}}) that is not nil and is not empty.
	-- If both are nil, return the current date component, if specified.
	-- This translates empty arguments passed to the template to nil, and
	-- optionally replaces a nil argument with a value from the current date.
	named = strip_to_nil(named)
	if named then
		return named
	end
	positional = strip_to_nil(positional)
	if positional then
		return positional
	end
	if component then
		return current[component]
	end
	return nil
end

local function get_dates(frame, want_mixture)
	-- Return date1, date2 from template parameters.
	-- Either may be nil if given arguments are invalid.
	-- If want_mixture is true, a missing date component is replaced
	-- from the current date, so can get a bizarre mixture of
	-- specified/current y/m/d as has been done by some "age" templates.
	-- TODO Accept a date as a string like "1 April 2016".
	local date1, date2
	local args = frame:getParent().args
	if want_mixture then
		date1 = Date(
			date_component(args.year1 , args[1], 'year' ),
			date_component(args.month1, args[2], 'month'),
			date_component(args.day1  , args[3], 'day'  )
		)
		date2 = Date(
			date_component(args.year2 , args[4], 'year' ),
			date_component(args.month2, args[5], 'month'),
			date_component(args.day2  , args[6], 'day'  )
		)
	else
		local fields = {}
		for i = 1, 6 do
			fields[i] = strip_to_nil(args[i])
		end
		date1 = Date(fields[1], fields[2], fields[3])
		if fields[4] and fields[5] and fields[6] then
			date2 = Date(fields[4], fields[5], fields[6])
		else
			date2 = Date('currentdate')
		end
	end
	return date1, date2
end

local function age_days(frame)
	-- Return age in days between two given dates, or
	-- between given date and current date.
	-- This code implements the logic in [[Template:Age in days]].
	-- Like {{Age in days}}, a missing argument is replaced from the current
	-- date, so can get a bizarre mixture of specified/current y/m/d.
	local date1, date2 = get_dates(frame, true)
	if not (date1 and date2) then
		return message('Need valid year, month, day')
	end
	local sign = ''
	local result = date2.jd - date1.jd
	if result < 0 then
		sign = '−'
		result = -result
	end
	return sign .. tostring(result)
end

local function _age_ym(diff)
	-- Return text specifying date difference in years, months.
	local sign = diff.isnegative and MINUS or ''
	local years, months = diff:age('ym')
	local mtext = number_name(months, 'month')
	local result
	if years > 0 then
		local ytext = number_name(years, 'year')
		if months == 0 then
			result = ytext
		else
			result = ytext .. ',&nbsp;' .. mtext
		end
	else
		if months == 0 then
			sign = ''
		end
		result = mtext
	end
	return sign .. result
end

local function age_ym(frame)
	-- Return age in years and months between two given dates, or
	-- between given date and current date.
	-- The older date is usually first; result is negative if the first is newer.
	local date1, date2 = get_dates(frame, false)
	if not date1 then
		return message('Need valid year, month, day')
	end
	if not date2 then
		return message('Second date should be year, month, day')
	end
	return _age_ym(date2 - date1)
end

--[[ TODO
All these templates usually have the older date first (otherwise result is negative).
                    * = date1, date2 positional; date2 defaults to current
age_days(frame)		* also accepts named y,m,d and text dates
age_years(frame)	*
age_yd(frame)		* also accepts text dates
age_ym(frame)		*
age_ymd(frame)		* also accepts named y,m,d; can omit d for "or"
age_ymwd(frame)		. named only; defaults to current
]]
local function age_years(frame)
	-- TODO d1, d2 positional; d2 defaults to current; usually d1 < d2
end
local function age_yd(frame)
	-- TODO
end
local function age_ymd(frame)
	-- TODO
end
local function age_ymwd(frame)
	-- TODO
end

local function gsd_ymd(frame)
	-- Return Gregorian serial date of the given date, or the current date.
	-- Like {{Gregorian serial date}}, a missing argument is replaced from the
	-- current date, so can get a bizarre mixture of specified/current y/m/d.
	-- This also accepts positional arguments, although the original template does not.
	-- The returned value is negative for dates before 1 January 1 AD despite
	-- the fact that GSD is not defined for earlier dates.
	local args = frame:getParent().args
	local date = Date(
		date_component(args.year , args[1], 'year' ),
		date_component(args.month, args[2], 'month'),
		date_component(args.day  , args[3], 'day'  )
	)
	if date then
		return tostring(date.gsd)
	end
	return message('Need valid year, month, day')
end

local function ymd_from_jd(frame)
	-- Return formatted date from a Julian date.
	-- The result is y-m-d or y-m-d H:M:S if input includes a fraction.
	-- The word 'Julian' is accepted for the Julian calendar.
	local args = frame:getParent().args
	local date = Date('juliandate', args[1], args[2])
	if date then
		return date:text()
	end
	return message('Need valid Julian date number')
end

local function ymd_to_jd(frame)
	-- Return Julian date (a number) from a date (y-m-d), or datetime (y-m-d H:M:S),
	-- or the current date ('currentdate') or current datetime ('currentdatetime').
	-- The word 'Julian' is accepted for the Julian calendar.
	local args = frame:getParent().args
	local date = Date(args[1], args[2], args[3], args[4], args[5], args[6], args[7])
	if date then
		return tostring(date.jd)
	end
	return message('Need valid year/month/day or "currentdate"')
end

return {
	age_days = age_days,
	age_years = age_years,
	age_yd = age_yd,
	age_ym = age_ym,
	age_ymd = age_ymd,
	age_ymwd = age_ymwd,
	gsd = gsd_ymd,
	JULIANDAY = ymd_to_jd,
	ymd_from_jd = ymd_from_jd,
	ymd_to_jd = ymd_to_jd,
}