Issues

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

Description

Hello,

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');

neither

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

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

My 2 cents!

Regards,

Raphaël Dehousse

Comments

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().

Thomas,

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.

Regards,

Raphaël Dehousse

In Zend_Date, line 2315: add

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

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

Same line 2799 :)

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

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.

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

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.

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 :)

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.

Does not work

And you won't apply the patch.

Ok, thank you anyway

Continue your great work!

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


$date->set('23:59', 'HH:mm');

surely works

Ok, Thanks

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

euh


$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.

The result:

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

(Tested on Windows using php 5.2.5)


$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());

works.

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:


if (($calc == 'set') || ($calc == 'cmp')) {
    if (isset($parsed['month'])) {
        --$parsed['month'];
    } else {
        $parsed['month'] = 0;
    }

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

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

Cheers,

Raphaël Dehousse

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.

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 (http://framework.zend.com/manual/en/…), 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 :)

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.

I'm using the version 1.10.2 :)

I agree that it should not be accepted :)

 
$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.

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.