/** * WordPress dependencies */ import { Button, DateTimePicker as DateTimePickerDropdown, Dropdown, } from '@safe-wordpress/components'; import { _x } from '@safe-wordpress/i18n'; import { useInstanceId } from '@safe-wordpress/compose'; /** * External dependencies */ import { formatDateToUtc, formatI18nDatetime, getSettings } from '@nab/date'; /** * Internal dependencies */ import './style.scss'; export type DateTimePickerProps = { readonly className?: string; readonly date: string; readonly onChange: ( val: string | false ) => void; readonly noDateLabel?: string; readonly hasNowLink?: boolean; readonly readonly?: boolean; }; export const DateTimePicker = ( { className = '', date, onChange, noDateLabel, hasNowLink = true, }: DateTimePickerProps ): JSX.Element => { const instanceId = useInstanceId( DateTimePicker ); const settings = getSettings(); const is12HourTime = /a(?!\\)/i.test( settings.formats.time .toLowerCase() // Test only the lower case a .replace( /\\\\/g, '' ) // Replace "//" with empty strings .split( '' ) .reverse() .join( '' ) // Reverse the string and test for "a" not followed by a slash ); return ( ( <> ) } renderContent={ () => ( <> onChange( value ? formatDateToUtc( value ) : false ) } is12Hour={ is12HourTime } /> { !! hasNowLink && ( ) } ) } /> ); };