>> 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.
>
> I guess I still don't see how:
> $Strp->format_datetime( $str, { time_zone => $tz1 } );
> $Strp->format_datetime( $str, { time_zone => $tz2 } );
>
> would be so evil. I want to get a formatted string based on pattern I
> provided as it would be displayed in the specified time_zone.
How much would you want to be overridable, and set in the constructor
of the DateTime::Format module? How much should we add to this other
than time_zone (format_timezone) ? locale (format_locale)? What about
adding and subtracting duration??
Here is better API idea, why not just make the hash ref to
format_datetime, a huge method wrapper!!!!
sub format_datetime {
my ( $self, $dt, %method_args ) = @_;
$dt = $dt->clone;
foreach my $m ( keys %method_args ) {
$m = 'set_time_zone' if $m = 'time_zone';
warn 'method not available' unless $dt->can( $m );
warn 'non array ref for args' unless ref $method_args{$m} eq
'ARRAY';
$dt->$m( @{$method_args{$m}} );
}
... other code using $dt
}
Then!! You could even go $dtf->format_datetime( $dt, { add => [ months
=> 1 ] } ) ? The reason is because you're simply mutating a copy of
the DateTime object, and this isn't really a good idea idea, even if
it does make your use case a single line or two shorter.
--
Evan Carroll
System Lord of the Internets
http://www.evancarroll.com