AbstractLoomFactory::fromDateTime()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 7
rs 9.4286
cc 2
eloc 4
nc 2
nop 2
1
<?php
2
/**
3
 * Loom
4
 * 
5
 * @copyright   Copyright (c) 2014 Warrick Bayman.
6
 * @author		Warrick Bayman <[email protected]>
7
 * @license     MIT License http://opensource.org/licenses/MIT
8
 * 
9
 */
10
11
namespace Loom;
12
13
14
use Loom\Contracts\LoomFactoryInterface;
15
16
/**
17
 * Class AbstractLoomFactory
18
 *
19
 * @package Loom
20
 */
21
abstract class AbstractLoomFactory implements LoomFactoryInterface
22
{
23
    /**
24
     * Create a new Loom instance
25
     *
26
     * @param AbstractUnit $unit
27
     *
28
     * @return Loom
29
     */
30
    abstract protected function createLoom(AbstractUnit $unit);
31
32
33
    /**
34
     * Create from microseconds
35
     * @param float $microseconds
36
     *
37
     * @return Loom
38
     */
39
    public function fromMicroseconds($microseconds)
40
    {
41
        return $this->createLoom(new Microseconds($microseconds));
42
    }
43
44
45
    /**
46
     * Create from milliseconds
47
     *
48
     * @param int $milliseconds
49
     *
50
     * @return Loom
51
     */
52
    public function fromMilliseconds($milliseconds)
53
    {
54
        return $this->createLoom(new Milliseconds($milliseconds));
55
    }
56
57
58
    /**
59
     * Create from seconds
60
     *
61
     * @param int $seconds
62
     *
63
     * @return Loom
64
     */
65
    public function fromSeconds($seconds)
66
    {
67
        return $this->createLoom(new Seconds($seconds));
68
    }
69
70
71
    /**
72
     * Create from minutes
73
     *
74
     * @param int $minutes
75
     *
76
     * @return Loom
77
     */
78
    public function fromMinutes($minutes)
79
    {
80
        return $this->createLoom(new Minutes($minutes));
81
    }
82
83
84
    /**
85
     * Create from hours
86
     *
87
     * @param int $hours
88
     *
89
     * @return Loom
90
     */
91
    public function fromHours($hours)
92
    {
93
        return $this->createLoom(new Hours($hours));
94
    }
95
96
97
    /**
98
     * Create from days
99
     *
100
     * @param int $days
101
     *
102
     * @return Loom
103
     */
104
    public function fromDays($days)
105
    {
106
        return $this->createLoom(new Days($days));
107
    }
108
109
110
    /**
111
     * Create from weeks
112
     *
113
     * @param int $weeks
114
     *
115
     * @return Loom
116
     */
117
    public function fromWeeks($weeks)
118
    {
119
        return $this->createLoom(new Weeks($weeks));
120
    }
121
122
123
    /**
124
     * Create from months
125
     *
126
     * @param int      $months
127
     * @param null|int $daysOfMonth
128
     *
129
     * @return Loom
130
     */
131
    public function fromMonths($months, $daysOfMonth = null)
132
    {
133
        return $this->createLoom(new Months($months, $daysOfMonth));
134
    }
135
136
137
    /**
138
     * Create from years
139
     *
140
     * @param int  $years
141
     * @param bool $solar
142
     *
143
     * @return Loom
144
     */
145
    public function fromYears($years, $solar = false)
146
    {
147
        return $this->createLoom(new Years($years, $solar));
148
    }
149
150
151
    /**
152
     * Create from a DateTime object
153
     *
154
     * @param  \DateTime    $dateTime
155
     * @param \DateTimeZone $timeZone
156
     *
157
     * @return Loom
158
     * @see    AbstractLoomFactory::fromTime()
159
     *
160
     */
161
    public function fromDateTime(\DateTime $dateTime, \DateTimeZone $timeZone = null)
162
    {
163
        if ($timeZone) {
164
            $dateTime->setTimezone($timeZone);
165
        }
166
        return $this->createLoom(new Seconds($dateTime->getTimestamp()));
167
    }
168
169
170
    /**
171
     * Make a copy of a Loom object
172
     *
173
     * @param Loom $loom
174
     * @deprecated 1.1
175
     *
176
     * @return Loom
177
     */
178
    public function copy(Loom $loom)
179
    {
180
        return $this->fromLoom($loom);
181
    }
182
183
184
    /**
185
     * Make a copy of the Loom object
186
     *
187
     * @param Loom $loom
188
     *
189
     * @return mixed
190
     */
191
    public function fromLoom(Loom $loom)
192
    {
193
        return $this->createLoom(new Milliseconds($loom->getMilliseconds()));
194
    }
195
}
196