amountFormatter.ts
9 months ago
convertLocalDateTimeToISOString.ts
7 months ago
formatTimestamp.ts
7 months ago
formatToDateLocalInput.ts
7 months ago
formatToDateTimeLocalInput.ts
7 months ago
getRelativeTimeString.ts
7 months ago
index.ts
7 months ago
prepareDefaultValuesFromSchema.ts
9 months ago
convertLocalDateTimeToISOString.ts
24 lines
| 1 | import {dateI18n, getDate} from '@wordpress/date'; |
| 2 | /** |
| 3 | * Convert a datetime-local string (e.g., "2025-10-21T15:30") to an ISO string. |
| 4 | * |
| 5 | * @since 4.13.0 |
| 6 | */ |
| 7 | export default function convertLocalDateTimeToISOString(localDateTime: string): string { |
| 8 | if (!localDateTime) { |
| 9 | return ''; |
| 10 | } |
| 11 | |
| 12 | // Interpret the provided wall time in the WordPress site timezone and |
| 13 | // return a site-local naive ISO-like string (no timezone). The server |
| 14 | // interprets naive strings in wp_timezone(). |
| 15 | const date = getDate(localDateTime); |
| 16 | if (isNaN(date.getTime())) { |
| 17 | return ''; |
| 18 | } |
| 19 | |
| 20 | // Return RFC3339 with timezone offset to satisfy JSON Schema `date-time` validation |
| 21 | // Example: 2025-10-21T22:00:00-04:00 |
| 22 | return dateI18n('Y-m-d\\TH:i:sP', date, undefined); |
| 23 | } |
| 24 |