יחידה:טווח זמנים: הבדלים בין גרסאות בדף
מאין תקציר עריכה |
מ 7 גרסאות של הדף wikipedia:he:יחידה:טווח_זמנים יובאו |
||
| (20 גרסאות ביניים של 7 משתמשים אינן מוצגות) | |||
| שורה 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['תאריך התחלה'] | ||
| שורה 32: | שורה 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 | local usingWikidata = false | ||
| שורה 41: | שורה 43: | ||
local usingWikidataPointInTime = false | local usingWikidataPointInTime = false | ||
local usingWikidataDuration = false | local usingWikidataDuration = false | ||
startDate, usingWikidataStartDate = WikidataSimpleFill(startDate, entityId, | |||
endDate, usingWikidataEndDate = WikidataSimpleFill(endDate, entityId, | 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 | usingWikidata = usingWikidata or usingWikidataStartDate or usingWikidataEndDate | ||
| שורה 61: | שורה 70: | ||
-- 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 | ||
| שורה 74: | שורה 103: | ||
if onlyEndDateText == nil then return end -- ignore only end date | if onlyEndDateText == nil then return end -- ignore only end date | ||
res = 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 == ' | if ongoingEvent then | ||
res = mw.ustring.format(' | 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 | ||
| שורה 86: | שורה 119: | ||
end | end | ||
elseif startDate~=nil and endDate~=nil then | elseif startDate~=nil and endDate~=nil then | ||
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(Date.parseDateRange, res, diffFormat, true) | local success, automaicDuration = pcall(Date.parseDateRange, res, diffFormat, true) | ||
| שורה 95: | שורה 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( | res = mw.ustring.format(dateRangeDiffFormat, res, duration) | ||
end | end | ||