How can PHP handle time calculations during daylight saving time changes, and what are the potential pitfalls to watch out for?

When handling time calculations during daylight saving time changes in PHP, it is important to use timezone-aware functions and consider the potential pitfalls such as duplicated or missing hours. One way to handle this is by using the DateTime class along with the DateTimeZone class to accurately handle time calculations.

// Set the timezone to the desired timezone
date_default_timezone_set('America/New_York');

// Create a DateTime object with the current time
$now = new DateTime();

// Add 1 hour to the current time
$now->modify('+1 hour');

// Output the modified time
echo $now->format('Y-m-d H:i:s');