Permalink
Browse files

Merge pull request #2074 from nanaya/beatmapset_date_offset

Data is in datetime which ignores timezone setting
  • Loading branch information...
peppy committed Dec 23, 2017
2 parents c4ea616 + b879c75 commit 291eeb3f7e7e74200e2bfdd142d200878588caca
Showing with 35 additions and 2 deletions.
  1. +10 −0 app/Models/Beatmapset.php
  2. +25 −2 app/helpers.php
@@ -167,11 +167,21 @@ public function getApprovedDateAttribute($value)
return (new Carbon($value))->subHours(8);
}
public function setApprovedDateAttribute($value)
{
$this->attributes['approved_date'] = parse_time_to_carbon($value)->addHours(8);
}
public function getSubmitDateAttribute($value)
{
return (new Carbon($value))->subHours(8);
}
public function setSubmitDateAttribute($value)
{
$this->attributes['submit_date'] = parse_time_to_carbon($value)->addHours(8);
}
public function beatmapDiscussions()
{
return $this->hasMany(BeatmapDiscussion::class, 'beatmapset_id', 'beatmapset_id');
@@ -908,8 +908,31 @@ function model_pluck($builder, $key, $class = null)
// helper returns null if it's 0 and parses the timestamp otherwise.
function get_time_or_null($timestamp)
{
if ($timestamp !== null && $timestamp !== 0) {
return Carbon\Carbon::createFromTimestamp($timestamp);
if ($timestamp !== 0) {
return parse_time_to_carbon($timestamp);
}
}
function parse_time_to_carbon($value)
{
if (!present($value)) {
return;
}
if (is_numeric($value)) {
return Carbon\Carbon::createFromTimestamp($value);
}
if (is_string($value)) {
return Carbon\Carbon::parse($value);
}
if ($value instanceof Carbon\Carbon) {
return $value;
}
if ($value instanceof DateTime) {
return Carbon\Carbon::instance($value);
}
}

0 comments on commit 291eeb3

Please sign in to comment.