• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer
Easy Digital Downloads a2z

Easy Digital Downloads a2z

Easy Digital Downloads a2z

  • Home
  • Plugins
  • Shortcodes
  • APIs
  • Classes
  • Files
  • Hooks
  • Sitemap
  • Blog
Home / APIs / EDD_API::get_dates() – Sets up the dates used to retrieve earnings/sales

You appear to be a bot. Output may be restricted

Description

Sets up the dates used to retrieve earnings/sales

Usage

$array = EDD_API::get_dates( $args );

Parameters

$args
( array ) optional – Arguments to override defaults

Returns

array $dates

Source

File name: easy-digital-downloads/includes/api/class-edd-api.php
Lines:

1 to 100 of 231
  public function get_dates( $args = array() ) {
    $dates = array();

    $defaults = array(
      'type'      => '',
      'product'   => null,
      'date'      => null,
      'startdate' => null,
      'enddate'   => null,
    );

    $args = wp_parse_args( $args, $defaults );

    $current_time = current_time( 'timestamp' );

    if ( 'range' === $args['date'] ) {
      $startdate          = strtotime( $args['startdate'] );
      $enddate            = strtotime( $args['enddate'] );
      $dates['day_start'] = date( 'd', $startdate );
      $dates['day_end']   = date( 'd', $enddate );
      $dates['m_start']   = date( 'n', $startdate );
      $dates['m_end']     = date( 'n', $enddate );
      $dates['year']      = date( 'Y', $startdate );
      $dates['year_end']   = date( 'Y', $enddate );
    } else {
      // Modify dates based on predefined ranges
      switch ( $args['date'] ) :

        case 'this_month' :
          $dates['day']       = 1;
          $dates['day_end']   = date( 't', $current_time );
          $dates['m_start']   = date( 'n', $current_time );
          $dates['m_end']     = date( 'n', $current_time );
          $dates['year']      = date( 'Y', $current_time );
        break;

        case 'last_month' :
          $dates['day']       = 1;
          $dates['m_start']   = date( 'n', $current_time ) == 1 ? 12 : date( 'n', $current_time ) - 1;
          $dates['m_end']     = $dates['m_start'];
          $dates['year']      = date( 'n', $current_time ) == 1 ? date( 'Y', $current_time ) - 1 : date( 'Y', $current_time );
          $dates['day_end']   = date( 't', strtotime( $dates['year'] . '-' . $dates['m_start'] . '-' . $dates['day'] ) );
          break;

        case 'today' :
          $dates['day']       = date( 'd', $current_time );
          $dates['day_end']   = date( 'd', $current_time );
          $dates['m_start']   = date( 'n', $current_time );
          $dates['m_end']     = date( 'n', $current_time );
          $dates['year']      = date( 'Y', $current_time );
        break;

        case 'yesterday' :

          $year               = date( 'Y', $current_time );
          $month              = date( 'n', $current_time );
          $day                = date( 'd', $current_time );

          if ( $month == 1 && $day == 1 ) {

            $year -= 1;
            $month = 12;
            $day   = cal_days_in_month( CAL_GREGORIAN, $month, $year );

          } elseif ( $month > 1 && $day == 1 ) {

            $month -= 1;
            $day   = cal_days_in_month( CAL_GREGORIAN, $month, $year );

          } else {

            $day -= 1;

          }

          $dates['day']       = $day;
          $dates['day_end']   = $day;
          $dates['m_start']   = $month;
          $dates['m_end']     = $month;
          $dates['year']      = $year;

        break;

        case 'this_quarter' :
          $month_now = date( 'n', $current_time );

          $dates['day']           = 1;

          if ( $month_now <= 3 ) {

            $dates['m_start']   = 1;
            $dates['m_end']     = 3;
            $dates['year']      = date( 'Y', $current_time );

          } else if ( $month_now <= 6 ) {

            $dates['m_start']   = 4;
            $dates['m_end']     = 6;
            $dates['year']      = date( 'Y', $current_time );

 
[1] [2] [3] Next »

 View on GitHub View on Trac

Published: 26th November 2019 | Last updated: 12th September 2021

Primary Sidebar

Information

Function name: EDD_API::get_dates
Class ref: EDD_API
Plugin ref: Easy Digital Downloads
Version: 2.11.6
Sourcefile: includes/api/class-edd-api.php
File ref: includes/api/class-edd-api.php
Deprecated?: No
API Letters: A,D,E,G

Footer

Easy Digital Downloads a2z
Easy Digital Downloads a2z
Easy Digital Downloads a2z
WordPress 5.9.3
WordPress a2z
WordPress core a2z
Genesis Theme Framework a2z
Jetpack a2z
WordPress develop tests
Easy Digital Downloads a2z
WooCommerce a2z
Yoast SEO a2z
WordPress Blocks

Site:  edd.wp-a2z.org
© Copyright Easy Digital Downloads a2z 2014-2022. All rights reserved.


Website designed and developed by Herb Miller
Proudly powered by WordPress and oik plugins

  • Home
  • Blog
  • Sitemap
  • Sites