Skip to content

Commit 7d20714

Browse files
authored
Rename methods to more natural names (#11)
1 parent ab9fdbc commit 7d20714

File tree

8 files changed

+197
-197
lines changed

8 files changed

+197
-197
lines changed

src/DateRange.php

Lines changed: 39 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,19 @@ final class DateRange implements DateRangeInterface, JsonSerializable
3030
private $state;
3131

3232
/**
33-
* @param DateTimeInterface|null $startTime
34-
* @param DateTimeInterface|null $endTime
33+
* @param DateTimeInterface|null $startDate
34+
* @param DateTimeInterface|null $endDate
3535
*/
36-
public function __construct(DateTimeInterface $startTime = null, DateTimeInterface $endTime = null)
36+
public function __construct(DateTimeInterface $startDate = null, DateTimeInterface $endDate = null)
3737
{
3838
$state = new UndefinedRange();
3939

40-
if (isset($startTime)) {
41-
$state = $state->setStartTime($startTime);
40+
if (isset($startDate)) {
41+
$state = $state->setStartDate($startDate);
4242
}
4343

44-
if (isset($endTime)) {
45-
$state = $state->setEndTime($endTime);
44+
if (isset($endDate)) {
45+
$state = $state->setEndDate($endDate);
4646
}
4747

4848
$this->state = $state;
@@ -57,8 +57,8 @@ public function __toString(): string
5757
{
5858
return sprintf(
5959
'%s/%s',
60-
$this->state->formatStartTime('c') ?: '-',
61-
$this->state->formatEndTime('c') ?: '-'
60+
$this->state->formatStartDate('c') ?: '-',
61+
$this->state->formatEndDate('c') ?: '-'
6262
);
6363
}
6464

@@ -68,11 +68,11 @@ public function __toString(): string
6868
public function __debugInfo()
6969
{
7070
return [
71-
'startTime' => $this->state->hasStartTime()
72-
? $this->state->getStartTime()
71+
'startDate' => $this->state->hasStartDate()
72+
? $this->state->getStartDate()
7373
: null,
74-
'endTime' => $this->state->hasEndTime()
75-
? $this->state->getEndTime()
74+
'endDate' => $this->state->hasEndDate()
75+
? $this->state->getEndDate()
7676
: null,
7777
];
7878
}
@@ -87,90 +87,90 @@ public function __debugInfo()
8787
public function jsonSerialize(): array
8888
{
8989
return [
90-
'startTime' => $this->state->formatStartTime(),
91-
'endTime' => $this->state->formatEndTime(),
90+
'startDate' => $this->state->formatStartDate(),
91+
'endDate' => $this->state->formatEndDate(),
9292
];
9393
}
9494

9595
/**
9696
* {@inheritdoc}
9797
*/
98-
public function hasStartTime(): bool
98+
public function hasStartDate(): bool
9999
{
100-
return $this->state->hasStartTime();
100+
return $this->state->hasStartDate();
101101
}
102102

103103
/**
104104
* {@inheritdoc}
105105
*/
106-
public function hasEndTime(): bool
106+
public function hasEndDate(): bool
107107
{
108-
return $this->state->hasEndTime();
108+
return $this->state->hasEndDate();
109109
}
110110

111111
/**
112112
* {@inheritdoc}
113113
*/
114-
public function getStartTime(): DateTimeInterface
114+
public function getStartDate(): DateTimeInterface
115115
{
116-
return $this->state->getStartTime();
116+
return $this->state->getStartDate();
117117
}
118118

119119
/**
120120
* {@inheritdoc}
121121
*/
122-
public function getEndTime(): DateTimeInterface
122+
public function getEndDate(): DateTimeInterface
123123
{
124-
return $this->state->getEndTime();
124+
return $this->state->getEndDate();
125125
}
126126

127127
/**
128128
* {@inheritdoc}
129129
*/
130-
public function setStartTime(DateTimeInterface $time): DateRangeInterface
130+
public function setStartDate(DateTimeInterface $start): DateRangeInterface
131131
{
132132
$clone = clone $this;
133-
$clone->state = $clone->state->setStartTime($time);
133+
$clone->state = $clone->state->setStartDate($start);
134134

135135
return $clone;
136136
}
137137

138138
/**
139139
* {@inheritdoc}
140140
*/
141-
public function setEndTime(DateTimeInterface $time): DateRangeInterface
141+
public function setEndDate(DateTimeInterface $end): DateRangeInterface
142142
{
143143
$clone = clone $this;
144-
$clone->state = $clone->state->setEndTime($time);
144+
$clone->state = $clone->state->setEndDate($end);
145145

146146
return $clone;
147147
}
148148

149149
/**
150150
* {@inheritdoc}
151151
*/
152-
public function isStartedAt(DateTimeInterface $time): bool
152+
public function isStartedOn(DateTimeInterface $date): bool
153153
{
154-
return $this->hasStartTime() && $this->state->compareStartTime($time) === 0;
154+
return $this->hasStartDate() && $this->state->compareStartDate($date) === 0;
155155
}
156156

157157
/**
158158
* {@inheritdoc}
159159
*/
160-
public function isEndedAt(DateTimeInterface $time): bool
160+
public function isEndedOn(DateTimeInterface $date): bool
161161
{
162-
return $this->hasEndTime() && $this->state->compareEndTime($time) === 0;
162+
return $this->hasEndDate() && $this->state->compareEndDate($date) === 0;
163163
}
164164

165165
/**
166166
* {@inheritdoc}
167167
*/
168168
public function isStarted(): bool
169169
{
170-
if ($this->hasStartTime()) {
171-
return $this->state->compareStartTime(new DateTimeImmutable()) <= 0;
170+
if ($this->hasStartDate()) {
171+
return $this->state->compareStartDate(new DateTimeImmutable()) <= 0;
172172
} else {
173-
return $this->hasEndTime();
173+
return $this->hasEndDate();
174174
}
175175
}
176176

@@ -179,32 +179,32 @@ public function isStarted(): bool
179179
*/
180180
public function isEnded(): bool
181181
{
182-
return $this->hasEndTime() && $this->state->compareEndTime(new DateTimeImmutable()) < 0;
182+
return $this->hasEndDate() && $this->state->compareEndDate(new DateTimeImmutable()) < 0;
183183
}
184184

185185
/**
186186
* {@inheritdoc}
187187
*/
188188
public function getDateInterval(): DateInterval
189189
{
190-
return $this->getStartTime()->diff($this->getEndTime());
190+
return $this->getStartDate()->diff($this->getEndDate());
191191
}
192192

193193
/**
194194
* {@inheritdoc}
195195
*/
196196
public function getDatePeriod(DateInterval $interval, int $option = 0): DatePeriod
197197
{
198-
return new DatePeriod($this->getStartTime(), $interval, $this->getEndTime(), $option);
198+
return new DatePeriod($this->getStartDate(), $interval, $this->getEndDate(), $option);
199199
}
200200

201201
/**
202202
* {@inheritdoc}
203203
*/
204204
public function split(DateInterval $interval): Traversable
205205
{
206-
$startDate = $this->getStartTime();
207-
$endDate = $this->getEndTime();
206+
$startDate = $this->getStartDate();
207+
$endDate = $this->getEndDate();
208208
$period = $this->getDatePeriod($interval, DatePeriod::EXCLUDE_START_DATE);
209209

210210
foreach ($period as $date) {

src/DateRangeInterface.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -28,78 +28,78 @@ interface DateRangeInterface
2828
public function __toString(): string;
2929

3030
/**
31-
* Returns whether the starting time is defined.
31+
* Returns whether the starting date is defined.
3232
*
3333
* @return bool
3434
*/
35-
public function hasStartTime(): bool;
35+
public function hasStartDate(): bool;
3636

3737
/**
38-
* Returns whether the ending time is defined.
38+
* Returns whether the ending date is defined.
3939
*
4040
* @return bool
4141
*/
42-
public function hasEndTime(): bool;
42+
public function hasEndDate(): bool;
4343

4444
/**
45-
* Returns the starting time point.
45+
* Returns the starting date point.
4646
*
4747
* @return DateTimeInterface
4848
*/
49-
public function getStartTime(): DateTimeInterface;
49+
public function getStartDate(): DateTimeInterface;
5050

5151
/**
52-
* Returns the ending time point.
52+
* Returns the ending date point.
5353
*
5454
* @return DateTimeInterface
5555
*/
56-
public function getEndTime(): DateTimeInterface;
56+
public function getEndDate(): DateTimeInterface;
5757

5858
/**
59-
* Sets new starting time point.
59+
* Sets new starting date point.
6060
*
61-
* @param DateTimeInterface $time
61+
* @param DateTimeInterface $start
6262
*
6363
* @return DateRangeInterface
6464
*/
65-
public function setStartTime(DateTimeInterface $time): DateRangeInterface;
65+
public function setStartDate(DateTimeInterface $start): DateRangeInterface;
6666

6767
/**
68-
* Sets new ending time point.
68+
* Sets new ending date point.
6969
*
70-
* @param DateTimeInterface $time
70+
* @param DateTimeInterface $end
7171
*
7272
* @return DateRangeInterface
7373
*/
74-
public function setEndTime(DateTimeInterface $time): DateRangeInterface;
74+
public function setEndDate(DateTimeInterface $end): DateRangeInterface;
7575

7676
/**
77-
* Tells whether range is started at specific time.
77+
* Tells whether range is started at specific date.
7878
*
79-
* @param DateTimeInterface $time
79+
* @param DateTimeInterface $date
8080
*
8181
* @return bool
8282
*/
83-
public function isStartedAt(DateTimeInterface $time): bool;
83+
public function isStartedOn(DateTimeInterface $date): bool;
8484

8585
/**
86-
* Tells whether range is ended at specific time.
86+
* Tells whether range is ended at specific date.
8787
*
88-
* @param DateTimeInterface $time
88+
* @param DateTimeInterface $date
8989
*
9090
* @return bool
9191
*/
92-
public function isEndedAt(DateTimeInterface $time): bool;
92+
public function isEndedOn(DateTimeInterface $date): bool;
9393

9494
/**
95-
* Tells whether range is started at current time.
95+
* Tells whether range is started at current date.
9696
*
9797
* @return bool
9898
*/
9999
public function isStarted(): bool;
100100

101101
/**
102-
* Tells whether range is ended at current time.
102+
* Tells whether range is ended at current date.
103103
*
104104
* @return bool
105105
*/

src/States/FiniteRange.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,72 +13,72 @@ final class FiniteRange extends RangeState
1313
/**
1414
* @var DateTimeInterface
1515
*/
16-
private $startTime;
16+
private $startDate;
1717

1818
/**
1919
* @var DateTimeInterface
2020
*/
21-
private $endTime;
21+
private $endDate;
2222

2323
/**
24-
* @param DateTimeInterface $startTime
25-
* @param DateTimeInterface $endTime
24+
* @param DateTimeInterface $startDate
25+
* @param DateTimeInterface $endDate
2626
*/
27-
public function __construct(DateTimeInterface $startTime, DateTimeInterface $endTime)
27+
public function __construct(DateTimeInterface $startDate, DateTimeInterface $endDate)
2828
{
29-
if ($endTime <= $startTime) {
30-
throw new DateRangeException('Invalid end time, must be after start');
29+
if ($endDate <= $startDate) {
30+
throw new DateRangeException('Invalid end date, must be after start');
3131
}
3232

33-
$this->startTime = $startTime;
34-
$this->endTime = $endTime;
33+
$this->startDate = $startDate;
34+
$this->endDate = $endDate;
3535
}
3636

3737
/**
3838
* {@inheritdoc}
3939
*/
40-
public function hasStartTime(): bool
40+
public function hasStartDate(): bool
4141
{
4242
return true;
4343
}
4444

4545
/**
4646
* {@inheritdoc}
4747
*/
48-
public function hasEndTime(): bool
48+
public function hasEndDate(): bool
4949
{
5050
return true;
5151
}
5252

5353
/**
5454
* {@inheritdoc}
5555
*/
56-
public function getStartTime(): DateTimeInterface
56+
public function getStartDate(): DateTimeInterface
5757
{
58-
return $this->startTime;
58+
return $this->startDate;
5959
}
6060

6161
/**
6262
* {@inheritdoc}
6363
*/
64-
public function getEndTime(): DateTimeInterface
64+
public function getEndDate(): DateTimeInterface
6565
{
66-
return $this->endTime;
66+
return $this->endDate;
6767
}
6868

6969
/**
7070
* {@inheritdoc}
7171
*/
72-
public function setStartTime(DateTimeInterface $time): RangeState
72+
public function setStartDate(DateTimeInterface $start): RangeState
7373
{
74-
return new FiniteRange($time, $this->endTime);
74+
return new FiniteRange($start, $this->endDate);
7575
}
7676

7777
/**
7878
* {@inheritdoc}
7979
*/
80-
public function setEndTime(DateTimeInterface $time): RangeState
80+
public function setEndDate(DateTimeInterface $end): RangeState
8181
{
82-
return new FiniteRange($this->startTime, $time);
82+
return new FiniteRange($this->startDate, $end);
8383
}
8484
}

0 commit comments

Comments
 (0)