You are viewing a plain text version of this content. The canonical link for it is here.
Posted to zeta-dev@incubator.apache.org by Tobias Schlitt <to...@schlitt.info> on 2011/01/27 18:06:17 UTC

[zeta-dev] Patch: DateTime functionality for Template

Hi,

I made a patch to expose DateTime stuff in the Template language. Please
find it for review here:

	https://issues.apache.org/jira/browse/ZETACOMP-50

It basically just exposes the procedural interface (where exists) of
DateTime to the template language.

There is one open issue, which needs to be discussed: DateTime
modification functions, such as date_sub() and friends, return the
modified DateTime object in addition. This requires an assignement
whenever these functions are used in a template. For example::

	{$foo = date_sub( $date, $interval )}

Otherwise, the Template engine would attempt to convert the returned
object to a string for output.

To avoid this inconvenience, I'd suggest to wrap the DateTime functions
and eat the return value. This means a slide variation from the behavior
known from PHP, but much more convenience for template authors.

What do you think?

Cheers,
Toby

-- 
Tobias Schlitt        http://schlitt.info        GPG Key: 0xC462BC14
Want to hire me? Need quality assurance?            http://qafoo.com
eZ Components are Zeta Components now!          http://bit.ly/9S7zbn

Re: [zeta-dev] Patch: DateTime functionality for Template

Posted by Tobias Schlitt <to...@schlitt.info>.
Hi Benjamin,

On 01/31/2011 02:26 PM, Benjamin Eberlei wrote:
> Ah nice approach to avoid the infinite loop, but I got a better one:
> 
> https://github.com/beberlei/Whitewashing/blob/master/DateTime/DateTime.php
> 
> Feel free to take this code, its new-bsd.

thanks for the recommendation. Using the procedural interface of
DateTime is indeed a good idea. I'll take your code as inspiration for
the final version.

> btw, I proposed an Immutable DateTime objects patch to the Internals list
> 1-2 month ago that was rejected for it adding a $immutable = true/false
> flag only instead of fixing the underyling problem. Fixing the underlying
> problem is too huge a task for my non-existant C skills though :-)

I doubt PHP will fix this issue by making the current DateTime
implementation immutable, since it would mean a BC break. Even if they'd
really do, that'd be for 5.3.$x  or even later, so we would need to work
around it anyway.

Therefore I'd really suggest we provide a proper implementation in
userland with our Base component.

Thanks for your feedback,
cheers,
Toby

-- 
Tobias Schlitt        http://schlitt.info        GPG Key: 0xC462BC14
Want to hire me? Need quality assurance?            http://qafoo.com
eZ Components are Zeta Components now!          http://bit.ly/9S7zbn

Re: [zeta-dev] Patch: DateTime functionality for Template

Posted by Benjamin Eberlei <ko...@beberlei.de>.
Ah nice approach to avoid the infinite loop, but I got a better one:

https://github.com/beberlei/Whitewashing/blob/master/DateTime/DateTime.php

Feel free to take this code, its new-bsd.

btw, I proposed an Immutable DateTime objects patch to the Internals list
1-2 month ago that was rejected for it adding a $immutable = true/false
flag only instead of fixing the underyling problem. Fixing the underlying
problem is too huge a task for my non-existant C skills though :-)

greetings,
Benjamin

On Mon, 31 Jan 2011 14:08:13 +0100, Tobias Schlitt <to...@schlitt.info>
wrote:
> Hi,
> 
> I had a quick chat with Derick during PHP Benelux about this patch. He
> suggested to make the DateTime objects in Template immutable. I'm pretty
> much for doing so and would actually desire to change that in PHP
> itself, if it would be possible.
> 
> Making DateTime objects immutable would result in much more sane
> behavior of date_modify(), date_add() and friends, since they would no
> more change the original object, but return a new one which has the
> desired manipulation applied.
> 
> We've an implementation for immutable DateTime lying around, which we
> could just move to Base/ so it's available for others easily, too. Find
> the code attached.
> 
> What do you think?
> 
> Regards,
> Toby

Re: [zeta-dev] Patch: DateTime functionality for Template

Posted by Benjamin Eberlei <ko...@beberlei.de>.
the private methods prevent an infinite loop after the clone calls the same method again, cloning again, and so on...

On Mon, 31 Jan 2011 19:59:49 +0100
Jerome Renard <je...@gmail.com> wrote:

> Hi Tobias,
> 
> On Mon, Jan 31, 2011 at 2:08 PM, Tobias Schlitt <to...@schlitt.info> wrote:
> 
> > Hi,
> >
> > I had a quick chat with Derick during PHP Benelux about this patch. He
> > suggested to make the DateTime objects in Template immutable. I'm pretty
> > much for doing so and would actually desire to change that in PHP
> > itself, if it would be possible.
> >
> > Making DateTime objects immutable would result in much more sane
> > behavior of date_modify(), date_add() and friends, since they would no
> > more change the original object, but return a new one which has the
> > desired manipulation applied.
> >
> > We've an implementation for immutable DateTime lying around, which we
> > could just move to Base/ so it's available for others easily, too. Find
> > the code attached.
> >
> > What do you think?
> >
> 
> Totally agree.
> 
> BTW your implementation of the DateTime extension looks a bit too complex.
> Do we really need all these private function *add() methods ? Wouldnt'it be
> possible to just avoid them
> and move their contents to the public ones ? I may have overlooked something
> though.
> 
> +1 for moving the code to Base anyway.
> 
> :)
> 
> -- 
> Jérôme Renard
> http://39web.fr | http://jrenard.info | http://twitter.com/jeromerenard

Re: [zeta-dev] Patch: DateTime functionality for Template

Posted by Jerome Renard <je...@gmail.com>.
Hi Tobias,

On Mon, Jan 31, 2011 at 2:08 PM, Tobias Schlitt <to...@schlitt.info> wrote:

> Hi,
>
> I had a quick chat with Derick during PHP Benelux about this patch. He
> suggested to make the DateTime objects in Template immutable. I'm pretty
> much for doing so and would actually desire to change that in PHP
> itself, if it would be possible.
>
> Making DateTime objects immutable would result in much more sane
> behavior of date_modify(), date_add() and friends, since they would no
> more change the original object, but return a new one which has the
> desired manipulation applied.
>
> We've an implementation for immutable DateTime lying around, which we
> could just move to Base/ so it's available for others easily, too. Find
> the code attached.
>
> What do you think?
>

Totally agree.

BTW your implementation of the DateTime extension looks a bit too complex.
Do we really need all these private function *add() methods ? Wouldnt'it be
possible to just avoid them
and move their contents to the public ones ? I may have overlooked something
though.

+1 for moving the code to Base anyway.

:)

-- 
Jérôme Renard
http://39web.fr | http://jrenard.info | http://twitter.com/jeromerenard

Re: [zeta-dev] Patch: DateTime functionality for Template

Posted by Tobias Schlitt <to...@schlitt.info>.
Hi,

I had a quick chat with Derick during PHP Benelux about this patch. He
suggested to make the DateTime objects in Template immutable. I'm pretty
much for doing so and would actually desire to change that in PHP
itself, if it would be possible.

Making DateTime objects immutable would result in much more sane
behavior of date_modify(), date_add() and friends, since they would no
more change the original object, but return a new one which has the
desired manipulation applied.

We've an implementation for immutable DateTime lying around, which we
could just move to Base/ so it's available for others easily, too. Find
the code attached.

What do you think?

Regards,
Toby

-- 
Tobias Schlitt        http://schlitt.info        GPG Key: 0xC462BC14
Want to hire me? Need quality assurance?            http://qafoo.com
eZ Components are Zeta Components now!          http://bit.ly/9S7zbn

Re: [zeta-dev] Patch: DateTime functionality for Template

Posted by Jerome Renard <je...@gmail.com>.
Hello,

On Thu, Jan 27, 2011 at 7:06 PM, Tobias Schlitt <to...@schlitt.info> wrote:

> Hi,
>
> I made a patch to expose DateTime stuff in the Template language. Please
> find it for review here:
>
>        https://issues.apache.org/jira/browse/ZETACOMP-50
>
>
I posted another patch (with explanations) in the comment.


> It basically just exposes the procedural interface (where exists) of
> DateTime to the template language.
>
> There is one open issue, which needs to be discussed: DateTime
> modification functions, such as date_sub() and friends, return the
> modified DateTime object in addition. This requires an assignement
> whenever these functions are used in a template. For example::
>
>        {$foo = date_sub( $date, $interval )}
>
> Otherwise, the Template engine would attempt to convert the returned
> object to a string for output.
>
> To avoid this inconvenience, I'd suggest to wrap the DateTime functions
> and eat the return value. This means a slide variation from the behavior
> known from PHP, but much more convenience for template authors.
>
> What do you think?
>
>
I am not sure if we should avoid an inconvenience by an auto-magic feature.

Have a nice day :)

-- 
Jérôme Renard
http://39web.fr | http://jrenard.info | http://twitter.com/jeromerenard