Details
-
Type:
Bug
-
Status:
Resolved
-
Priority:
Major
-
Resolution: Won't Fix
-
Affects Version/s: 1.6.0, 1.6.1, 1.6.2, 1.7 Preview Release
-
Fix Version/s: 1.8.0
-
Component/s: Zend_Validate
-
Labels:None
Description
I understand what you are saying and that is why I insist on this... and posted a new example.
I understand changer the timezone after the a Zend_Date object has been instanciated will result in problem as Zend_Date should be based on the default timezone.
In my environement, the default timezone is not set in the php.ini, so I set it ONCE
in the bootstrap; then I have some problems with the date validator. So in my last example, I tried to reproduce the problem in a simple script (without MVC, forms and so on...). I set the default time zone in the begining of the script (and I won't change it) and I get different result if it is set to the US or China... Same thing if I change the default timezone explicitly in the php.ini and I do not set it in the script...
I get an unexpected result when I define the format 'yyyy/MM/dd' + timezone China but not with the default format.
------------------------------------------------------
Sorry it seems I don't have the right to add a comment... That's why I am editing the issue.
About the issue; If this behavior is normal, the documentation at http://framework.zend.com/manual/en/zend.date.html#zend.date.setdefaulttimezone is ambiguous or wrong then.
About the code I sent, even if I set the default timezone once then instantiate Zend_date
date_default_timezone_set("Asia/Taipei"); require_once 'Zend/Validate/Date.php'; $date = "1980/06/30"; $vali = new Zend_Validate_Date('yyyy/MM/dd'); print "\n".date_default_timezone_get()."\n"; $result = $vali->isValid($date); var_dump($result);
outputs:
Asia/Taipei
bool(false)
In the documentation it is specified:
"When creating Zend_Date instances, their timezone will automatically become the current default timezone!"
So is there something I do not get? ![]()
------------------------------------------------------
This is another spooky example:
CODE:
require_once 'Zend/Validate/Date.php'; $date = "1980/06/30"; $vali = new Zend_Validate_Date('yyyy/MM/dd'); print "\n".date_default_timezone_get()."\n"; $result = $vali->isValid($date); var_dump($result); date_default_timezone_set("Asia/Taipei"); print "\n".date_default_timezone_get()."\n"; $result = $vali->isValid($date); var_dump($result);
OUTPUT:
America/New_York bool(true) Asia/Taipei bool(false)
--------------------------------------------
For some specific dates, Zend_Validate_Date when defining a specific format does not return an expected result:
Expected behavior
$date = "1980-06-30";
$vali = new Zend_Validate_Date();
// $vali->isValid($date) returns TRUE
UNexpected behavior !!!
$date = "1980/06/30";
$vali = new Zend_Validate_Date('yyyy/MM/dd');
// $vali->isValid($date) returns FALSE but should be TRUE
Expected behavior
$date = "1980/06/29";
$vali = new Zend_Validate_Date('yyyy/MM/dd');
// $vali->isValid($date) returns TRUE
This is a big problem for me as I use a date validator on a form for an order entry tool using this format of date (for China). So in this case the customer born the June 30th 1980 can not by the product we sell... I had to implement a custom validator to treat this issue.
I reworked you example:
But I get a boolean TRUE returned.
I can't reproduce your problem.