Content deleted Content added
new collection; try different birth date and age procedures: reject empty birth date; show age in days if months < 1, or months if years < 2, otherwise years |
convert to camelCase per dominant style |
||
Line 2:
local _Date, _current_date
local function
-- Return objects exported from the date module or its sandbox.
if not _Date then
Line 39:
Collection.__index = Collection
local function
-- If text is a string, return its trimmed content, or nil if empty.
-- Otherwise return text (which may, for example, be nil).
Line 94:
end
local function
-- Return a sort key in a span if specified.
-- Assume value is a valid number which has not overflowed.
Line 119:
end
local
abbr = {
off = 'abbr_off',
Line 177:
}
local function
-- Return part of a date after performing an optional operation.
local Date =
local args = frame:getParent().args
local parms = {}
Line 195:
return message('Need valid date')
end
local add =
if add then
for item in add:gmatch('%S+') do
Line 205:
end
local prefix, result
local sortable =
if sortable then
local value = (date.partial and date.partial.first or date).jdz
prefix =
end
local show =
if show ~= 'hide' then
result = date[show]
Line 224:
end
local function
-- Return wikitext representing an age or duration.
local text = Collection.new()
Line 295:
end
local function
-- Return a formatted date difference using the given parameters
-- which have been validated.
Line 335:
local show = parms.show -- may be nil; default is set below
local abbr = parms.abbr or 'abbr_off'
local
if abbr ~= 'abbr_off' then
end
if not show then
Line 343:
if parms.disp == 'disp_age' then
if diff.years < 3 then
if diff.years >= 1 then
show = 'ym'
Line 355:
end
if type(show) ~= 'table' then
show =
end
if parms.disp == 'disp_raw' then
abbr = 'abbr_raw'
elseif parms.want_sc then
end
local
round = parms.round,
duration = parms.want_duration,
Line 374:
value = -value
end
prefix =
end
local
prefix = prefix,
suffix = parms.suffix, -- not currently used
format = parms.format,
join = parms.sep or
isnegative = diff.isnegative,
range = parms.range,
Line 387:
return prefix or ''
end
local values = { diff:age(show.id,
if values[1] then
return
end
return message('Parameter show=' .. show.id .. ' is not supported here')
end
local function
-- Parse template parameters and return one of:
-- * date (a date table, if single)
Line 404:
-- specified/current y/m/d as has been done by some "age" templates.
-- Some results may be placed in table getopt.
local Date,
getopt = getopt or {}
local fix = getopt.fix and 'fix' or ''
Line 410:
local args = frame:getParent().args
local fields = {}
local
args.month or args.month1 or args.month2 or
args.day or args.day1 or args.day2
if
fields[1] = args.year1 or args.year
fields[2] = args.month1 or args.month
Line 427:
local imax = 0
for i = 1, 6 do
fields[i] =
if fields[i] then
imax = i
Line 434:
local nodefault = imax == 0 and getopt.nomissing
local dates = {}
if
local
if getopt.want_mixture then
-- Cannot be partial since empty fields are set from current.
local components = { 'year', 'month', 'day' }
for i = 1,
fields[i] = fields[i] or
end
for i = 1,
local index = i == 1 and 1 or 4
dates[i] = Date(fields[index], fields[index+1], fields[index+2])
end
else
for i = 1,
local index = i == 1 and 1 or 4
local y, m, d = fields[index], fields[index+1], fields[index+2]
Line 476:
end
local function
-- Return the result required by the specified template.
-- Can use sortable=x where x = on/off/debug in any supported template.
Line 579:
end
if name == 'age_days' then
local su =
if su then
if su == 'abbr' or su == 'full' then
Line 593:
want_mixture = spec.want_mixture,
}
local date1, date2 =
if type(date1) == 'string' then
return date1
end
local format =
if format then
format = 'format_' .. format
Line 614:
round = yes(args.round),
sep = spec.sep,
sortable =
}
if (spec.negative or frame.args.negative) == 'error' and parms.diff.isnegative then
return message('The second date should not be before the first date')
end
return
end
Line 625:
-- Implement [[Template:Birth date and age]].
local args = frame:getParent().args
local date =
if type(date) == 'string' then
return date -- error text
end
local Date =
local now = Date('currentdate')
local diff = now - date
Line 644:
end
end
local df =
local result = df and
'(<span class="bday">%-Y-%m-%d</span>) </span>%-d %B %-Y' or
Line 652:
'<span class="noprint ForceAgeToShow"> ' ..
'(age ' ..
diff = diff,
show = show,
Line 663:
end
local function
-- Implement [[Template:Gregorian serial date]].
-- Return Gregorian serial date of the given date, or the current date.
-- The returned value is negative for dates before 1 January 1 AD
-- despite the fact that GSD is not defined for such dates.
local date =
if type(date) == 'string' then
return date
Line 675:
end
local function
-- Return formatted date from a Julian date.
-- The result includes a time if the input includes a fraction.
-- The word 'Julian' is accepted for the Julian calendar.
local Date =
local args = frame:getParent().args
local date = Date('juliandate', args[1], args[2])
Line 688:
end
local function
-- Return Julian date (a number) from a date which may include a time,
-- or the current date ('currentdate') or current date and time ('currentdatetime').
-- The word 'Julian' is accepted for the Julian calendar.
local Date =
local args = frame:getParent().args
local date = Date(args[1], args[2], args[3], args[4], args[5], args[6], args[7])
Line 701:
end
local function
-- Implement [[Template:Time interval]].
-- There are two positional arguments: date1, date2.
-- The default for each is the current date and time.
-- Result is date2 - date1 formatted.
local Date =
local args = frame:getParent().args
local parms = {
Line 714:
}
local fix = yes(args.fix) and 'fix' or ''
local date1 = Date(fix, 'partial',
if not date1 then
return message('Invalid start date in first parameter')
end
local date2 = Date(fix, 'partial',
if not date2 then
return message('Invalid end date in second parameter')
end
parms.diff = date2 - date1
for argname, translate in pairs(
local parm =
if parm then
parm = translate[parm]
Line 742:
end
else
parms.show =
end
end
parms.round = true
end
return
end
return {
age_generic =
birth_date_and_age = bda, -- Template:Birth_date_and_age
gsd =
extract =
jd_to_date =
JULIANDAY =
time_interval =
}
|