יחידה:תאריך: הבדלים בין גרסאות בדף

מאין תקציר עריכה
מ 3 גרסאות של הדף wikipedia:he:יחידה:תאריך יובאו
 
(27 גרסאות ביניים של 5 משתמשים אינן מוצגות)
שורה 164: שורה 164:
     end
     end


     --ofset
     --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("Calanders dont match", 2)
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, "‎","")
mw.log('תאריך' .. ":" .. wikitext)
-- BC to minus
-- BC to minus
wikitext = mw.ustring.gsub( wikitext, "([0-9]+) לפנה[\"״]ס" , "-%1")
wikitext = mw.ustring.gsub( wikitext, "([0-9]+) לפנה[\"״]ס" , "-%1")
שורה 462: שורה 462:
for a in pairs(months) do
for a in pairs(months) do
wikitext = mw.ustring.gsub(wikitext, ' ?ב?'..a, ' ' .. months[a])  
wikitext = mw.ustring.gsub(wikitext, ' ?ב?'..a, ' ' .. months[a])  
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)
-- if there are alphabet chars return nil (unexpected character)
שורה 552: שורה 557:
function Date:toHebrewString()
function Date:toHebrewString()
local hebrewStr = ''
local hebrewStr = ''
local year = self.year
if (self.precision >= Date.PRECISION.MY100) and (self.precision <= Date.PRECISION.MY) then
if self.year>0 then
        return (self.year/1000000) .. ' מיליון שנים לספירה'
        else
        return (-self.year/1000000) ..' מיליון שנים לפנה״ס'
        end
elseif (self.precision >=Date.PRECISION.KY100) and (self.precision <= Date.PRECISION.KY) then
if self.year>0 then
        return 'האלף ה־'.. (self.year/1000)
        else
        return 'האלף ה־'.. (-self.year/1000) ..' לפנה״ס'
        end
elseif self.precision == Date.PRECISION.YEAR100 then
if year>0 then
        return 'המאה ה־'.. math.ceil(self.year/100)
else
        return 'המאה ה־'.. math.ceil(-self.year/100) ..' לפנה״ס'
        end
elseif self.precision == Date.PRECISION.YEAR10 then
        local year = math.floor((self.year < 0 and -1 * self.year or self.year)  / 10) * 10
        if self.year>0 then
        if year%100==0 then
        return  'העשור הראשון של המאה ה־'.. tostring((year/100)+1)
        else
        return 'שנות ה־' .. tostring(year%100) .. ' של המאה ה־'.. tostring(math.ceil(year/100))
        end
        else
        if year%100==0 then
        return  'העשור הראשון של המאה ה־'.. tostring((year/100))..' לפנה״ס'
        else
        return 'שנות ה־' .. tostring(year%100) .. ' של המאה ה־'.. tostring(math.ceil(year/100))..' לפנה״ס'
        end
        end
end
     if self.year ~= nil then
     if self.year ~= nil then
         if self.year < 0 then
         if self.year < 0 then
שורה 565: שורה 606:


     --month
     --month
     if self.precision < Date.PRECISION.MONTH then
     if self.precision>=Date.PRECISION.YEAR and self.precision < Date.PRECISION.MONTH then
         return hebrewStr
         return hebrewStr
     end
     end
שורה 669: שורה 710:
         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)
שורה 751: שורה 804:
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)")
שורה 759: שורה 812:
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]=='הווה')
if not useCurrent then
t2 = Date.newFromWikitext( parts[2] )
t2 = Date.newFromWikitext( parts[2] )
else
else
שורה 776: שורה 831:
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
שורה 839: שורה 899:
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
שורה 849: שורה 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"
שורה 857: שורה 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")
"(כ)־([א-ת])", "%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
שורה 887: שורה 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
שורה 919: שורה 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


שורה 924: שורה 1,014:
Date['חשב טווח'] =  parseDateRangeSafe;
Date['חשב טווח'] =  parseDateRangeSafe;
Date['parseDateRange'] =  parseDateRange;
Date['parseDateRange'] =  parseDateRange;
Date['מקושר'] = linkStrDateUnsafe;


return Date
return Date