ZF-8952: Notice: Undefined index: second in Zend_Date

Issue Type: Bug Created: 2010-01-27T07:31:52.000+0000 Last Updated: 2010-11-20T01:45:52.000+0000 Status: Resolved Fix version(s): - 1.9.7 (11/Jan/10)

Reporter: Raphael Dehousse (thymus) Assignee: Thomas Weidner (thomas) Tags: - Zend_Date

Related issues: Attachments: - ZF-8952.patch



I do not know if you consider it as a bug but

$date = new Zend_Date(); $date->setTime('2359', 'HHmm');

will generate notices :

Notice: Undefined index: second in Zend/Date.php on line 2795 Notice: Undefined index: second in Zend/Date.php on line 2315

but not

$date = new Zend_Date(); $date->setTime('2359', 'HHmmss');


$date = new Zend_Date(); $date->setTime('235900', 'HHmmss');

So, it's only when we do not care about seconds in setTime.

My 2 cents!


Raphaël Dehousse


Posted by Thomas Weidner (thomas) on 2010-01-27T10:07:30.000+0000

Closing as non-issue.

Time is always represented by Hour, Minute and Second.

Format can be used to change the order of input, but not to give other parameters or to omit them. When you have to set an abritary format use set() instead of setTime().

Posted by Raphael Dehousse (thymus) on 2010-02-07T05:37:39.000+0000


With all the respect I owe you, I do not understand why a notice is not considered as a possible bug. I understand that setTime is maybe not exactly what I need, and that set could solve the problem, but, here, a simple "isset" could resolve the problem or by throwing an error telling that seconds are needed, I do not know, but here, it's not really error-safe for the developer that would omit the seconds.


Raphaël Dehousse

Posted by Raphael Dehousse (thymus) on 2010-02-15T07:47:22.000+0000

In Zend_Date, line 2315: add

if (!isset($parsed['second'])) { $parsed['second'] = 0; }

like there is for case "self::TIME_SHORT:" some lines below.

Posted by Raphael Dehousse (thymus) on 2010-02-15T07:48:37.000+0000

Same line 2799 :)

Posted by Raphael Dehousse (thymus) on 2010-02-15T07:51:49.000+0000

Dear Thomas,

I really like the Zend Framework and I think that I have shown good will by providing patches to the issues I reported.

Would it be possible to see any action from you? A response?

Thank you very much for your cooperation.

Raphaël Dehousse

Posted by Thomas Weidner (thomas) on 2010-02-18T22:20:42.000+0000

There is no additional benefit of adding the same non-informational, frustrating comment into several issues which are even not related to each other.

As already stated I am replying when I have reproduced or not reproduced an issue.

Please remember that most people, including me, have a real live job and working on the framework in their sparetime. This means that response to a issue will not be written within 3 minutes.

I would ask you to keep on the issue itself and not to bother me with the same text multiple times when there is no response within 3 minutes.

Posted by Raphael Dehousse (thymus) on 2010-03-01T02:39:35.000+0000

Hello Thomas,

Sorry for my many comments.

I will keep on the issue now.

What do you think about the "patch" I proposed? Since the check is already there in some places, could you put it also where I said?

Thank you for your patience and cooperation.

Best regards,

Raphaël Dehousse

Posted by Thomas Weidner (thomas) on 2010-03-01T13:38:07.000+0000

There is no attached patch to this issue

There is no "check" integrated... Zend_Date works localized and for some locales changes have been made

TIME_MEDIUM is not allowed to be without second... to allow medium dates without a given second is itself a failure... therefor the notice is correct in the provided example.

Posted by Raphael Dehousse (thymus) on 2010-03-02T00:45:37.000+0000

Here is the patch :)

If I do not use the APi correctly, could you help me by providing the correct method I should use?

The input I receive is 2359, not 23:59, neither 23:59:00, neither 235900, just 2359.

How could I set the time simply by using Zend_Date? With setTime, it works perfectly, the problem is just the notice :)

Thank you for your patience :)

Posted by Thomas Weidner (thomas) on 2010-03-02T14:08:52.000+0000

As stated in my first reply:

When you don't give a complete time, you need to use set(). setTime() requires a complete time to be given. The format parameter is only available to allow switching the tokens.

As stated in my third reply:

TIME_MEDIUM is not allowed to be without seconds. MEDIUM is always with hour, minute and second. Without second it could be TIME_SHORT depending on the locale.

Posted by Raphael Dehousse (thymus) on 2010-03-03T00:04:42.000+0000

Does not work

And you won't apply the patch.

Ok, thank you anyway

Continue your great work!

Posted by Thomas Weidner (thomas) on 2010-03-03T12:13:16.000+0000

No way... there are even unittests...

<pre class="highlight">
$date->set('23:59', 'HH:mm');

surely works

Posted by Raphael Dehousse (thymus) on 2010-03-10T05:01:00.000+0000

Ok, Thanks

But anyway, an "isset" was not so hard :D

Posted by Raphael Dehousse (thymus) on 2010-03-10T05:12:13.000+0000


<pre class="highlight">
$dateSetTime = new Zend_Date();
$dateSetTime->setTime(str_pad('2359', 6, '0'), 'HHmmss');

$this->assertEquals(23, $dateSetTime->get(Zend_Date::HOUR));
$this->assertEquals(59, $dateSetTime->get(Zend_Date::MINUTE));

$dateSet = new Zend_Date();
$dateSet->set('235900', 'HHmmss');

$this->assertEquals(23, $dateSet->get(Zend_Date::HOUR));
$this->assertEquals(59, $dateSet->get(Zend_Date::MINUTE));

$this->assertEquals($dateSetTime->get(), $dateSet->get());

fail :/

So, I cannot use your solution. I need to use ->setTime(str_pad('2359', 6, '0'), 'HHmmss'); But I do not know why. I'm figuring out.

Posted by Raphael Dehousse (thymus) on 2010-03-10T05:13:49.000+0000

The result:

Failed asserting that two strings are equal. --- Expected +++ Actual @@ @@ -1268261940 +82740

(Tested on Windows using php 5.2.5)

Posted by Raphael Dehousse (thymus) on 2010-03-10T05:24:58.000+0000

<pre class="highlight">
$dateSetTime = new Zend_Date();
$dateSetTime->setTime(str_pad('2359', 6, '0'), 'HHmmss');
$dateSetTime->setDate('2010-01-01', 'yyyy-MM-dd');

$this->assertEquals(23, $dateSetTime->get(Zend_Date::HOUR));
$this->assertEquals(59, $dateSetTime->get(Zend_Date::MINUTE));

$dateSet = new Zend_Date();
$dateSet->set('235900', 'HHmmss');
$dateSet->setDate('2010-01-01', 'yyyy-MM-dd');

$this->assertEquals(23, $dateSet->get(Zend_Date::HOUR));
$this->assertEquals(59, $dateSet->get(Zend_Date::MINUTE));

$this->assertEquals($dateSetTime->get(), $dateSet->get());


Ok, I'll do like that. But you see that it's not the same behavior. The "set" method will reset the date line 2628:

<pre class="highlight">
if (($calc == 'set') || ($calc == 'cmp')) {
    if (isset($parsed['month'])) {
    } else {
        $parsed['month'] = 0;

    if (isset($parsed['day'])) {
    } else {
        $parsed['day'] = 0;

    if (isset($parsed['year'])) {
        $parsed['year'] -= 1970;
    } else {
        $parsed['year'] = 0;


Raphaël Dehousse

Posted by Thomas Weidner (thomas) on 2010-03-12T03:38:21.000+0000

to 1.) Isset would not work... Additionally within trunk and branch no notice is thrown.

to 2.) Your issue was regarding a notice which is thrown. It was not regarding non-tokenized dates to be recognised.

It is known that non-tokenized string can not be recognised and there are already issues regarding this problem.

The main reason is that you could have

HHmmss = 1234

Which could mean 1h2m34sec OR 1h23m4sec OR 12h3m4sec

And there is actually no way to detect the correct values.

Posted by Raphael Dehousse (thymus) on 2010-03-12T04:04:33.000+0000

For me, HHmmss = 1234 => 12h34m00sec

For the moment, isn't it possible to do, if we want

  • 1h2m34sec => Hmss
  • 1h23m4sec => Hmms
  • 12h3m4sec => HHms

I'm not sure this is possible. Following the documentation (…), I would say yes, but you know it better than me. And in the case the user provide only 1234 for HHmmss, then, the result should be 12h34m00sec

But anyway, you are right, the first subject was the notice. If you say that no notice occurs on your side, then, maybe it's because php is not configured to show them? Or my php show notices that should not occur :)

Posted by Thomas Weidner (thomas) on 2010-03-12T04:29:23.000+0000

The reason is that I am testing against 1.10.x as 1.9 is no longer developed.

And my opinion would be a not recognised date.

When you say "HHmmss" and only "HHmm" is given then the date should not be accepted.

Posted by Raphael Dehousse (thymus) on 2010-03-12T04:33:07.000+0000

I'm using the version 1.10.2 :)

I agree that it should not be accepted :)

Posted by Shaddy Zeineddine (shaddyz) on 2010-11-15T19:00:59.000+0000

<pre class="highlight"> 
$date->setTime($event['event_time'], 'h:mma');

given that $event['event_time'] = '7:00pm';

this generates the error:

Undefined index: second on line 2728 of /var/web/unityla-dev/libraries/Zend/Date.php

Zend_Date version string "$Id: Date.php 17696 2009-08-20 20:12:33Z thomas $"

This is not expected behavior.

Posted by Thomas Weidner (thomas) on 2010-11-20T01:45:52.000+0000

Unable to verify the error. Line 2728 is the method header.

I expect that this error was already solved in past because line 2811 checks if the array key exists. Please use the actual release.

Have you found an issue?

See the Overview section for more details.


© 2006-2016 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.