Completed
Push — 16470-hide-recipients-on-bulk-... ( 9688d4 )
by Shawn
02:27
created

DateFormat   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 14
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 14
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A dateFormat() 0 11 3
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: sdibble
5
 * Date: 12/12/2016
6
 * Time: 12:11 PM
7
 */
8
9
namespace SET\Handlers;
10
11
use Carbon\Carbon;
12
13
trait DateFormat
14
{
15
    public function dateFormat($date)
16
    {
17
        // Already Y-m-d
18
        if (preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $date)) return $date;
19
20
        //Convert Carbon to Y-m-d
21
        if ($date instanceof Carbon) return $date->format('Y-m-d');
22
23
        // sqlite Y-m-d H:i:s to Y-m-d
24
        return Carbon::createFromFormat('Y-m-d H:i:s', $date)->format('Y-m-d');
25
    }
26
}