ページ「モジュール:Citation/CS1/Date validation」と「モジュール:Citation/CS1/Date validation/sandbox」の間の差分
表示
(ページ間の差分)
削除された内容 追加された内容
YYYY-M-DDも許可 |
|date=不明 指定時のアンカーを変更 |
||
39行目: | 39行目: | ||
local access_ts, tomorrow_ts; -- to hold Unix time stamps representing the dates |
local access_ts, tomorrow_ts; -- to hold Unix time stamps representing the dates |
||
accessdate = mw.ustring.gsub(accessdate, "[年月日]", "-"):gsub("-$", ""); -- 日本語版独自処理: YYYY年MM月DD日形式の日付を予めYYYY-MM-DD形式に変換する |
|||
accessdate = accessdate:gsub("年", "-"); |
|||
accessdate = accessdate:gsub("月", "-"); |
|||
accessdate = accessdate:gsub("日", "-"); |
|||
accessdate = accessdate:gsub("-$", ""); |
|||
good1, access_ts = pcall (lang_object.formatDate, lang_object, 'U', accessdate ); -- convert accessdate value to Unix timestamp |
good1, access_ts = pcall (lang_object.formatDate, lang_object, 'U', accessdate ); -- convert accessdate value to Unix timestamp |
||
good2, tomorrow_ts = pcall (lang_object.formatDate, lang_object, 'U', 'today + 2 days' ); -- today midnight + 2 days is one second more than all day tomorrow |
good2, tomorrow_ts = pcall (lang_object.formatDate, lang_object, 'U', 'today + 2 days' ); -- today midnight + 2 days is one second more than all day tomorrow |
||
408行目: | 405行目: | ||
These patterns are used for both date validation and for reformatting. This table should not be moved to ~/Configuration |
These patterns are used for both date validation and for reformatting. This table should not be moved to ~/Configuration |
||
because changes to this table require changes to check_date() and to reformatter() and reformat_date() |
because changes to this table require changes to check_date() and to reformatter() and reformat_date() |
||
日本語版独自の変更: アンカー用の接尾辞のパターンを%aから[a-zA-Z]に変更(mw.ustring.match()使用時に「年」のような漢字も%aにマッチするため) |
|||
]] |
]] |
||
413行目: | 412行目: | ||
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'}, -- 日本語版独自仕様: 月と日の先頭の0は省略可能とする(暫定) |
||
['ymd_ja'] = {'^(%d%d%d%d)年(%d%d?)月(%d%d?)日$', 'y', 'm', 'd'}, |
|||
-- month-initial: month day, year |
-- month-initial: month day, year |
||
['Mdy'] = {'^(%D-) +([1-9]%d?), +((%d%d%d%d?) |
['Mdy'] = {'^(%D-) +([1-9]%d?), +((%d%d%d%d?)[a-zA-Z]?)$', 'm', 'd', 'a', 'y'}, |
||
-- month-initial day range: month day–day, year; days are separated by endash |
-- month-initial day range: month day–day, year; days are separated by endash |
||
['Md-dy'] = {'^(%D-) +([1-9]%d?)[%-–]([1-9]%d?), +((%d%d%d%d) |
['Md-dy'] = {'^(%D-) +([1-9]%d?)[%-–]([1-9]%d?), +((%d%d%d%d)[a-zA-Z]?)$', 'm', 'd', 'd2', 'a', 'y'}, |
||
-- day-initial: day month year |
-- day-initial: day month year |
||
['dMy'] = {'^([1-9]%d?) +(%D-) +((%d%d%d%d?) |
['dMy'] = {'^([1-9]%d?) +(%D-) +((%d%d%d%d?)[a-zA-Z]?)$', 'd', 'm', 'a', 'y'}, |
||
-- year-initial: year month day; day: 1 or 2 two digits, leading zero allowed; not supported at en.wiki |
-- year-initial: year month day; day: 1 or 2 two digits, leading zero allowed; not supported at en.wiki |
||
-- ['yMd'] = {'^((%d%d%d%d?) |
-- ['yMd'] = {'^((%d%d%d%d?)[a-zA-Z]?) +(%D-) +(%d%d?)$', 'a', 'y', 'm', 'd'}, |
||
-- day-range-initial: day–day month year; days are separated by endash |
-- day-range-initial: day–day month year; days are separated by endash |
||
['d-dMy'] = {'^([1-9]%d?)[%-–]([1-9]%d?) +(%D-) +((%d%d%d%d) |
['d-dMy'] = {'^([1-9]%d?)[%-–]([1-9]%d?) +(%D-) +((%d%d%d%d)[a-zA-Z]?)$', 'd', 'd2', 'm', 'a', 'y'}, |
||
-- day initial month-day-range: day month - day month year; uses spaced endash |
-- day initial month-day-range: day month - day month year; uses spaced endash |
||
['dM-dMy'] = {'^([1-9]%d?) +(%D-) +[%-–] +([1-9]%d?) +(%D-) +((%d%d%d%d) |
['dM-dMy'] = {'^([1-9]%d?) +(%D-) +[%-–] +([1-9]%d?) +(%D-) +((%d%d%d%d)[a-zA-Z]?)$', 'd', 'm', 'd2', 'm2', 'a', 'y'}, |
||
-- month initial month-day-range: month day – month day, year; uses spaced endash |
-- month initial month-day-range: month day – month day, year; uses spaced endash |
||
['Md-Mdy'] = {'^(%D-) +([1-9]%d?) +[%-–] +(%D-) +([1-9]%d?), +((%d%d%d%d) |
['Md-Mdy'] = {'^(%D-) +([1-9]%d?) +[%-–] +(%D-) +([1-9]%d?), +((%d%d%d%d)[a-zA-Z]?)$','m', 'd', 'm2', 'd2', 'a', 'y'}, |
||
-- day initial month-day-year-range: day month year - day month year; uses spaced endash |
-- day initial month-day-year-range: day month year - day month year; uses spaced endash |
||
['dMy-dMy'] = {'^([1-9]%d?) +(%D-) +(%d%d%d%d) +[%-–] +([1-9]%d?) +(%D-) +((%d%d%d%d) |
['dMy-dMy'] = {'^([1-9]%d?) +(%D-) +(%d%d%d%d) +[%-–] +([1-9]%d?) +(%D-) +((%d%d%d%d)[a-zA-Z]?)$', 'd', 'm', 'y', 'd2', 'm2', 'a', 'y2'}, |
||
-- month initial month-day-year-range: month day, year – month day, year; uses spaced endash |
-- month initial month-day-year-range: month day, year – month day, year; uses spaced endash |
||
['Mdy-Mdy'] = {'^(%D-) +([1-9]%d?), +(%d%d%d%d) +[%-–] +(%D-) +([1-9]%d?), +((%d%d%d%d) |
['Mdy-Mdy'] = {'^(%D-) +([1-9]%d?), +(%d%d%d%d) +[%-–] +(%D-) +([1-9]%d?), +((%d%d%d%d)[a-zA-Z]?)$', 'm', 'd', 'y', 'm2', 'd2', 'a', 'y2'}, |
||
-- these date formats cannot be converted, per se, but month name can be rendered short or long |
-- these date formats cannot be converted, per se, but month name can be rendered short or long |
||
-- month/season year - month/season year; separated by spaced endash |
-- month/season year - month/season year; separated by spaced endash |
||
['My-My'] = {'^(%D-) +(%d%d%d%d) +[%-–] +(%D-) +((%d%d%d%d) |
['My-My'] = {'^(%D-) +(%d%d%d%d) +[%-–] +(%D-) +((%d%d%d%d)[a-zA-Z]?)$', 'm', 'y', 'm2', 'a', 'y2'}, |
||
-- month/season range year; months separated by endash |
-- month/season range year; months separated by endash |
||
['M-My'] = {'^(%D-)[%-–](%D-) +((%d%d%d%d) |
['M-My'] = {'^(%D-)[%-–](%D-) +((%d%d%d%d)[a-zA-Z]?)$', 'm', 'm2', 'a', 'y'}, |
||
-- month/season year or proper-name year; quarter year when First Quarter YYYY etc. |
-- month/season year or proper-name year; quarter year when First Quarter YYYY etc. |
||
['My'] = {'^([^%d–]-) +((%d%d%d%d) |
['My'] = {'^([^%d–]-) +((%d%d%d%d)[a-zA-Z]?)$', 'm', 'a', 'y'}, -- this way because endash is a member of %D; %D- will match January–March 2019 when it shouldn't |
||
['yM_ja'] = {'^(%d%d%d%d)年(%d%d*月)$', 'y', 'm'}, |
|||
-- these date formats cannot be converted |
-- these date formats cannot be converted |
||
['Sy4-y2'] = {'^(%D-) +((%d%d)%d%d)[%-–]((%d%d) |
['Sy4-y2'] = {'^(%D-) +((%d%d)%d%d)[%-–]((%d%d)[a-zA-Z]?)$'}, -- special case Winter/Summer year-year (YYYY-YY); year separated with unspaced endash |
||
['Sy-y'] = {'^(%D-) +(%d%d%d%d)[%-–]((%d%d%d%d) |
['Sy-y'] = {'^(%D-) +(%d%d%d%d)[%-–]((%d%d%d%d)[a-zA-Z]?)$'}, -- special case Winter/Summer year-year; year separated with unspaced endash |
||
['y-y'] = {'^(%d%d%d%d?)[%-–]((%d%d%d%d?) |
['y-y'] = {'^(%d%d%d%d?)[%-–]((%d%d%d%d?)[a-zA-Z]?)$', 'y', 'a', 'y2'}, -- year range: YYY-YYY or YYY-YYYY or YYYY–YYYY; separated by unspaced endash; 100-9999 |
||
['y4-y2'] = {'^((%d%d)%d%d) |
['y4-y2'] = {'^((%d%d)%d%d)–((%d%d)[a-zA-Z]?)$', 'y', 'c', 'a', 'y2'}, -- year range: YYYY–YY; separated by unspaced endash |
||
-- 日本語版独自仕様: y-mと区別するため、ハイフンをパターンに含めない |
|||
['y'] = {'^((%d%d%d%d?)%a?)$', 'y'}, -- year; here accept either YYY or YYYY |
|||
['y_ja'] = {'^(%d%d%d%d?)年$', 'y'}, -- year; here accept either YYY or YYYY |
|||
['y'] = {'^((%d%d%d%d?)[a-zA-Z]?)$', 'y'}, -- year; here accept either YYY or YYYY |
|||
-- 以下は日本語版独自のパターン |
|||
['y-m'] = {'^(%d%d%d%d)%-(%d%d?)$', 'y', 'm'}, -- y4-y2と区別するため、Enダッシュはパターンに含めない |
|||
['ymd_ja'] = {'^([1-9][0-9][0-9][0-9])年([0-9][0-9]?月)([0-9][0-9]?)日$', 'y', 'm', 'd'}, |
|||
['y-y_ja'] = {'^([1-9][0-9][0-9][0-9]?)年? *[%-–] *([1-9][0-9][0-9][0-9]?)年$', 'y', 'y2'}, |
|||
['y_ja'] = {'^([1-9][0-9][0-9][0-9]?)年$', 'y'}, |
|||
['ym_ja'] = {'^([1-9][0-9][0-9][0-9])年([0-9][0-9]?月)$', 'y', 'm'}, |
|||
['ym-ym_ja'] = {'^([1-9][0-9][0-9][0-9]?)年([0-9][0-9]?月) *[%-–] *([1-9][0-9][0-9][0-9]?)年([0-9][0-9]?月)$', 'y', 'm', 'y2', 'm2'}, |
|||
['ym-m_ja'] = {'^([1-9][0-9][0-9][0-9]?)年([0-9][0-9]?月?) *[%-–] *([0-9][0-9]?月)$', 'y', 'm', 'm2'}, |
|||
['ymd-ymd_ja'] = {'^([1-9][0-9][0-9][0-9]?)年([0-9][0-9]?月)([0-9][0-9]?)日 *[%-–] *([1-9][0-9][0-9][0-9]?)年([0-9][0-9]?月)([0-9][0-9]?)日$', 'y', 'm', 'd', 'y2', 'm2', 'd2'}, |
|||
['ymd-md_ja'] = {'^([1-9][0-9][0-9][0-9]?)年([0-9][0-9]?月)([0-9][0-9]?)日 *[%-–] *([0-9][0-9]?月)([0-9][0-9]?)日$', 'y', 'm', 'd', 'm2', 'd2'}, |
|||
['ymd-d_ja'] = {'^([1-9][0-9][0-9][0-9]?)年([0-9][0-9]?月)([0-9][0-9]?)日? *[%-–] *([0-9][0-9]?)日$', 'y', 'm', 'd', 'd2'}, |
|||
} |
} |
||
508行目: | 519行目: | ||
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; |
anchor_year = year; |
||
if #year + #month + #day < 8 then -- 年・月・日の先頭の0を省略した場合(英語版ではエラー) |
|||
add_prop_cat ('omitted-zero-in-ymd-date'); -- 日本語版独自のプロパティカテゴリで追跡する |
|||
end |
|||
elseif mw.ustring.match(date_string, patterns['Mdy'][1]) then -- month-initial: month day, year |
elseif mw.ustring.match(date_string, patterns['Mdy'][1]) then -- month-initial: month day, year |
||
651行目: | 665行目: | ||
return false; |
return false; |
||
end |
end |
||
-- メインモジュールのmake_citeref_id()で検出を行う都合で、以下の処理は暫定的に無効化する |
|||
--if '年' == mu.ustring.sub(anchor_year, -1) then -- 日本語版独自処理: anchor_yearの末尾が「年」であれば |
|||
-- anchor_year = year; -- 「年」をアンカーに含めないようにする |
|||
--end |
|||
-- 日本語版独自 |
-- ここから日本語版独自の日付形式 |
||
elseif |
elseif mw.ustring.match(date_string, patterns['ymd_ja'][1]) then -- ja: year month day |
||
year, month, day = |
year, month, day = mw.ustring.match(date_string, patterns['ymd_ja'][1]); |
||
month = get_month_number (month); |
month = get_month_number (month:gsub('^0(%d)', '%1')); |
||
if 0 == month |
if 0 == month or 0 == tonumber(day) then |
||
return false; |
|||
end |
|||
anchor_year = year; |
anchor_year = year; |
||
elseif |
elseif mw.ustring.match(date_string, patterns['ym_ja'][1]) then -- ja: year month |
||
year, month = |
year, month = mw.ustring.match(date_string, patterns['ym_ja'][1]); |
||
month = get_month_number |
month = get_month_number(month:gsub('^0([1-9])', '%1')); |
||
if 0 == month then |
if 0 == month then |
||
return false; |
|||
end |
|||
anchor_year = year; |
anchor_year = year; |
||
elseif mw.ustring.match(date_string, patterns['y_ja'][1]) then |
|||
elseif date_string:match("^[1-9]%d%d%d?年$") then -- ja: year; here accept either YYY or YYYY |
|||
year = |
year = mw.ustring.match(date_string, patterns['y_ja'][1]); |
||
if false == is_valid_year(year) then |
if false == is_valid_year(year) then |
||
return false; |
return false; |
||
672行目: | 694行目: | ||
anchor_year = year; |
anchor_year = year; |
||
elseif mw.ustring.match(date_string, patterns['y-m'][1]) then -- YYYY-MM、結合文字にハイフンマイナスを使用している場合 |
|||
elseif date_string:match("^%d%d%d%d%-%d%d$") then -- numerical year month format |
|||
year, month = |
year, month = mw.ustring.match(date_string, patterns['y-m'][1]); |
||
month = tonumber(month); |
month = tonumber(month); |
||
if 12 < month or 1 > month |
if 12 < month or 1 > month then return false; end -- month number not valid |
||
if tonumber(year) % 100 < month then -- 2003-05のように年の範囲とも解釈できる場合 |
|||
if not in_array (param, {'access-date', 'archive-date'}) then -- 年月だけの入力でもエラーにならない引数の場合に限定して |
|||
add_prop_cat ('ambiguous-date-format'); -- 日本語版独自のプロパティカテゴリで追跡する |
|||
end |
|||
end |
|||
anchor_year = year; |
anchor_year = year; |
||
elseif mw.ustring.match(date_string, patterns['y-y_ja'][1]) then |
|||
year, year2 = mw.ustring.match(date_string, patterns['y-y_ja'][1]); |
|||
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 |
|||
elseif mw.ustring.match(date_string, patterns['ym-ym_ja'][1]) then |
|||
year, month, year2, month2 = mw.ustring.match(date_string, patterns['ym-ym_ja'][1]); |
|||
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 0 ~= get_month_number(month) and 0 ~= get_month_number(month2) and is_valid_month_range_style(month, month2) then -- both must be month year, same month style |
|||
month = get_month_number(month); |
|||
month2 = get_month_number(month2); |
|||
elseif 0 ~= get_season_number(month, param) and 0 ~= get_season_number(month2, param) then -- both must be season year, not mixed |
|||
month = get_season_number(month, param); |
|||
month2 = get_season_number(month2, param); |
|||
else |
|||
return false; |
|||
end |
|||
elseif mw.ustring.match(date_string, patterns['ym-m_ja'][1]) then |
|||
year, month, month2 = mw.ustring.match(date_string, patterns['ym-m_ja'][1]); |
|||
if (not is_valid_month_season_range(month, month2, param)) or (not is_valid_year(year)) then return false; end |
|||
if 0 ~= get_month_number(month) then -- determined to be a valid range so just check this one to know if month or season |
|||
month = get_month_number(month); |
|||
month2 = get_month_number(month2); |
|||
if 0 == month or 0 == month2 then return false; end |
|||
elseif tonumber(month) then |
|||
month = tonumber(month); |
|||
month2 = get_month_number(month2); |
|||
if 12 < month or 1 > month or 0 == month2 then return false; end -- month number not valid |
|||
else |
|||
month = get_season_number(month, param); |
|||
month2 = get_season_number(month2, param); |
|||
end |
|||
year2 = year; |
|||
elseif mw.ustring.match(date_string, patterns['ymd-ymd_ja'][1]) then |
|||
year, month, day, year2, month2, day2 = mw.ustring.match(date_string, patterns['ymd-ymd_ja'][1]); |
|||
if tonumber(year2) <= tonumber(year) then return false; end -- must be sequential years, left to right, earlier to later |
|||
if not is_valid_year(year2) or not is_valid_month_range_style(month, month2) then return false; end -- year2 no more than one year in the future; months same style |
|||
month = get_month_number (month); -- for metadata |
|||
month2 = get_month_number (month2); |
|||
if 0 == month or 0 == month2 then return false; end -- both must be valid |
|||
elseif mw.ustring.match(date_string, patterns['ymd-md_ja'][1]) then |
|||
year, month, day, month2, day = mw.ustring.match(date_string, patterns['ymd-md_ja'][1]); |
|||
if (not is_valid_month_season_range(month, month2)) or not is_valid_year(year) then return false; end -- date range order is left to right: earlier to later; |
|||
month = get_month_number (month); -- for metadata |
|||
month2 = get_month_number (month2); |
|||
year2 = year; |
|||
elseif mw.ustring.match(date_string, patterns['ymd-d_ja'][1]) then |
|||
year, month, day, day2 = mw.ustring.match(date_string, patterns['ymd-d_ja'][1]); |
|||
if tonumber(day) >= tonumber(day2) then return false; end -- date range order is left to right: earlier to later; dates may not be the same; |
|||
month = get_month_number (month); |
|||
if 0 == month then return false; end -- return false if month text isn't one of the twelve months |
|||
month2 = month; -- for metadata |
|||
year2 = year; |
|||
-- END 日本語版独自 |
-- END 日本語版独自 |
||
767行目: | 853行目: | ||
elseif v.val:match("^nd%a?$") then -- ToDo: I18N -- if |date=nd with or without a CITEREF disambiguator |
elseif v.val:match("^nd%a?$") then -- ToDo: I18N -- if |date=nd with or without a CITEREF disambiguator |
||
good_date, anchor_year, COinS_date = true, v.val:match("((nd)%a?)"); -- ToDo: I18N -- "nd"; no error when date parameter is set to no date |
good_date, anchor_year, COinS_date = true, v.val:match("((nd)%a?)"); -- ToDo: I18N -- "nd"; no error when date parameter is set to no date |
||
elseif mw.ustring.match(v.val, "^不明[a-zA-Z]?$") then -- 日本語版独自: |date=不明 |
|||
anchor_year = mw.ustring.gsub(v.val, '不明', 'n.d.', 1); -- 従来のテンプレートに倣い、アンカーの日付は"n.d."とする |
|||
good_date, COinS_date = true, v.val, 'n.d.'; |
|||
else |
else |
||
good_date, anchor_year, COinS_date = check_date (v.val, k, tCOinS_date); -- go test the date |
good_date, anchor_year, COinS_date = check_date (v.val, k, tCOinS_date); -- go test the date |
||
end |
end |
||
elseif 'year' == k then -- if the parameter is |year= it should hold only a year value |
elseif 'year' == k then -- if the parameter is |year= it should hold only a year value |
||
if mw.ustring.match(v.val, "^[1-9][0-9][0-9][0-9]?[a-zA-Z]?年$") then -- 日本語版独自: 末尾に「年」が付いたパターン |
|||
if v.val:match("^[1-9]%d%d%d?%a?$") then -- if |year = 3 or 4 digits only with or without a CITEREF disambiguator |
|||
good_date, anchor_year, COinS_date = true, v.val:match("((%d+)[a-zA-Z]?)"); |
|||
elseif v.val:match("^[1-9]%d%d%d?%a?$") then -- if |year = 3 or 4 digits only with or without a CITEREF disambiguator |
|||
good_date, anchor_year, COinS_date = true, v.val:match("((%d+)%a?)"); |
good_date, anchor_year, COinS_date = true, v.val:match("((%d+)%a?)"); |
||
end |
end |
||
885行目: | 976行目: | ||
['mdy'] = {'%s %s, %s', 'm', 'd', 'y'}, -- |df=mdy |
['mdy'] = {'%s %s, %s', 'm', 'd', 'y'}, -- |df=mdy |
||
['dmy'] = {'%s %s %s', 'd', 'm', 'y'}, -- |df=dmy |
['dmy'] = {'%s %s %s', 'd', 'm', 'y'}, -- |df=dmy |
||
['ymd'] = {'%s-%s-%s', 'y', 'm', 'd'}, -- 日本語版独自。月と日の先頭の0を許容したので、ymdからymdへの変換も行う |
|||
-- ['yMd'] = {'%s %s %s', 'y', 'm', 'd'}, -- |df=yMd; not supported at en.wiki |
-- ['yMd'] = {'%s %s %s', 'y', 'm', 'd'}, -- |df=yMd; not supported at en.wiki |
||
['ja'] = {'%s年%s%s日', 'y', 'm', 'd'}, -- 日本語版独自。「月」はConfigurationで指定されている |
['ja'] = {'%s年%s%s日', 'y', 'm', 'd'}, -- 日本語版独自。「月」はConfigurationで指定されている |
||
944行目: | 1,036行目: | ||
['ja'] = {'%s年%s', 'y', 'm'}, -- 日本語版独自。「月」はConfigurationで指定されている |
['ja'] = {'%s年%s', 'y', 'm'}, -- 日本語版独自。「月」はConfigurationで指定されている |
||
}, |
}, |
||
-- 下記全件日本語版独自 |
|||
-- 下記全件日本語版独自 |
|||
['ymd_ja'] = { |
['ymd_ja'] = { |
||
['mdy'] = {'%s %s, %s', 'm', 'd', 'y'}, -- |df=mdy |
['mdy'] = {'%s %s, %s', 'm', 'd', 'y'}, -- |df=mdy |
||
['dmy'] = {'%s %s %s', 'd', 'm', 'y'}, -- |df=dmy |
['dmy'] = {'%s %s %s', 'd', 'm', 'y'}, -- |df=dmy |
||
['ymd'] = {'%s-%s-%s', 'y', 'm', 'd'}, -- |df=ymd |
|||
['ja'] = {'%s年%s%s日', 'y', 'm', 'd'}, |
['ja'] = {'%s年%s%s日', 'y', 'm', 'd'}, |
||
}, |
}, |
||
[' |
['ym_ja'] = { |
||
[' |
['any'] = {'%s %s', 'm', 'y'}, |
||
['ja'] = {'%s年%s', 'y', 'm'}, |
['ja'] = {'%s年%s', 'y', 'm'}, |
||
}, |
}, |
||
964行目: | 1,058行目: | ||
['y-y'] = { |
['y-y'] = { |
||
['any'] = {'%s–%s', 'y', 'y2'}, |
['any'] = {'%s–%s', 'y', 'y2'}, |
||
['ja'] = {'%s年 |
['ja'] = {'%s年 - %s年', 'y', 'y2'}, |
||
}, |
|||
['y4-y2'] = { |
|||
['any'] = {'%s–%s', 'y', 'y2'}, |
|||
['ja'] = {'%s年 - %s年', 'y', 'y2'}, |
|||
}, |
|||
['y-m'] = { |
|||
['any'] = {'%s %s', 'm', 'y'}, |
|||
['ja'] = {'%s年%s', 'y', 'm'}, |
|||
}, |
}, |
||
-- ['yMd'] = { -- not supported at en.wiki |
-- ['yMd'] = { -- not supported at en.wiki |
||
972行目: | 1,074行目: | ||
-- ['ja'] = {'%s年%s%s日', 'y', 'm', 'd'}, -- 日本語版独自。「月」はConfigurationで指定されている |
-- ['ja'] = {'%s年%s%s日', 'y', 'm', 'd'}, -- 日本語版独自。「月」はConfigurationで指定されている |
||
-- }, |
-- }, |
||
['y-y_ja'] = { |
|||
['any'] = {'%s–%s', 'y', 'y2'}, |
|||
['ja'] = {'%s年 - %s年', 'y', 'y2'}, |
|||
}, |
|||
['ym-ym_ja'] = { |
|||
['any'] = {'%s %s – %s %s', 'm', 'y', 'm2', 'y2'}, |
|||
['ja'] = {'%s年%s - %s年%s', 'y', 'm', 'y2', 'm2'}, |
|||
}, |
|||
['ym-m_ja'] = { |
|||
['any'] = {'%s–%s %s', 'm', 'm2', 'y'}, |
|||
['ja'] = {'%s年%s - %s', 'y', 'm', 'm2'}, |
|||
}, |
|||
['ymd-ymd_ja'] = { |
|||
['mdy'] = {'%s %s, %s – %s %s, %s', 'm', 'd', 'y', 'm2', 'd2', 'y2'}, |
|||
['dmy'] = {'%s %s %s – %s %s %s', 'd', 'm', 'y', 'd2', 'm2', 'y2'}, |
|||
['ja'] = {'%s年%s%s日 - %s年%s%s日', 'y', 'm', 'd', 'y2', 'm2', 'd2'}, |
|||
}, |
|||
['ymd-md_ja'] = { |
|||
['mdy'] = {'%s %s – %s %s, %s', 'm', 'd', 'm2', 'd2', 'y'}, |
|||
['dmy'] = {'%s %s – %s %s %s', 'd', 'm', 'd2', 'm2', 'y'}, |
|||
['ja'] = {'%s年%s%s日 - %s%s日', 'y', 'm', 'd', 'm2', 'd2'}, |
|||
}, |
|||
['ymd-d_ja'] = { |
|||
['dmy'] = {'%s–%s %s %s', 'd', 'd2', 'm', 'y'}, |
|||
['mdy'] = {'%s %s–%s, %s', 'm', 'd', 'd2', 'y'}, |
|||
['ja'] = {'%s年%s%s日 - %s日', 'y', 'm', 'd', 'd2'}, |
|||
}, |
|||
} |
} |
||
local function reformatter (date, pattern_idx, format_param, mon_len) |
local function reformatter (date, pattern_idx, format_param, mon_len) |
||
if not in_array (pattern_idx, {'ymd', 'Mdy', 'Md-dy', 'dMy', 'yMd', 'd-dMy', 'dM-dMy', 'Md-Mdy', 'dMy-dMy', 'Mdy-Mdy', 'My-My', 'M-My', 'My', 'ymd_ja', ' |
if not in_array (pattern_idx, {'ymd', 'Mdy', 'Md-dy', 'dMy', 'yMd', 'd-dMy', 'dM-dMy', 'Md-Mdy', 'dMy-dMy', 'Mdy-Mdy', 'My-My', 'M-My', 'My', 'ymd_ja', 'ym_ja', 'y_ja', 'y', 'y-y', 'y4-y2', 'y-m', 'y-y_ja', 'ym-ym_ja', 'ym-m_ja', 'ymd-ymd_ja', 'ymd-md_ja', 'ymd-d_ja'}) then |
||
return; -- not in this set of date format patterns then not a reformattable date |
return; -- not in this set of date format patterns then not a reformattable date |
||
end |
end |
||
if 'ymd' == format_param and in_array (pattern_idx, { |
if 'ymd' == format_param and in_array (pattern_idx, {'Md-dy', 'd-dMy', 'dM-dMy', 'Md-Mdy', 'dMy-dMy', 'Mdy-Mdy', 'My-My', 'M-My', 'My', 'ym_ja', 'y', 'y-y', 'y4-y2', 'y-m', 'y-y_ja', 'ym-ym_ja', 'ym-m_ja', 'ymd-ymd_ja', 'ymd-md_ja', 'ymd-d_ja'}) then |
||
-- 日本語版独自の変更: 月と日の先頭の0を許容したので、ymdからymdへの変換も行う |
|||
return; -- ymd date ranges not supported at en.wiki; no point in reformatting ymd to ymd |
|||
return; -- ymd date ranges not supported at en.wiki |
|||
end |
end |
||
if 'ja' ~= format_param and in_array (pattern_idx, {'My', 'M-My', 'My-My', 'y', 'y_ja', 'y-y'}) then -- these are not dmy/mdy so can't be 'reformatted' into either, except for ja |
if 'ja' ~= format_param and in_array (pattern_idx, {'My', 'M-My', 'My-My', 'ym_ja', 'y', 'y_ja', 'y-y', 'y4-y2', 'y-m', 'y-y_ja', 'ym-ym_ja', 'ym-m_ja'}) then -- these are not dmy/mdy so can't be 'reformatted' into either, except for ja |
||
format_param = 'any'; -- so format-agnostic |
|||
end |
|||
if 'ja' ~= format_param and in_array (pattern_idx, {'My', 'M-My', 'My-My', 'y', 'y_ja', 'y-y'}) then -- these are not dmy/mdy so can't be 'reformatted' into either, except for ja |
|||
format_param = 'any'; -- so format-agnostic |
format_param = 'any'; -- so format-agnostic |
||
end |
end |
||
1,016行目: | 1,142行目: | ||
else -- here for single date formats (except ymd) |
else -- here for single date formats (except ymd) |
||
t.y = t.a; -- use the anchor year capture when reassembling the date |
t.y = t.a; -- use the anchor year capture when reassembling the date |
||
end |
|||
end |
|||
do -- 日本語版独自処理 |
|||
if 'y4-y2' == pattern_idx then |
|||
t.y2 = t.c .. t.y2; -- 2つ目の年の上2桁を補う |
|||
end |
|||
if t.m then |
|||
t.m = t.m:gsub ('0(%d)', '%1'); -- 先頭の0を除去する |
|||
if t.d then |
|||
t.d = mw.ustring.gsub(t.d, '日', ''):gsub ('0(%d)', '%1'); -- t.dから'日'と先頭の0を除去する |
|||
end |
|||
end |
end |
||
end |
end |
||
-- 日本語版独自の変更: ymd形式をymd形式に変換する都合上、条件文の順序を入れ替える |
|||
if tonumber(t.m) then -- if raw month is a number (converting from ymd) |
|||
if 'ymd' == format_param then -- when converting to ymd |
|||
t.y = t.y:gsub ('%a', ''); -- strip CITREF disambiguator if present; anchor year already known so process can proceed; TODO: maint message? |
|||
if 1582 > tonumber (t.y) then -- ymd format dates not allowed before 1582 |
|||
return; |
|||
end |
|||
t.m = string.format ('%02d', tonumber(t.m) or get_month_number (t.m)); -- make sure that month and day are two digits |
|||
-- 変換元がymd形式の場合にget_month_number()の呼び出しを避ける |
|||
t.d = string.format ('%02d', t.d); |
|||
elseif tonumber(t.m) then -- if raw month is a number (converting from ymd) |
|||
if 's' == mon_len then -- if we are to use abbreviated month names |
if 's' == mon_len then -- if we are to use abbreviated month names |
||
if 'ja' ~= format_param then |
if 'ja' ~= format_param then |
||
1,033行目: | 1,180行目: | ||
end |
end |
||
end |
end |
||
if t.d then -- y-mの形式で入力された場合はt.dが存在しない |
|||
t.d = t.d:gsub ('0(%d)', '%1'); -- strip leading '0' from day if present |
|||
t.d = t.d:gsub ('0(%d)', '%1'); -- strip leading '0' from day if present |
|||
t.y = t.y:gsub ('%a', ''); -- strip CITREF disambiguator if present; anchor year already known so process can proceed; TODO: maint message? |
|||
if 1582 > tonumber (t.y) then -- ymd format dates not allowed before 1582 |
|||
return; |
|||
end |
end |
||
t.m = string.format ('%02d', get_month_number (t.m)); -- make sure that month and day are two digits |
|||
t.d = string.format ('%02d', t.d); |
|||
elseif mon_len then -- if mon_len is set to either 'short' or 'long' |
elseif mon_len then -- if mon_len is set to either 'short' or 'long' |
||
for _, mon in ipairs ({'m', 'm2'}) do -- because there can be two month names, check both |
for _, mon in ipairs ({'m', 'm2'}) do -- because there can be two month names, check both |
||
1,121行目: | 1,263行目: | ||
for pattern_idx, pattern in pairs (patterns) do |
for pattern_idx, pattern in pairs (patterns) do |
||
if mw.ustring.match (param_val.val, pattern[1]) then |
if mw.ustring.match (param_val.val, pattern[1]) then |
||
if in_array (param_name, {'access-date', 'archive-date'}) then -- 日本語版独自:access-dateとarchive-dateは常にYYYY年M月D日と表示 |
if in_array (param_name, {'access-date', 'archive-date'}) then |
||
new_date = reformatter (param_val.val, pattern_idx, 'ja', len_a); -- 日本語版独自:access-dateとarchive-dateは常にYYYY年M月D日と表示 |
|||
new_date = reformatter (param_val.val, pattern_idx, 'ja', len_a); |
|||
elseif is_set (format) then |
|||
new_date = reformatter (param_val.val, pattern_idx, format, len_p); |
|||
else |
else |
||
new_date = reformatter (param_val.val, pattern_idx, |
new_date = reformatter (param_val.val, pattern_idx, format, len_p); |
||
end |
end |
||
1,156行目: | 1,296行目: | ||
for param_name, param_val in pairs(date_parameters_list) do -- for each date-holding parameter in the list |
for param_name, param_val in pairs(date_parameters_list) do -- for each date-holding parameter in the list |
||
if is_set (param_val.val) and |
if is_set (param_val.val) and |
||
not mw.ustring.match (param_val.val, patterns.ymd[1]) |
not mw.ustring.match (param_val.val, patterns.ymd[1]) and -- for those that are not ymd dates (ustring because here digits may not be Western) |
||
not mw.ustring.match (param_val.val, patterns['y-m'][1]) then -- 日本語版独自: YYYY-MMの形式の場合も除外する |
|||
param_val.val, n = param_val.val:gsub ('%-', '–'); -- replace any hyphen with ndash |
param_val.val, n = param_val.val:gsub ('%-', '–'); -- replace any hyphen with ndash |
||
if 0 ~= n then |
if 0 ~= n then |