# stream/3.2.0/classes/class-date-interval.php

Stream – Activity Log &amp; Audit Trail, version 3.2.0. 112 lines.

- Page: https://pluginprobe.com/plugins/stream/3.2.0/code/classes/class-date-interval.php
- Raw: https://pluginprobe.com/plugins/stream/3.2.0/raw/classes/class-date-interval.php
- Modified: 2017-03-15T01:11:20+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/stream/3.2.0/code/classes/class-date-interval.php#L10-L20`.

```php
<?php
namespace WP_Stream;

// Load Carbon to Handle dates much easier
if ( ! class_exists( 'Carbon\Carbon' ) ) {
	require_once wp_stream_get_instance()->locations['inc_dir'] . 'lib/Carbon.php';
}

use Carbon\Carbon;

class Date_Interval {
	/**
	 * Contains an array of all available intervals
	 *
	 * @var array $intervals
	 */
	public $intervals;

	/**
	 * Class constructor
	 */
	public function __construct() {
		// Get all default intervals
		$this->intervals = $this->get_predefined_intervals();
	}

	/**
	 * @return mixed|void
	 */
	public function get_predefined_intervals() {
		$timezone = get_option( 'timezone_string' );

		if ( empty( $timezone ) ) {
			$gmt_offset = (int) get_option( 'gmt_offset' );
			$timezone   = timezone_name_from_abbr( null, $gmt_offset * 3600, true );
			if ( false === $timezone ) {
				$timezone = timezone_name_from_abbr( null, $gmt_offset * 3600, false );
			}
			if ( false === $timezone ) {
				$timezone = null;
			}
		}

		return apply_filters(
			'wp_stream_predefined_date_intervals',
			array(
				'today' => array(
					'label' => esc_html__( 'Today', 'stream' ),
					'start' => Carbon::today( $timezone )->startOfDay(),
					'end'   => Carbon::today( $timezone )->endOfDay(),
				),
				'yesterday' => array(
					'label' => esc_html__( 'Yesterday', 'stream' ),
					'start' => Carbon::today( $timezone )->startOfDay()->subDay(),
					'end'   => Carbon::today( $timezone )->startOfDay()->subSecond(),
				),
				'last-7-days' => array(
					'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 7 ),
					'start' => Carbon::today( $timezone )->subDays( 7 ),
					'end'   => Carbon::today( $timezone ),
				),
				'last-14-days' => array(
					'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 14 ),
					'start' => Carbon::today( $timezone )->subDays( 14 ),
					'end'   => Carbon::today( $timezone ),
				),
				'last-30-days' => array(
					'label' => sprintf( esc_html__( 'Last %d Days', 'stream' ), 30 ),
					'start' => Carbon::today( $timezone )->subDays( 30 ),
					'end'   => Carbon::today( $timezone ),
				),
				'this-month' => array(
					'label' => esc_html__( 'This Month', 'stream' ),
					'start' => Carbon::today( $timezone )->startOfMonth(),
					'end'   => Carbon::today( $timezone )->endOfMonth(),
				),
				'last-month' => array(
					'label' => esc_html__( 'Last Month', 'stream' ),
					'start' => Carbon::today( $timezone )->startOfMonth()->subMonth(),
					'end'   => Carbon::today( $timezone )->startOfMonth()->subSecond(),
				),
				'last-3-months' => array(
					'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 3 ),
					'start' => Carbon::today( $timezone )->subMonths( 3 ),
					'end'   => Carbon::today( $timezone ),
				),
				'last-6-months' => array(
					'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 6 ),
					'start' => Carbon::today( $timezone )->subMonths( 6 ),
					'end'   => Carbon::today( $timezone ),
				),
				'last-12-months' => array(
					'label' => sprintf( esc_html__( 'Last %d Months', 'stream' ), 12 ),
					'start' => Carbon::today( $timezone )->subMonths( 12 ),
					'end'   => Carbon::today( $timezone ),
				),
				'this-year' => array(
					'label' => esc_html__( 'This Year', 'stream' ),
					'start' => Carbon::today( $timezone )->startOfYear(),
					'end'   => Carbon::today( $timezone )->endOfYear(),
				),
				'last-year' => array(
					'label' => esc_html__( 'Last Year', 'stream' ),
					'start' => Carbon::today( $timezone )->startOfYear()->subYear(),
					'end'   => Carbon::today( $timezone )->startOfYear()->subSecond(),
				),
			),
			$timezone
		);
	}
}

```
