[Catalyst] Dealing with timestamps from Postgres

Adam Jimerson vendion at gmail.com
Thu Nov 3 12:21:44 GMT 2011


On Thu, Nov 3, 2011 at 6:55 AM, Kieren Diment <diment at gmail.com> wrote:

> On 03/11/2011, at 9:40 PM, Adam Jimerson wrote:
>
> > The problem I see with doing it this way: $formatted_date_string =3D
> > $c->model('DB::TableName')->find($row_index)->date_field->mdy('/'); is
> > that It looks like I would
> > have to do this every time I grab a date from the database.  That is fi=
ne
> > but there are times in my app where I pull everything from the database
> to
> > display like so:
> >
> > my $things =3D $c->stash->{mydata_rs}->search(
> >       undef,
> >       {
> >               order_by =3D> { -asc =3D> 'uniq' },
> >       },
> > );
> >
>
>
> One option is to define a method in whatever Result class mydata_rs
> produces:
>
> sub my_date_format {
>        my $self =3D shift;
>        return $self->date_field->mdy('/');
> }
>
>
> then in your template:
>
> [% WHILE (row =3D mydata_rs.next); row.my_date_format ; END %]
>
> or you can just call the datetime methods in the template:
>
> [% WHILE (row =3D mydata_rs.next); row.my_date_field.ymd('/') ; END %]
>
>
 So if I go the latter route and call it from the template I won't have to
use a sub like that to do the formatting correct?  Also would it accept a
ymd hms format or do they have to be separate?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.scsys.co.uk/pipermail/catalyst/attachments/20111103/019b4=
220/attachment.htm


More information about the Catalyst mailing list