HEX
Server: LiteSpeed
System: Linux server315.web-hosting.com 4.18.0-553.54.1.lve.el8.x86_64 #1 SMP Wed Jun 4 13:01:13 UTC 2025 x86_64
User: globfdxw (6114)
PHP: 8.1.34
Disabled: NONE
Upload Files
File: /home/globfdxw/www/wp-content/plugins/give/src/Admin/common/formatTimestamp.ts
import {dateI18n, getDate, getSettings} from '@wordpress/date';
/**
 * Format the timestamp using the WordPress site settings for timezone and format.
 *
 * @since 4.13.0 updated to use the @wordpress/date functions
 * @since 4.10.0
 */
export function formatTimestamp(timestamp: string | null | undefined, includeTime: boolean = true): string {
    // Handle null, undefined, or empty string
    if (!timestamp) {
        return '—';
    }

    // Parse timestamps using WordPress site timezone. Works with naive and offset/Z strings.
    const date = getDate(timestamp);

    // Check if the date is valid
    if (isNaN(date.getTime())) {
        return '—';
    }

    const {formats} = getSettings();
    const datePart = dateI18n(formats.date || 'F j, Y', date, undefined);
    if (includeTime) {
        const timePart = dateI18n(formats.time || 'g:i a', date, undefined);
        return `${datePart} ${timePart}`;
    }

    return datePart;
}