-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathClock.php
More file actions
62 lines (50 loc) · 1.16 KB
/
Copy pathClock.php
File metadata and controls
62 lines (50 loc) · 1.16 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
<?php
class Clock {
static protected $instance;
static function format( $format )
{
return self::$instance -> getDateTime() -> format ( $format );
}
static function date ( $format )
{
return self::$instance -> format ( $format );
}
static function setInstance( $a_instance )
{
self::$instance = $a_instance;
}
static function getDateTime()
{
if (!isset( self::$instance))
self::$instance = new RealClock();
return self::$instance -> _getDateTime();
}
static function addTime( $interval )
{
if(self::$instance instanceof ModelledClock )
{
self::$instance -> _addTime( $interval );
}
else throw new Exception ('programming error: cannot add time to RealClock instance' );
}
}
class RealClock extends Clock {
function _getDateTime()
{
return new DateTime();
}
}
class ModelledClock extends Clock {
private $datetime;
function __construct() {
$this -> datetime = new DateTime( '00010101T000000' );
}
function _getDateTime()
{
return $this -> datetime;
}
function _addTime( $date_interval )
{
$this -> datetime -> add( new DateInterval ( $date_interval ));
}
}