import { Button, Tooltip } from '@wordpress/components'; import { Icon, calendar } from '@wordpress/icons'; import { Moment } from 'moment'; import { RefObject } from 'react'; import DateRange from 'calypso/components/date-range'; import { useLocalizedMoment } from 'calypso/components/localized-moment'; import useMomentSiteZone from 'calypso/my-sites/stats/hooks/use-moment-site-zone'; import { DateControlProps } from './types'; import './style.scss'; const COMPONENT_CLASS_NAME = 'date-control'; const DateControl = ( { onApplyButtonClick, onShortcutClick, onDateControlClick, tooltip, dateRange, overlay, shortcutList, }: DateControlProps ) => { const moment = useLocalizedMoment(); const siteToday = useMomentSiteZone(); const getButtonLabel = () => { const localizedStartDate = moment( dateRange.chartStart ); const localizedEndDate = moment( dateRange.chartEnd ); // If it's the same day, show single date. if ( localizedStartDate.isSame( localizedEndDate, 'day' ) ) { return localizedStartDate.format( 'LL' ); } // Only show year for the second date. if ( localizedStartDate.year() === localizedEndDate.year() && localizedStartDate.isSame( moment(), 'year' ) ) { return `${ localizedStartDate.format( 'MMM D' ) } - ${ localizedEndDate.format( 'MMM D, YYYY' ) }`; } return `${ localizedStartDate.format( 'll' ) } - ${ localizedEndDate.format( 'll' ) }`; }; return (