Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime CPAN distribution.

Report information
The Basics
Id: 60930
Status: resolved
Priority: 0/
Queue: DateTime

People
Owner: Nobody in particular
Requestors: mschwern [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: 0.61
Fixed in: 0.65



Subject: One-off formatting
Right now, its very awkward to format a DateTime object the way the user want it formatted, as opposed to the creator. You have to... my $old_formatter = $date->formatter; $date->set_formatter($my_format); my $string = "$date"; $date->set_formatter($old_foramtter); Alternatively, clone it. my $copy = $date->clone; $date->set_formatter($my_format); my $string = "$date"; Bleh. It would be very handy if you could do a one-off format specifying the formatter same as with set_formatter. my $string = $date->format_as($my_format); This would allow you to pass around DateTime objects and have the using code conveniently format them as needed rather than the creator trying to predict the format. This thread kicked it off: http://www.nntp.perl.org/group/perl.datetime/2010/08/msg7573.html
On Wed Sep 01 02:46:32 2010, MSCHWERN wrote: Show quoted text
> Right now, its very awkward to format a DateTime object the way the user > want it formatted, as opposed to the creator. You have to... > > my $old_formatter = $date->formatter; > $date->set_formatter($my_format); > my $string = "$date"; > $date->set_formatter($old_foramtter); > > Alternatively, clone it. > > my $copy = $date->clone; > $date->set_formatter($my_format); > my $string = "$date"; > > Bleh. It would be very handy if you could do a one-off format > specifying the formatter same as with set_formatter. > > my $string = $date->format_as($my_format); > > This would allow you to pass around DateTime objects and have the using > code conveniently format them as needed rather than the creator trying > to predict the format. > > This thread kicked it off: > http://www.nntp.perl.org/group/perl.datetime/2010/08/msg7573.html
I'm not clear on whether $my_format is an object or a string of some sort. Either way, there are already APIs for this. With a formatter object you can write: $formatter->format_datetime($datetime); If it's a string you have format_cldr and strftime. What am I missing?
Subject: Re: [rt.cpan.org #60930] One-off formatting
Date: Fri, 15 Oct 2010 11:55:39 -0400
To: bug-DateTime [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
On 2010.10.15 10:50 AM, Dave Rolsky via RT wrote: Show quoted text
> I'm not clear on whether $my_format is an object or a string of some > sort. Either way, there are already APIs for this. With a formatter > object you can write: > > $formatter->format_datetime($datetime); > > If it's a string you have format_cldr and strftime. > > What am I missing?
Nothing, that's what I wanted but inverted. You ask the $formatter to format the $datetime object. I was looking to do the same thing, but inverted: $datetime->format_with($formatter). The above solves the problem, but I'd never made the connection. So its a documentation/education issue. -- 29. The Irish MPs are not after "Me frosted lucky charms". -- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army http://skippyslist.com/list/
Subject: Re: [rt.cpan.org #60930] One-off formatting
Date: Sat, 16 Oct 2010 10:44:32 -0500 (CDT)
To: Michael G Schwern via RT <bug-DateTime [...] rt.cpan.org>
From: Dave Rolsky <autarch [...] urth.org>
On Fri, 15 Oct 2010, Michael G Schwern via RT wrote: Show quoted text
> The above solves the problem, but I'd never made the connection. So its a > documentation/education issue.
I added a section on the datetime project ecosystem to the DateTime.pm docs for the next release. I'm not sure how much that will help, since the docs are already really long. I wonder if anyone will read that far. -dave /*============================================================ http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) ============================================================*/
Subject: Re: [rt.cpan.org #60930] One-off formatting
Date: Sat, 16 Oct 2010 12:43:23 -0400
To: bug-DateTime [...] rt.cpan.org
From: Michael G Schwern <schwern [...] pobox.com>
On 2010.10.16 11:44 AM, autarch@urth.org via RT wrote: Show quoted text
> <URL: http://rt.cpan.org/Ticket/Display.html?id=60930 > > > On Fri, 15 Oct 2010, Michael G Schwern via RT wrote: >
>> The above solves the problem, but I'd never made the connection. So its a >> documentation/education issue.
> > I added a section on the datetime project ecosystem to the DateTime.pm > docs for the next release. > > I'm not sure how much that will help, since the docs are already really > long. I wonder if anyone will read that far.
If it'll show up while grepping for "formatter" then yes. -- 87. If the thought of something makes me giggle for longer than 15 seconds, I am to assume that I am not allowed to do it. -- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army http://skippyslist.com/list/