1 <?php
2 /* --------------------------------------------------------------
3 CustomerDateOfBirth.inc.php 2015-06-26 gm
4 Gambio GmbH
5 http://www.gambio.de
6 Copyright (c) 2015 Gambio GmbH
7 Released under the GNU General Public License (Version 2)
8 [http://www.gnu.org/licenses/gpl-2.0.html]
9 --------------------------------------------------------------
10 */
11
12 /**
13 * Value Object
14 *
15 * Class CustomerDateOfBirth
16 *
17 * Represents a customer birth date
18 *
19 * @category System
20 * @package Customer
21 * @subpackage ValueObjects
22 * @extends DateTime
23 */
24 class CustomerDateOfBirth extends DateTime
25 {
26 /**
27 * Is null date?
28 * @var bool
29 */
30 protected $isNullDate = false;
31
32
33 /**
34 * Constructor of the class CustomerDateOfBirth.
35 *
36 * @param string $p_dateOfBirth Customer's date of birth.
37 */
38 public function __construct($p_dateOfBirth = '0000-01-01 00:00:00')
39 {
40 $dateOfBirth = $p_dateOfBirth;
41 if(strpos($dateOfBirth, '0000') === 0 || empty($dateOfBirth) || $dateOfBirth === '00.00.0000')
42 {
43 $dateOfBirth = '0000-01-01 00:00:00';
44 }
45
46 if($dateOfBirth === '0000-01-01 00:00:00')
47 {
48 $this->isNullDate = true;
49 }
50
51 parent::__construct($dateOfBirth);
52 }
53
54
55 /**
56 * Formats a date by a given pattern and ensures, that dates that represent empty data are formatted to
57 * '0000-00-00 00:00:00'
58 *
59 * @param string $p_format Date format.
60 *
61 * @return mixed|string Formatted date.
62 */
63 public function format($p_format)
64 {
65 $formattedDate = parent::format($p_format);
66 if($this->isNullDate)
67 {
68 $formattedDate = preg_replace('/\d/i', '0', $formattedDate);
69 }
70
71 return $formattedDate;
72 }
73 }