Skip to content

Beautiful Open-Source Form Builder

Fix time issue on scheduled form close (#467)

Chirag Chhatrala6f7692541f2f
diff --git a/app/Models/Forms/Form.php b/app/Models/Forms/Form.php
index 5bc2dc1a8..2088a7247 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);