Download wp-calypso/client/my-sites/stats/hooks/utils.ts from Devendra174/react-code-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.29 kB
-
https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/my-sites/stats/hooks/utils.ts
- Command line
-
hf download hf://datasets/Devendra174/react-code-dataset/wp-calypso/client/my-sites/stats/hooks/utils.ts
-
curl -L -o utils.ts https://huggingface.co/datasets/Devendra174/react-code-dataset/resolve/main/wp-calypso/client/my-sites/stats/hooks/utils.ts
1.29 kB
| export interface QueryStatsParams { | |
| date?: string; | |
| start_date?: string; | |
| days?: number; | |
| max?: number; | |
| num?: number; | |
| period?: string; | |
| summarize?: number; | |
| filter_by_country?: string; | |
| } | |
| const getDaysOfMonthFromDate = ( date: string ): number => { | |
| const dateObj = new Date( date ); | |
| const year = dateObj.getFullYear(); | |
| const month = dateObj.getMonth() + 1; | |
| return new Date( year, month, 0 ).getDate(); | |
| }; | |
| const daysInYearFromDate = ( date: string ) => { | |
| const dateObj = new Date( date ); | |
| const year = dateObj.getFullYear(); | |
| return ( year % 4 === 0 && year % 100 > 0 ) || year % 400 === 0 ? 366 : 365; | |
| }; | |
| export const processQueryParams = ( query: QueryStatsParams ) => { | |
| // `num` is only for the period `day`. | |
| const num = query.num || 1; | |
| // `max` is probably set to 0 to fetch all results. | |
| const max = query.max ?? 10; | |
| const date = query.date || new Date().toISOString().split( 'T' )[ 0 ]; | |
| // Calculate the number of days to query based on the period. | |
| let days = num; | |
| switch ( query.period ) { | |
| case 'week': | |
| days = 7; | |
| break; | |
| case 'month': | |
| days = getDaysOfMonthFromDate( date ); | |
| break; | |
| case 'year': | |
| days = daysInYearFromDate( date ); | |
| break; | |
| } | |
| return { | |
| ...query, | |
| start_date: query.start_date || '', | |
| num, | |
| max, | |
| date, | |
| days, | |
| }; | |
| }; | |