Files
HRM-System/scratch/test_timezone_conversion.php

25 lines
916 B
PHP

<?php
require __DIR__.'/../vendor/autoload.php';
$app = require_once __DIR__.'/../bootstrap/app.php';
$kernel = $app->make(Illuminate\Contracts\Console\Kernel::class);
$kernel->bootstrap();
use Carbon\Carbon;
$testInputs = [
'2026-05-05 10:11:00', // raw local format
'2026-05-05T02:11:00.000Z', // UTC ISO format sent by JS agent
'Tue May 05 2026 10:11:00 GMT+0800', // JS format with offset
];
foreach ($testInputs as $input) {
echo "--- Input: '$input' ---\n";
$parsedWithTz = Carbon::parse($input, 'Asia/Manila');
echo "Parsed with default TZ: " . $parsedWithTz->toDateTimeString() . " | TZ: " . $parsedWithTz->tzName . "\n";
// Now convert the timezone to Asia/Manila explicitly (handles UTC inputs)
$converted = $parsedWithTz->setTimezone('Asia/Manila');
echo "After setTimezone: " . $converted->toDateTimeString() . " | TZ: " . $converted->tzName . "\n\n";
}