Subject: | Enhancement of DateTime::Format::Strptime |
Date: | Fri, 11 May 2012 13:41:31 +0200 |
To: | "bug-datetime-format-strptime [...] rt.cpan.org" <bug-datetime-format-strptime [...] rt.cpan.org> |
From: | Tørmoen Joakim <Joakim.Tormoen [...] evry.com> |
Hello Sir,
First let me start by saying thank you for creating and maintaining the DateTime package.
In one of my projects i have extended the DateTime::Duration package, so i needed the DateTime package to return a object of this class instead.
So i looked into the DateTime and discovered the possibility to set the constant duration_class. This enables DateTime to return a custom duration object.
So i extended DateTime and changed the constant. But then the problem with DateTime::Format::Strptime occures, i also rely on this package.
This means that it also now needs to return a object of my custom extended DateTime class.
So i applied logic based on the same principles that is in the DateTime core class around returning a custom Duration object to the DateTime::Format::Strptime package.
I choose the same solution principles in order to be consistent through the hole package namespace.
I thought that most likely some other people have also had this desire, and that it could be that others want to do the same as me.
So i therefor humbly ask you to take a look at my small diff, and to consider if that is something you could include in the package.
Attached is a small and very simple test file, and the modified Strptime.pm
(A full diff is below)
If you think this is a useful feature but want it implemented in another way, please contact me with your comments, and i will see what i can do.
Best regards
Joakim
[root@localhost Format]# diff Strptime.pm /tmp/DateTime-Format-Strptime-1.5000/lib/DateTime/Format/Strptime.pm
22,23d21
< use constant core_datetime_class => 'DateTime';
<
389c387
< $epoch_dt = $self->core_datetime_class->from_epoch(
---
Show quoted text
> $epoch_dt = DateTime->from_epoch(
513c511
< $self->core_datetime_class->from_day_of_year(
---
Show quoted text> DateTime->from_day_of_year(
559c557
< $self->core_datetime_class->new(
---
Show quoted text> DateTime->new(
665c663
< $self->core_datetime_class->new(
---
Show quoted text> DateTime->new(
1020,1021c1018,1019
< $regex =~ s|%{(\w+)}|($self->core_datetime_class->can($1)) ? "(.+)" : ".+"|eg;
< $field_list =~ s|(%{(\w+)})|($self->core_datetime_class->can($2)) ? "#$2#" : $1 |eg;
---
Show quoted text> $regex =~ s|%{(\w+)}|(DateTime->can($1)) ? "(.+)" : ".+"|eg;
> $field_list =~ s|(%{(\w+)})|(DateTime->can($2)) ? "#$2#" : $1 |eg;
Message body is not shown because sender requested not to inline it.
Message body is not shown because sender requested not to inline it.