-
Notifications
You must be signed in to change notification settings - Fork 1
/
CurrencyRateDate.php
65 lines (51 loc) · 1.18 KB
/
CurrencyRateDate.php
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
<?php
/**
* (c) itmedia.by <info@itmedia.by>
*/
namespace Submarine\NbrbExchangeRatesBundle;
class CurrencyRateDate
{
/**
* @var \DateTime
*/
private $date;
/**
* @var float
*/
private $rate;
/**
* CurrencyRateDate constructor.
* @param \DateTime $date
* @param float $rate
*/
public function __construct(\DateTime $date, $rate)
{
$this->date = $date;
$this->rate = $rate;
}
static public function createFromXML(\SimpleXMLElement $xmlElement = null)
{
$dateArray = explode('/', (string)$xmlElement->attributes()[0]);
if (count($dateArray) === 3) {
$dateTime = new \DateTime();
$dateTime->setDate($dateArray[2], $dateArray[0], $dateArray[1]);
$dateTime->setTime(0, 0, 0);
return new CurrencyRateDate($dateTime, (float)$xmlElement->Rate);
}
return new CurrencyRateDate(new \DateTime(), null);
}
/**
* @return float
*/
public function getRate()
{
return $this->rate;
}
/**
* @return \DateTime
*/
public function getDate()
{
return $this->date;
}
}