Utente:Lucamauri/Sandbox/ParserTime

Da Wikipedia, l'enciclopedia libera.
Vai alla navigazione Vai alla ricerca

#time[modifica | modifica wikitesto]

Template:Hl1 | <translate> Code</translate> Template:Hl1 | <translate> Description</translate> Template:Hl1 | <translate>

Current output
([{<tvar|fullurl>{fullurl:Help:Extension:ParserFunctions{{#translation:}}|action=purge}}</> Purge this page's cache] to update)</translate>

Template:Hl2 colspan="3"| <translate> Year</translate>
Y <translate> 4-digit year.</translate> 2024
y <translate> 2-digit year.</translate> 24
L <translate> 1 if it's a leap year, 0 if not.</translate> 1
o[note 1] <translate>

ISO-8601 year of the specified week.</translate>[note 2]

2024[note 3]
  1. ^ <translate> Requires PHP 5.1.0 and newer and rev:45208.</translate>
  2. ^ <translate> This has the same value as Y, except that if the ISO week number (W) belongs to the previous or next year, that year is used instead.</translate>
  3. ^ <translate> Will output literal o if note 1 not fulfilled.</translate>
Template:Hl2 colspan="3"| <translate> Month</translate>
n <translate> Month index, not zero-padded.</translate> 4
m <translate> Month index, zero-padded.</translate> 04
M <translate> An abbreviation of the month name, in the site language.</translate> apr
F <translate> The full month name in the site language.</translate> aprile
xg <translate>

Output the full month name in the genitive form for site languages that distinguish between genitive and nominative forms. This option is useful for many Slavic languages like Polish, Russian, Belarusian, Czech, Slovak, Slovene, Ukrainian, etc.</translate>

<translate> For Polish:</translate>
{{#time:F Y|June 2010|pl}} → czerwiec 2010
<translate> (nominative)</translate>
{{#time:d xg Y|20 June 2010|pl}} → 20 czerwca 2010
<translate> (genitive)</translate>
Template:Hl2 colspan="3"| <translate> Day of the month or the year</translate>
j <translate> Day of the month, not zero-padded.</translate> 19
d <translate> Day of the month, zero-padded.</translate> 19
z <translate> Day of the year (January 1 = 0).
[[#ref_{{{1}}}|^]] To get the ISO day of the year add 1.</translate>
109
Template:Hl2 colspan="3"| <translate> Week and day of the week</translate>
W <translate> ISO 8601 week number, zero-padded.</translate> 16
N <translate> ISO 8601 day of the week (Monday = 1, Sunday = 7).</translate> 5
w <translate> Number of the day of the week (Sunday = 0, Saturday = 6).</translate> 5
D <translate> An abbreviation for the day of the week. Rarely internationalized.</translate> ven
l <translate> The full weekday name. Rarely internationalized.</translate> venerdì
Template:Hl2 colspan="3"| <translate> Hour</translate>
a <translate> "am" during the morning (00:00:00 → 11:59:59), "pm" otherwise (12:00:00 → 23:59:59).</translate> pm
A <translate> Uppercase version of a above.</translate> PM
g <translate> Hour in 12-hour format, not zero-padded.</translate> 5
h <translate> Hour in 12-hour format, zero-padded.</translate> 05
G <translate> Hour in 24-hour format, not zero-padded.</translate> 17
H <translate> Hour in 24-hour format, zero-padded.</translate> 17
Template:Hl2 colspan="3"| <translate> Minutes and seconds</translate>
i <translate> Minutes past the hour, zero-padded.</translate> 44
s <translate> Seconds past the minute, zero-padded.</translate> 04
U <translate> Unix time.</translate> <translate> Seconds since January 1 1970 00:00:00 GMT.</translate> 1713548644
id="TimeZone" Template:Hl2 colspan="3"| <translate> Timezone (as of 1.22wmf2)</translate>
e <translate> Timezone identifier.</translate> UTC
I <translate> Whether or not the date is in daylight savings time.</translate> 0
O <translate> Difference to Greenwich time (GMT)</translate> +0000
P <translate> Difference to Greenwich time (GMT), with colon</translate> +00:00
T <translate> Timezone abbreviation.</translate> UTC
Z <translate> Timezone offset in seconds.</translate> 0
Template:Hl2 colspan="3"| <translate> Miscellaneous</translate>
t <translate> Number of days in the current month.</translate> 30
c iso8601>Y-m-d"T"H:i:s+00:00</>.</translate> 2024-04-19T17:44:04+00:00
r <translate> RFC 5322 formatted date, equivalent to <tvar|rfc5322>D, j M Y H:i:s +0000</>, with weekday name and month name not internationalized.</translate> Fri, 19 Apr 2024 17:44:04 +0000
Template:Hl2 colspan="3" | <translate> Non-Gregorian calendars</translate>
Template:Hl3 colspan="3" | <translate> Islamic</translate>
xmj <translate> Day of the month.</translate> 10
xmF <translate> Full month name.</translate> Shawwal
xmn <translate> Month index.</translate> 10
xmY <translate> Full year.</translate> 1445
Template:Hl3 colspan="3" | <translate> Iranian (Jalaly)</translate>
xit <translate> Number of days in the month.</translate> 31
xiz <translate> Day of the year.</translate> 30
xij <translate> Day of the month.</translate> 31
xiF <translate> Full month name.</translate> Farvardin
xin <translate> Month index.</translate> 1
xiY <translate> Full year.</translate> 1403
xiy <translate> 2-digit year.</translate> 03
Template:Hl3 colspan="3" | <translate> Hebrew</translate>
xjj <translate> Day of the month.</translate> 11
xjF <translate> Full month name.</translate> Nisan
xjt <translate> Number of days in month.</translate> 30
xjx <translate> Genitive form of the month name.</translate> Nisan
xjn <translate> Month number.</translate> 7
xjY <translate> Full year.</translate> 5784
Template:Hl3 colspan="3" | <translate> Thai solar</translate>
xkY <translate> Full year in Thai solar calendar.
Template:TNT For years before 1941 the dates in Jan-Mar range are not calculated properly.</translate>
2567
Template:Hl3 colspan="3" | <translate> Minguo/Juche year</translate>
xoY <translate> Full year.</translate> 113
Template:Hl3 colspan="3" | <translate> Japanese nengo</translate>
xtY <translate> Full year.</translate> 令和6
Template:Hl2 colspan="3" | <translate> Flags</translate>
xn <translate> Format the next numeric code as a raw ASCII number.</translate> time>{{#time:H, xnH}}</> produces <tvar|hindi>०६, 06</>.</translate>
xN <translate> Like xn, but as a toggled flag, which endures until the end of the string or until the next appearance of xN in the string.</translate>
xr <translate> Format the next number as a roman numeral. Only works for numbers up to 10,000
(upto 3,000 in pre MediaWiki 1.20).</translate>
{{#time:xrY}} → MMXXIV
xh <translate> Format the next number as a Hebrew numeral.</translate> {{#time:xhY}} → ב'כ"ד

<translate> This parser function takes a date and/or time (in the Gregorian calendar) and formats it according to the syntax given. A date/time object can be specified; the default is the value of the [[<tvar|magic>Special:MyLanguage/Help:Magic words#Date and time</>|magic word]] <tvar|currenttimestamp>{{CURRENTTIMESTAMP}}</> – that is, the time the page was last rendered into HTML.</translate>

{{#time: format string }}
{{#time: format string | date/time object }}
{{#time: format string | date/time object | language code }}
{{#time: format string | date/time object | language code | local }}

<translate> The list of accepted formatting codes is given in the table to the right. Any character in the formatting string that is not recognized is passed through unaltered; this applies also to blank spaces (the system does not need them for interpreting the codes). There are also two ways to escape characters within the formatting string:

  1. A backslash followed by a formatting character is interpreted as a single literal character
  2. Characters enclosed in double quotes are considered literal characters, and the quotes are removed.

In addition, the digraph xx is interpreted as a single literal "x".</translate>

{{#time: Y-m-d }}2024-04-19
{{#time: [[Y]] m d }}2024 04 19
{{#time: [[Y (year)]] }}2024 (24UTCpmFri, 19 Apr 2024 17:44:04 +0000)
{{#time: [[Y "(year)"]] }}2024 (year)
{{#time: i's" }}44'04"

<translate> The date/time object can be in any format accepted by PHP's <tvar|strtotime>strtotime()</> function. Both absolute (eg 20 December 2000) and relative (eg +20 hours) times are accepted.</translate>

{{#time: r|now}}Fri, 19 Apr 2024 17:44:04 +0000
{{#time: r|+2 hours}}Fri, 19 Apr 2024 19:44:04 +0000
{{#time: r|now + 2 hours}}Fri, 19 Apr 2024 19:44:04 +0000
{{#time: r|20 December 2000}}Wed, 20 Dec 2000 00:00:00 +0000
{{#time: r|December 20, 2000}}Wed, 20 Dec 2000 00:00:00 +0000
{{#time: r|2000-12-20}}Wed, 20 Dec 2000 00:00:00 +0000
{{#time: r|2000 December 20}}Errore: orario non valido.

<translate> The language code in ISO 639-3 (?) allows the string to be displayed in the chosen language</translate>

{{#time:d F Y|1988-02-28|nl}}28 februari 1988
{{#time:l|now|uk}}п'ятниця
{{#time:d xg Y|20 June 2010|pl}}20 czerwca 2010

<translate> The local parameter specifies if the date/time object refers to the local timezone or to UTC.
This is a boolean parameters: its value is determined by casting the value of the argument (see the official PHP documentation for details on how string are cast to boolean values).</translate>

<span class="citation wikicite" id="endnote_<translate>Please note that, if the variable $wgLocaltimezone is set to UTC, there is no difference in the output when local is set to true or false</translate>">[[#ref_<translate>Please note that, if the variable $wgLocaltimezone is set to UTC, there is no difference in the output when local is set to true or false</translate>|^reminder]]

<translate>See the following examples for details:</translate>

{{#time: Y F d H:i:s|now|it|0}}2024 aprile 19 17:44:04
{{#time: Y F d H:i:s|now|it|1}}2024 aprile 19 19:44:04
{{#time: Y F d H:i:s|+2 hours||0}}2024 aprile 19 19:44:04
{{#time: Y F d H:i:s|+2 hours||1}}2024 aprile 19 21:44:04
{{#time:c|2019-05-16T17:05:43+02:00|it}}2019-05-16T15:05:43+00:00
{{#time:c|2019-05-16T17:05:43+02:00|it|0}}2019-05-16T15:05:43+00:00
{{#time:c|2019-05-16T17:05:43+02:00|it|true}}2019-05-16T17:05:43+02:00

<translate> If you've calculated a Unix timestamp, you may use it in date calculations by pre-pending an @ symbol.</translate>

{{#time: U | now }}1713548644
{{#time: r | @1713548644 }}Fri, 19 Apr 2024 17:44:04 +0000

Template:Warning

Template:Warning

<translate> Full or partial absolute dates can be specified; the function will "fill in" parts of the date that are not specified using the current values:</translate>

{{#time: Y | January 1 }}2024

Template:Warning

<translate> A four-digit number is always interpreted as a year, never as hours and minutes:[1]</translate>

{{#time: Y m d H:i:s | 1959 }}1959 04 19 00:00:00

<translate> A six-digit number is interpreted as hours, minutes and seconds if possible, but otherwise as an error (not, for instance, a year and month):</translate>

{{#time: Y m d H:i:s | 195909 }}2024 04 19 19:59:09 <translate>

Input is treated as a time rather than a year+month code.</translate>

{{#time: Y m d H:i:s | 196009 }}Errore: orario non valido. <translate>

Although 19:60:09 is not a valid time, 196009 is not interpreted as September 1960.</translate>

<translate> The function performs a certain amount of date mathematics:</translate>

{{#time: d F Y | January 0 2008 }}31 dicembre 2007
{{#time: d F | January 32 }}Errore: orario non valido.
{{#time: d F | February 29 2008 }}29 febbraio
{{#time: d F | February 29 2007 }}01 marzo
{{#time:Y-F|now -1 months}}2024-marzo

<translate> The total length of the format strings of the calls of <tvar|time>#time</> is limited to 6000 characters[2].

Time Zone issue[modifica | modifica wikitesto]

There is a bug in this #time parser function (more specifically in PHP DateTime) that does not allow the passing-in of non-integers as relative time zone offsets. This issue does not apply when using an on-the-hour time zone, such as EDT. For example:</translate>

  • {{#time:g:i A | -4 hours }} ==> 1:44 PM

<translate> However, Venezuela is on a -4.5 hours time offset from UTC, and thus using its time zone will not normally allow the correct calculation of a relative time zone offset. Here's what happens:</translate>

  • {{#time:g:i A | -4.5 hours }} ==> 2:44 AM

<translate> To workaround this issue, simply convert the time into minutes or seconds, like this:</translate>

  • {{#time:g:i A | -270 minutes }} ==> 1:14 PM
  • {{#time:g:i A | -16200 seconds }} ==> 1:14 PM

<translate> (Tim Starling, the developer of this function, provided the exact syntax for this solution.)</translate>

#timel[modifica | modifica wikitesto]

<translate> This function is identical to <tvar|time>{{#time: ... }}</>, when the local parameter is set to true, so it always uses the local time of the wiki (as set in <tvar|1>Template:Ll</>).
Syntax of the function is:</translate>

{{#timel: format string }}
{{#timel: format string | date/time object }}
{{#timel: format string | date/time object | language code }}

<span class="citation wikicite" id="endnote_<translate>Please note that, if the variable $wgLocaltimezone is set to UTC, there is no difference in the output when local is set to true or false</translate>">[[#ref_<translate>Please note that, if the variable $wgLocaltimezone is set to UTC, there is no difference in the output when local is set to true or false</translate>|^reminder]]

For instance, see the following examples:

{{#time:c|now|it}}2024-04-19T17:44:04+00:00
{{#time:c|now|it|0}}2024-04-19T17:44:04+00:00
{{#time:c|now|it|1}}2024-04-19T19:44:04+02:00
{{#timel:c|now|it}}2024-04-19T19:44:04+02:00
Warning Example from https://no.wikipedia.org/wiki/Maldiskusjon:Sommertid

Template:Warning

  1. ^ Prior to Template:Rev in 2011 this was not the case.
  2. ^ ExtParserFunctions.php at phabricator.wikimedia.org