Skip to content

Commit

Permalink
Fix setField Issue on timestamps when no dateFormat was set
Browse files Browse the repository at this point in the history
  • Loading branch information
airmoi committed Aug 3, 2017
1 parent 3f5389e commit d3ca039
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Object/Record.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public function setField($field, $value, $repetition = 0)
$fieldFormat = $this->layout->getField($field)->result;

if ($fieldFormat == 'date' || $fieldFormat == 'timestamp') {
$dateFormat = $this->fm->getProperty('dateFormat');
$dateFormat = $this->fm->getProperty('dateFormat') === null ? 'm/d/Y' : $this->fm->getProperty('dateFormat');
try {
if ($fieldFormat == 'date') {
$convertedValue = DateFormat::convert($value, $dateFormat, 'm/d/Y');
Expand Down
48 changes: 46 additions & 2 deletions tests/unit/src/Object/FieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,65 @@ public function testValidateNumericOnly()
*/
public function testValidateFourDigitDate()
{
$validValues = ["06/17/2017"];
//Test with date Field
//DateFormat auto convert 2 to 4 digits
$validValues = ["06/17/2017", "06/17/17"];
foreach ($validValues as $value) {
$this->record->setField('dateFourDigit_field', $value);
$this->record->validate('dateFourDigit_field');
}


$invalidValues = ["06/17/17"];
/*$invalidValues = ["06/17/17"];
foreach ($invalidValues as $value) {
$this->fm->dateFormat = 'm/d/y';
$e = null;
try {
$this->record->setField('dateFourDigit_field', $value);
$this->record->validate('dateFourDigit_field');
} catch (FileMakerValidationException $e) {
}
$this->assertInstanceOf(FileMakerValidationException::class, $e);
}*/

//Test with Timestamp Field
//DateFormat auto convert 2 to 4 digits
$validValues = ["06/17/2017 00:00:00", "06/17/17 00:00:00"];
foreach ($validValues as $value) {
$this->record->setField('timestamp_field', $value);
$this->record->validate('timestamp_field');
}


/*$invalidValues = ["06/17/17 00:00:00"];
foreach ($invalidValues as $value) {
$e = null;
try {
$this->record->setField('timestamp_field', $value);
$this->record->validate('timestamp_field');
} catch (FileMakerValidationException $e) {
}
$this->assertInstanceOf(FileMakerValidationException::class, $e);
}*/

//Test with text Fields
$validValues = ["06/17/2017"];
foreach ($validValues as $value) {
$this->record->setField('textFourDigitDate_field', $value);
$this->record->validate('textFourDigitDate_field');
}


$invalidValues = ["06/17/17"];
foreach ($invalidValues as $value) {
$e = null;
try {
$this->record->setField('textFourDigitDate_field', $value);
$this->record->validate('textFourDigitDate_field');
} catch (FileMakerValidationException $e) {

}
$this->assertInstanceOf(FileMakerValidationException::class, $e);
}
Expand Down

0 comments on commit d3ca039

Please sign in to comment.