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

מאין תקציר עריכה
מ 3 גרסאות של הדף wikipedia:he:יחידה:תאריך יובאו
 
(32 גרסאות ביניים של 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
שורה 444: שורה 444:
['דצמבר']= 12
['דצמבר']= 12
}
}
local calendar = nil
if mw.ustring.find( wikitext, '<small>%(%[%[הלוח היוליאני%|יוליאני%]%]%)</small>' ) then
calendar = Date.CALENDAR.JULIAN
wikitext = mw.ustring.gsub( wikitext, "<small>%(%[%[הלוח היוליאני%|יוליאני%]%]%)</small>", "" )
end
-- Remove instances of [ and ]
-- Remove instances of [ and ]
wikitext = mw.ustring.gsub( wikitext, "[%[%]]", "" )
wikitext = mw.ustring.gsub( wikitext, "[%[%]]", "" )
שורה 452: שורה 456:
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)
-- BC to minus
-- BC to minus
wikitext = mw.ustring.gsub( wikitext, "([0-9]+) לפנה\"ס" , "-%1")
wikitext = mw.ustring.gsub( wikitext, "([0-9]+) לפנה[\"״]ס" , "-%1")
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)
assert(not mw.ustring.find(wikitext, '%a'), "Unexpected format")
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),' ')


     local definition = {}
     local definition = {}
definition.calendar = calendar
if #parts==3 then -- DMY date
if #parts==3 then -- DMY date
definition.year = tonumber(parts[3])
definition.year = tonumber(parts[3])
שורה 540: שורה 548:
     end
     end
     return iso .. ':' .. prepend( self.second, '0', 2 ) .. formatUtcOffsetForIso( self.utcoffset )
     return iso .. ':' .. prepend( self.second, '0', 2 ) .. formatUtcOffsetForIso( self.utcoffset )
end
--[[
    Return a hebrew representation of Date as a string
    @return string
]]--
function Date:toHebrewString()
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 < 0 then
            hebrewStr = mw.ustring.format('%d לפנה״ס',  (-1*self.year))
        else
if self.calendar == Date.CALENDAR.JULIAN and self.year > 1583 then
hebrewStr = mw.ustring.format('%d <small>([[הלוח היוליאני|יוליאני]])</small>',  (self.year))
else
hebrewStr = mw.ustring.format('%d',  self.year)
end
        end
    end
    --month
    if self.precision>=Date.PRECISION.YEAR and self.precision < Date.PRECISION.MONTH then
        return hebrewStr
    end
    local months = { 'ינואר','פברואר', 'מרץ', 'אפריל', 'מאי', 'יוני', 'יולי', 'אוגוסט', 'ספטמבר', 'אוקטובר', 'נובמבר','דצמבר' }
    hebrewStr = months[self.month] .. ' ' .. hebrewStr
    --day
    if self.precision < Date.PRECISION.DAY then
        return hebrewStr
    end
    hebrewStr = mw.ustring.format('%d ב%s', self.day, hebrewStr)
    --hour
    if self.precision < Date.PRECISION.HOUR then
        return hebrewStr
    end
    hebrewStr = mw.ustring.format('%s בשעה %d',  hebrewStr, self.hour)
    --minute
    if self.precision < Date.PRECISION.MINUTE then
        return hebrewStr .. formatUtcOffsetForIso( self.utcoffset )
    end
    hebrewStr = hebrewStr .. ':' .. prepend( self.minute, '0', 2 )
    --second
    if self.precision < Date.PRECISION.SECOND then
        return hebrewStr .. formatUtcOffsetForIso( self.utcoffset )
    end
    return hebrewStr .. ':' .. prepend( self.second, '0', 2 ) .. formatUtcOffsetForIso( self.utcoffset )
end
end


שורה 549: שורה 644:
function Date:toString( language )
function Date:toString( language )
     if language == nil then
     if language == nil then
         language = mw.language.getContentLanguage()
         return self:toIso8601()
     elseif type( language ) == 'string' then
    end
    if language == 'he' then
    return self:toHebrewString()
     end
    --[[if type( language ) == 'string' then
         language = mw.language.new( language )
         language = mw.language.new( language )
     end
     end
 
   
     --return language:formatDate( 'r', self:toIso8601() )
     return language:formatDate( 'r', self:toIso8601() )]]
     return self:toIso8601()
     return self:toIso8601()
end
end
שורה 611: שורה 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)
שורה 693: שורה 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)")
שורה 701: שורה 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
שורה 718: שורה 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
שורה 781: שורה 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
שורה 791: שורה 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"
שורה 799: שורה 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
שורה 829: שורה 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
שורה 861: שורה 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


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


return Date
return Date