|
23 | 23 |
|
24 | 24 | use App\Libs\Config; |
25 | 25 | use App\Validator\VolumesRequestValidator; |
| 26 | +use Carbon\Carbon; |
26 | 27 | use Core\Db\CDBQuery; |
27 | 28 | use Core\Db\DBPagination; |
28 | 29 | use Core\Utils\CUtils; |
29 | 30 | use App\Table\VolumeTable; |
30 | 31 | use App\Table\PoolTable; |
31 | | -use Date_HumanDiff; |
32 | 32 | use Exception; |
33 | 33 | use Psr\Http\Message\ServerRequestInterface as Request; |
34 | 34 | use GuzzleHttp\Psr7\Response; |
@@ -178,21 +178,25 @@ public function index(Request $request, Response $response): Response |
178 | 178 | 'where' => $where ]); |
179 | 179 |
|
180 | 180 | foreach ($pagination->paginate($this->volumeTable, $sqlQuery, $countquery, $params) as $volume) { |
181 | | - // Calculate volume expiration |
182 | | - // If volume have already been used |
| 181 | + /** |
| 182 | + * Calculate volume expiration only if volume has already been written |
| 183 | + */ |
183 | 184 | if ($volume['lastwritten'] != "0000-00-00 00:00:00" && !is_null($volume['lastwritten'])) { |
184 | | - // Calculate expiration date only if volume status is Full or Used |
| 185 | + /** |
| 186 | + * Calculate expiration date only if volume status is Full or Used |
| 187 | + */ |
185 | 188 | if ($volume['volstatus'] == 'Full' || $volume['volstatus'] == 'Used') { |
186 | | - $dh = new Date_HumanDiff(); |
187 | | - $dateTimeFormatShort = explode(' ', $this->config->get('datetime_format', 'Y-m-d H:i:s')); |
188 | | - $volume['expire'] = date( |
189 | | - $dateTimeFormatShort[0], |
190 | | - strtotime($volume['lastwritten']) + $volume['volretention'] |
191 | | - ); |
192 | | - $volume['expire'] = $dh->get( |
193 | | - strtotime($volume['lastwritten']) + $volume['volretention'], |
194 | | - time() |
195 | | - ) . ' (' . $volume['expire'] . ')'; |
| 189 | + if ($this->config->has('datetime_format_short')) { |
| 190 | + $dateTimeFormatShort = $this->config->get('datetime_format_short'); |
| 191 | + } else { |
| 192 | + $dateTimeFormatShort = explode(' ', $this->config->get('datetime_format', 'Y-m-d H:i:s')); |
| 193 | + $dateTimeFormatShort = $dateTimeFormatShort[0]; |
| 194 | + } |
| 195 | + |
| 196 | + $volumeExpiration = Carbon::parse($volume['lastwritten'])->addSeconds($volume['volretention']); |
| 197 | + $volume['expire'] = |
| 198 | + $volumeExpiration->format($dateTimeFormatShort) . |
| 199 | + ' (in ' . (int) Carbon::now()->diffInDays($volumeExpiration) . ' day(s) )'; |
196 | 200 | } else { |
197 | 201 | $volume['expire'] = 'n/a'; |
198 | 202 | } |
|
0 commit comments