-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimeTravel.php
More file actions
71 lines (52 loc) · 1.32 KB
/
TimeTravel.php
File metadata and controls
71 lines (52 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/**
* Created by PhpStorm.
* User: quentin
* Date: 04/11/18
* Time: 13:08
*/
namespace TimeTravel;
class TimeTravel
{
private $start;
private $end;
public function getTravelInfo()
{
$start = $this->getStart();
$end = $this->getEnd();
$result = $start->diff($end);
return "il y a " . $result->format('%Y années, %m mois, %d jours, %h heures %i minutes, %s secondes') . " entre les deux dates";
}
public function setStart()
{
$this->start = new \DateTime('1985-12-31');;
}
public function getStart()
{
return $this->start;
}
public function getEnd()
{
return $this->end;
}
public function findDate($interval)
{
$jump = new \DateInterval('PT' . $interval . 'S');
$end = new \DateTime();
$end = clone $this->start;
$end = $end->sub($jump);
$this->end = $end;
return $this->end;
}
public function backToFutureStepByStep($jump)
{
$result = [];
$start = $this->getStart();
$end = $this->getEnd();
$steps = new \DatePeriod($end, $jump, $start, \DatePeriod::EXCLUDE_START_DATE);
foreach ($steps as $step) {
$result[] = $step->format('M - d - Y - H - i');
}
return $result;
}
}