Last modified: 2013-11-01 23:18:22 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T9133, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 7133 - sprintftime aka #time can't handle timezones
sprintftime aka #time can't handle timezones
Status: NEW
Product: MediaWiki extensions
Classification: Unclassified
ParserFunctions (Other open bugs)
unspecified
All All
: Low enhancement with 5 votes (vote)
: ---
Assigned To: Nobody - You can work on this!
: patch, patch-need-review
: 7986 13357 15045 28353 (view as bug list)
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2006-08-27 12:28 UTC by Sebastian Moleski
Modified: 2013-11-01 23:18 UTC (History)
10 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
Patch to add all date() key letters (2.99 KB, patch)
2006-08-27 20:16 UTC, Aryeh Gregor (not reading bugmail, please e-mail directly)
Details
local specifier to work with local timezone (1.54 KB, patch)
2006-08-27 23:04 UTC, Sebastian Moleski
Details

Description Sebastian Moleski 2006-08-27 12:28:27 UTC
I submit the two additional modifiers "L" (determines, if a year is a leap year)
and "W" (determines the day of the week as a number according to ISO-8601) as
described at http://www.php.net/date.

Index: Language.php
===================================================================
--- Language.php	(revision 16223)
+++ Language.php	(working copy)
@@ -474,9 +474,16 @@
 				case 'D':
 					$s .= $this->getWeekdayAbbreviation( self::calculateWeekday( $ts ) );
 					break;
+				case 'W':
+					$s .= self::calculateWeekday( $ts ) - 1;
+					break;
 				case 'j':
 					$num = intval( substr( $ts, 6, 2 ) );
 					break;
+				case 'L':
+					if (date( 'L', wfTimestamp( TS_UNIX, $ts ) ))
+						$s .= "1";
+					break;
 				case 'l':
 					$s .= $this->getWeekdayName( self::calculateWeekday( $ts ) );
 					break;
Comment 1 Sebastian Moleski 2006-08-27 12:36:14 UTC
That should be a lowercase 'w', the uppercase means something different. My
apologies. Here the updated patch:

Index: Language.php
===================================================================
--- Language.php (revision 16223)
+++ Language.php (working copy)
@@ -474,9 +474,16 @@
case 'D':
$s .= $this->getWeekdayAbbreviation( self::calculateWeekday( $ts ) );
break;
+ case 'w':
+ $s .= self::calculateWeekday( $ts ) - 1;
+ break;
case 'j':
$num = intval( substr( $ts, 6, 2 ) );
break;
+ case 'L':
+ if (date( 'L', wfTimestamp( TS_UNIX, $ts ) ))
+ $s .= "1";
+ break;
case 'l':
$s .= $this->getWeekdayName( self::calculateWeekday( $ts ) );
break;
Comment 2 Sebastian Moleski 2006-08-27 12:43:59 UTC
As of PHP 5.1.0, 'N' is used for ISO-compliant day-of-week calculation so I've
added it too:

Index: Language.php
===================================================================
--- Language.php	(revision 16223)
+++ Language.php	(working copy)
@@ -474,9 +474,19 @@
 				case 'D':
 					$s .= $this->getWeekdayAbbreviation( self::calculateWeekday( $ts ) );
 					break;
+				case 'w':
+					$s .= date( 'w', wfTimestamp( TS_UNIX, $ts ) );
+					break;
+				case 'N':
+					$s .= date( 'N', wfTimestamp( TS_UNIX, $ts ) );
+					break;
 				case 'j':
 					$num = intval( substr( $ts, 6, 2 ) );
 					break;
+				case 'L':
+					if (date( 'L', wfTimestamp( TS_UNIX, $ts ) ))
+						$s .= "1";
+					break;
 				case 'l':
 					$s .= $this->getWeekdayName( self::calculateWeekday( $ts ) );
 					break;
Comment 3 Danny B. 2006-08-27 13:19:43 UTC
Can we add "z", "W" and "t", please? At least "t" would be very practical. Thanks.
Comment 4 Aryeh Gregor (not reading bugmail, please e-mail directly) 2006-08-27 20:16:57 UTC
Created attachment 2277 [details]
Patch to add all date() key letters

No reason not to add all of them.  For a number I've just called date(), as
Sebastian did, because there's no other way to get stuff like day of the week
or RFC 2822 format from the timestamp in a few lines.

**This patch does not work correctly**, because I don't understand how
timezones work in MediaWiki.  Anything that calls date() returns times/dates
based on my local timezone, while the actual timestamp passed is UTC.  This
needs to be corrected by someone who knows how timezones work in MediaWiki.  It
should be pretty easy, but I haven't figured out exactly how internal date
storage works yet.

Note that SaAe should be internationalized.  Also note that since the
timestamps will always have the same time zone (right?), eOPTZ (and maybe I)
could possibly benefit quite a bit from memoization.
Comment 5 Aryeh Gregor (not reading bugmail, please e-mail directly) 2006-08-27 20:17:51 UTC
(ParserFunctions should be in the component list . . .)
Comment 6 Sebastian Moleski 2006-08-27 20:23:03 UTC
The timezone is usually that of the server. So if you tested your code own your
own MediaWiki installation, you will get the appropriate timezone. Wikimedia
servers run on UTC (I think). You should take a look in Language.php to see how
the new variables LOCALHOUR, LOCALDATE, etc. are implemented to get an idea of
what is necessary to work with different time zones.
Comment 7 Sebastian Moleski 2006-08-27 23:04:30 UTC
Created attachment 2278 [details]
local specifier to work with local timezone

I've added another patch, that allows for local (i.e. timezone dependent) time
calculations by adding a new time specifier "local", e.g.
{{#time:Ymdhis|local}} creates a MW timestamp for the current local time and
date.
Comment 8 Bård Dahlmo 2007-09-16 12:28:16 UTC
When using the {{#timel:}} function to display formatted time, it shows the time in whatever timezone the server is configured to use. But there is no way to display the timezone for the time shown. This is important when one is in DST and the displayed time is normal time. So "e", "I" and "T" would be useful to avoid the confusion.
Comment 9 Dan Collins 2007-09-16 12:39:43 UTC
Whoever fixes this should also fix bug 7986
Comment 10 Bergi 2010-11-15 17:09:46 UTC
(In reply to comment #8)
> So "e", "I" and "T" would be useful to avoid the confusion.

The I parameter would be really useful. In the German Wikipedia we have the problem that there is a date (not yet, otherwise we could use {{LOCALDATE}}-{{CURRENTDATE}}) of which we want to the UTC time. {{#time:I|{{{date}}} }} should help to find out whether the {{{date}}} was in MESZ or MEZ (fixme?).

I propose this bug not to be an enhancement but of normal priority.
Comment 11 Niklas Laxström 2011-03-20 10:48:38 UTC
*** Bug 7986 has been marked as a duplicate of this bug. ***
Comment 12 Niklas Laxström 2011-03-20 10:51:10 UTC
*** Bug 15045 has been marked as a duplicate of this bug. ***
Comment 13 Niklas Laxström 2011-03-20 10:52:51 UTC
The problem here is that sprintfDate gets a adjusted timestamp and it knows nothing about the timezone. Thus we can't currently support format characters that output timezone or any other which need to know the timezone.
Comment 14 Niklas Laxström 2011-04-22 10:04:43 UTC
*** Bug 28353 has been marked as a duplicate of this bug. ***
Comment 15 au 2012-06-17 17:44:55 UTC
Hi Sebastian & Aryeh, thank you for the patch!

As you may already know, MediaWiki is currently revamping its PHP-based parser
into a "Parsoid" prototype component, to support the rich-text Visual Editor
project:

   https://www.mediawiki.org/wiki/Parsoid
   https://www.mediawiki.org/wiki/Visual_editor

Folks interested in enhancing the parser's capabilities are very much welcome
to join the Parsoid project, and contribute patches as Git branches:

   https://www.mediawiki.org/wiki/Git/Tutorial#How_to_submit_a_patch

Compared to .diff attachments in Bugzilla tickets, Git branches are much easier
for us to review, refine and merge features together.

Each change set has a distinct URL generated by the "git review" tool, which
can be referenced in Bugzilla by pasting its gerrit.wikimedia.org URL as a
comment.

If you run into any issues with the patch process, please feel free to ask on
irc.freenode.net #wikimedia-dev and the wikitext-l mailing list. Thank you!
Comment 16 Ryan Kaldari 2013-11-01 23:18:22 UTC
*** Bug 13357 has been marked as a duplicate of this bug. ***

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links