|
@@ 109-124 (lines=16) @@
|
| 106 |
|
* @return string |
| 107 |
|
* @throws \Exception |
| 108 |
|
*/ |
| 109 |
|
public function startOfWeek($date = null) |
| 110 |
|
{ |
| 111 |
|
$now = clone $this->dateTimeProvider->get(); |
| 112 |
|
|
| 113 |
|
if ($date) { |
| 114 |
|
$now = $this->modifyDate($now, $date); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
|
$year = $now->format('o'); // o = ISO-8601 year number |
| 118 |
|
$week = $now->format('W'); // W = ISO-8601 week number of year, weeks starting on Monday |
| 119 |
|
|
| 120 |
|
$startOfWeek = $now->setISODate($year, $week); |
| 121 |
|
$startOfWeek->setTime(0, 0, 0); |
| 122 |
|
|
| 123 |
|
return $startOfWeek->format(\DateTime::ISO8601); |
| 124 |
|
} |
| 125 |
|
|
| 126 |
|
/** |
| 127 |
|
* Gets the first day of the month for the specified date with the hour 00:00:00 |
|
@@ 134-149 (lines=16) @@
|
| 131 |
|
* @return string |
| 132 |
|
* @throws \Exception |
| 133 |
|
*/ |
| 134 |
|
public function startOfMonth($date = null) |
| 135 |
|
{ |
| 136 |
|
$now = clone $this->dateTimeProvider->get(); |
| 137 |
|
|
| 138 |
|
if ($date) { |
| 139 |
|
$now = $this->modifyDate($now, $date); |
| 140 |
|
} |
| 141 |
|
|
| 142 |
|
$year = $now->format('Y'); |
| 143 |
|
$month = $now->format('m'); |
| 144 |
|
|
| 145 |
|
$startOfMonth = $now->setDate($year, $month, 1); |
| 146 |
|
$startOfMonth->setTime(0, 0, 0); |
| 147 |
|
|
| 148 |
|
return $startOfMonth->format(\DateTime::ISO8601); |
| 149 |
|
} |
| 150 |
|
|
| 151 |
|
/** |
| 152 |
|
* Gets the first day of the year for the specified date with the hour 00:00:00 |