אונטערשייד צווישן ווערסיעס פון "יחידה:דאטום"

קפיצה לניווט קפיצה לחיפוש
1,003 בייטן צוגעלייגט ,  פֿאַר 2 יאָר
דיוק
(אידיש)
(דיוק)
 
(14 מיטלסטע ווערסיעס פון 2 באַניצער נישט געוויזן.)
שורה 261: שורה 261:
      
      
     return year, month, day
     return year, month, day
end
--[[ get month name and day (as numeric string), in either order, and return their numbers as day, month
    if optional parameter 'reverse' is true, return month first
]]--
local function monthDay(dateTable, reverse)
local months = {
['יאנואר']= 1,
['פעברואר']= 2,
['מערץ']= 3,
['אפריל']= 4,
['מאי']= 5,
['יוני']= 6,
['יולי']= 7,
['אויגוסט']= 8,
['סעפטעמבער']= 9,
['אקטאבער']= 10,
['נאוועמבער']= 11,
['דעצעמבער']= 12
}
local month = nil
    local day = nil
    for _, value in ipairs(dateTable) do
        if months[value] then
            month = months[value]
        else
            day = tonumber(value)
        end
    end
    if reverse then
        return month, day
    else
        return day, month
    end
end
end


שורה 422: שורה 458:


     return Date.new( definition )
     return Date.new( definition )
end
local function extractNumbers(inputString)
    local numbers = inputString:match("^(%d+[%s%d-]*)")
    return numbers or ""
end
end


שורה 430: שורה 471:
]]
]]
function Date.newFromWikitext( wikitext )
function Date.newFromWikitext( wikitext )
local months = {
['ינואר']= 1,
['פברואר']= 2,
['מרץ']= 3,
['אפריל']= 4,
['מאי']= 5,
['יוני']= 6,
['יולי']= 7,
['אוגוסט']= 8,
['ספטמבר']= 9,
['אוקטובר']= 10,
['נובמבר']= 11,
['דצמבר']= 12
}
local calendar = nil
local calendar = nil
if mw.ustring.find( wikitext, '<small>%(%[%[יוליאנישער קאלענדאר%|יוליאניש%]%]%)</small>' ) then
if mw.ustring.find( wikitext, '<small>%(%[%[יוליאנישער קאלענדאר%|יוליאניש%]%]%)</small>' ) then
שורה 456: שורה 483:
wikitext = mw.ustring.gsub(wikitext, "&rlm;","")
wikitext = mw.ustring.gsub(wikitext, "&rlm;","")
wikitext = mw.ustring.gsub(wikitext, "&lrm;","")
wikitext = mw.ustring.gsub(wikitext, "&lrm;","")
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")
    wikitext = mw.ustring.gsub( wikitext, "([0-9]+) אא[\"״]ר" , "-%1")
for a in pairs(months) do
    wikitext = mw.ustring.gsub( wikitext, "([0-9]+) בצ[\"״]ר" , "-%1")
wikitext = mw.ustring.gsub(wikitext, ' ?ב?'..a, ' ' .. months[a])  
    wikitext = mw.ustring.gsub( wikitext, "([0-9]+) פד[\"״]צ" , "-%1")
end


if mw.ustring.match(wikitext, '^המאה ה[־-]%d+$') then
if mw.ustring.match(wikitext, '^המאה ה[־-]%d+$') then
שורה 468: שורה 495:
                 return Date.new( { year=tonumber(yearStr)*100, month=0, day=0, precision= Date.PRECISION.YEAR100 } )
                 return Date.new( { year=tonumber(yearStr)*100, month=0, day=0, precision= Date.PRECISION.YEAR100 } )
end
end
-- if there are alphabet chars return nil (unexpected character)
 
assert(not mw.ustring.find(wikitext, '%a'), "Unexpected format")
    if mw.ustring.match(wikitext, "%d+['ס]?ט[ען]ר? י") then
local yearStr = mw.ustring.match(wikitext, "(%d+)['ס]?ט[ען]ר? י")
                return Date.new( { year=tonumber(yearStr)*100, month=0, day=0, precision= Date.PRECISION.YEAR100 } )
end
 
local parts = mw.text.split(mw.text.trim(wikitext),' ')
local parts = mw.text.split(mw.text.trim(wikitext),' ')


שורה 476: שורה 507:
if #parts==3 then -- DMY date
if #parts==3 then -- DMY date
definition.year = tonumber(parts[3])
definition.year = tonumber(parts[3])
definition.month = tonumber(parts[2])
definition.day, definition.month = monthDay({parts[1], parts[2]})
definition.day = tonumber(parts[1])
assert(definition.year, "Could not recognize year")
assert(definition.year, "Could not recognize year")
assert(definition.month<13 and definition.month>0, "Could not recognize month number")
assert(definition.month<13 and definition.month>0, "Could not recognize month number")
שורה 483: שורה 513:
definition.precision = Date.PRECISION.DAY
definition.precision = Date.PRECISION.DAY
elseif  #parts==2 then -- MY date
elseif  #parts==2 then -- MY date
definition.year = tonumber(parts[2])
definition.month, definition.year = monthDay(parts, true)
definition.month = tonumber(parts[1])
definition.precision = Date.PRECISION.MONTH
definition.precision = Date.PRECISION.MONTH
assert(definition.year<1e7, "Could not recognize year")
assert(definition.year<1e7, "Could not recognize year")
שורה 561: שורה 590:
if (self.precision >= Date.PRECISION.MY100) and (self.precision <= Date.PRECISION.MY) then
if (self.precision >= Date.PRECISION.MY100) and (self.precision <= Date.PRECISION.MY) then
if self.year>0 then
if self.year>0 then
         return (self.year/1000000) .. ' מיליון שנים לספירה'
         return (self.year/1000000) .. ' מיליאן יאר צום ציילונג'
         else
         else
         return (-self.year/1000000) ..' מיליון שנים לפנה״ס'
         return (-self.year/1000000) ..' מיליאן יאר פד"צ'
         end
         end
elseif (self.precision >=Date.PRECISION.KY100) and (self.precision <= Date.PRECISION.KY) then
elseif (self.precision >=Date.PRECISION.KY100) and (self.precision <= Date.PRECISION.KY) then
שורה 737: שורה 766:
     local fd = ''
     local fd = ''
     if self.precision >= Date.PRECISION.DAY then
     if self.precision >= Date.PRECISION.DAY then
         fd = self.year < 0 and (-1 * self.year) .. ' לפנה"ס' or fd .. self.year
         fd = self.year < 0 and (-1 * self.year) .. ' פד"צ' or fd .. self.year
         if options.link then fd = '[[' .. fd .. ']]' end
         if options.link then fd = '[[' .. fd .. ']]' end
         local d = '2000-' .. prepend(self.month, '0', 2) .. '-' .. prepend(self.day, '0', 2)
         local d = '2000-' .. prepend(self.month, '0', 2) .. '-' .. prepend(self.day, '0', 2)
שורה 743: שורה 772:
         fd = fd .. '. ' .. lang:formatDate(options.link and '[[j xg]]' or 'j xg', d)
         fd = fd .. '. ' .. lang:formatDate(options.link and '[[j xg]]' or 'j xg', d)
elseif self.precision >= Date.PRECISION.MONTH then
elseif self.precision >= Date.PRECISION.MONTH then
fd = self.year < 0 and (-1 * self.year) .. ' לפנה"ס' or fd .. self.year
fd = self.year < 0 and (-1 * self.year) .. ' פד"צ' or fd .. self.year
local month = mw.getContentLanguage():formatDate('F', '2000-' .. self.month)
local month = mw.getContentLanguage():formatDate('F', '2000-' .. self.month)
if options.link then fd = '[[' .. fd .. ']]' end
if options.link then fd = '[[' .. fd .. ']]' end
fd = month .. ' ' .. fd
fd = month .. ' ' .. fd
     elseif self.precision >= Date.PRECISION.YEAR then
     elseif self.precision >= Date.PRECISION.YEAR then
         fd = self.year < 0 and (-1 * self.year) .. ' לפנה"ס' or fd .. self.year
         fd = self.year < 0 and (-1 * self.year) .. ' פד"צ' or fd .. self.year
         if options.link ~= 'nem' then fd = '[[' .. fd .. ']]' end
         if options.link ~= 'nem' then fd = '[[' .. fd .. ']]' end
     elseif self.precision == Date.PRECISION.YEAR10 then
     elseif self.precision == Date.PRECISION.YEAR10 then
         local year = math.floor((self.year < 0 and -1 * self.year or self.year)  / 10) * 10
         local year = math.floor((self.year < 0 and -1 * self.year or self.year)  / 10) * 10
         fd = 'שנות ה-' .. tostring(year%100) .. ' של המאה ה-'.. tostring(ceil(year/100))
         fd = 'שנות ה-' .. tostring(year%100) .. ' של המאה ה-'.. tostring(ceil(year/100))
         fd = self.year < 0 and year .. ' לפנה"ס' or tostring(year)
         fd = self.year < 0 and year .. ' פד"צ' or tostring(year)
     elseif self.precision == Date.PRECISION.YEAR100 then
     elseif self.precision == Date.PRECISION.YEAR100 then
         if self.year < 0 then
         if self.year < 0 then
             fd = 'המאה ה-' .. math.floor(-1 * self.year / 100) .. ' לפנה"ס'
             fd = 'המאה ה-' .. math.floor(-1 * self.year / 100) .. ' פד"צ'
         else
         else
             fd = 'המאה ה-' ..math.floor(self.year / 100)
             fd = 'המאה ה-' ..math.floor(self.year / 100)
שורה 812: שורה 841:
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]=='הווה')
local useCurrent = #parts<2 or (parts[2] == 'היינט' or parts[2]=='הווה' or parts[2]=='אנגייענד' or parts[2]=='איצט')
if not useCurrent then
if not useCurrent then
שורה 912: שורה 941:
if frame.args[2] == 'ימים' then
if frame.args[2] == 'ימים' then
diffFormat = {'days'}
diffFormat = {'days'}
elseif frame.args[2] == 'שנים' then
elseif frame.args[2] == 'יארן' then
diffFormat = {'years'}
diffFormat = {'years'}
elseif frame.args[2] == 'שנים וימים' then
elseif frame.args[2] == 'שנים וימים' then
שורה 935: שורה 964:
if frame.args[2] == "גיל" then
if frame.args[2] == "גיל" then
str= mw.ustring.gsub(str,"כ־(.+) שנים","%1 בערך")
str= mw.ustring.gsub(str,"כ־(.+) שנים","%1 בערך")
str= mw.ustring.gsub(str," יאר","")
str= mw.ustring.gsub(str," שנים","")
end
end
שורה 942: שורה 971:
str= mw.ustring.gsub(str,"כ(.+)","%1");
str= mw.ustring.gsub(str,"כ(.+)","%1");
str= mw.ustring.gsub(str,"־(.+)","%1");
str= mw.ustring.gsub(str,"־(.+)","%1");
str= mw.ustring.gsub(str," יאר","")
str= mw.ustring.gsub(str," יאָרן","")
if str == "שנתיים" then
if str == "שנתיים" then
str = 2
str = 2
end
end
if str == "שנה" then
if str == "יאר" then
str = 1
str = 1
end
end
str = mw.ustring.gsub(str," שנה", "")
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
שורה 958: שורה 987:
return str
return str
else
else
return frame.args['error'] or '<span class="scribunto-error">שגיאת תאריך: '..res..'</span>[[קאטעגאריע:בלעטער מיט דאטום פעלערן]]'
return frame.args['error'] or '<span class="scribunto-error">דאטום פעלער: '..res..'</span>[[קאטעגאריע:בלעטער מיט דאטום פעלערן]]'
end
end
end
end
שורה 964: שורה 993:
function parseStrDateSafe(frame)
function parseStrDateSafe(frame)
local dateType = frame.args[2]
local dateType = frame.args[2]
if dateType =='שנה' then
if dateType =='יאר' then
dateType = 'Y'
dateType = 'Y'
elseif dateType=='חודש' then
elseif dateType=='מאנאט' then
dateType = 'M'
dateType = 'M'
elseif dateType=='יום' then
elseif dateType=='טאג' then
dateType='D'
dateType='D'
end
end
שורה 975: שורה 1,004:
if success then
if success then
if dateType=='Y' and mw.ustring.sub( res, 0, 1)=='-' then
if dateType=='Y' and mw.ustring.sub( res, 0, 1)=='-' then
res = mw.ustring.sub( res, 2).. ' לפנה"ס'
res = mw.ustring.sub( res, 2).. ' פד"צ'
end
end
return res
return res
else
else
return frame.args['error'] or '<span class="scribunto-error">שגיאת תאריך: '..res..'</span>[[קאטעגאריע:בלעטער מיט דאטום פעלערן]]'
return frame.args['error'] or '<span class="scribunto-error">דאטום פעלער: '..res..'</span>[[קאטעגאריע:בלעטער מיט דאטום פעלערן]]'


end
end
שורה 1,011: שורה 1,040:
end
end


Date['חשב'] = parseStrDateSafe;
Date['רעכן'] = parseStrDateSafe;
Date['חשב טווח'] =  parseDateRangeSafe;
Date['רעכן אפשטאנד'] =  parseDateRangeSafe;
Date['parseDateRange'] =  parseDateRange;
Date['parseDateRange'] =  parseDateRange;
Date['מקושר'] = linkStrDateUnsafe;
Date['מקושר'] = linkStrDateUnsafe;


return Date
return Date

נאוויגאציע מעניו