The Problem We All Face
⏰ Your user in Tokyo picks 2 PM → New York sees 1 AM 💀
📅 Calendar exports show wrong times
🌍 DST changes break everything
Here’s how I built a converter that handles all this – and how you can clone it.
Step 1: Steal My Base Code
git clone https://github.com/codewithmikee/laravel-timezone-handler
Why start from scratch? This includes:
- Pre-built service class
- Working demo UI
- Passing tests (mostly 😉)
Step 2: The Magic Methods
Convert Anywhere → UTC
// Static call (no user context)
$utcTime = UserTimeZoneHandler::toUtc(
'2023-01-01 14:00',
'Asia/Tokyo'
);
User-Friendly Instance Mode
// In controller
$handler = new UserTimeZoneHandler($user->timezone);
// All conversions use the user’s zone
$localTime = $handler->toUserTimeZone($event->start_time);
Step 3: Avoid My Carbon Mistake
I wasted hours on this failed test:
public function testGoogleFormatting() {
$time = Carbon::parse(...); // Fails!
}
Why? Laravel extends Carbon. Always use:
use Illuminate\Support\Carbon; // Not Carbon\Carbon!
Step 4: Add Your Secret Sauce
- New Calendar Provider?
// Add to formatForProvider()
'zoom' => $utcTime->format('Ymd\THis\Z')
- Custom Time Ranges
$converted = UserTimeZoneHandler::convertTimeRanges(
$businessHours,
'America/Chicago',
'Europe/Paris'
);
Step 5: Launch Your Demo
php artisan serve
Visit http://localhost:8000/timezone-converter
to see:
Why This Works
- ✅ Handles 597 timezones (including weird ones like
Australia/Lord_Howe
) - ✅ Tests cover DST/edge cases
- ✅ No hidden dependencies
Clone & Customize:
github.com/codewithmikee/laravel-timezone-handler
Thanks for sharing 🙌