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

2,911 בייטן צוגעלייגט ,  פֿאַר 2 יאָר
דיוק
ק (rv)
 
(דיוק)
 
(21 מיטלסטע ווערסיעס פון 6 באַניצער נישט געוויזן.)
שורה 164: שורה 164:
     end
     end


     --ofset
     --offset
     if offset ~= nil then
     if offset ~= nil then
         if offset == 'Z' then
         if offset == 'Z' then
שורה 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


שורה 337: שורה 373:
t2 = Date.julianToGregorian(t2)
t2 = Date.julianToGregorian(t2)
else
else
error("Calanders dont match", 2)
error("Calendars don't match", 2)
end
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;","")
mw.log('תאריך' .. ":" .. 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")
    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")
 
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
 
    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
end
-- if there are alphabet chars return nil (unexpected character)
 
assert(not mw.ustring.find(wikitext, '%a'), "Unexpected format")
local parts = mw.text.split(mw.text.trim(wikitext),' ')
local parts = mw.text.split(mw.text.trim(wikitext),' ')


שורה 471: שורה 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")
שורה 478: שורה 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")
שורה 556: שורה 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
שורה 604: שורה 638:
         return hebrewStr
         return hebrewStr
     end
     end
    local months = { 'יאנואר','פעברואר', 'מערץ', 'אפריל', 'מאי', 'יוני', 'יולי', 'אויגוסט', 'סעפטעמבער', 'אקטאבער', 'נאוועמבער','דעצעמבער' }
    local months = { 'יאנואר','פעברואר', 'מערץ', 'אפריל', 'מאי', 'יוני', 'יולי', 'אויגוסט', 'סעפטעמבער', 'אקטאבער', 'נאוועמבער','דעצעמבער' }
     hebrewStr = months[self.month] .. ' ' .. hebrewStr
     hebrewStr = months[self.month] .. ' ' .. hebrewStr


שורה 611: שורה 645:
         return hebrewStr
         return hebrewStr
     end
     end
    hebrewStr = mw.ustring.format('%d %s', self.day, hebrewStr)
    hebrewStr = mw.ustring.format('%d %s', self.day, hebrewStr)


     --hour
     --hour
שורה 705: שורה 739:
         time2 = Date.newFromIso8601(mw.getContentLanguage():formatDate('c', nil, true), true)
         time2 = Date.newFromIso8601(mw.getContentLanguage():formatDate('c', nil, true), true)
     end
     end
    local age = time2.year - time1.year
local age = {year, month, day}
    if time2.month < time1.month or (time2.month == time1.month and time2.day < time1.day) then
age.year = time2.year - time1.year
        age = age - 1
age.month = time2.month - time1.month
    end
age.day = time2.day - time1.day
if age.day < 0 then
local lastMonth = time2.month - 1
if lastMonth == 0 then
lastMonth = 12
end
age.day = age.day + maxDaysInMonth[lastMonth]
age.month = age.month - 1
end
if age.month < 0 then
age.month = age.month + 12
age.year = age.year - 1
end
     if time1.year < 0 and time2.year > 0 then
     if time1.year < 0 and time2.year > 0 then
         age = age - 1
         age.year = age.year - 1
     end
     end
    return age
 
return age
end
end


function Date:formatDate(options)
function Date:formatDate(options)
שורה 720: שורה 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)
שורה 726: שורה 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)
שורה 787: שורה 833:
dateRangeStr = mw.text.killMarkers(dateRangeStr)
dateRangeStr = mw.text.killMarkers(dateRangeStr)
dateRangeStr = mw.ustring.gsub(dateRangeStr, "&rlm;","")
dateRangeStr = mw.ustring.gsub(dateRangeStr, "&rlm;","")
   mw.log("טווח תאריכים:" .. 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)")
שורה 795: שורה 841:
local t1 = Date.newFromWikitext( parts[1] )
local t1 = Date.newFromWikitext( parts[1] )
local t2
local t2
if #parts==2 then
local useCurrent = #parts<2 or (parts[2] == 'היינט' or parts[2]=='הווה' or parts[2]=='אנגייענד' or parts[2]=='איצט')
if not useCurrent then
t2 = Date.newFromWikitext( parts[2] )
t2 = Date.newFromWikitext( parts[2] )
else
else
שורה 812: שורה 860:
if hasDays and ((t1.precision>=Date.PRECISION.MONTH and t2.precision<Date.PRECISION.MONTH) or (t1.precision<Date.PRECISION.MONTH and t2.precision>=Date.PRECISION.MONTH)) then
if hasDays and ((t1.precision>=Date.PRECISION.MONTH and t2.precision<Date.PRECISION.MONTH) or (t1.precision<Date.PRECISION.MONTH and t2.precision>=Date.PRECISION.MONTH)) then
return '' -- Ambiguous date range
-- Ambiguous date range
if t2.year - t1.year > 2 then
diffFormat = {'years'}
else
return ''
end
end
end
local NO_GUESS, MONTH_GUESS, DAY_GUESS = 0, 1, 2
local NO_GUESS, MONTH_GUESS, DAY_GUESS = 0, 1, 2
שורה 875: שורה 928:
return dif
return dif
else
else
return outputPrefix..lang:formatDuration(dif, diffFormat)
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
שורה 883: שורה 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
diffFormat = {'years', 'days'}
elseif frame.args[2] == "הפרש" then
elseif frame.args[2] == "הפרש" then
diffFormat = "raw"
diffFormat = "raw"
שורה 893: שורה 953:
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")
"(כ)־([א-ת])", "%1%2")
str= mw.ustring.gsub(str,"וגם ([0-9])","ו-%1")
str= mw.ustring.gsub(str,"וגם ([א-ת])","ו%1");


if frame.args[2] == "גיל" then
if frame.args[2] == "גיל" then
שורה 916: שורה 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," יאָר", "")
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
שורה 931: שורה 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
שורה 937: שורה 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
שורה 948: שורה 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


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
end
return linkedDateStr
end
end


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


return Date
return Date