Help:Datatype "Date"

From semantic-mediawiki.org
Help:Datatype "Date"帮助:数据类型“Date”
Date
Holds particular points in time
Further information
Provided by: Semantic MediaWiki
Since version: 1.4.0
Until version: still in use
Datatype ID:
_dat
In this wiki: Date
Table of Contents

The datatype Date is used for data values that represent points in time. It is able to support dates throughout human history in a unified format, and it offers internationalisation options for supporting more languages. All dates and times refer to the "local time" of the server (or the wiki). A wiki may define what timezone this refers to by common conventions. For export, times are given without timezone information. However, time offsets to that local time are supported.

Since Semantic MediaWiki 1.8.0Released on 2 December 2012 and compatible with MW 1.17.0 - 1.22.x
(except 1.22.1).
dates are stored in a fully serialised format, including the calendar model.

Display format[edit]

Dates are displayed in a simple format that cannot be changed with the language setting in the user preferences. Month names in displayed dates are just translated based on the wiki's current language (if translated names are available). User settings are not taken into account for displaying dates.

Display takes into account if parts of a date were omitted. So a date specified as "2008" will also be printed as "2008" everywhere, even though it might be interpreted as "Jan 1 2008 00:00:00" when comparing it to other dates.

Result formatters[edit]

#ISO[edit]

In case you want to keep the simple format in printout request of queries (Inline queries or Concepts) you may use "ISO" behind the printout requests of this type. Thus instead of displaying "Jan 9 2008" (achieved with printout request ?birthday) you will get "2008-01-09" (achieved with printout request ?birthday#ISO) which is a plain format representing an ISO formatted international date string.

#ISO-P[edit]

Unlike the "ISO" result formatter which completes partial dates, the "ISO-P" (P for "partial") formatter renders partial dates in ISO formatting:

  • 2022 → 2022
  • April 2022 → 2022-04
  • 1 April 2022 → 2022-04-01

Rationale: Sometimes, only a year or a year and month are specified for a date, e.g. during planning of events. At a later point in time, the date is completed with a month and day.

This formatter is available starting with Semantic MediaWiki 4.1.0Released on 21 January 2023 and compatible with MW 1.35.0 - 1.37.x..

#MEDIAWIKI[edit]

Starting with Semantic MediaWiki 1.7.0Released on 1 January 2012 and compatible with MW 1.16.x - 1.19.x. you can also use "MEDIAWIKI" behind the printout request to use the MediaWiki's i18n methods for time and date formatting. It has superior i18n support, but cannot handle all possible values such as BC dates.

To correspond with the MediaWiki output, "MEDIAWIKI" will recognize the user settings in terms of preference and language settings.

#LOCL[edit]

Starting with Semantic MediaWiki 2.4.0Released on 9 July 2016 and compatible with MW 1.19.0 - 1.27.x.1 it is also possible to display values in a per language predefined format for a total of four precisions:

  1. Y (year)
  2. F Y (year, month)
  3. F j, Y (year, month, day)
  4. H:i:s, j F Y (year, month, day, hour, minute, second)
  5. TO in local time set in users preferences (see Local_time.)
  6. @de-at in local time for a specific language (here Austrian German)

The predefined format will be shown to the user according to his or her preference setting for language (user language). It will always be used when browsing data via special page "Browse" or for the annotated data values shown on a property page of type "Date". The shown precision depends on the data value annotated to the respective property: If a date without timestamp information is annotated like e.g. [[Has date::2016/08/17]] the browsing interfaces and queries will automatically select the "F j, Y" precision to format it for display: "August 16, 2016" (English), etc.

When the local time of the user differs from the server time, local time can be used. See Local_time.

If a precision was not specified for a language the default formatting for English will apply.
Examples

See the help page on <sandbox.semantic-mediawiki.org> for a live example.

#F (free formatted)[edit]

Starting with Semantic MediaWiki 2.4.0Released on 9 July 2016 and compatible with MW 1.19.0 - 1.27.x. 2, the free format is supported where a options string in form of D M j G:i:s T Y (see DateTime) can be used to generate an individual printout. Limitations:

  • Dates like 10000 BC (prehistoric) are not supported by the formatter (the ISO date --10000-01-01 is returned instead) other BC(E) dates like 2 Feb 900 BC will be formatted as -0900/01/25 or -0900/02/02 JL.
  • Dates stored with a JD(JL) are not automatically transformed and instead marked with JL to indicate its model
{{#ask:
 [[Example]]
 |?Date#GR-F[Y/m/d H:i:s]=Label 1 (GR)
 |?Date#-F[Y/m/d H:i:s]=Label 2
 |?Date#-F[D M j G:i:s T Y]=Label 3
 |?Date#-F[l jS \of F Y h:i:s A]=Label 4
}}

#SORTKEY[edit]

Return a number that helps comparing time data items. For dates in the Julian Day era (roughly from 4713 BCE onwards) its is equivalent to the the Julian Day number. For earlier dates, the (negative) year number with a fraction for the date is used (times are ignored).

#JD[edit]

Returns the Julian day of a date value.

Input examples[edit]

Examples of typical input dates in English language are
annotation result remark
[[Has date::Feb 11 2000 10:00:01]] Feb 11 2000 10:00:01 complete date with time
[[Has date::Feb 11 2000]] Feb 11 2000 just date
[[Has date::Feb 2000]] Feb 2000 month and year
[[Has date::2000]] 2000 year by itself
[[Has date::Feb 11 2000 10:00:01 PM]] Feb 11 2000 10:00:01 PM complete date with time, PM
[[Has date::Feb 11 2000 22:00:01]] Feb 11 2000 22:00:01 complete date with 24h time
[[Has date::2000-02-11T22:00:01]] 2000-02-11T22:00:01 ISO-style date
[[Has date::2000-02-11T22:00:01+02:00]] 2000-02-11T22:00:01+02:00 ISO-style date with offset
[[Has date::2000 February 2]] 2000 February 2 varying order of inputs is supported
[[Has date::2-3-2000]] 2-3-2000 preferred interpretation, month or day, sometimes depends on language settings
[[Has date::2/3/2000]] 2/3/2000 various kinds of separators are recognized in all languages
[[Has date::Jan 1 300 BC]] Jan 1 300 BC dates BC/before common era are supported
[[Has date::14000000000 BC]] 14000000000 BC estimated age of the universe
[[Has date::Feb 11 2000 Jl]] Feb 11 2000 Jl date of the Julian Calendar
[[Has date::Feb 11 1492 Gr]] Feb 11 1492 Gr date is treated as Gregorian
[[Has date::Feb 11 2000 10:00 GMT]] Feb 11 2000 10:00 GMT date with time zone shortcut
[[Has date::2000-02-22]] 2000-02-22 MySQL date format
[[Has date::Sun Jun 20 23:21:05 +0200]] Sun Jun 20 23:21:05 +0200 per se an incorrect ISO date
NoteNote: Starting with Semantic MediaWiki 3.2.0Released on 7 September 2020 and compatible with MW 1.31.0 - 1.35.x. this annotation format will be recognized.3
The annotation in the following examples is incorrect
wrong annotation result remark
[[Has date::1999-00-00]] 1999-00-00"1999-00-00" contains a sequence that could not be interpreted against an available match matrix for date components. MySQL partial date format
[[Has date::Sun Jun 20 23:21:05 1993]] Sun Jun 20 23:21:05 1993 unrecognized order

Other languages may also support additional strings as month names, and they may choose different preferred interpretations of ambiguous dates. The basic format, however, is the same.

Further examples[edit]

API example

Calendar models[edit]

At the moment, Type:Date supports two calendar models: Gregorian and Julian In 1582 the Catholic Church introduced a reform of the calendar Julian calendar. So dates before 24. February 1582 are supposed to refer to Julian calendar by default. The dates after the reform are considered Gregorian accordingly. However, one can manually specify the calendar model of the entered date by annotating it with Jl or Gr (Old Style (OS) is also understood). Internally, Type:Date uses the proleptic Gregorian calendar, an extension of the Greogorian calendar to the past, to represent dates.

Semantic MediaWiki 1.8.0Released on 2 December 2012 and compatible with MW 1.17.0 - 1.22.x
(except 1.22.1).
added support for new output formats "GR" and "JL" that can be used in inline queries to define the desired calendar model that should be displayed. The same strings also work as modifiers when writing dates. If nothing is given, SMW will assume the same default calendar model on input and on output.

Instead of displaying the annotated date „6 November 1796 Jl“ with the output statement ?Geburtsdatum, one may have this date displayed as „17 November 1796 Gr“ by using the output statement ?Geburtsdatum#GR.

Semantic MediaWiki 2.4.0Released on 9 July 2016 and compatible with MW 1.19.0 - 1.27.x. is to indicate the calendar model for a date if is not a Greogorian calendar date and SMW_DV_TIMEV_CM1 can be used to disable this option.

Maximal date range[edit]

Type:Date is able to handle dates across history with full precision for storing, and substantial precision for sorting and querying. The range of supported past dates should encompass the Beginning of Time according to most of today's theories. The range of supported future dates is limited more strictly, but it does also allow year numbers in the order of 10^9.

Era information[edit]

Display of era information for positive years (if denoted) is supported starting with Semantic MediaWiki 2.4.0Released on 9 July 2016 and compatible with MW 1.19.0 - 1.27.x..5

BC, negative years, and the year 0[edit]

Years before common era (aka BC) can be denoted using "BC" in a date. It is assumed that there is no "year 0": the historic sequence of years was ..., 2 BC, 1 BC, 1 AD, 2AD, ... When given as an input, the year 0 (BC or not) is interpreted as 1 BC, but this use is discouraged.

The internal numeric date model used in SMW supports the year 0, and considers it to be the same as "1 BC". According to this convention, e.g., the year "-100" is the same as "101 BC". This convention agrees with ISO 6801 and the remarks in XML Schema Datatypes 2nd Edition (the latter uses a different convention that disallows year 0, but it explicitly endorses the ISO convention and announces the future use of this in XML). Note that the implementation currently does not support the specification of negative year numbers as input; negative numbers are only used internally.

Time offsets and timezones[edit]

Time offests are supported (e.g. "1 1 2008 12:00-2:00"). As explained above, those refer to the local time. Time offsets take leap years into account, e.g. the date "Feb 28 2004 23:00+2:00" is equivalent to "29 February 2004 01:00:00", while "Feb 28 1900 23:00+2:00" is equivalent to "1 March 1900 01:00:00". Additionally, offsets can be specified by the common shortcuts for time zones (e.g. ADT, AST, CET, CST, CXT, EST, HAC, HAT, HNR, MEZ, MST, NFT): "1 March 1998 08:00:00 EST".

Sorting dates in tabular outputs[edit]

The sortable table code of MediaWiki cannot handle dates. To make them sort properly, one needs to provide numeric sortkeys using the "data-sort-value" attribute in td elements (look at the HTML of any real SMW table for examples). To allow this to be done, the new parameter "#SORTKEY" was added to this datatype by which one can obtain a numeric sortkey as needed for "data-sort-value". For example, the following query displays dates and their sortkeys:

{{#ask:
 [[Modification date::+]]
 |?Modification date
 |?Modification date#SORTKEY
}}

For properties that can have many values, only one "#SORTKEY" must be used (since the whole table row is sorted as one, even if many dates are in one cell). This can be achieved by using parameter "+limit" like in this example:

{{#ask:
 [[Testdate::+]]
 |?Testdate
 |?Testdate#SORTKEY |+limit=1
}}

Handling of incomplete dates[edit]

The implementation notices and stores whether parts of a date/time have been omitted (as in "2008" or "May 2007"). For all exporting and sorting purposes, incomplete dates are completed with defaults (usually using the earliest possible time, i.e. interpreting "2008" as "Jan 1 2008 00:00:00"). But the information on what was unspecified is kept internally for improving behaviour e.g. for outputs (defaults are not printed when querying for a value).

Only the minor parts of a date can be omitted: "May 2008" works, but "May 1" does not. This is so, since the latter could not be given a sensible default interpretation when sorting dates. To support sorting and querying, all dates must be interpretable as a concrete precise time point, and this is done internally when required, even for incomplete dates.

Technical notes[edit]

See 1

  • TimeValueFormatter::getCaptionFromDataItem uses the content language which is either the default content language or if available the page content language
  • ExtraneousLanguage::getPreferredDateFormatByPrecision determines a PHP DateTime format string as preference for a specific language in combination with a precision
  • IntlTimeFormatter::getLocalizedFormat (#LOCL) uses ExtraneousLanguage::getPreferredDateFormatByPrecision to determine the preferred localized representation for a date/time output

Open Issues[edit]

  • SMW does not yet offer full support for dates of 10,000 BC and earlier.(see SMW issue 5153).6
  • The customised date formatting of MediaWiki can only be used for dates between typically between 1901-12-14 and 2038-01-19.
  • Internationalisation is incomplete: "BC", "AD", "PM", "AM" are fixed for all languages.
  • Conversion between (historic) calendar models is not supported yet.




References

  1. a b c  |  Semantic MediaWiki: GitHub pull request gh:smw:1545
  2. ^  |  Semantic MediaWiki: GitHub pull request gh:smw:1389
  3. ^  |  Semantic MediaWiki: GitHub pull request gh:smw:4692
  4. ^  |  Semantic MediaWiki: GitHub pull request gh:smw:1397
  5. ^  |  Semantic MediaWiki: GitHub pull request gh:smw:1396
  6. ^  |  Semantic MediaWiki: GitHub issue gh:smw:5153