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
formatToDateTimeLocalInput.ts
21 lines
| 1 | import {dateI18n, getDate} from '@wordpress/date'; |
| 2 | |
| 3 | /** |
| 4 | * Format the date and time to a datetime-local input compatible string |
| 5 | * @since 4.13.0 |
| 6 | */ |
| 7 | export default function formatToDateTimeLocalInput(dateString: string) { |
| 8 | if (!dateString) { |
| 9 | return ''; |
| 10 | } |
| 11 | |
| 12 | // Interpret server-provided naive strings as site timezone (WordPress timezone), |
| 13 | // and preserve the wall time for the datetime-local input. |
| 14 | const dateObj = getDate(dateString); |
| 15 | if (isNaN(dateObj.getTime())) { |
| 16 | return ''; |
| 17 | } |
| 18 | |
| 19 | return dateI18n('Y-m-d\\TH:i', dateObj, undefined); |
| 20 | } |
| 21 |