- Регистрация
- 1 Мар 2015
- Сообщения
- 1,481
- Баллы
- 155
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
Why start from scratch? This includes:
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
// Add to formatForProvider()
'zoom' => $utcTime->format('Ymd\THis\Z')
$converted = UserTimeZoneHandler::convertTimeRanges(
$businessHours,
'America/Chicago',
'Europe/Paris'
);
Step 5: Launch Your Demo
php artisan serve
Visit to see:
Why This Works
Clone & Customize:
? 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
Why start from scratch? This includes:
- Pre-built service class
- Working demo UI
- Passing tests (mostly ?)
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 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: