format( 'Y-m-d' ) === $date ? $result : null; } public static function nextDay( string $date ): ?DateTimeImmutable { $next = ( new DateTimeImmutable( $date, new DateTimeZone( 'UTC' ) ) )->modify( '+1 day' )->format( 'Y-m-d' ); return new DateTimeImmutable( $next . ' 00:00:00', wp_timezone() ); } public static function local( string $date, string $clock ): ?DateTimeImmutable { $value = $date . ' ' . ( 5 === strlen( $clock ) ? $clock . ':00' : $clock ); $result = DateTimeImmutable::createFromFormat( '!Y-m-d H:i:s', $value, wp_timezone() ); return $result && $result->format( 'Y-m-d H:i:s' ) === $value ? $result : null; } public static function timestamp( int $timestamp ): DateTimeImmutable { return ( new DateTimeImmutable( '@' . $timestamp ) )->setTimezone( wp_timezone() ); } public static function iso( int $timestamp ): string { return self::timestamp( $timestamp )->format( DATE_ATOM ); } public static function sql( DateTimeInterface $instant ): string { return DateTimeImmutable::createFromInterface( $instant )->setTimezone( new DateTimeZone( 'UTC' ) )->format( 'Y-m-d H:i:s' ); } public static function fromSql( string $instant ): int { return ( new DateTimeImmutable( $instant, new DateTimeZone( 'UTC' ) ) )->getTimestamp(); } }