Jump to content

Extension:UniversalCalendar

From mediawiki.org
MediaWiki extensions manual
UniversalCalendar
Release status: beta
Implementation Parser function , Hook
Description UniversalCalendar is a powerful MediaWiki extension that provides accurate date conversion functionality between 30+ calendar systems. Whether it's Gregorian, Lunar, Islamic, or Mayan calendars, you can easily convert and format dates between them.
Author(s) HoshinoKennjitalk
Latest version v1.1.0 (2026/02/20)
Compatibility policy Master maintains backward compatibility.
MediaWiki 1.39.0
PHP 8.4.0
Licence MIT License
Download
https://github.com/akimoto-akira/UniversalCalendar/blob/main/README.md
#Version History
Help studio.purelight.net.cn/calendar.php

Installation

[edit]
  • Download and place the file(s) in a directory called UniversalCalendar in your extensions/ folder.
  • Add the following code at the bottom of your LocalSettings.php file:
    wfLoadExtension( 'UniversalCalendar' );
    
  • Yes Done – Navigate to Special:Version on your wiki to verify that the extension is successfully installed.

Supported Calendars

[edit]

UniversalCalendar supports the following calendar systems:

Code Calendar Name Description
GC Gregorian Calendar Modern international standard calendar
JUC Julian Calendar Predecessor of the Gregorian calendar
LC Chinese Lunar Calendar With 24 solar terms support
CHC Chinese Historical Calendar Dynastic era name system
SGC Sexagenary Calendar Heavenly Stems and Earthly Branches system
IC Islamic Calendar Pure lunar calendar system
HC Hebrew Calendar Jewish calendar
JC Japanese Calendar Era name system
PC Persian Calendar Official calendar of Iran
BC Buddhist Calendar Used in Thailand and other countries
CC Coptic Calendar Egyptian Coptic Church calendar
EC Ethiopian Calendar Official calendar of Ethiopia
RC Roman Calendar Ancient Roman calendar
MC Mayan Calendar Includes Long Count, Tzolkin, and Haab
ROCT Republic of China Taiwan Calendar ROC calendar used in Taiwan
JUH Juche Calendar Juche calendar used in North Korea
DAI Dai Calendar Xishuangbanna Dai ethnic calendar
DDAI Dehong Dai Calendar Dehong Dai ethnic calendar
INC Indian National Calendar Official calendar of India
SAKA Saka Calendar Traditional Indian calendar
CSK Chula Sakarat Calendar Traditional Thai calendar
YI Yi Calendar Yi ethnic traditional calendar
FRC French Republican Calendar French Revolution period calendar
TBC Tibetan Calendar Tibetan traditional calendar
MONG Mongolian Calendar Mongolian ethnic traditional calendar
VS Vikram Samvat Calendar Official calendar of Nepal
ZOR Zoroastrian Calendar Zoroastrian religious calendar
KHM Khmer Calendar Traditional Cambodian calendar
CHR Cherokee Calendar Cherokee tribal calendar
INU Inuit Calendar Inuit people's calendar
VN Vietnamese Calendar Traditional Vietnamese calendar
JAV Javanese Calendar Traditional Javanese calendar

About Chinese Historical Calendar Data

[edit]

The Chinese Historical Calendar (CHC) uses hybrid data sources:

  • Accurate data range: 1970 to 2100, sourced from Purple Mountain Observatory, Beijing
  • Approximate algorithm range: Dates outside the above range use approximate algorithms
  • Future improvement plan: Next version will adopt astronomical algorithms to replace approximate algorithms

Historical Date Error Margin:

Even with astronomical algorithms, historical date conversions have theoretical errors due to long-term cumulative effects of celestial motion:

  • Within 500 years of data range: ±1 day error
  • Within 1000 years of data range: ±3 days error
  • Within 2000 years of data range: ±7 days error

This extension supports dates as early as 2070 BCE (establishment of Xia Dynasty). Date conversion results for this period are for historical research reference only.

Era Names and Dating Systems:

Due to the linear timeline design of the calendar plugin, special historical periods are handled as follows:

  • Era Name Origin: The era name system began with Emperor Wu of Han's Jianyuan era (140 BCE); periods before this have no era names
  • Pre-Qin Period: Xia, Shang, Zhou, and Warring States periods use dynasty names and emperor names as dating identifiers
  • Multiple Regime Periods: During periods of coexisting regimes (Three Kingdoms, Northern and Southern Dynasties, Five Dynasties and Ten Kingdoms), the mainstream historical view is adopted to select the primary regime, or emperor names are used instead of era names
  • Timeline Uniqueness: Each time point corresponds to only one dating method, ensuring deterministic conversion results

This design ensures linear consistency in calendar conversion and avoids ambiguity of multiple dating systems for the same date.

About ROC Calendar:

The "Republic of China" (ROC) calendar was the official dating system used in mainland China from the fall of the Qing Dynasty to the establishment of the People's Republic of China (1912-1949). After 1949, the regime relocated to Taiwan and continues to use the ROC calendar to this day.

To accurately reflect historical facts and current usage, this extension separates the ROC calendar into two systems:

  • CHC (Chinese Historical Calendar): Includes ROC dating from 1912-1949 as part of mainland China's historical chronology
  • ROCT (Republic of China Taiwan Calendar): Represents the ROC calendar system continuously used in Taiwan after 1949

This separation design aligns with the plugin's linear timeline principle. When different regions use different dating systems at the same time point, they are distinguished by different calendar codes, ensuring accuracy and clarity in chronological conversion.


Usage

[edit]

Special Page

[edit]

Visit Special:CalendarConverter to use the graphical interface for calendar conversion and viewing calendar grids.

Features

[edit]
  1. Date Conversion: Convert dates between different calendar systems
  2. Calendar Grid Display: View calendar grids for specified months
  3. Dual Calendar Comparison: Display two calendar systems side by side
  4. Solar Terms Display: Display 24 solar terms in Chinese Lunar Calendar grids (marked in red)
  5. Nine-Nines Display: Display Nine-Nines information in Chinese Lunar Calendar grids (marked in blue)

Special Markers in Calendar Grids

[edit]

In the Chinese Lunar Calendar grid on Special:CalendarConverter:

  • Solar Term Dates: Display solar term names (red, e.g., "Lichun", "Yushui", etc.)
  • Nine-Nines First Day: Display period names (blue, e.g., "First Nine", "Second Nine", etc.)
  • Display Priority: Solar Terms > Nine-Nines (solar terms are shown when present, Nine-Nines shown otherwise)

About 24 Solar Terms

[edit]

The 24 solar terms are an important component of traditional Chinese calendar, reflecting the sun's position changes along the ecliptic:

  • Calculation Method: Based on precise solar longitude calculation (one solar term every 15 degrees)
  • Algorithm Source: Uses astronomical algorithms from Jean Meeus' "Astronomical Algorithms" Chapter 25
  • Calculation Precision: Minute-level accuracy
  • Support Range: Supports solar term calculation for any year

About Nine-Nines (Shujiujiu)

[edit]

Nine-Nines is a traditional Chinese method for marking the coldest period of winter:

  • Start Time: Begins from Winter Solstice (solar longitude 270°)
  • Calculation Method: Each 9-day period is one "nine", with 9 periods totaling 81 days
  • Nine Names: First Nine, Second Nine, Third Nine... Ninth Nine
  • Cultural Significance: Marks the coldest period of the year, as the saying goes "walking on ice during Third and Fourth Nines"

Parser Functions

[edit]

UniversalCalendar provides four parser functions that can be used directly in Wiki pages.

1. Date Conversion: {{#calendarconvert:}}

[edit]

Convert dates from one calendar system to another, or format dates within the same calendar.

Syntax:

{{#calendarconvert:source_calendar|target_calendar|date|optional_params}}

Parameters:

  • source_calendar: Calendar code of the source date (required)
  • target_calendar: Calendar code to convert to (required)
  • date: Date string in format CODE:YYYY-MM-DD (required)
  • optional_params: Named parameters
    • format=format_type: Output format (default/long/short, etc.)
    • lang=language_code: Output language (defaults to page language)

2. Calendar Grid: {{#calendargrid:}}

[edit]

Generate a calendar table for a specified calendar system, with support for date links and dual-calendar display.

Syntax:

{{#calendargrid:calendar_code|link_format|year|month|day}}

Parameters:

  • calendar_code: Calendar code to display (required)
  • link_format: Date link template using placeholders (required)
    • Y: Year
    • M: Month
    • D: Day
    • T: Solar term name (for solar term links)
  • year: Year number (optional)
  • month: Month number (optional)
  • day: Day number (optional)

3. Calendar Format: {{#calendarformat:}}

[edit]

Format calendar dates directly using named parameters, supporting complex calendar systems.

Syntax:

{{#calendarformat:calendar_code|param1=value1|param2=value2|...}}

Parameters:

  • calendar_code: Calendar identifier (required)
  • named_parameters: Varies by calendar system
    • Common parameters:
      • format=format_type: Output format
      • lang=language_code: Output language

4. Calendar Unit Names: {{#calendarunit:}}

[edit]

Get localized names for specific units (months, days, solar terms, etc.) in a calendar system.

Syntax:

{{#calendarunit:calendar_code|unit_type|value|optional_params}}

Parameters:

  • calendar_code: Calendar identifier (required)
  • unit_type: Type of unit to query (required)
  • value: Numeric value of the unit (required, except for calendar-name)
  • optional_params: Named parameters
    • lang=language_code: Output language
    • format=format_type: Format type
    • context=context: Context information (e.g., leap for leap month)

Supported Unit Types:

Unit Type Description Applicable Calendars
calendar-name Calendar name All calendars
month Month name All calendars
day Day name Lunar, Tibetan, etc.
weekday Weekday name All calendars
era Era/reign name JC, CHC, etc.
dynasty Dynasty name CHC
stem Heavenly Stem SGC
branch Earthly Branch SGC
zodiac Zodiac animal SGC, LC, etc.
solarterm Solar term LC
tzolkin-name Tzolkin name MC
haab-month Haab month MC
season Season YI

Chinese Aliases

[edit]

All parser functions support Chinese aliases:

English Function Simplified Chinese Traditional Chinese
calendarconvert 历法转换 曆法轉換
calendargrid 历法表 曆法表
calendarformat 历法格式化 曆法格式化
calendarunit 历法单位 曆法單位


Configuration Options

[edit]

Configure the following options in LocalSettings.php:

Cache Settings

[edit]
// Enable caching (default: true)
$wgUniversalCalendarCacheEnabled = true;

// Cache TTL in seconds (default: 86400 = 24 hours)
$wgUniversalCalendarCacheTTL = 86400;

Dai Calendar Settings

[edit]
// Dai calendar new moon calculation cache size (default: 1000 years)
$wgUniversalCalendarDaiNewMoonCacheSize = 1000;

// Dai calendar timezone offset (default: 8 for UTC+8, Yunnan timezone)
$wgUniversalCalendarDaiTimezoneOffset = 8;

Configuration Example

[edit]
// LocalSettings.php

// Enable extension
wfLoadExtension( 'UniversalCalendar' );

// Custom configuration
$wgUniversalCalendarCacheEnabled = true;
$wgUniversalCalendarCacheTTL = 3600; // 1 hour cache
$wgUniversalCalendarDaiTimezoneOffset = 8; // UTC+8

Multi-language Support

[edit]

This extension is developed with Chinese and English as base languages. Translations and formatting for these two languages have been fully tested and proofread. Support for other languages has not yet been comprehensively reviewed.

Included Translation Files

[edit]

This extension includes translation files for the following languages:

  • Chinese: Simplified Chinese (zh-hans), Traditional Chinese (zh-hant)
  • English: English (en)
  • Japanese: 日本語 (ja)
  • Korean: 한국어 (ko)
  • Spanish: Español (es)
  • French: Français (fr)
  • German: Deutsch (de)
  • Italian: Italiano (it)
  • Portuguese: Português (pt)
  • Russian: Русский (ru)
  • Arabic: العربية (ar)
  • Hindi: हिन्दी (hi)
  • Thai: ไทย (th)
  • Vietnamese: Tiếng Việt (vi)
  • Indonesian: Bahasa Indonesia (id)
  • Malay: Bahasa Melayu (ms)
  • Filipino: Filipino (tl)
  • Turkish: Türkçe (tr)
  • Polish: Polski (pl)
  • Dutch: Nederlands (nl)

Note: Translations for languages other than Chinese and English may contain inaccuracies or incompleteness. Feedback and improvement suggestions from native speakers are welcome.

Complexity of Language Localization

[edit]

Different calendars have the following variations across languages:

  • Terminology Differences: The same calendar concept may use completely different vocabulary in different languages
  • Word Order Differences: Date format component order varies by language (e.g., "year-month-day" vs "day-month-year")
  • Number Systems: Some languages use special number representations (e.g., Chinese numerals, Arabic-Indic numerals, etc.)
  • Cultural Conventions: Calendar names and month names are influenced by cultural background

Therefore, comprehensive multi-language support requires not only modifying localization files (i18n) but may also require adjusting PHP code logic to accommodate special requirements of different languages.

Translation Selection Considerations

[edit]

When handling translations, we consider multiple factors:

  • Multiple Verification: After receiving feedback, we consult multiple authoritative sources for verification
  • Version Differences: The same concept may have multiple translation versions, requiring balanced selection
  • Understanding Priority: Finding balance between accuracy and ease of understanding

Example: Roman Calendar Date Names

Key dates in a Roman month (1st, 7th, 15th days) have multiple translation versions in Chinese:

  • Version A: 朔日、五日/七日、十五日 (literal number translation)
  • Version B: 朔日、月中、望日 (borrowing Chinese calendar terms)
  • This extension uses: 朔日、上节、月中 (balancing calendar meaning and understanding convenience)

This choice preserves the original meaning of the Roman calendar while being easy for Chinese users to understand.

Reporting Translation Issues

[edit]

If you find translation issues in any language, feedback is welcome, but please note:

  1. Provide Clear Examples: Explain what the current output is and what the expected output should be
  2. Detailed Explanation: Explain why the current translation is incorrect or doesn't conform to language conventions
  3. Native Speaker Priority: Feedback from native speakers of the language is recommended to ensure translation accuracy and authenticity
  4. Provide Context: Specify the usage scenario and calendar type
  5. Reference Materials: If possible, provide authoritative reference materials or literature

Contributing Translations

[edit]

If you wish to improve translations for a language:

  1. Check the corresponding language JSON file in the i18n/ directory
  2. If code logic modifications are needed, submit an Issue on GitHub explaining the requirements
  3. Provide complete test cases and expected results
  4. Follow MediaWiki's i18n best practices


Version History

[edit]

v1.1.0 (2026-02-20)

[edit]

New Features:

  • Precise 24 Solar Terms Calculation
    • Uses Jean Meeus astronomical algorithms to replace approximate algorithms
    • Based on precise solar longitude calculation (one solar term every 15 degrees)
    • Minute-level precision
    • Supports solar term calculation for any year
  • Nine-Nines (Shujiujiu) Feature
    • Added NineNines class representing the nine periods
    • Calculates from Winter Solstice, each 9-day period is one "nine", totaling 81 days
    • Displays the first day of each nine period in calendar grids (e.g., "First Nine", "Second Nine", etc.)
    • Priority: Solar Terms > Nine-Nines (solar terms shown when present, Nine-Nines shown otherwise)
  • Added Juche Calendar (JUH) Support
    • Gregorian-based calendar system
    • Year 1 corresponds to 1912 CE (birth year of Kim Il-sung)
    • Complete date conversion and formatting functionality

Technical Improvements:

  • Added SolarTermCalculator.php - Precise solar term calculator
  • Added NineNines.php - Nine-Nines calculation class
  • Updated ChineseLunarCalendar.php - Uses precise algorithms for solar terms and Nine-Nines calculation
  • Updated CalendarGridGenerator.php - Adds solar terms and Nine-Nines information to calendar grid cells
  • Updated SpecialCalendarConverter.php - Supports solar terms and Nine-Nines display
  • Enhanced multi-language support (English, Simplified Chinese, Traditional Chinese)
  • Optimized calendar conversion performance
  • Updated stylesheets with new blue marker style for Nine-Nines

v1.0.0 (Initial Release)

[edit]

Core Features:

  • Support for 30+ calendar systems
  • 4 parser functions
  • Special Page graphical interface
  • Support for 20+ language interfaces
  • Built-in caching mechanism
  • Basic 24 solar terms support (approximate algorithm)