Строка 409: |
Строка 409: |
| local patterns = { | | local patterns = { |
| -- year-initial numerical year-month-day | | -- year-initial numerical year-month-day |
− | ['ymd'] = {'^(%d%d%d%d)%-(%d%d)%-(%d%d)$', 'y', 'm', 'd'}, | + | ['ymd'] = {'^(%d%d%d%d)%-(%d%d)%-(%d%d)$', 'y', 'm', 'd'}, |
− | ['ym'] = {'^(%d%d%d%d)%-(%d%d)$', 'y', 'm'},
| |
| -- month-initial: month day, year | | -- month-initial: month day, year |
| ['Mdy'] = {'^(%D-) +([1-9]%d?), +((%d%d%d%d?)%a?)$', 'm', 'd', 'a', 'y'}, | | ['Mdy'] = {'^(%D-) +([1-9]%d?), +((%d%d%d%d?)%a?)$', 'm', 'd', 'a', 'y'}, |
Строка 442: |
Строка 441: |
| ['Sy-y'] = {'^(%D-) +(%d%d%d%d)[%-–]((%d%d%d%d)%a?)$'}, -- special case Winter/Summer year-year; year separated with unspaced endash | | ['Sy-y'] = {'^(%D-) +(%d%d%d%d)[%-–]((%d%d%d%d)%a?)$'}, -- special case Winter/Summer year-year; year separated with unspaced endash |
| ['y-y'] = {'^(%d%d%d%d?)[%-–]((%d%d%d%d?)%a?)$'}, -- year range: YYY-YYY or YYY-YYYY or YYYY–YYYY; separated by unspaced endash; 100-9999 | | ['y-y'] = {'^(%d%d%d%d?)[%-–]((%d%d%d%d?)%a?)$'}, -- year range: YYY-YYY or YYY-YYYY or YYYY–YYYY; separated by unspaced endash; 100-9999 |
− | -- ['y4-y2'] = {'^((%d%d)%d%d)[%-–]((%d%d)%a?)$'}, -- year range: YYYY–YY; separated by unspaced endash
| + | ['y4-y2'] = {'^((%d%d)%d%d)[%-–]((%d%d)%a?)$'}, -- year range: YYYY–YY; separated by unspaced endash |
| ['y'] = {'^((%d%d%d%d?)%a?)$'}, -- year; here accept either YYY or YYYY | | ['y'] = {'^((%d%d%d%d?)%a?)$'}, -- year; here accept either YYY or YYYY |
| } | | } |
Строка 501: |
Строка 500: |
| year, month, day = date_string:match (patterns['ymd'][1]); | | year, month, day = date_string:match (patterns['ymd'][1]); |
| if 12 < tonumber(month) or 1 > tonumber(month) or 1582 > tonumber(year) or 0 == tonumber(day) then return false; end -- month or day number not valid or not Gregorian calendar | | if 12 < tonumber(month) or 1 > tonumber(month) or 1582 > tonumber(year) or 0 == tonumber(day) then return false; end -- month or day number not valid or not Gregorian calendar |
− | anchor_year = year;
| |
− |
| |
− | elseif date_string:match (patterns['ym'][1]) then -- year-initial numerical year month format
| |
− | year, month = date_string:match (patterns['ym'][1]);
| |
− | if 12 < tonumber(month) or 1 > tonumber(month) or 1582 > tonumber(year) then return false; end -- month number not valid or not Gregorian calendar
| |
| anchor_year = year; | | anchor_year = year; |
| | | |
Строка 631: |
Строка 625: |
| if not is_valid_year(year2) then return false; end -- no year farther in the future than next year | | if not is_valid_year(year2) then return false; end -- no year farther in the future than next year |
| | | |
− | -- elseif mw.ustring.match(date_string, patterns['y4-y2'][1]) then -- Year range: YYYY–YY; separated by unspaced endash
| + | elseif mw.ustring.match(date_string, patterns['y4-y2'][1]) then -- Year range: YYYY–YY; separated by unspaced endash |
− | -- local century;
| + | local century; |
− | -- year, century, anchor_year, year2 = mw.ustring.match(date_string, patterns['y4-y2'][1]);
| + | year, century, anchor_year, year2 = mw.ustring.match(date_string, patterns['y4-y2'][1]); |
− | -- anchor_year = year .. '–' .. anchor_year; -- assemble anchor year from both years
| + | anchor_year = year .. '–' .. anchor_year; -- assemble anchor year from both years |
| | | |
− | -- if 13 > tonumber(year2) then return false; end -- don't allow 2003-05 which might be May 2003
| + | if 13 > tonumber(year2) then return false; end -- don't allow 2003-05 which might be May 2003 |
− | -- year2 = century .. year2; -- add the century to year2 for comparisons
| + | year2 = century .. year2; -- add the century to year2 for comparisons |
− | -- if tonumber(year) >= tonumber(year2) then return false; end -- left to right, earlier to later, not the same
| + | if tonumber(year) >= tonumber(year2) then return false; end -- left to right, earlier to later, not the same |
− | -- if not is_valid_year(year2) then return false; end -- no year farther in the future than next year
| + | if not is_valid_year(year2) then return false; end -- no year farther in the future than next year |
| | | |
− | -- if in_array (param, {'date', 'publication-date', 'year'}) then -- here when 'valid' abbreviated year range; if one of these parameters
| + | if in_array (param, {'date', 'publication-date', 'year'}) then -- here when 'valid' abbreviated year range; if one of these parameters |
− | -- add_prop_cat ('year-range-abbreviated'); -- add properties cat
| + | add_prop_cat ('year-range-abbreviated'); -- add properties cat |
− | -- end
| + | end |
| | | |
| elseif mw.ustring.match(date_string, patterns['y'][1]) then -- year; here accept either YYY or YYYY | | elseif mw.ustring.match(date_string, patterns['y'][1]) then -- year; here accept either YYY or YYYY |
Строка 785: |
Строка 779: |
| year = year_string:match ('(%d%d%d%d?)'); | | year = year_string:match ('(%d%d%d%d?)'); |
| | | |
− | if ( date_string:match ('%d%d%d%d%-%d%d%-%d%d') or date_string:match ('%d%d%d%d%-%d%d') ) and year_string:match ('%d%d%d%d%a') then --special case where both date and year are required YYYY-MM-DD and YYYYx | + | if date_string:match ('%d%d%d%d%-%d%d%-%d%d') and year_string:match ('%d%d%d%d%a') then --special case where both date and year are required YYYY-MM-DD and YYYYx |
| date1 = date_string:match ('(%d%d%d%d)'); | | date1 = date_string:match ('(%d%d%d%d)'); |
| year = year_string:match ('(%d%d%d%d)'); | | year = year_string:match ('(%d%d%d%d)'); |
Строка 800: |
Строка 794: |
| end | | end |
| | | |
− | -- elseif mw.ustring.match(date_string, "%d%d%d%d[%-–]%d%d") then -- YYYY-YY date ranges
| + | elseif mw.ustring.match(date_string, "%d%d%d%d[%-–]%d%d") then -- YYYY-YY date ranges |
− | -- local century;
| + | local century; |
− | -- date1, century, date2 = mw.ustring.match(date_string, "((%d%d)%d%d)[%-–]+(%d%d)");
| + | date1, century, date2 = mw.ustring.match(date_string, "((%d%d)%d%d)[%-–]+(%d%d)"); |
− | -- date2 = century..date2; -- convert YY to YYYY
| + | date2 = century..date2; -- convert YY to YYYY |
− | -- if year ~= date1 and year ~= date2 then
| + | if year ~= date1 and year ~= date2 then |
− | -- result = 0;
| + | result = 0; |
− | -- end
| + | end |
| | | |
| elseif date_string:match ("%d%d%d%d?") then -- any of the standard formats of date with one year | | elseif date_string:match ("%d%d%d%d?") then -- any of the standard formats of date with one year |