Difference between revisions of "Template:CurrentTimeIn"

From blackwiki
Jump to navigation Jump to search
imported>Pcb21
imported>Zyxw
m (Since <tt> is obsolete in HTML5, replace it with <kbd> – see HTML element#tt, Wikipedia:HTML5, and mw:Help:Extension:Linter/obsolete-tag. using AWB)
 
(9 intermediate revisions by 6 users not shown)
Line 1: Line 1:
<!-- Thanks to Tim Starling's recent changes to expression evaluation code, this template is now fast! -->
+
<includeonly>[[Lists of time zones|{{utc|{{#expr:({{{UsualDifferenceFromUTCForThisLocation|0}}})+({{{DSTAdjustment|0}}})}}}}]]</includeonly><noinclude>
<!-- Note that the implementation of separating out the DSTAdjustment from the "base" difference -->
+
This template prints the current UTC time offset by (UsualDifferenceFromUTCForThisLocation + DSTAdjustment) hours.
<!-- means that we don't have to update hundreds of pages everytime there is a DST change. Instead, we only need -->
 
<!-- change those listed at Template:CurrentDaylightSavingsOffsets -->
 
[[List of time zones|{{utc|{{add2|{{{UsualDifferenceFromUTCForThisLocation}}}|{{{DSTAdjustment}}}}}}}]]
 
<noinclude>
 
  
==Usage instructions==
+
; Syntax<nowiki>:</nowiki>
 +
: <kbd><nowiki>{{</nowiki>{{PAGENAME}} ''<nowiki>[</nowiki>'' <nowiki>|</nowiki></kbd>
 +
:: <kbd>''<nowiki>[</nowiki>'' UsualDifferenceFromUTCForThisLocation=''hours''<nowiki>|</nowiki> ''<nowiki>]</nowiki>''</kbd>
 +
:: <kbd>''<nowiki>[</nowiki>'' DSTAdjustment=''hours''<nowiki>|</nowiki> ''<nowiki>]</nowiki>''</kbd>
 +
: <kbd>''<nowiki>]</nowiki>'' <nowiki>}}</nowiki></kbd>
 +
Missing parameters (or completely empty parameters, without even any blank in the ''hours'' value) are treated like zero.
  
This template prints the current UTC time offset by ($UsualDifferenceFromUTCForThisLocation + $DSTAdjustment) hours where the terms beginning with $ are named arguments to the template.
+
; Rationale<nowiki>:</nowiki>
 +
The reason we separate out the "usual" difference from UTC and the DST adjustment is that the first part remains constant forever.
 +
 
 +
Whereas the second part changes twice a year.
 +
 
 +
This arrangement is the best way to minimize the number of pages we have to change when the clock changes.
  
==Rationale==
+
; Examples<nowiki>:</nowiki>
 +
<pre>The current time in London is {{CurrentTimeIn|
 +
  UsualDifferenceFromUTCForThisLocation=0|
 +
  DSTAdjustment={{Current daylight saving offset in Europe}}}}</pre>
 +
and
 +
<pre>The current time in Paris is {{CurrentTimeIn|
 +
  UsualDifferenceFromUTCForThisLocation=1|
 +
  DSTAdjustment={{Current daylight saving offset in Europe}}}}</pre>
 +
and when the clocks change in Europe, the only page we have to change is {{tl|Current daylight saving offset in Europe}} which is minimal number of pages.
  
The reason we separate out the "usual" difference from UTC and the DST adjustment is that the first part remains constant forever.
+
This template is usually wrapped by another template which controls the positioning of the time on the page. One example is {{tl|CurrentTimeInHeader}} which puts the time near the top of the page.
Whereas the second part changes twice a year. This arrangement is the best way to minimize the number of pages we have to change when the clock changes. For example we can write
 
  
:<nowiki> The current time in London is {{CurrentTimeIn|UsualDifferenceFromUTCForThisLocation = 0 | DSTAdjustment = {{CurrentDaylightSavingsOffsets/Europe}}</nowiki>
+
; See also<nowiki>:</nowiki>
 +
* [[Template:Utc]]
  
and
+
[[Category:Date mathematics templates|{{PAGENAME}}]]
  
:<nowiki> The current time in Paris is {{CurrentTimeIn|UsualDifferenceFromUTCForThisLocation = 1 | DSTAdjustment = {{CurrentDaylightSavingsOffsets/Europe}}</nowiki>
 
  
and when the clocks change in Europe, the only page we have to change is {{tl|CurrentDaylightSavingsOffsets/Europe}} which is minimal number of pages. This template is usually wrapped by another template which controls the positioning of the time on the page. One example is {{tl|CurrentTimeInHeader}} which puts the time near the top of the page.
 
 
</noinclude>
 
</noinclude>

Latest revision as of 06:55, 5 August 2018

This template prints the current UTC time offset by (UsualDifferenceFromUTCForThisLocation + DSTAdjustment) hours.

Syntax:
{{CurrentTimeIn [ |
[ UsualDifferenceFromUTCForThisLocation=hours| ]
[ DSTAdjustment=hours| ]
] }}

Missing parameters (or completely empty parameters, without even any blank in the hours value) are treated like zero.

Rationale:

The reason we separate out the "usual" difference from UTC and the DST adjustment is that the first part remains constant forever.

Whereas the second part changes twice a year.

This arrangement is the best way to minimize the number of pages we have to change when the clock changes.

Examples:
The current time in London is {{CurrentTimeIn|
  UsualDifferenceFromUTCForThisLocation=0|
  DSTAdjustment={{Current daylight saving offset in Europe}}}}

and

The current time in Paris is {{CurrentTimeIn|
  UsualDifferenceFromUTCForThisLocation=1|
  DSTAdjustment={{Current daylight saving offset in Europe}}}}

and when the clocks change in Europe, the only page we have to change is {{Current daylight saving offset in Europe}} which is minimal number of pages.

This template is usually wrapped by another template which controls the positioning of the time on the page. One example is {{CurrentTimeInHeader}} which puts the time near the top of the page.

See also: