| Server IP : 35.80.110.71 / Your IP : 216.73.216.221 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/client-portal-laravel/current/scripts/util/ |
Upload File : |
<?php
require __DIR__.'/../vendor/autoload.php';
use Carbon\Carbon;
// Simulate the scenario:
// Admin stored times: 09:00 - 14:00 (in Denver time)
// Date from CarbonPeriod: 2026-01-26
// Timezone: America/Denver
$date = Carbon::parse('2026-01-26 00:00:00', 'UTC'); // Date from period (in UTC)
$startTimeStr = '09:00:00';
$endTimeStr = '14:00:00';
$timezone = 'America/Denver';
$slotDuration = 45;
echo "=== TEST SCENARIO ===\n";
echo "Date from CarbonPeriod: {$date->toIso8601String()}\n";
echo "Stored start_time: {$startTimeStr}\n";
echo "Stored end_time: {$endTimeStr}\n";
echo "Timezone: {$timezone}\n\n";
// MY FIX - Parse directly in target timezone
$startTime = Carbon::parse("{$date->format('Y-m-d')} {$startTimeStr}", $timezone);
$endTime = Carbon::parse("{$date->format('Y-m-d')} {$endTimeStr}", $timezone);
echo "=== WITH MY FIX ===\n";
echo "Start time: {$startTime->toIso8601String()} ({$startTime->format('g:i A')})\n";
echo "End time: {$endTime->toIso8601String()} ({$endTime->format('g:i A')})\n\n";
// Generate slots
echo "=== GENERATED SLOTS ===\n";
$current = $startTime->copy();
$slots = [];
while ($current->copy()->addMinutes($slotDuration)->lte($endTime)) {
$slots[] = $current->format('g:i A');
$current->addMinutes($slotDuration);
}
echo implode(', ', $slots)."\n\n";
// OLD BUGGY CODE for comparison
echo "=== OLD BUGGY CODE ===\n";
$startTimeBuggy = $date->copy()->setTimezone($timezone)->setTimeFromTimeString($startTimeStr);
$endTimeBuggy = $date->copy()->setTimezone($timezone)->setTimeFromTimeString($endTimeStr);
echo "Start time: {$startTimeBuggy->toIso8601String()} ({$startTimeBuggy->format('g:i A')})\n";
echo "End time: {$endTimeBuggy->toIso8601String()} ({$endTimeBuggy->format('g:i A')})\n";
$currentBuggy = $startTimeBuggy->copy();
$slotsBuggy = [];
while ($currentBuggy->copy()->addMinutes($slotDuration)->lte($endTimeBuggy)) {
$slotsBuggy[] = $currentBuggy->format('g:i A');
$currentBuggy->addMinutes($slotDuration);
}
echo 'Slots: '.implode(', ', $slotsBuggy)."\n";