Skip to content

Commit

Permalink
Fixed bug with wrong date format
Browse files Browse the repository at this point in the history
  • Loading branch information
sleeping-owl committed Oct 20, 2014
1 parent 5bca6c3 commit c88b2c0
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/SleepingOwl/Admin/Models/Form/FormItem/Date.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,11 @@ public function render()
'data-date-picktime' => false
]);
}

public function getValidationRules()
{
$rules = parent::getValidationRules();
$rules[] = 'date';
return $rules;
}
}
8 changes: 8 additions & 0 deletions src/SleepingOwl/Admin/Models/Form/FormItem/Timestamp.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ public function render()
'data-date-useseconds' => $this->showSeconds,
], DateFormatter::SHORT, $this->showSeconds ? DateFormatter::MEDIUM : DateFormatter::SHORT);
}

public function getValidationRules()
{
$rules = parent::getValidationRules();
$rules[] = 'date';
return $rules;
}

}
8 changes: 7 additions & 1 deletion src/SleepingOwl/DateFormatter/DateFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ public static function format($date, $dateFormat = self::SHORT, $timeFormat = se
{
if ( ! $date instanceof Carbon)
{
$date = new Carbon($date);
try
{
$date = new Carbon($date);
} catch (\Exception $e)
{
return null;
}
}
if ( ! function_exists('datefmt_create'))
{
Expand Down
3 changes: 2 additions & 1 deletion src/SleepingOwl/Models/SleepingOwlModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ public function fromDateTime($value)
$result = parent::fromDateTime($value);
} catch (InvalidArgumentException $e)
{
$value = strtotime($value);
$format = $this->getDateFormat();
$value = new Carbon($value);
$value = Carbon::createFromTimestamp($value);
return $value->format($format);
}
return $result;
Expand Down

0 comments on commit c88b2c0

Please sign in to comment.