> Why then does parse_datetime automatically convert from a string to a
> timezone?
> Shouldn't it then just always return a datetime in floating context?

It doesn't "convert" it "reads it as".

> my $dt = $Strp->parse_datetime($my_string); #Floating

Not floating, that is whatever the time_zone you have set in the
::Format module. Or, if the Format module reads in a different time
zone from the string as in the case of %z and %Z in strptime.

> Not overriding time_zone, just format_datetime if and only if a option is
> set.  The attribute 'time_zone' seems pretty generic to me, it's not
> 'parse_time_zone' or 'time_zone_from_string'.  The confusing part is that
> it's just named 'time_zone'.

I'm not arguing that it is the best name in the world, I'm just saying
it is simply the respective constructor argument that well behaved
DateTime::Format module will provide under the hood to DateTime.

> Actually that would be pretty cool, because I could parse all of my DateTime
> strings to UTC and format all my DateTime objects to a desired time_zone
> within a single formatter.

You can already do this.

foreach ( qw/timezone list here/ ) {
 state $dtf = DateTime::Format::Strptime->new({ time_zone => UTC });
 my $dt = $dtf->parse_datetime( $str );
 $dt->set_time_zone( $_  );
 say "time zone $_";
 say $dtf->format_datetime( $dt );
}

> Also, why is it practical to do something like the following for parsing
> which you appear to be fine with:
>
> my $Strp = new DateTime::Format::Strptime(
>     pattern => $user->datetime_pattern,
>     time_zone => 'America/New_York',
> );
>
> my $Strp2 = new DateTime::Format::Strptime(
>     pattern => $user->datetime_pattern,
>     time_zone => 'America/Chicago',
> );

It is not, this is why I created DateTimeX::Format, because I wanted
each and every DateTimeX::Format module to support a runtime override
for the constructor arguments to DateTimeX::Format modules. So in my
world you could just

> my $Strp = new DateTimeX::Format::Strptime(
>     pattern => $user->datetime_pattern,
> );

$Strp->parse_datetime( $str, { time_zone => $tz } );

But the difference is I'm not really adding functionality, and nothing
is happening under the hood to the DateTime object, just a new value
will be supplied to the DateTime constructor.

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

Reply via email to