בדוקי עריכות אוטומטית, אינטערפעיס רעדאקטארן, אינטערפעיס אדמיניסטראַטאָרן, סיסאפן, צוות טכני, מעדכנים, מייבא
263
רעדאגירונגען
ק (rv) |
(ייבוא מוויקיפדיה העברית, ראה רשימת התורמים) |
||
| שורה 164: | שורה 164: | ||
end | end | ||
-- | --offset | ||
if offset ~= nil then | if offset ~= nil then | ||
if offset == 'Z' then | if offset == 'Z' then | ||
| שורה 445: | שורה 445: | ||
} | } | ||
local calendar = nil | local calendar = nil | ||
if mw.ustring.find( wikitext, '<small>%(%[%[ | if mw.ustring.find( wikitext, '<small>%(%[%[הלוח היוליאני%|יוליאני%]%]%)</small>' ) then | ||
calendar = Date.CALENDAR.JULIAN | calendar = Date.CALENDAR.JULIAN | ||
wikitext = mw.ustring.gsub( wikitext, "<small>%(%[%[ | wikitext = mw.ustring.gsub( wikitext, "<small>%(%[%[הלוח היוליאני%|יוליאני%]%]%)</small>", "" ) | ||
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") | ||
| שורה 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) | ||
| שורה 593: | שורה 598: | ||
else | else | ||
if self.calendar == Date.CALENDAR.JULIAN and self.year > 1583 then | if self.calendar == Date.CALENDAR.JULIAN and self.year > 1583 then | ||
hebrewStr = mw.ustring.format('%d <small>([[ | hebrewStr = mw.ustring.format('%d <small>([[הלוח היוליאני|יוליאני]])</small>', (self.year)) | ||
else | else | ||
hebrewStr = mw.ustring.format('%d', self.year) | hebrewStr = mw.ustring.format('%d', self.year) | ||
| שורה 604: | שורה 609: | ||
return hebrewStr | return hebrewStr | ||
end | end | ||
local months = { ' | local months = { 'ינואר','פברואר', 'מרץ', 'אפריל', 'מאי', 'יוני', 'יולי', 'אוגוסט', 'ספטמבר', 'אוקטובר', 'נובמבר','דצמבר' } | ||
hebrewStr = months[self.month] .. ' ' .. hebrewStr | hebrewStr = months[self.month] .. ' ' .. hebrewStr | ||
| שורה 611: | שורה 616: | ||
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: | שורה 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 = {year, month, day} | |||
age.year = time2.year - time1.year | |||
age.month = time2.month - time1.month | |||
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 | |||
end | end | ||
function Date:formatDate(options) | function Date:formatDate(options) | ||
| שורה 787: | שורה 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)") | ||
| שורה 795: | שורה 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 | ||
| שורה 812: | שורה 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 | ||
-- 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 | ||
| שורה 840: | שורה 864: | ||
readableInterval['years'] = readableInterval['years'] or 0 | readableInterval['years'] = readableInterval['years'] or 0 | ||
if not (guessLevel==NO_GUESS) and not (guessLevel==DAY_GUESS and hasYears and #diffFormat==1 and readableInterval['days']>31) then | if not (guessLevel==NO_GUESS) and not (guessLevel==DAY_GUESS and hasYears and #diffFormat==1 and readableInterval['days']>31) then | ||
outputPrefix=' | outputPrefix='כ־' | ||
end | end | ||
if inclusive then | if inclusive then | ||
| שורה 875: | שורה 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 | ||
| שורה 893: | שורה 922: | ||
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 | ||
| שורה 916: | שורה 940: | ||
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 | ||
| שורה 923: | שורה 947: | ||
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: | שורה 956: | ||
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 | ||
| שורה 952: | שורה 977: | ||
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 | ||
| שורה 960: | שורה 1,012: | ||
Date['חשב טווח'] = parseDateRangeSafe; | Date['חשב טווח'] = parseDateRangeSafe; | ||
Date['parseDateRange'] = parseDateRange; | Date['parseDateRange'] = parseDateRange; | ||
Date['מקושר'] = linkStrDateUnsafe; | |||
return Date | return Date | ||
רעדאגירונגען