Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add timezone column to events table enhancement #371

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app-modules/event-importer/src/Data/EventData.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Enums\EventType;
use App\Traits\HasUniqueIdentifier;
use Carbon\Carbon;
use Spatie\LaravelData\Attributes\Validation\Timezone;
use Spatie\LaravelData\Data;

class EventData extends Data
Expand All @@ -20,6 +21,8 @@ public function __construct(
public Carbon $starts_at,
public Carbon $ends_at,
public null|Carbon $cancelled_at,
#[Timezone()]
public string $timezone,
public EventType $event_type,
public EventServices $service,
public string $service_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected function mapIntoEventData(array $data): EventData
'url' => $data['url'],
'starts_at' => Carbon::parse($data['start']['local']),
'ends_at' => Carbon::parse($data['end']['local']),
'timezone' => Carbon::parse($data['start']['timezone']),
// Yes "canceled" is misspelled
'cancelled_at' => 'canceled' === $data['status'] || 'event_cancelled' === Arr::get($data, 'event_sales_status.message_code')
? now()
Expand Down
1 change: 1 addition & 0 deletions app-modules/event-importer/src/Services/LumaHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ protected function mapIntoEventData(array $data): EventData
'url' => "https://lu.ma/" . $data['event']['url'],
'starts_at' => Carbon::parse($data['event']['start_at'])->setTimezone($data['event']['timezone']),
'ends_at' => Carbon::parse($data['event']['end_at'])->setTimezone($data['event']['timezone']),
'timezone' => $data['event']['timezone'],
'event_type' => match ($data['event']['location_type']) {
'online', 'zoom', => EventType::Online,
'offline', 'unknown' => EventType::Live,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class MeetupGraphqlHandler extends AbstractEventHandler
protected function mapIntoEventData(array $data): EventData
{
$event = $data['node'];

return EventData::from([
'id' => $event['id'],
'name' => $event['title'],
Expand All @@ -30,6 +31,7 @@ protected function mapIntoEventData(array $data): EventData
'starts_at' => Carbon::parse($event['dateTime']),
// Meetup (graphql) does not provide an event end time
'ends_at' => Carbon::parse($event['dateTime'])->addHours(2),
'timezone' => Carbon::parse($event['dateTime'])->timezoneName,
'event_type' => match ($event['eventType']) {
'ONLINE' => EventType::Online,
'PHYSICAL' => EventType::Live,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ protected function mapIntoEventData(array $data): EventData
'starts_at' => Carbon::createFromTimestampMs($data['time']),
// Meetup (rest) does not provide an event end time
'ends_at' => Carbon::createFromTimestampMs($data['time'])->addHours(2),
'timezone' => Carbon::createFromTimestampMs($data['time'])->utcOffset($data['utc_offset'] / 1000)->timezoneName,
'event_type' => match ($data['eventType']) {
'ONLINE' => EventType::Online,
'PHYSICAL' => EventType::Live,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public function test_active_eventbrite_event_is_imported_correctly(): void
$this->assertEquals(null, $active_event->rsvp_count);
$this->assertEquals('2018-03-10 08:30:00', $active_event->active_at->toDateTimeString());
$this->assertEquals('2018-03-10 17:30:00', $active_event->expire_at->toDateTimeString());
$this->assertEquals('America/New_York', $active_event->timezone);
$this->assertEquals('https://www.eventbrite.com/e/bsides-greenville-2018-tickets-39146789100', $active_event->url);
$this->assertNull($active_event->cancelled_at);

Expand Down
2 changes: 2 additions & 0 deletions app-modules/event-importer/tests/Feature/LumaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ public function test_active_luma_event_is_imported_correctly(): void

$this->assertEquals(null, $event1->rsvp_count);
$this->assertEquals('2024-08-06 11:30:00', $event1->active_at->toDateTimeString());
$this->assertEquals('America/New_York', $event1->timezone);
$this->assertEquals('https://lu.ma/uxweg758', $event1->url);
$this->assertNull($event1->cancelled_at);

Expand Down Expand Up @@ -80,6 +81,7 @@ public function test_active_luma_event_is_imported_correctly(): void
$this->assertEquals(null, $event2->rsvp_count);
$this->assertEquals('2024-09-03 11:30:00', $event2->active_at->toDateTimeString());
$this->assertEquals('2024-09-03 12:30:00', $event2->expire_at->toDateTimeString());
$this->assertEquals('America/New_York', $event2->timezone);
$this->assertEquals('https://lu.ma/0w9vm5fw', $event2->url);
$this->assertNull($event2->cancelled_at);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function test_meetup_event_is_imported_correctly(): void

$this->assertEquals(19, $event->rsvp_count);
$this->assertEquals(1577833200, $event->active_at->utc()->unix());
$this->assertEquals('America/New_York', $event->timezone);
$this->assertEquals('https://www.meetup.com/defcon864/events/301411834', $event->uri);
$this->assertNull($event->cancelled_at);
$this->assertNotNull($event->venue);
Expand Down
8 changes: 4 additions & 4 deletions app-modules/event-importer/tests/Feature/MeetupRestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function test_active_meetup_event_is_imported_correctly(): void
$this->assertNull($active_event->venue_id);
$this->assertEquals('upcoming', $active_event->status);
$this->assertNull($active_event->cancelled_at);

$this->assertEquals('America/New_York', $active_event->timezone);
}

public function test_cancelled_meetup_event_is_imported_correctly(): void
Expand Down Expand Up @@ -73,9 +73,9 @@ public function test_cancelled_meetup_event_is_imported_correctly(): void
protected function getMeetupUrl(string $service_api_key): string
{
return 'https://api.meetup.com/' . $service_api_key . '/events?sign=1&photo-host=public' .
'&status=upcoming%2Ccancelled%2Cpast&page=100&' .
'no_earlier_than=' . now()->subDays(env('EVENT_IMPORTER_MAX_DAYS_IN_PAST', 30))->format('Y-m-d') . 'T00%3A00%3A00' .
'&no_later_than=' . now()->addDays(180)->format('Y-m-d') . 'T23%3A59%3A59';
'&status=upcoming%2Ccancelled%2Cpast&page=100&' .
'no_earlier_than=' . now()->subDays(env('EVENT_IMPORTER_MAX_DAYS_IN_PAST', 30))->format('Y-m-d') . 'T00%3A00%3A00' .
'&no_later_than=' . now()->addDays(180)->format('Y-m-d') . 'T23%3A59%3A59';
}

protected function apiResponse(string $file): string
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration {
public function up(): void
{
Schema::table('events', function (Blueprint $table) {
$table->string('timezone')->after('active_at')->default('America/New_York');
});
}

public function down(): void
{
Schema::table('events', function (Blueprint $table) {
$table->dropColumn('timezone');
});
}
};
Loading