LLMS_Abstract_Post_Data::set_period( string $period = 'today' )
Set the dates passed on a date range period
Parameters Parameters
- $period
-
(string) (Optional) Date range period.
Default value: 'today'
Return Return
(void)
Source Source
File: includes/abstracts/llms.abstract.post.data.php
public function set_period( $period = 'today' ) {
$now = current_time( 'timestamp' );
switch ( $period ) {
case 'all_time':
$curr_start = 0;
$curr_end = $now;
$prev_start = 0;
$prev_end = $now;
break;
case 'last_year':
$curr_start = strtotime( 'first day of january last year', $now );
$curr_end = strtotime( 'last day of december last year', $now );
$prev_start = strtotime( 'first day of january last year', $curr_start );
$prev_end = strtotime( 'last day of december last year', $curr_start );
break;
case 'year':
$curr_start = strtotime( 'first day of january this year', $now );
$curr_end = strtotime( 'last day of december this year', $now );
$prev_start = strtotime( 'first day of january last year', $now );
$prev_end = strtotime( 'last day of december last year', $now );
break;
case 'last_month':
$curr_start = strtotime( 'first day of previous month', $now );
$curr_end = strtotime( 'last day of previous month', $now );
$prev_start = strtotime( 'first day of previous month', $curr_start );
$prev_end = strtotime( 'last day of previous month', $curr_start );
break;
case 'month':
$curr_start = strtotime( 'first day of this month', $now );
$curr_end = strtotime( 'last day of this month', $now );
$prev_start = strtotime( 'first day of previous month', $now );
$prev_end = strtotime( 'last day of previous month', $now );
break;
case 'last_week':
$curr_start = strtotime( 'monday this week', $now - WEEK_IN_SECONDS );
$curr_end = $now;
$prev_start = strtotime( 'monday previous week', $curr_start - WEEK_IN_SECONDS );
$prev_end = $curr_start - DAY_IN_SECONDS;
break;
case 'week':
$curr_start = strtotime( 'monday this week', $now );
$curr_end = $now;
$prev_start = strtotime( 'monday previous week', $now );
$prev_end = $curr_start - DAY_IN_SECONDS;
break;
case 'yesterday':
$curr_start = $now - DAY_IN_SECONDS;
$curr_end = $curr_start;
$prev_start = $curr_start - DAY_IN_SECONDS;
$prev_end = $prev_start;
break;
case 'today':
default:
$curr_start = $now;
$curr_end = $now;
$prev_start = $now - DAY_IN_SECONDS;
$prev_end = $prev_start;
}// End switch().
$this->dates = array(
'current' => array(
'start' => strtotime( 'midnight', $curr_start ),
'end' => strtotime( 'tomorrow', $curr_end ) - 1,
),
'previous' => array(
'start' => strtotime( 'midnight', $prev_start ),
'end' => strtotime( 'tomorrow', $prev_end ) - 1,
),
);
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 3.31.0 | Introduced. |