模块:Citation/CS1/Date validation:修订间差异
imported>WhitePhosphorus 小 取消WhitePhosphorus(对话)的编辑;更改回Liangent的最后一个版本 |
imported>Antigng |
||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
--[[--------------------------< I S _ V A L I D _ D A T E _ F R O M _ A _ P O I N T >------------------------- | |||
将日期验证的逻辑拆分出来,供其它模块使用 | |||
]] | |||
local function is_valid_date_from_a_point (date, point_ts) | |||
local lang = mw.getContentLanguage(); | |||
local good1, good2; | |||
local access_ts, tomorrow_ts; -- to hold unix time stamps representing the dates | |||
good1, access_ts = pcall( lang.formatDate, lang, 'U', date ); -- convert date value to unix timesatmp | |||
good2, tomorrow_ts = pcall( lang.formatDate, lang, 'U', 'today + 2 days' ); -- today midnight + 2 days is one second more than all day tomorrow | |||
if good1 and good2 then | |||
access_ts = tonumber (access_ts); -- convert to numbers for the comparison | |||
tomorrow_ts = tonumber (tomorrow_ts); | |||
else | |||
return false; -- one or both failed to convert to unix time stamp | |||
end | |||
if point_ts <= access_ts and access_ts < tomorrow_ts then -- the point <= date < tomorrow's date | |||
return true; | |||
else | |||
return false; -- date out of range | |||
end | |||
end | |||
--[[--------------------------< I S _ V A L I D _ A C C E S S D A T E >---------------------------------------- | --[[--------------------------< I S _ V A L I D _ A C C E S S D A T E >---------------------------------------- | ||
| 第17行: | 第39行: | ||
local function is_valid_accessdate (accessdate) | local function is_valid_accessdate (accessdate) | ||
accessdate = accessdate:gsub("年", "-"); | accessdate = accessdate:gsub("年", "-"); | ||
accessdate = accessdate:gsub("月", "-"); | accessdate = accessdate:gsub("月", "-"); | ||
accessdate = accessdate:gsub("日", "-"); | accessdate = accessdate:gsub("日", "-"); | ||
accessdate = accessdate:gsub("-$", ""); | accessdate = accessdate:gsub("-$", ""); | ||
return is_valid_date_from_a_point (accessdate, 979516800); | |||
end | end | ||
| 第637行: | 第641行: | ||
end | end | ||
return {dates = dates, year_date_check = year_date_check} -- return exported functions | return {dates = dates, year_date_check = year_date_check, is_valid_date_from_a_point = is_valid_date_from_a_point} | ||
-- return exported functions | |||