Modulo:Stardate/man

Da Wikitrek.
Vai alla navigazione Vai alla ricerca

Questa è la pagina di documentazione per Modulo:Stardate

Module:Stardate converts between real-world Gregorian dates and Star Trek TNG-era stardates, and vice-versa.

The conversion follows the most widely accepted TNG-era convention:

  • Stardate 41000.0 = 1 January 2364
  • 1000 stardate units span exactly one full year
  • Each stardate unit therefore equals 1/1000 of a year
  • Leap years are accounted for when mapping days within a given year

This module is intended to be called via a wrapper template using {{{{#invoke:}}}}, but it also exposes internal Lua functions for use by other modules.

Usage

Via wrapper template (recommended)

Use template {{Stardate}} containing:

{{#invoke:Stardate | {{{1}}} | date={{{date|}}} | stardate={{{stardate|}}} | format={{{format|full}}} }}

Then call it from any page:

Wikitext Output
41202.2 41202.2
41000x 41000x
2364-02-26 2364-02-26
2364 2364

Direct #invoke (without a wrapper template)

{{#invoke:Stardate | toStardate  | date=2364-03-15 }}
{{#invoke:Stardate | toStardate  | date=2364-03-15 | format=year }}
{{#invoke:Stardate | toRealDate  | stardate=41153.7 }}
{{#invoke:Stardate | toRealDate  | stardate=41153.7 | format=year }}

From another Lua module

local stardate = require('Module:Stardate')

-- date → stardate
local sd = stardate._toStardate(2364, 3, 15, 'full')   -- returns "41202.2"

-- stardate → date
local dt = stardate._toRealDate(41153.7, 'full')        -- returns "2364-02-26"

Entry points

toStardate

Converts a real date to a TNG-era stardate.

Parameter Required Description
date Yes The date to convert, in yyyy-mm-dd format (e.g. 2364-03-15).
format No Controls the output format. See the table below. Defaults to full.

toRealDate

Converts a TNG-era stardate to a real date.

Parameter Required Description
stardate Yes The stardate to convert, as a decimal number (e.g. 41153.7). Must not be negative.
format No Controls the output format. See the table below. Defaults to full.

format parameter

Shared by both entry points. Controls how the result is rendered.

Value toStardate output toRealDate output
full (default) Stardate with one decimal place (e.g. 41202.2) Full date as yyyy-mm-dd (e.g. 2364-03-15)
year Millennium prefix with a trailing x (e.g. 41000x) Year only (e.g. 2364)

Internal API

The following functions are exposed on the module table for direct Lua-to-Lua use. They bypass frame parsing and validation — callers are responsible for passing correct types.

_toStardate(y, m, d, format)

Parameter Type Description
y number Year.
m number Month (1–12).
d number Day of month (1–31).
format string "full" or "year".

Returns a formatted stardate string.

_toRealDate(sd, format)

Parameter Type Description
sd number Stardate value (e.g. 41153.7).
format string "full" or "year".

Returns a formatted date string.


Error handling

Both public entry points validate their input. On failure they return an HTML <span class="error"> element containing a human-readable message. Validation covers:

  • Missing required parameters (date or stardate).
  • Malformed date strings (must match yyyy-mm-dd exactly).
  • Out-of-range month or day values, including correct per-month maximums and leap-year handling (e.g. Feb 29 is accepted only in leap years).
  • Non-numeric or negative stardate values.
  • Unrecognised format values.

Conversion convention

The module uses the epoch and scaling rules most commonly cited in Star Trek reference material:

Rule Value
Stardate 41000.0 = 1 January 2364
Year length 1000 stardate units per year
Intra-year mapping Fractional position = (day-of-year − 1) ÷ (days in that year)
Leap years Handled per the Gregorian calendar; the day-count of each year is used when mapping fractions

Because each year maps to exactly 1000 stardate units regardless of whether it has 365 or 366 days, individual stardate units are slightly longer in leap years than in common years. Round-trip conversion (date → stardate → date) is exact for every valid Gregorian date.