From 6f7692541f2f53b1bac92244d2a16b7af445d49f Mon Sep 17 00:00:00 2001 From: Chirag Chhatrala <60499540+chiragchhatrala@users.noreply.github.com> Date: Thu, 27 Jun 2024 21:48:56 +0530 Subject: [PATCH] Fix time issue on scheduled form close (#467) * Fix time issue on scheduled form close * handle empty value * fix lint --------- Co-authored-by: Julien Nahum --- app/Models/Forms/Form.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/app/Models/Forms/Form.php b/app/Models/Forms/Form.php index 5bc2dc1a..2088a724 100644 --- a/app/Models/Forms/Form.php +++ b/app/Models/Forms/Form.php @@ -19,6 +19,7 @@ use Illuminate\Support\Str; use Spatie\Sluggable\HasSlug; use Spatie\Sluggable\SlugOptions; use Stevebauman\Purify\Facades\Purify; +use Carbon\Carbon; class Form extends Model implements CachableAttributes { @@ -194,6 +195,21 @@ class Form extends Model implements CachableAttributes $this->attributes['tags'] = json_encode($value); } + public function setClosesAtAttribute($value) + { + $this->attributes['closes_at'] = ($value) ? Carbon::parse($value)->setTimezone('UTC') : null; + } + + public function getClosesAtAttribute($value) + { + if (!$value) { + return $value; + } + // Retrieve the desired timezone from the request or default to 'UTC' + $timezone = request()->get('timezone', 'UTC'); + return Carbon::parse($value)->setTimezone($timezone)->toIso8601String(); + } + public function getIsClosedAttribute() { return $this->closes_at && now()->gt($this->closes_at);