PluginProbe
Parse.ly / 3.8.4
Parse.ly v3.8.4
3.24.1 3.24.0 3.23.7 3.23.6 3.23.5 3.23.4 3.23.3 3.16.0 3.16.1 3.16.2 3.16.3 3.16.4 3.17.0 3.18.0 3.18.1 3.19.0 3.19.1 3.19.2 3.19.3 3.2.0 3.2.1 3.20.0 3.20.1 3.20.2 3.20.3 All 105 releases
wp-parsely / src / blocks / shared / utils / api.ts

api.ts in Parse.ly 3.8.4, at src/blocks/shared/utils/api.ts

48 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { removeDaysFromDate } from './date';
2
3 export interface AnalyticsApiQueryParams extends AnalyticsApiOptionalQueryParams {
4 type: string,
5 }
6
7 export interface AnalyticsApiOptionalQueryParams extends ApiPeriodRange {
8 pub_date_start?: string;
9 pub_date_end?: string;
10 sort?: string;
11 limit?: number;
12 page?: number;
13 author?: string;
14 tag?: string;
15 section?: string;
16 segment?: string;
17 }
18
19 export interface ApiPeriodRange {
20 period_start?: string; // Defaults to 3 days ago.
21 period_end?: string; // Defaults to current date and time.
22 }
23
24 /**
25 * Gets `period_start` and `period_end` params for API.
26 *
27 * @param {number} days Number of days for which to calculate the period range.
28 *
29 * @return {ApiPeriodRange} API query params.
30 */
31 export function getApiPeriodParams( days: number ): ApiPeriodRange {
32 return {
33 period_start: `${ days }d`,
34 period_end: '',
35 };
36 }
37
38 /**
39 * Gets period start date for API.
40 *
41 * @param {number} days Number of days for which to calculate the period start date.
42 *
43 * @return {string} period start date.
44 */
45 export function getApiPeriodStartDate( days: number ): string {
46 return removeDaysFromDate( new Date().toISOString(), days - 1 ) + 'T00:00';
47 }
48