/var/www/html_uk/wp-content/plugins/automatewoo/includes/Rest_Api/Utilities/DateHelper.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php

namespace AutomateWoo\Rest_Api\Utilities;

use 
AutomateWoo\Log;
use 
DateTimeInterface;

/**
 * DateHelper Trait
 *
 * @since 6.0.12
 */
trait DateHelper {

    
/**
     * Helper to get date data from a Log object.
     *
     * @param Log    $log  The log object.
     * @param string $type The type of date data to get. Valid options are '' (empty),
     *                     'opened', or 'clicked'.
     *
     * @return string
     */
    
private function get_date_response_from_log$log$type '' ) {
        
$type   = empty( $type ) ? $type "_{$type}";
        
$method "get_date{$type}";

        if ( ! 
is_callable( [ $log$method ] ) ) {
            return 
'';
        }

        
$date $log->$method();

        return ( 
$date instanceof DateTimeInterface ) ? $this->prepare_date_response$date ) : '';
    }

    
/**
     * Prepare a date object for a REST Response.
     *
     * @param DateTimeInterface $date A date object.
     *
     * @return string
     */
    
protected function prepare_date_responseDateTimeInterface $date ) {
        return 
mysql_to_rfc3339$date->format'Y-m-d H:i:s' ) );
    }
}