Completed
Push — master ( 57351b...4c8ea7 )
by Arjay
01:16
created

DateTime::showWeekNumber()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Yajra\DataTables\Html\Editor\Fields;
4
5
class DateTime extends Field
6
{
7
    protected $type = 'datetime';
8
9
    /**
10
     * Make a new instance of a field.
11
     *
12
     * @param string $name
13
     * @param string $label
14
     * @return Field|\DateTime
15
     */
16
    public static function make($name, $label = '')
17
    {
18
        return parent::make($name, $label)->format('YYYY-MM-DD hh:mm a');
19
    }
20
21
    /**
22
     * Set format to military time (24 hrs).
23
     *
24
     * @return Field|Time
25
     */
26
    public function military()
27
    {
28
        return $this->format('YYYY-MM-DD HH:mm');
29
    }
30
31
    /**
32
     * @param \DateTime $dateTime
33
     * @param string $format
34
     * @return $this
35
     * @see https://editor.datatables.net/examples/dates/options-min-max.html
36
     */
37
    public function minDate(\DateTime $dateTime, $format = 'Y-m-d')
38
    {
39
        $this->attributes['opts']['minDate'] = "new Date('" . $dateTime->format($format) . "')";
40
41
        return $this;
42
    }
43
44
    /**
45
     * @param \DateTime $dateTime
46
     * @param string $format
47
     * @return $this
48
     * @see https://editor.datatables.net/examples/dates/options-min-max.html
49
     */
50
    public function maxDate(\DateTime $dateTime, $format = 'Y-m-d')
51
    {
52
        $this->attributes['opts']['maxDate'] = "new Date('" . $dateTime->format($format) . "')";
53
54
        return $this;
55
    }
56
57
    /**
58
     * @param bool $state
59
     * @return $this
60
     * @see https://editor.datatables.net/examples/dates/options-week-numbers.html
61
     */
62
    public function showWeekNumber($state = true)
63
    {
64
        $this->attributes['opts']['showWeekNumber'] = $state;
65
66
        return $this;
67
    }
68
69
    /**
70
     * @param array $days
71
     * @return $this
72
     * @see https://editor.datatables.net/examples/dates/options-disable-days.html
73
     */
74
    public function disableDays(array $days)
75
    {
76
        $this->attributes['opts']['disableDays'] = $days;
77
78
        return $this;
79
    }
80
81
    /**
82
     * @param int $minutes
83
     * @return $this
84
     * @see https://editor.datatables.net/examples/dates/time-increment.html
85
     */
86
    public function minutesIncrement($minutes)
87
    {
88
        $this->attributes['opts']['minutesIncrement'] = $minutes;
89
90
        return $this;
91
    }
92
93
    /**
94
     * @param int $seconds
95
     * @return $this
96
     * @see https://editor.datatables.net/examples/dates/time-increment.html
97
     */
98
    public function secondsIncrement($seconds)
99
    {
100
        $this->attributes['opts']['secondsIncrement'] = $seconds;
101
102
        return $this;
103
    }
104
105
    /**
106
     * @param array $hours
107
     * @return $this
108
     * @see https://editor.datatables.net/examples/dates/datetime.html
109
     */
110
    public function hoursAvailable(array $hours)
111
    {
112
        $this->attributes['opts']['hoursAvailable'] = $hours;
113
114
        return $this;
115
    }
116
117
    /**
118
     * @param array $minutes
119
     * @return $this
120
     * @see https://editor.datatables.net/examples/dates/datetime.html
121
     */
122
    public function minutesAvailable(array $minutes)
123
    {
124
        $this->attributes['opts']['minutesAvailable'] = $minutes;
125
126
        return $this;
127
    }
128
}
129