Skip to content

Commit 1d34ea4

Browse files
committed
Merge pull request #6 from ootatter/datetime_sec
add datetime validation rule regex date time sec for date time fields.
2 parents 65c0c82 + b304b6a commit 1d34ea4

3 files changed

Lines changed: 17 additions & 2 deletions

File tree

Model/Behavior/AddValidationRuleBehavior.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public function datetime(Model $model, $wordvalue, $format = 'ymd', $regex = nul
364364

365365
$value = array_shift($wordvalue);
366366

367-
$pattern = '%^(.+) (\d+:\d+[APap][Mm])$|^(.+) (\d+:\d+)$%';
367+
$pattern = '%^(.+) (\d+:\d+[APap][Mm])$|^(.+) (\d+:\d+|\d+:\d+:\d+)$%';
368368
preg_match($pattern, $value, $match);
369369
if(!empty($match[1]) && !empty($match[2])) {
370370
$date = $match[1];

Test/Case/Model/Behavior/AddValidationRuleTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,5 +434,20 @@ function testDatetimeYyyymmdd() {
434434

435435
}
436436

437+
function testDateTimeField(){
438+
$data = array(
439+
'ValidationRule' => array(
440+
'datetime_valid'=>array(
441+
'year' => '2013',
442+
'month' => '01',
443+
'day' => '24',
444+
)
445+
),
446+
);
447+
$this->ValidationRule->create( $data );
448+
$this->assertTrue( $this->ValidationRule->validates() );
449+
$this->assertEquals('2013-01-24 00:00:00',$this->ValidationRule->data['ValidationRule']['datetime_valid']);
450+
}
451+
437452

438453
}

Test/Fixture/ValidationRuleFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class ValidationRuleFixture extends CakeTestFixture {
1717
'telFaxJp' => array('type' => 'text', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
1818
'mobileEmailJp' => array('type' => 'text', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
1919
'passwordValid' => array('type' => 'text', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
20-
'datetime_valid' => array('type' => 'text', 'null' => true, 'default' => NULL, 'collate' => 'utf8_general_ci', 'charset' => 'utf8'),
20+
'datetime_valid' => array('type' => 'datetime', 'null' => true, 'default' => NULL),
2121
);
2222

2323
var $records = array(

0 commit comments

Comments
 (0)