Ticket #852 (closed defect: fixed)

Opened 16 months ago

Last modified 16 months ago

Validators for 'time' and 'timestamp' fields do not exist

Reported by: mark.pearson Owned by: somebody
Priority: minor Milestone: 0.10.4
Component: Other Version: 0.10.0
Severity: Keywords: Validators time timestamp
Cc: Has Test:
Status: Has Patch:

Description

The Doctrine manual specifies in sections 3.4.4.11 and 3.4.4.12 that 'timestamp' and 'time' field types are available. However, turning on validation with Doctrine::VALIDATE_ALL highlights some problems with validation of these field types.

The class below is used as a testbed to reproduce these problems:

class DateTimeTest extends Doctrine_Record {
    public function setTableDefinition() {
        $this->hasColumn('theTime', 'time', null, array('notnull'));
        $this->hasColumn('theTimestamp', 'timestamp', null, array('notnull'));
    }
    
    public function setUp() {      
    }
}

Running the following script:

require_once('...Doctrine/lib/Doctrine.php');
spl_autoload_register(array('Doctrine', 'autoload'));

$db = Doctrine_Manager::connection('mysql://....');

Doctrine::loadModels('models/types'); // This is where DateTimeTest.php lives
Doctrine_Manager::getInstance()->setAttribute(Doctrine::ATTR_VALIDATE, Doctrine::VALIDATE_ALL);

$dtt = new DateTimeTest;

$dtt->theTime = '12:34:56';
$dtt->theTimestamp = 'This is not a timestamp';

if (!$dtt->isValid()) {
    print_r($dtt->getErrorStack());
}

produces the following (incorrect output)

Doctrine_Validator_ErrorStack Object
(
    [errors:protected] => Array
        (
            [theTime] => Array
                (
                    [0] => type
                )

        )

    [classname:protected] => DateTimeTest
    [_locator:protected] => 
    [_resources:protected] => Array
        (
        )

)

The 'time' field has a valid value according to the manual but fails validation whilst the 'timestamp' field has an invalid value but passes.

Attachments

patch.txt (1.1 KB) - added by mark.pearson 16 months ago.
Patch for Validator.php
Time.php (2.0 KB) - added by mark.pearson 16 months ago.
Time validator class
Timestamp.php (2.2 KB) - added by mark.pearson 16 months ago.
Timestamp validator class

Change History

Changed 16 months ago by mark.pearson

Patch for Validator.php

Changed 16 months ago by mark.pearson

Time validator class

Changed 16 months ago by mark.pearson

Timestamp validator class

Changed 16 months ago by jwage

  • status changed from new to closed
  • resolution set to fixed

(In [4069]) fixes #852

Note: See TracTickets for help on using tickets.