(I thought I posted this but now can't find it)

I'm now just overriding the accessors for each date column and keeping the date in MySQL's format.

I'd still be interesting in knowing how a has_a solution should work all together.

Here's my (prototype) code:

package My::DBI; use base 'Class::DBI::mysql'; sub setup { my $sub_class = shift; my $table = shift; $sub_class->set_up_table($table); for my $col_name ($sub_class->all_columns) { my $col_type = $sub_class->column_type($col_name); if($col_type eq 'date') { # customize accessor to do euro formatting my $real_accessor = "_${col_name}_accessor"; no strict 'refs'; *{$sub_class.'::'.$col_name} = sub { my $self = shift; if(@_) { # setting my $date = shift; if($date =~ m! (\d+) / (\d+) (?:/ (\d+) )+!x) { my $y = $3; $y += ($y < 70) ? 2000 : 1900 if($y < 100); $date = sprintf "%4d-%02d-%02d", $y,$2,$1; } return $self->$real_accessor($date); } else { my $date = $self->$real_accessor(@_); $date =~ s!(\d{4})-(\d\d)-(\d\d)!$3/$2/$1!; return $date; } } } } + }
Some debugging:
DB<1> p $s->ses_date 23/06/2003 DB<2> x $s->{ses_date} 0 '2003-06-23' DB<3> $s->ses_date('1/2/3') DB<4> p $s->{ses_date} 2003-02-01 DB<5> x $s->{ses_date} 0 '2003-02-01'

In reply to Re: Date conversion with Class::DBI by bsb
in thread Date conversion with Class::DBI by bsb

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.