Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the DateTime-Format-Strptime CPAN distribution.

Report information
The Basics
Id: 77130
Status: resolved
Priority: 0/
Queue: DateTime-Format-Strptime

People
Owner: Nobody in particular
Requestors: Joakim.Tormoen [...] evry.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



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.

On Fri May 11 07:45:23 2012, Joakim.Tormoen@evry.com wrote: Show quoted text
> 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.
Sorry for the slow response. I think allowing this makes sense. If you are still interested in working on this, I'd greatly prefer a pull request against https://github.com/autarch/DateTime-Format-Strptime, or at the very least a full (including the new tests) in a separate file attachment. Pasting a diff into the body of a ticket makes very hard to pull it back out. However, this needs to be implemented as an optional parameter that gets passed to the constructor, not as a constant. Also, let's just name it "datetime_class". Then you don't need to subclass Strptime too. Cheers, -dave