Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Commit

Permalink
Added static getInstance to JDate as an alias for calling new JDate.
Browse files Browse the repository at this point in the history
  • Loading branch information
eddieajau committed Aug 12, 2011
1 parent 4937f77 commit 7ff1d17
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 28 deletions.
44 changes: 30 additions & 14 deletions docs/manual/appendices/changelog.xml
Expand Up @@ -11,10 +11,13 @@
<listitem>
<para>Moved JString from Utilites package to String package.
Added JStringNormalize.
Renamed DatabaseException to JDatabaseException.
Fixed several instances of database exceptions being thrown without error
Renamed
DatabaseException to JDatabaseException.
Fixed several instances of database exceptions being
thrown without error
messages or codes.
Removed old CHANGELOG.</para>
Removed old CHANGELOG.
</para>
</listitem>
<listitem>
<para>This manual was added.</para>
Expand All @@ -34,34 +37,47 @@
<listitem>
<para>Implemented a color field for JForm. This uses the native color picker in Opera 11 and
falls back to MooRainbow in all other browsers. Also adds the corresponding JFormRule for
validation.</para>
validation.
</para>
</listitem>
<listitem>
<para>Implemented graceful failure when update manifest is not available</para>
</listitem>
<listitem>
<para>Allow components to remove the admin menu entry in their postflight script, and not
throw errors during uninstall if the menu entries are not there.</para>
throw errors during uninstall if the menu entries are not there.
</para>
</listitem>
<listitem>
<para>Implemented fluid interface for setter and mutator methods in document package.
JDocument: parse(), addScript(), addScriptDeclaration(), addStyleSheet(),
addStyleDeclaration(), setBase(), setBuffer(), setCharset(), setDescription(),
setDirection(), setGenerator(), setLanguage(), setLineEnd(), setLink(), setMetaData(),
setMimeEncoding(), setModifiedDate(), setTab(), setTitle(), setType().
JDocument:
parse(), addScript(), addScriptDeclaration(), addStyleSheet(),
addStyleDeclaration(), setBase(), setBuffer(), setCharset(), setDescription(),
setDirection(), setGenerator(), setLanguage(), setLineEnd(), setLink(), setMetaData(),
setMimeEncoding(), setModifiedDate(), setTab(), setTitle(), setType().
JDocumentFeed: addItem(), setEnclosure().
JDocumentHTML: addCustomTag(), addFavicon(), addHeadLink(), mergeHeadData(),
setBuffer(), setHeadData(), _fetchTemplate(), _parseTemplate().
setBuffer(), setHeadData(), _fetchTemplate(), _parseTemplate().
JDocumentJSON: setName().
JDocumentOpensearch: addImage(), addUrl(), setShortName().
JDocumentXml: setName().</para>
JDocumentXml: setName().
</para>
</listitem>
<listitem>
<para>Fixed 'Call to a member function qn() on a non-object in
libraries/joomla/form/fields/rules.php on line 304'.</para>
<para>Fixed 'Call to a member function qn() on a non-object in
libraries/joomla/form/fields/rules.php'.
</para>
</listitem>
<listitem>
<para></para>
<para>Added new static JDate::getInstance method as a proxy for new JDate().
Allows for inline
construction, for example:
</para>
<programlisting><![CDATA[
echo JDate::getInstance()->format('Y-m-d H:i:s');
]]>
</programlisting>
<para>Added tests for JDate class</para>
</listitem>
<listitem>
<para></para>
Expand Down
40 changes: 26 additions & 14 deletions libraries/joomla/utilities/date.php
Expand Up @@ -155,18 +155,14 @@ public function __get($name)
$value = $this->format('z', true);
break;

case 'day':
$value = $this->format('d', true);
break;

case 'hour':
$value = $this->format('H', true);
break;

case 'isleapyear':
$value = (boolean) $this->format('L', true);
break;

case 'day':
$value = $this->format('d', true);
break;

case 'hour':
$value = $this->format('H', true);
break;
Expand All @@ -175,6 +171,10 @@ public function __get($name)
$value = $this->format('i', true);
break;

case 'second':
$value = $this->format('s', true);
break;

case 'month':
$value = $this->format('m', true);
break;
Expand All @@ -183,10 +183,6 @@ public function __get($name)
$value = $this->format('S', true);
break;

case 'second':
$value = $this->format('s', true);
break;

case 'week':
$value = $this->format('W', true);
break;
Expand Down Expand Up @@ -219,6 +215,22 @@ public function __toString()
return (string) parent::format(self::$format);
}

/**
* Proxy for new JDate().
*
* @param string $date String in a format accepted by strtotime(), defaults to "now".
* @param mixed $tz Time zone to be used for the date.
*
* @return void
* @since 11.3
*
* @throws JException
*/
public static function getInstance($date = 'now', $tz = null)
{
return new JDate($date, $tz);
}

/**
* Translates day of week number to a string.
*
Expand Down Expand Up @@ -399,7 +411,7 @@ public function setOffset($offset)
{
// Deprecation warning.
JLog::add('JDate::setOffset() is deprecated.', JLog::WARNING, 'deprecated');

// Only set the timezone if the offset exists.
if (isset(self::$offsets[(string) $offset]))
{
Expand Down Expand Up @@ -446,7 +458,7 @@ public function toFormat($format = '%Y-%m-%d %H:%M:%S', $local = false)
{
// Deprecation warning.
JLog::add('JDate::toFormat() is deprecated.', JLog::WARNING, 'deprecated');

// Set time zone to GMT as strftime formats according locale setting.
date_default_timezone_set('GMT');

Expand Down

0 comments on commit 7ff1d17

Please sign in to comment.