/**
 * Utility functions.
 *
 * Site Kit by Google, Copyright 2020 Google LLC
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
/**
 * WordPress dependencies
 */
import { applyFilters } from '@wordpress/hooks';
import { _n, sprintf } from '@wordpress/i18n';

/**
 * Gets the current dateRange string.
 *
 * @return {string} the date range string.
 */
export function getCurrentDateRange() {
	/**
	 * Filter the date range used for queries.
	 *
	 * @param String The selected date range. Default 'Last 28 days'.
	 */
	const dateRange = applyFilters( 'googlesitekit.dateRange', 'last-28-days' );
	const daysMatch = dateRange.match( /last-(\d+)-days/ );

	if ( daysMatch && daysMatch[ 1 ] ) {
		return sprintf(
			/* translators: %s: Number of days matched. */
			_n( '%s day', '%s days', parseInt( daysMatch[ 1 ], 10 ), 'google-site-kit' ),
			daysMatch[ 1 ]
		);
	}

	throw new Error( 'Unrecognized date range slug used in `googlesitekit.dateRange`.' );
}

/**
 * Gets the current dateRange slug.
 *
 * @return {string} the date range slug.
 */
export function getCurrentDateRangeSlug() {
	return applyFilters( 'googlesitekit.dateRange', 'last-28-days' );
}

@@ -725,16 +725,20 @@
 import %7B
+ __,
  _n, spr
@@ -1663,12 +1663,747 @@
 -days' );%0A%7D%0A
+%0A/**%0A * Gets the hash of available date ranges.%0A *%0A * @since n.e.x.t%0A *%0A * @return %7BObject%7D The object hash where every key is a date range slug, and the value is an object with the date range slug and its translation.%0A */%0Aexport function getAvailableDateRanges() %7B%0A%09/* translators: %25s: Number of days to request data. */%0A%09const template = __( 'Last %25s days', 'google-site-kit' );%0A%0A%09return %7B%0A%09%09'last-7-days': %7B%0A%09%09%09slug: 'last-7-days',%0A%09%09%09label: sprintf( template, 7 ),%0A%09%09%7D,%0A%09%09'last-14-days': %7B%0A%09%09%09slug: 'last-14-days',%0A%09%09%09label: sprintf( template, 14 ),%0A%09%09%7D,%0A%09%09'last-28-days': %7B%0A%09%09%09slug: 'last-28-days',%0A%09%09%09label: sprintf( template, 28 ),%0A%09%09%7D,%0A%09%09'last-90-days': %7B%0A%09%09%09slug: 'last-90-days',%0A%09%09%09label: sprintf( template, 90 ),%0A%09%09%7D,%0A%09%7D;%0A%7D%0A

Add getAvailableDateRanges function.