local Error = require('Module:Error')local this = ;
this.calendars = ;
function this.registerCalendar(moduleName, ...) moduleName = require(moduleName); --debug only: not lazily this.calendars[#(this.calendars)] = moduleName; --indexed by number, module loaded lazily for i = 1, arg.n do this.calendars[arg[i]] = moduleName; -- indexed by code, module loaded lazily end;end;
this.registerCalendar("Module:Sandbox/DixonD/Datetime/Gregorian", "Gregorian", "g"); --first position is the defaultthis.registerCalendar("Module:Sandbox/DixonD/Datetime/Julian", "Julian", "j");-- more calendars may be added later in new modules pluggable here into this factory...
function this.selectCalendar(index) if index
local calendar = this.calendars[index]; if calendar
if type(calendar)
nil then return tostring(Error.error); end; -- replace the moduleName given ad value of any calendar key by the newly loaded calendar object for k, v in pairs(this.calendars) do if v
return calendar;end;
-- main functionsfunction this.julianDay(year, month, day, hour, minute, second, calendar) calendar = this.selectCalendar(calendar); if calendar
return calendar.julianDay(year, month, day, hour, minute, second);end;
function this.dateOfJulianDay(julianDay, calendar) calendar = this.selectCalendar(calendar); if calendar
return calendar.dateOfJulianDay(julianDay);end;
function this.yearOfJulianDay(julianDay, calendar) calendar = this.selectCalendar(calendar); if calendar
return calendar.yearOfJulianDay(julianDay);end; function this.monthOfJulianDay(julianDay, calendar) calendar = this.selectCalendar(calendar); if calendar
return calendar.monthOfJulianDay(julianDay);end; function this.dayOfJulianDay(julianDay, calendar) calendar = this.selectCalendar(calendar); if calendar
return calendar.dayOfJulianDay(julianDay);end; function this.weekdayOfJulianDay(julianDay, calendar) calendar = this.selectCalendar(calendar); if calendar
return calendar.weekdayOfJulianDay(julianDay);end; function this.hourOfJulianDay(julianDay, calendar) calendar = this.selectCalendar(calendar); if calendar
return calendar.hourOfJulianDay(julianDay);end; function this.minuteOfJulianDay(julianDay, calendar) calendar = this.selectCalendar(calendar); if calendar
return calendar.minuteOfJulianDay(julianDay);end; function this.secondOfJulianDay(julianDay, calendar) calendar = this.selectCalendar(calendar); if calendar
return calendar.secondOfJulianDay(julianDay);end;
return this;