Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #60774 (DateInterval::format("%a") is always zero when an interval i... #148

Closed
wants to merge 1 commit into from

Conversation

lonnylot
Copy link

@lonnylot lonnylot commented Aug 5, 2012

Bug #60774 (DateInterval::format("%a") is always zero when an interval is created using the createFromDateString method)

Fixed using the same method bug 49778 used.

…l is

created using the createFromDateString method)
bool(false)
}
2
(unknown)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I understand - why it's unknown if the string says "2 days"?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The %a modifier is only for the total number of days between two dates. Since there is only 1 date we don't have a difference.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The %a modifier is only for the total number of days between two dates.
Since there is only 1 date we don't have a difference.

On Sun, Aug 5, 2012 at 11:37 PM, Stanislav Malyshev <
reply@reply.github.com

wrote:

  • int(0)
  • ["d"]=>
  • int(2)
  • ["h"]=>
  • int(0)
  • ["i"]=>
  • int(0)
  • ["s"]=>
  • int(0)
  • ["invert"]=>
  • int(0)
  • ["days"]=>
  • bool(false)
    +}
    +2
    +(unknown)

I'm not sure I understand - why it's unknown if the string says "2 days"?


Reply to this email directly or view it on GitHub:
https://github.com/php/php-src/pull/148/files#r1309145

Lonny Kapelushnik
http://lonnylot.com
(732) 807-5509

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's actually no dates at all in this example, just the interval. And I thought the whole point of the interval is that you don't need two dates - you just have relative interval, like "2 days interval". I don't see why %a there can't be 2 days.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I'm aware the %a is supposed to be the total number of days in the interval. I think you're right that if the interval is 2 days then %a could be set to 2. However, with other intervals, such as 1 month, you would not be able to set the %a unless the interval was relative to todays date.

Additionally, the example in the createfromdatestring docs say that instantiating from the constructor or createfromdatestring static method should create the same results. In bug 49778 Derick changed the the constructor so that %a would be (unknown). My patch makes the results of createfromdatestring match the constructor results.

@lstrojny
Copy link
Contributor

lstrojny commented Nov 4, 2012

Ping @derickr

@derickr
Copy link
Member

derickr commented Nov 4, 2012

As comments indicated, %a should not have filled in something - only %d should have that. %a is a calculated value that only make sense if the interval is linked to two dates. I am not quite sure what I like it to say "(unknown)" though... just an empty string might be better?

@lonnylot
Copy link
Author

@derickr I am not against the change, but I want to also bring up that it would be a bigger BC break if we changed "(unknown)". The output would have to change for both the constructor AND the static call to createFromDateString. The constructor was changed to be "(unknown)" in 2010 (http://svn.php.net/viewvc/?view=revision&revision=295928).

If the BC break is fine w/ everyone I think we should also send an E_WARNING. That way people become aware the format('%a') should only be used when there is a difference between TWO dates and they are using it incorrectly. Hopefully that will help to alleviate any confusion between %a and %d.

@derickr
Copy link
Member

derickr commented Nov 10, 2012

I wouldn't like a warning here. There is no reason for it and they are difficult to deal with. You can already detect this problem by seeing "(unknown)".

@lonnylot
Copy link
Author

Did I misunderstand your previous reply[1]? I thought you were suggesting to change "(unknown)" to ""?

If we change "(unknown)" to "" then people will start testing w/ empty(). To prevent people from doing that I think it would make sense to warn them that they are using it wrong and that "" is not the same as 0.

Of course, my opinion is only valid if we are changing "(unknown)" to "". If we aren't then I agree we should not send an E_WARNING and we should just return "(unknown)" like we currently do w/ the constructor.

[1] #148 (comment)

@derickr
Copy link
Member

derickr commented Nov 10, 2012

I was just saying that I don't like "(unknown)"—I hadn't realised that was used before already, so no need to change it now.

@lonnylot
Copy link
Author

Any chance of this making it into 5.5?

@derickr
Copy link
Member

derickr commented Mar 31, 2013

I've merged it after adding the .c parser files too, but for some odd reason I can't close this PR.

@derickr derickr closed this Mar 31, 2013
@lonnylot
Copy link
Author

Can someone close the related bug https://bugs.php.net/bug.php?id=60774

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants