Module:SetDateRange: Difference between revisions

From The Seven Sages of Rome
No edit summary
No edit summary
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
local p = {};  
local p = {};  
local function isStringSet(s)
return s ~= nil and s ~= ''
end


p.set = function( f )
p.set = function( f )
Line 7: Line 11:


local args = f.args
local args = f.args
local date_range = nil
if args.start_date and args.end_date then
local fixed_date = args.fixed_date:gsub("-", "/")
date_range = args.start_date .. "-" .. args.end_date
local start_date = args.start_date:gsub("-", "/")
elseif args.start_date then
local end_date = args.end_date:gsub("-", "/")
date_range = args.start_date
local islamic_date = args.islamic_date
elseif args.end_date then
local hebrew_date = args.hebrew_date
date_range = args.end_date
local date_range = ""
local sort_date = ""
local date_range_property = args.date_range_property
local sort_date_property = args.sort_date_property
if isStringSet(fixed_date) then
date_range = fixed_date
sort_date = fixed_date
elseif isStringSet(start_date) and isStringSet(end_date) then
date_range = start_date .. " - " .. end_date
sort_date = start_date
elseif isStringSet(start_date) then
date_range = start_date
sort_date = start_date
elseif isStringSet(end_date) then
date_range = end_date
sort_date = end_date
end
end
local property = {}
local property = {}
property["Has Date Range"] = date_range
property[sort_date_property] = sort_date
property[date_range_property] = date_range
local result = mw.smw.set( property )
if isStringSet(islamic_date) then
property["Has Islamic Date Of Text Composition"] = islamic_date
date_range = date_range .. " (<span data-toggle='tooltip' title='Anno Hegirae (Islamic calendar)'>" .. islamic_date .. "<sup>AH</sup></span>)"
end
if isStringSet(hebrew_date) then
property["Has Hebrew Date Of Text Composition"] = hebrew_date
date_range = date_range .. " (<span data-toggle='tooltip' title='Anno Mundi (Hebrew calendar)'>" .. hebrew_date .. "<sup>AM</sup></span>)"
end
local result = mw.smw.set(property)
if result == false then
if result == false then
Line 26: Line 59:
return date_range
return date_range
end
end


return p
return p

Latest revision as of 09:05, 25 March 2025

Module Documentation: SetDateRange

This module is used in Semantic MediaWiki to determine and set appropriate date properties for sorting and display. It takes various date inputs, prioritizes them based on availability, and sets corresponding Semantic MediaWiki properties.

Usage

To invoke this module, use the following syntax within a template:

{{#invoke:SetDateRange|set
 | fixed_date={{{Has Date Of Text Composition|}}}
 | start_date={{{Has Start Date Of Composition|}}}
 | end_date={{{Has End Date Of Composition|}}}
 | islamic_date={{{Has Islamic Date Of Text Composition|}}}
 | hebrew_date={{{Has Hebrew Date Of Text Composition|}}}
 | date_range_property=Has Date Range Of Text Composition
 | sort_date_property=Has Sort Date Of Text Composition}}

Parameters

  • fixed_date: A fixed date value (YYYY-MM-DD format, converted to YYYY/MM/DD for consistency)
  • start_date: The beginning date of a range
  • end_date: The ending date of a range
  • islamic_date: Optional Islamic calendar date
  • hebrew_date: Optional Hebrew calendar date
  • date_range_property: The Semantic MediaWiki property where the displayed date range will be stored
  • sort_date_property: The Semantic MediaWiki property where the sorting date will be stored

Behavior

  1. If a fixed_date is provided, it is used for both display and sorting.
  2. If start_date and end_date are both provided, a date range is created with start_date as the sorting date.
  3. If only start_date is available, it is used for both display and sorting.
  4. If only end_date is available, it is used for both display and sorting.
  5. If islamic_date or hebrew_date are provided, they are added to the display output along with tooltips explaining their meaning.
  6. The generated output includes Bootstrap 4 tooltips for AH (Anno Hegirae, Islamic calendar) and AM (Anno Mundi, Hebrew calendar).

Example Output

If a manuscript has a start date of 1500-01-01, an end date of 1500-12-31, an Islamic date of 905, and a Hebrew date of 5260, the rendered output might look like:

1500/01/01 - 1500/12/31 (<span data-toggle="tooltip" title="Anno Hegirae (Islamic calendar)">905<sup>AH</sup></span>) (<span data-toggle="tooltip" title="Anno Mundi (Hebrew calendar)">5260<sup>AM</sup></span>)

Notes

  • Bootstrap 4 tooltips require initialization via JavaScript:
$(document).ready(function() {
    $('[data-toggle="tooltip"]').tooltip();
});

This module enhances the display and semantic organization of historical dates, including cross-calendar representation, for improved research and usability.


local p = {}; 

local function isStringSet(s)
	return s ~= nil and s ~= ''
end

p.set = function( f )
	if not mw.smw then
        return "mw.smw module not found"
	end

	local args = f.args
	
	local fixed_date = args.fixed_date:gsub("-", "/")
	local start_date = args.start_date:gsub("-", "/")
	local end_date = args.end_date:gsub("-", "/")
	local islamic_date = args.islamic_date
	local hebrew_date = args.hebrew_date
	
	local date_range = ""
	local sort_date = ""
	
	local date_range_property = args.date_range_property
	local sort_date_property = args.sort_date_property
	
	if isStringSet(fixed_date) then
		date_range = fixed_date
		sort_date = fixed_date
	elseif isStringSet(start_date) and isStringSet(end_date) then
		date_range = start_date .. " - " .. end_date
		sort_date = start_date
	elseif isStringSet(start_date) then
		date_range = start_date
		sort_date = start_date
	elseif isStringSet(end_date) then
		date_range = end_date
		sort_date = end_date
	end
	
	local property = {}
	property[sort_date_property] = sort_date
	property[date_range_property] = date_range
	
	if isStringSet(islamic_date) then
		property["Has Islamic Date Of Text Composition"] = islamic_date
		date_range = date_range .. " (<span data-toggle='tooltip' title='Anno Hegirae (Islamic calendar)'>" .. islamic_date .. "<sup>AH</sup></span>)"
	end
	
	if isStringSet(hebrew_date) then
		property["Has Hebrew Date Of Text Composition"] = hebrew_date
		date_range = date_range .. " (<span data-toggle='tooltip' title='Anno Mundi (Hebrew calendar)'>" .. hebrew_date .. "<sup>AM</sup></span>)"
	end
	
	local result = mw.smw.set(property)
	
	if result == false then
		print("Error: Couldn't set date range")
	end
	
	return date_range
end

return p