amountFormatter.ts
11 months ago
convertLocalDateTimeToISOString.ts
10 months ago
formatTimestamp.ts
10 months ago
formatToDateLocalInput.ts
10 months ago
formatToDateTimeLocalInput.ts
10 months ago
getRelativeTimeString.ts
10 months ago
index.ts
10 months ago
prepareDefaultValuesFromSchema.ts
11 months ago
formatToDateLocalInput.ts
21 lines
| 1 | import {dateI18n, getDate} from '@wordpress/date'; |
| 2 | |
| 3 | /** |
| 4 | * Format the date to a date-local input compatible string |
| 5 | * @since 4.13.0 |
| 6 | */ |
| 7 | export default function formatToDateLocalInput(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 date input. |
| 14 | const dateObj = getDate(dateString); |
| 15 | if (isNaN(dateObj.getTime())) { |
| 16 | return ''; |
| 17 | } |
| 18 | |
| 19 | return dateI18n('Y-m-d', dateObj, undefined); |
| 20 | } |
| 21 |