Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-03 Thread Paul

On Thursday, 03 November, 2011 at 02:31:56 GMT, Santiago Zarate wrote:

If i'm not wrong, being basically a DateTime object you should be able
to do whatever you like with it instead of having to do a search 
replace, consider using DBIx::Class::InflateColumn to have DBIx do the
job for you every time you need to use that specific model...


Indeed. Consider using a formatter: 
https://metacpan.org/module/DateTime#Formatters-And-Stringification

--

.

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-03 Thread Tomas Doran


On 3 Nov 2011, at 02:05, Adam Jimerson wrote:


but in my Catalyst app the
date looks like this 2011-05-07T13:53:41.  The T instead of the  
space is driving me crazy, I think it is coming from  
DateTime::Format:Pg


As other people have noted, what's happening is that  
DateTime::Format:Pg is parsing the dates you get out of Postgres, and  
handing you a DateTime object back.


You're then printing that with no formatting, as you're basically  
getting an ISO8601 timestamp out.


Have a look at the docs for DateTime and the associated  
DateTime::Format::XX things :)


Cheers
t0m



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-03 Thread Adam Jimerson
The problem I see with doing it this way: $formatted_date_string =
 $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 fine
but there are times in my app where I pull everything from the database to
display like so:

my $things = $c-stash-{mydata_rs}-search(
undef,
{
order_by = { -asc = 'uniq' },
},
);

where each item has a timestamp of when it was created and when it was last
modified, would I have to do another search to get the datetime formatted
or worse pull them one by one building a hash_ref or array?

On Thu, Nov 3, 2011 at 6:04 AM, Tomas Doran bobtf...@bobtfish.net wrote:


 On 3 Nov 2011, at 02:05, Adam Jimerson wrote:

  but in my Catalyst app the
 date looks like this 2011-05-07T13:53:41.  The T instead of the space
 is driving me crazy, I think it is coming from DateTime::Format:Pg


 As other people have noted, what's happening is that DateTime::Format:Pg
 is parsing the dates you get out of Postgres, and handing you a DateTime
 object back.

 You're then printing that with no formatting, as you're basically getting
 an ISO8601 timestamp out.

 Have a look at the docs for DateTime and the associated
 DateTime::Format::XX things :)

 Cheers
 t0m




 __**_
 List: Catalyst@lists.scsys.co.uk
 Listinfo: 
 http://lists.scsys.co.uk/cgi-**bin/mailman/listinfo/catalysthttp://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/**
 catalyst@lists.scsys.co.uk/http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/

___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-03 Thread Kieren Diment
On 03/11/2011, at 9:40 PM, Adam Jimerson wrote:

 The problem I see with doing it this way: $formatted_date_string =
 $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 fine
 but there are times in my app where I pull everything from the database to
 display like so:
 
 my $things = $c-stash-{mydata_rs}-search(
   undef,
   {
   order_by = { -asc = 'uniq' },
   },
 );
 


One option is to define a method in whatever Result class mydata_rs produces:

sub my_date_format {
my $self = shift;
return $self-date_field-mdy('/');
}   


then in your template:

[% WHILE (row = mydata_rs.next); row.my_date_format ; END %]

or you can just call the datetime methods in the template:

[% WHILE (row = mydata_rs.next); row.my_date_field.ymd('/') ; END %]



 where each item has a timestamp of when it was created and when it was last
 modified, would I have to do another search to get the datetime formatted
 or worse pull them one by one building a hash_ref or array?
 
 On Thu, Nov 3, 2011 at 6:04 AM, Tomas Doran bobtf...@bobtfish.net wrote:
 
 
 On 3 Nov 2011, at 02:05, Adam Jimerson wrote:
 
 but in my Catalyst app the
 date looks like this 2011-05-07T13:53:41.  The T instead of the space
 is driving me crazy, I think it is coming from DateTime::Format:Pg
 
 
 As other people have noted, what's happening is that DateTime::Format:Pg
 is parsing the dates you get out of Postgres, and handing you a DateTime
 object back.
 
 You're then printing that with no formatting, as you're basically getting
 an ISO8601 timestamp out.
 
 Have a look at the docs for DateTime and the associated
 DateTime::Format::XX things :)
 
 Cheers
 t0m
 
 
 
 
 __**_
 List: Catalyst@lists.scsys.co.uk
 Listinfo: 
 http://lists.scsys.co.uk/cgi-**bin/mailman/listinfo/catalysthttp://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/**
 catalyst@lists.scsys.co.uk/http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/
 
 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/


___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-03 Thread Adam Jimerson
On Thu, Nov 3, 2011 at 6:55 AM, Kieren Diment dim...@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 =
  $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 fine
  but there are times in my app where I pull everything from the database
 to
  display like so:
 
  my $things = $c-stash-{mydata_rs}-search(
undef,
{
order_by = { -asc = 'uniq' },
},
  );
 


 One option is to define a method in whatever Result class mydata_rs
 produces:

 sub my_date_format {
my $self = shift;
return $self-date_field-mdy('/');
 }


 then in your template:

 [% WHILE (row = mydata_rs.next); row.my_date_format ; END %]

 or you can just call the datetime methods in the template:

 [% WHILE (row = 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?
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-03 Thread Tomas Doran


On 3 Nov 2011, at 12:21, Adam Jimerson wrote:


 Also would it accept a ymd hms format or do they have to be separate?


Please see the fine documentation for DateTime.

Another option is to add a 'format_date' method to your view, and use  
the expose_methods config setting for View::TT..


In your TT code you'd then say [% WHILE (row = mydata_rs.next);  
format_date(row.my_date_field); END %]


Cheers
t0m




___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-03 Thread will trillich
On Thu, Nov 3, 2011 at 12:36 PM, Tomas Doran bobtf...@bobtfish.net wrote:

 Another option is to *add a 'format_date' method to your view*, and use
 the *expose_methods *config setting for View::TT..

 In your TT code you'd then say [% WHILE (row = mydata_rs.next);
 format_date(row.my_date_field)**; END %]


/lurkInteresting...

Aha, that's what *
http://search.cpan.org/~mstrout/Catalyst-View-TT-0.37/lib/Catalyst/View/TT.pm#expose_methods
* is talking about. Hadn't noticed that before.

Neat!

-- 
The very nucleus of Character: to do what you know you should do, when you
don't want to do it. Stephen Covey
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-03 Thread Tomas Doran


On 3 Nov 2011, at 15:38, will trillich wrote:

Aha, that's what http://search.cpan.org/~mstrout/Catalyst-View-TT-0.37/lib/Catalyst/View/TT.pm#expose_methods 
 is talking about. Hadn't noticed that before.


Not noticed it before (fair enough), or not clear enough in the  
documentation?


Cheers
t0m



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-03 Thread Adam Jimerson
On Thu, Nov 3, 2011 at 11:38 AM, will trillich
will.trill...@serensoft.comwrote:

 On Thu, Nov 3, 2011 at 12:36 PM, Tomas Doran bobtf...@bobtfish.netwrote:

 Another option is to *add a 'format_date' method to your view*, and use
 the *expose_methods *config setting for View::TT..

 In your TT code you'd then say [% WHILE (row = mydata_rs.next);
 format_date(row.my_date_field)**; END %]


 /lurkInteresting...

 Aha, that's what *
 http://search.cpan.org/~mstrout/Catalyst-View-TT-0.37/lib/Catalyst/View/TT.pm#expose_methods
 * is talking about. Hadn't noticed that before.

 Neat!


Agreed thanks for pointing that out, I might try that out once I get a
chance to play around with my app again
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-03 Thread will trillich
Catalyst sure is wide and deep. One can get a reasonably advanced app
running in Catalyst without knowing broad stretches of what goes on, or
*can* go on, under the hood. There's so much possible, and so many handy
methods and plugins that you're gonna A) overlook things on the mad dash to
the goal or B) not understand the value of things until much later (like
abstracting code to a library, it often takes a few iterations before the
utility becomes obvious).

This case was a combination of both.

I often struggle to find the answer to a has someone else solved this
already question, and wind up rolling my own solution... only to run in to
someone else's cleverer, cleaner approaches later (often by accident). In
order to have 'perfect documentation' it must meet two criteria: A) explain
the utility and usage (benefits and how-to) *in a way that I can grok* and
B) show up on my radar *in my searches*. Both of these depend a helluva lot
on my own activity and context, making compliance impossible. :)

Sometimes scar tissue is the only (best?) way to really learn.



On Thu, Nov 3, 2011 at 3:46 PM, Tomas Doran bobtf...@bobtfish.net wrote:


 On 3 Nov 2011, at 15:38, will trillich wrote:

  Aha, that's what http://search.cpan.org/~**mstrout/Catalyst-View-TT-0.37/
 **lib/Catalyst/View/TT.pm#**expose_methodshttp://search.cpan.org/~mstrout/Catalyst-View-TT-0.37/lib/Catalyst/View/TT.pm#expose_methodsis
  talking about. Hadn't noticed that before.


 Not noticed it before (fair enough), or not clear enough in the
 documentation?


 Cheers
 t0m



 __**_
 List: Catalyst@lists.scsys.co.uk
 Listinfo: 
 http://lists.scsys.co.uk/cgi-**bin/mailman/listinfo/catalysthttp://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/**
 catalyst@lists.scsys.co.uk/http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/




-- 
The very nucleus of Character: to do what you know you should do, when you
don't want to do it. Stephen Covey
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-03 Thread Tomas Doran


On 3 Nov 2011, at 19:03, will trillich wrote:

In order to have 'perfect documentation' it must meet two criteria:  
A) explain the utility and usage (benefits and how-to) in a way that  
I can grok and B) show up on my radar in my searches. Both of these  
depend a helluva lot on my own activity and context, making  
compliance impossible. :)


Sometimes scar tissue is the only (best?) way to really learn.


Sure, I totally agree.

I'm also entirely certain that the documentation as it stands fails at  
meeting (or at least is way before the standard it could be) in your  
criteria for (A), and therefore will fail to meet a good many other  
people's version of the same criteria.


As someone who has 'just got it', you are absolutely the best placed  
person to modify the documentation to add to the benefits (and maybe  
provide an example) as to make it more clear to people, so that the  
documentation _will_ fulfill that criteria for a broader range of  
people who happen to read it in future.


Cheers
t0m





___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-03 Thread will trillich
Pushy, pushy. :) I'll see what I can come up with.


On Thu, Nov 3, 2011 at 2:29 PM, Tomas Doran bobtf...@bobtfish.net wrote:


 On 3 Nov 2011, at 19:03, will trillich wrote:

  In order to have 'perfect documentation' it must meet two criteria: A)
 explain the utility and usage (benefits and how-to) in a way that I can
 grok and B) show up on my radar in my searches. Both of these depend a
 helluva lot on my own activity and context, making compliance impossible. :)

 Sometimes scar tissue is the only (best?) way to really learn.


 Sure, I totally agree.

 I'm also entirely certain that the documentation as it stands fails at
 meeting (or at least is way before the standard it could be) in your
 criteria for (A), and therefore will fail to meet a good many other
 people's version of the same criteria.

 As someone who has 'just got it', you are absolutely the best placed
 person to modify the documentation to add to the benefits (and maybe
 provide an example) as to make it more clear to people, so that the
 documentation _will_ fulfill that criteria for a broader range of people
 who happen to read it in future.


 Cheers
 t0m





 __**_
 List: Catalyst@lists.scsys.co.uk
 Listinfo: 
 http://lists.scsys.co.uk/cgi-**bin/mailman/listinfo/catalysthttp://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/**
 catalyst@lists.scsys.co.uk/http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/




-- 
The very nucleus of Character: to do what you know you should do, when you
don't want to do it. Stephen Covey
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-03 Thread Denny
On Thu, 2011-11-03 at 15:20 -0500, will trillich wrote:
 The very nucleus of Character: to do what you know you should do,
 when you don't want to do it. Stephen Covey

Good .sig quote for a thread about documentation  :)




___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


[Catalyst] Dealing with timestamps from Postgres

2011-11-02 Thread Adam Jimerson
I'm hoping someone can help me with an issue that I am having with dates
and timestamps that I am pulling out of my Postgres server.
In my database my time stamps are stored like this 2011-05-07 13:53:41-04
(timestamp with time zone), but in my Catalyst app the
date looks like this 2011-05-07T13:53:41.  The T instead of the space is
driving me crazy, I think it is coming from DateTime::Format:Pg
which Catalyst had me install when I first set up my application to use the
database.  Other than doing a find and replace then stash the
results every time I want to pull back a date or timestamp is
there something else that I can do?
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-02 Thread Santiago Zarate
If i'm not wrong, being basically a DateTime object you should be able
to do whatever you like with it instead of having to do a search 
replace, consider using DBIx::Class::InflateColumn to have DBIx do the
job for you every time you need to use that specific model...


On Wed, Nov 2, 2011 at 9:05 PM, Adam Jimerson vend...@gmail.com wrote:
 I'm hoping someone can help me with an issue that I am having with dates and
 timestamps that I am pulling out of my Postgres server.
 In my database my time stamps are stored like this 2011-05-07 13:53:41-04
 (timestamp with time zone), but in my Catalyst app the
 date looks like this 2011-05-07T13:53:41.  The T instead of the space is
 driving me crazy, I think it is coming from DateTime::Format:Pg
 which Catalyst had me install when I first set up my application to use the
 database.  Other than doing a find and replace then stash the
 results every time I want to pull back a date or timestamp is
 there something else that I can do?
 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/



___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/


Re: [Catalyst] Dealing with timestamps from Postgres

2011-11-02 Thread Rippl, Steve
One way (if using DBIx::Class)

$dt_object = $c-model('DB::TableName')-find($row_index)-date_field

(or however your get your resultset)

$formatted_date_string = $dt_object-mdy('/');

where the mdy('/') can be whatever the DateTime object you're retrieving
supports (see CPAN docs).

Can obviously be combined into

$formatted_date_string =
 $c-model('DB::TableName')-find($row_index)-date_field-mdy('/');

I just split it up to illustrate where the DateTime object is coming from.




On Wed, Nov 2, 2011 at 7:05 PM, Adam Jimerson vend...@gmail.com wrote:

 I'm hoping someone can help me with an issue that I am having with dates
 and timestamps that I am pulling out of my Postgres server.
 In my database my time stamps are stored like this 2011-05-07 13:53:41-04
 (timestamp with time zone), but in my Catalyst app the
 date looks like this 2011-05-07T13:53:41.  The T instead of the space is
 driving me crazy, I think it is coming from DateTime::Format:Pg
 which Catalyst had me install when I first set up my application to use
 the database.  Other than doing a find and replace then stash the
 results every time I want to pull back a date or timestamp is
 there something else that I can do?

 ___
 List: Catalyst@lists.scsys.co.uk
 Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
 Searchable archive:
 http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
 Dev site: http://dev.catalyst.perl.org/




-- 
Steve Rippl
Technology Director
Woodland Public Schools
360 841 2730
___
List: Catalyst@lists.scsys.co.uk
Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst
Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/
Dev site: http://dev.catalyst.perl.org/