יחידה:טווח זמנים: הבדלים בין גרסאות בדף

יצירת דף עם התוכן "local Date = require('Module:תאריך') local Arguments = require( "Module:Arguments" ) local function WikidataSimpleFill(parameter, entityId, property) --..."
 
מ 7 גרסאות של הדף wikipedia:he:יחידה:טווח_זמנים יובאו
 
(24 גרסאות ביניים של 7 משתמשים אינן מוצגות)
שורה 4: שורה 4:
local function WikidataSimpleFill(parameter, entityId, property)  
local function WikidataSimpleFill(parameter, entityId, property)  
-- this doesnt handle unkown values, multi value etc
-- this doesnt handle unkown values, multi value etc
if parameter~=nil then return parameter end
if parameter~=nil then return parameter, false end
local wikidataVal = mw.wikibase.getBestStatements( entityId, property )
local wikidataVal = mw.wikibase.getBestStatements( entityId, property )
if #wikidataVal > 0 then
if #wikidataVal > 0 then
local propValue = wikidataVal[1].mainsnak
local propValue = wikidataVal[1].mainsnak
return mw.wikibase.renderSnak( propValue )  
return mw.wikibase.renderSnak( propValue ) , true
end
end
return nil
return nil, false
end
end


שורה 18: שורה 18:
local entityId = args['qid'] or mw.wikibase.getEntityIdForCurrentPage()
local entityId = args['qid'] or mw.wikibase.getEntityIdForCurrentPage()
if (entityId == '-' or entityId=='') then entityId = nil end
local pointInTime = args['נקודת זמן']
local pointInTime = args['נקודת זמן']
local startDate = args['תאריך התחלה']
local startDate = args['תאריך התחלה']
local endDate = args['תאריך סיום']
local endDate = args['תאריך סיום']
local wikidataStartDate = args['תאריך התחלה-ויקינתונים'] or 'P580'
local wikidataEndDate = args['תאריך סיום-ויקינתונים'] or 'P582'
local showEditWikidata = true
-- text to show if we have only end date. Example: "Last even - %s" where %s is time. nil - will not show end date
-- text to show if we have only end date. Example: "Last even - %s" where %s is time. nil - will not show end date
שורה 28: שורה 33:
-- Whether to show time diff between start and end day when applicable. Example: כן.
-- Whether to show time diff between start and end day when applicable. Example: כן.
local showTimeDiff = args['הצגת הפרשת זמנים']
local showTimeDiff = args['הצגת הפרשת זמנים']
local dateRangeDiffFormat = args['פורמט הצגה'] or '%s (%s)'
local usingWikidata = false
if  entityId~=nil then
if  entityId~=nil then
-- todo: support different fallbacks for properties
-- todo: support different fallbacks for properties
startDate = WikidataSimpleFill(startDate, entityId, 'P580' )
local usingWikidataStartDate = false
endDate = WikidataSimpleFill(endDate, entityId, 'P582' )
local usingWikidataEndDate = false
local usingWikidataPointInTime = false
local usingWikidataDuration = false
wikidataStartDate = mw.text.split( wikidataStartDate, ' *, *', false )
wikidataEndDate = mw.text.split( wikidataEndDate, ' *, *', false )
for _, wikidataStartProp in pairs(wikidataStartDate) do
startDate, usingWikidataStartDate = WikidataSimpleFill(startDate, entityId, wikidataStartProp )
end
for _, wikidataEndProp in pairs(wikidataEndDate) do
endDate, usingWikidataEndDate = WikidataSimpleFill(endDate, entityId, wikidataEndProp )
end
usingWikidata = usingWikidata or usingWikidataStartDate or usingWikidataEndDate
if startDate == nil and endDate == nil then
pointInTime, usingWikidataPointInTime  = WikidataSimpleFill(pointInTime, entityId, 'P585' )
usingWikidata = usingWikidata or usingWikidataPointInTime
end
if showTimeDiff == 'כן' then
if showTimeDiff == 'כן' then
duration = WikidataSimpleFill(duration, entityId, 'P2047' )
duration, usingWikidataDuration = WikidataSimpleFill(duration, entityId, 'P2047' )
if usingWikidataDuration then
-- workaround for T261543
duration = mw.ustring.gsub( duration, '(%d+) יממה', '%1 ימים' )
end
usingWikidata = usingWikidata or usingWikidataDuration
end
end
end
end


-- Whether the event still continues. this will show <START>-present. Example: כן
-- Whether the event still continues. this will show <START>-present. Example: כן
local ongoingEvent = args['נמשך']
local defaultOngoingEvent = args['נמשך'] == 'כן'
local ongoingEvent = defaultOngoingEvent
local endDateOngoingEvent = args['הווה']
local presentText = args['טקסט הווה']
local diffFormat = 'auto' -- TODO: better handling for different scales
local diffFormat = 'auto' -- TODO: better handling for different scales
if  endDate~=nil and endDate~='' then
if endDateOngoingEvent~=nil then
-- set default ongoingEvent as false
ongoingEvent = false
for v in string.gmatch(endDateOngoingEvent, "[^,]+") do
if v:match('^%s*(.-)%s*$') == endDate then
-- set as true if end date specific that match endDateOngoingEvent
ongoingEvent = true
if presentText then endDate=presentText end
end
end
else
-- explicity end date was specified, hence it is not ongoing
ongoingEvent = false
end
end
-- simple case of single point in time
-- simple case of single point in time
שורה 52: שורה 102:
if startDate == nil and endDate~=nil  then
if startDate == nil and endDate~=nil  then
if onlyEndDateText == nil then return end -- ignore only end date
if onlyEndDateText == nil then return end -- ignore only end date
return mw.ustring.format(onlyEndDateText, endDate)
res = mw.ustring.format(onlyEndDateText, endDate)
elseif startDate ~= nil and endDate==nil  then
elseif startDate ~= nil and (endDate==nil or (ongoingEvent and endDate~=nil)) then
if ongoingEvent == 'כן' then
if ongoingEvent then
res = mw.ustring.format('%s - הווה', startDate)
dateFormat = '%s–%s'
if mw.ustring.match(startDate, ' ') or (endDate and mw.ustring.match(endDate, ' ')) then
dateFormat = '%s – %s'
end
res = mw.ustring.format(dateFormat, startDate, endDate or 'הווה')
-- try to fallback to automatic duration if duration is not available
-- try to fallback to automatic duration if duration is not available
if showTimeDiff == 'כן' and duration==nil then
if showTimeDiff == 'כן' and duration==nil then
local success, automaicDuration = pcall(dateModule.parseDateRange, startDate, diffFormat, true)
local success, automaicDuration = pcall(Date.parseDateRange, startDate, diffFormat, true)
if success then duration = automaicDuration end
if success then duration = automaicDuration end
end
end
שורה 65: שורה 119:
end
end
elseif startDate~=nil and endDate~=nil  then
elseif startDate~=nil and endDate~=nil  then
res = mw.ustring.format('%s - %s', startDate, endDate)
dateFormat = '%s–%s'
if mw.ustring.match(startDate, ' ') or mw.ustring.match(endDate, ' ') then
dateFormat = '%s %s'
end
res = mw.ustring.format(dateFormat, startDate, endDate)
if showTimeDiff == 'כן' and duration==nil then
if showTimeDiff == 'כן' and duration==nil then
local success, automaicDuration = pcall(dateModule.parseDateRange, dateRange, diffFormat, true)
local success, automaicDuration = pcall(Date.parseDateRange, res, diffFormat, true)
if success then duration = automaicDuration end
if success then duration = automaicDuration end
end
end
שורה 74: שורה 132:
-- append the duration
-- append the duration
if showTimeDiff == 'כן' and duration~=nil and duration~='' then
if showTimeDiff == 'כן' and duration~=nil and duration~='' and res~=nil then
res = mw.ustring.format('%s (%s)', res, duration)
res = mw.ustring.format(dateRangeDiffFormat, res, duration)
end
if showEditWikidata and usingWikidata and res~=nil and res~='' and entityId~=nil then
local link = mw.title.makeTitle( 0, entityId, '', 'wikidata' ):fullUrl('uselang=he')
res = res .. mw.ustring.format(' [[File:Blue pencil RTL.svg|15px|link=%s|עריכת הנתון בוויקינתונים]]', link)
end
end
return res
return res