Hello,

please consider adding DefaultFormatter in next release of DateTime package
as it
very useful when using DBIx::Class with InflateColumn::Datetime.

Without DefaultFormatter I have to set formatter for every datetime column
on every DBIC object

With DefaultFormatter I can simply do:

package MyDateTimeFormatter;
sub format_datetime {
   return $_[1]->ymd . '  ' . $_[1]->hms ;
}


use MyDateTimeFormatter;
use DateTime;
DateTime->DefaultFormatter('MyDateTimeFormatter');

print $DBICResultSet->find(1)->datetimecolumn;

and get '2010-11-11 11:11:11'  instead of '2010-11-11T11:11:11'


It's no easy way to subclass DateTime and pass a new class name to
DBIx Helper classes as they have hardcoded DateTime classname.

InflateColumn::DateTime usues formatters for inflating/deflating columns
only for
storage engines, and when using dynamic class loader
it's real pain to format datetime columns for printing to user

--
regards
piotr pogorzelski
*** /usr/lib/perl5/DateTime.pm	2010-07-30 23:31:27.000000000 +0200
--- lib/DateTime.pm	2010-11-24 11:40:02.000000000 +0100
***************
*** 109,114 ****
--- 109,126 ----
  }
  __PACKAGE__->DefaultLocale('en_US');
  
+ my $DefaultFormatter;
+ 
+ sub DefaultFormatter {
+     my $class = shift;
+ 
+     if (@_) {
+         $DefaultFormatter = shift;
+     }
+     return $DefaultFormatter;
+ }
+ 
+ 
  my $BasicValidate = {
      year => {
          type      => SCALAR,
***************
*** 816,823 ****
  sub _stringify {
      my $self = shift;
  
!     return $self->iso8601 unless $self->{formatter};
!     return $self->{formatter}->format_datetime($self);
  }
  
  sub hms {
--- 828,836 ----
  sub _stringify {
      my $self = shift;
  
!     return $self->{formatter}->format_datetime($self) if $self->{formatter};
!     return $DefaultFormatter->format_datetime($self) if $DefaultFormatter;
!     return $self->iso8601 ;
  }
  
  sub hms {

Reply via email to