On Tue, Dec 15, 2009 at 3:39 PM, Kevin McGrath <kmcgr...@baknet.com> wrote:
> I guess I'm just not very good at explaining the feature.  If I have a
> formatter that is related to a time_zone then I feel that input and output
> of that formatter should be able to be based on that time zone.

The problem is DateTime is made to simulate a pipeline
`Text().asDateTime().asText()` what it provides is the conversion to
and from a string. The logical way to do what you want is
`Text().asDateTime().convertToTimezone($tz).asText()`. But, yet you
seem to be fixated on doing this Text().asDateTime().asText($tz), The
issue with that is it doesn't really model real world problems or the
mechanics. Making something as text in a different timezone, would
require a conversion which isn't really aptly described by a method
name like "format_datetime", even your code does this
"$dt->clone->set_time_zone($self->time_zone);".

The other problem is that you were suggesting overriding TimeZone to
make it confusingly apply to output patterns in the same explicit way
that it is currently applied to input patterns.  Lets look at your
provided code:

my $Strp = new DateTime::Format::Strptime(
     pattern => '%T',
     locale => 'en_AU',
     time_zone => 'Australia/Melbourne',
     format_with_time_zone => 1
);

What should this do on parse_datetime? Read a datetime as if it was
from Austrailia/Melbourne? And then what on formate_datetime? convert
it it to Austrailia/Melbourne, which it is already in for the output?

What you would really want is something like this

my $Strp = new DateTime::Format::Strptime(
     pattern => '%T',
     locale => 'en_AU',
     time_zone => 'Australia/Melbourne',
     output_time_zone => 'America/Chicago'
);

But even then? Is this really practical? People that were tasked with
the same thing you're doing might uselessly create a
DateTime::Format::Strptime object for each output timezone they
needed, when all they had to do was call the ->set_time_zone method on
the $dt object returned from parse_datetime, and then go on with life
feeding it to format_datetime.

-- 
Evan Carroll
System Lord of the Internets
http://www.evancarroll.com

Reply via email to