|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace SilverStripe\ORM\Tests; |
|
4
|
|
|
|
|
5
|
|
|
use SilverStripe\i18n\i18n; |
|
6
|
|
|
use SilverStripe\ORM\FieldType\DBField; |
|
7
|
|
|
use SilverStripe\Dev\SapphireTest; |
|
8
|
|
|
use SilverStripe\ORM\FieldType\DBTime; |
|
9
|
|
|
use SilverStripe\Security\Member; |
|
10
|
|
|
|
|
11
|
|
|
class DBTimeTest extends SapphireTest |
|
12
|
|
|
{ |
|
13
|
|
|
protected function setUp() |
|
14
|
|
|
{ |
|
15
|
|
|
parent::setUp(); |
|
16
|
|
|
i18n::set_locale('en_NZ'); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
public function dataTestParse() |
|
20
|
|
|
{ |
|
21
|
|
|
return [ |
|
22
|
|
|
// Test am-pm conversion |
|
23
|
|
|
['11:01 pm', '23:01:00'], |
|
24
|
|
|
['11:01 am', '11:01:00'], |
|
25
|
|
|
['12:01 pm', '12:01:00'], |
|
26
|
|
|
['12:01 am', '00:01:00'], |
|
27
|
|
|
// Test seconds |
|
28
|
|
|
['11:01.01 pm', '23:01:01'], |
|
29
|
|
|
['12:01.01', '12:01:01'], |
|
30
|
|
|
]; |
|
31
|
|
|
} |
|
32
|
|
|
|
|
33
|
|
|
/** |
|
34
|
|
|
* @dataProvider dataTestParse |
|
35
|
|
|
* @param string $input |
|
36
|
|
|
* @param string $expected |
|
37
|
|
|
*/ |
|
38
|
|
|
public function testParse($input, $expected) |
|
39
|
|
|
{ |
|
40
|
|
|
$time = DBField::create_field('Time', $input); |
|
41
|
|
|
$this->assertEquals( |
|
42
|
|
|
$expected, |
|
43
|
|
|
$time->getValue(), |
|
44
|
|
|
"Date parsed from {$input} should be {$expected}" |
|
45
|
|
|
); |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
public function testNice() |
|
49
|
|
|
{ |
|
50
|
|
|
$time = DBTime::create_field('Time', '17:15:55'); |
|
51
|
|
|
$this->assertRegexp('#5:15:55 PM#i', $time->Nice()); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function testShort() |
|
55
|
|
|
{ |
|
56
|
|
|
$time = DBTime::create_field('Time', '17:15:55'); |
|
57
|
|
|
$this->assertRegexp('#5:15 PM#i', $time->Short()); |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
public function testTimeStamp() |
|
61
|
|
|
{ |
|
62
|
|
|
$time = DBTime::create_field('Time', '01:00:00'); |
|
63
|
|
|
$this->assertEquals(3600, $time->getTimestamp()); |
|
|
|
|
|
|
64
|
|
|
$time = DBTime::create_field('Time', '23:30:00'); |
|
65
|
|
|
$this->assertEquals(3600*23.5, $time->getTimestamp()); |
|
66
|
|
|
} |
|
67
|
|
|
} |
|
68
|
|
|
|