JDate::toRFC822() does not return offset corretly

This forum is for reporting bugs in Joomla!. Please don't report problems with extensions in here.
Locked
User avatar
webamoeba
Joomla! Explorer
Joomla! Explorer
Posts: 433
Joined: Fri Sep 16, 2005 9:13 am
Contact:

JDate::toRFC822() does not return offset corretly

Post by webamoeba » Tue Oct 06, 2009 1:40 pm

Description:
When using $local=true, the JDate::toRFC822() method correctly calculates the date and time with the offset. However is always outputs '+0000' at the end of the returned string. The JDate::toISO8601() method on the other hand correctly evaluates this and appends the offset in the form +00:00.

Reported on:
J!1.5

Related files:
libraries/joomla/html/html.php

Proposed fix(es):
I have created a patch to resolve this problem. This patch borrows code from JDate::toISO8601() with a few tweaks. To test the patch try the following before and after applying:

Code: Select all

// get now
$now = JFactory::getDate();

echo 'UTC+0:'.$now->toRFC822();
echo '<p>';

$now->setOffset(1);
echo 'UTC+1:'.$now->toRFC822(true);
echo '<p>';

$now->setOffset(-1);
echo 'UTC-1:'.$now->toRFC822(true);
You do not have the required permissions to view the files attached to this post.

User avatar
webamoeba
Joomla! Explorer
Joomla! Explorer
Posts: 433
Joined: Fri Sep 16, 2005 9:13 am
Contact:

Re: JDate::toRFC822() does not return offset corretly

Post by webamoeba » Wed Oct 07, 2009 10:09 am

Just spotted another problem with JDate. The constructor attempts to parse a number of different date and time formats, including RFC 2822. There is a minor error in the way in which it deals with mililtary time zones - http://www.timeanddate.com/library/abbr ... /military/.

Militay time zones are expressed as aplha letters from A - Z. JDate processes as one of three types, A-L, [URL banned] and Z. However the way in A-L and [URL banned] are slected is flawed. For example if the offset were defined as "[" (an illegal char in an RFC 2822 value) JDate will incorrectly evaluate this as in the range N-Y. Here is the problem area:

Code: Select all

$ord = ord($matches[7]);
if ($ord < ord('M')) {
	$tzOffset = (ord('A') - $ord - 1) * $oneHour;
} elseif ($ord >= ord('M') && $matches[7] != 'Z') {
	$tzOffset = ($ord - ord('M')) * $oneHour;
} elseif ($matches[7] == 'Z') {
	$tzOffset = 0;
}
This should be:

Code: Select all

$ord = ord($matches[7]);
if ($ord < ord('M') && $ord >= ord('A')) {
	$tzOffset = (ord('A') - $ord - 1) * $oneHour;
} elseif ($ord >= ord('M') $ord < ord('Z')) {
	$tzOffset = ($ord - ord('M')) * $oneHour;
} elseif ($matches[7] == 'Z') {
	$tzOffset = 0;
}

User avatar
webamoeba
Joomla! Explorer
Joomla! Explorer
Posts: 433
Joined: Fri Sep 16, 2005 9:13 am
Contact:

Re: JDate::toRFC822() does not return offset corretly

Post by webamoeba » Wed Oct 07, 2009 10:12 am

I should also point out that there is a major lack of comments in the JDate constructor. This makes it really hard to understand looking at it for the first time. This bit of code would rteally benefit from some code comments. If I can help recitify this let me know.


Locked

Return to “Joomla! 1.5 Bug Reporting”