יחידה:תאריך: הבדלים בין גרסאות בדף
מ פרסור מאות |
מ 3 גרסאות של הדף wikipedia:he:יחידה:תאריך יובאו |
||
| (15 גרסאות ביניים של 4 משתמשים אינן מוצגות) | |||
| שורה 164: | שורה 164: | ||
end | end | ||
-- | --offset | ||
if offset ~= nil then | if offset ~= nil then | ||
if offset == 'Z' then | if offset == 'Z' then | ||
| שורה 337: | שורה 337: | ||
t2 = Date.julianToGregorian(t2) | t2 = Date.julianToGregorian(t2) | ||
else | else | ||
error(" | error("Calendars don't match", 2) | ||
end | end | ||
end | end | ||
| שורה 456: | שורה 456: | ||
wikitext = mw.ustring.gsub(wikitext, "‏","") | wikitext = mw.ustring.gsub(wikitext, "‏","") | ||
wikitext = mw.ustring.gsub(wikitext, "‎","") | wikitext = mw.ustring.gsub(wikitext, "‎","") | ||
-- BC to minus | -- BC to minus | ||
wikitext = mw.ustring.gsub( wikitext, "([0-9]+) לפנה[\"״]ס" , "-%1") | wikitext = mw.ustring.gsub( wikitext, "([0-9]+) לפנה[\"״]ס" , "-%1") | ||
| שורה 804: | שורה 804: | ||
dateRangeStr = mw.text.killMarkers(dateRangeStr) | dateRangeStr = mw.text.killMarkers(dateRangeStr) | ||
dateRangeStr = mw.ustring.gsub(dateRangeStr, "‏","") | dateRangeStr = mw.ustring.gsub(dateRangeStr, "‏","") | ||
local outputPrefix = '' | local outputPrefix = '' | ||
local parts = mw.text.split(dateRangeStr,' | local parts = mw.text.split(dateRangeStr,' *[–%-] *') | ||
assert(#parts==2 or #parts==1, "Date range expected format is from - to or from (e.g from - now)") | assert(#parts==2 or #parts==1, "Date range expected format is from - to or from (e.g from - now)") | ||
| שורה 812: | שורה 812: | ||
local t1 = Date.newFromWikitext( parts[1] ) | local t1 = Date.newFromWikitext( parts[1] ) | ||
local t2 | local t2 | ||
local useCurrent = #parts<2 or (parts[2] == 'היום' or parts[2]=='הווה') | |||
if not useCurrent then | |||
t2 = Date.newFromWikitext( parts[2] ) | t2 = Date.newFromWikitext( parts[2] ) | ||
else | else | ||
| שורה 897: | שורה 899: | ||
return dif | return dif | ||
else | else | ||
local res = outputPrefix..lang:formatDuration(dif, diffFormat) | |||
-- post process formatDuration which is not good enough | |||
res= mw.ustring.gsub(res,"כ־([א-ת])","כ%1") | |||
res= mw.ustring.gsub(res,"וגם ([0-9])","ו־%1") | |||
res= mw.ustring.gsub(res,"וגם ([א-ת])","ו%1") | |||
return res | |||
end | end | ||
end | end | ||
| שורה 907: | שורה 914: | ||
elseif frame.args[2] == 'שנים' then | elseif frame.args[2] == 'שנים' then | ||
diffFormat = {'years'} | diffFormat = {'years'} | ||
elseif frame.args[2] == 'שנים וימים' then | |||
diffFormat = {'years', 'days'} | |||
elseif frame.args[2] == "הפרש" then | elseif frame.args[2] == "הפרש" then | ||
diffFormat = "raw" | diffFormat = "raw" | ||
| שורה 915: | שורה 924: | ||
end | end | ||
local inclusive = (frame.args["כולל"]=="כן") | |||
local inclusive= (frame.args["כולל"]=="כן") | |||
local success, res = pcall(parseDateRange, frame.args[1], diffFormat, inclusive) | local success, res = pcall(parseDateRange, frame.args[1], diffFormat, inclusive) | ||
if success then | if success then | ||
local str=res | local str=res | ||
-- the following translations are needed because the underline function | -- the following translations are needed because the underline function | ||
-- local format is wierd | -- local format is wierd | ||
str = mw.ustring.gsub(str, | str = mw.ustring.gsub(str, "(כ)־([א-ת])", "%1%2") | ||
if frame.args[2] == "גיל" then | if frame.args[2] == "גיל" then | ||
| שורה 945: | שורה 949: | ||
str = 1 | str = 1 | ||
end | end | ||
str = mw.ustring.gsub(str," שנה", "") | |||
if tonumber(str) > 0 and | if tonumber(str) > 0 and | ||
tonumber(parseDateRange(frame.args[1], "raw", inclusive)) < 0 then | tonumber(parseDateRange(frame.args[1], "raw", inclusive)) < 0 then | ||
| שורה 977: | שורה 982: | ||
end | end | ||
end | |||
function linkStrDateUnsafe(frame) | |||
local dateStr = frame.args[1] | |||
local linkedDateStr = dateStr | |||
-- Strip [ and ] chars | |||
linkedDateStr = mw.ustring.gsub(linkedDateStr, '%[', '') | |||
linkedDateStr = mw.ustring.gsub(linkedDateStr, '%]', '') | |||
-- Link D M Y, return [[D M]] [[Y]] | |||
linkedDateStr = mw.ustring.gsub(linkedDateStr, '^(%d+ %a+) (%d+)$', '[[%1]] [[%2]]') | |||
-- Link D M, return [[D M]] | |||
if mw.ustring.find(linkedDateStr, '%[') == nil then | |||
linkedDateStr = mw.ustring.gsub(linkedDateStr, '^(%d+) (%a+)$', '[[%1 %2]]') | |||
end | |||
-- Link M Y, return [[M]] [[Y]] | |||
if mw.ustring.find(linkedDateStr, '%[') == nil then | |||
linkedDateStr = mw.ustring.gsub(linkedDateStr, '^(%a+) (%d+)$', '[[%1]] [[%2]]') | |||
end | |||
-- Link Y, return [[Y]] | |||
if mw.ustring.find(linkedDateStr, '%[') == nil then | |||
linkedDateStr = mw.ustring.gsub(linkedDateStr, '^(%d+)$', '[[%1]]') | |||
end | |||
-- Unknown date string format, return the original string | |||
if mw.ustring.find(linkedDateStr, '%[') == nil then | |||
linkedDateStr = dateStr | |||
end | |||
return linkedDateStr | |||
end | end | ||
| שורה 982: | שורה 1,014: | ||
Date['חשב טווח'] = parseDateRangeSafe; | Date['חשב טווח'] = parseDateRangeSafe; | ||
Date['parseDateRange'] = parseDateRange; | Date['parseDateRange'] = parseDateRange; | ||
Date['מקושר'] = linkStrDateUnsafe; | |||
return Date | return Date | ||