Skip to content

Commit

Permalink
Fix date issue
Browse files Browse the repository at this point in the history
  • Loading branch information
asika32764 committed Apr 15, 2018
1 parent 547049a commit 7df51bc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 22 deletions.
14 changes: 14 additions & 0 deletions src/Helper/DateHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,20 @@ public static function getDate($time = 'now', $tzOffset = null)
return Factory::getDate($time, $tzOffset);
}

/**
* getServerDate
*
* @param string $time
*
* @return Date
*
* @since __DEPLOY_VERSION__
*/
public static function getServerDate($time = 'now')
{
return Factory::getDate($time);
}

// public static function toUTCTime($date, $format = null, $from = null)
// {
// if ($currentTimezone)
Expand Down
37 changes: 15 additions & 22 deletions src/Model/AdminModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ class AdminModel extends CrudModel
/**
* Constructor
*
* @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request).
* @param JoomlaContainer $container Service container.
* @param \JRegistry $state The model state.
* @param \JDatabaseDriver $db The database adapter.
* @param array $config An array of configuration options (name, state, dbo, table_path, ignore_request).
* @param JoomlaContainer $container Service container.
* @param \JRegistry $state The model state.
* @param \JDatabaseDriver $db The database adapter.
*
* @throws \Exception
*/
public function __construct($config = array(), JoomlaContainer $container = null, \JRegistry $state = null, \JDatabaseDriver $db = null)
{
Expand Down Expand Up @@ -74,6 +76,7 @@ public function __construct($config = array(), JoomlaContainer $container = null
* @param array $data The form data.
*
* @return boolean True on success, False on error.
* @throws \Exception
*/
public function save($data)
{
Expand Down Expand Up @@ -175,10 +178,11 @@ public function checkout($pk = null)
/**
* Saves the manually set order of records.
*
* @param array $pks An array of primary key ids.
* @param array $order THe new ordering list.
* @param array $pks An array of primary key ids.
* @param array $order THe new ordering list.
*
* @return mixed
* @throws \Exception
*/
public function reorder($pks = null, $order = array())
{
Expand Down Expand Up @@ -252,13 +256,14 @@ public function reorder($pks = null, $order = array())
/**
* Prepare and sanitise the table data prior to saving.
*
* @param Table $table A reference to a JTable object.
* @param Table|\JTable $table A reference to a JTable object.
*
* @return void
*/
protected function prepareTable(\JTable $table)
{
$date = DateHelper::getDate('now');

$user = $this->container->get('user');
$key = $table->getKeyName();

Expand All @@ -283,11 +288,7 @@ protected function prepareTable(\JTable $table)
// Created date
if (property_exists($table, 'created'))
{
if ($table->created)
{
$table->created = DateHelper::toServerTime($table->created);
}
else
if (!$table->created)
{
$table->created = $date->toSql();
}
Expand All @@ -296,11 +297,7 @@ protected function prepareTable(\JTable $table)
// Publish_up date
if (property_exists($table, 'publish_up'))
{
if ($table->publish_up)
{
$table->publish_up = DateHelper::toServerTime($table->publish_up);
}
else
if (!$table->publish_up)
{
$table->publish_up = $this->db->getNullDate();
}
Expand All @@ -309,11 +306,7 @@ protected function prepareTable(\JTable $table)
// Publish_down date
if (property_exists($table, 'publish_down'))
{
if ($table->publish_down)
{
$table->publish_down = DateHelper::toServerTime($table->publish_down);
}
else
if (!$table->publish_down)
{
$table->publish_down = $this->db->getNullDate();
}
Expand Down

0 comments on commit 7df51bc

Please sign in to comment.