Re: [Catalyst] Setting time zone and locale on dates.

2007-05-22 Thread Chisel Wright
On Tue, May 22, 2007 at 01:55:23AM +0100, Matt S Trout wrote:
 DBIx::Class::InflateColumn::DateTime will do this part for you these days.

I'd noticed that floating around but never found the tuits to
investigate.

Maybe I should install the tinker on my laptop and investigate on my
next commute.

C.
-- 
Chisel Wright
e: [EMAIL PROTECTED]
w: http://www.herlpacker.co.uk/

  For this and the answers to many other questions don't ask me.

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


Re: [Catalyst] Setting time zone and locale on dates.

2007-05-22 Thread Pedro Melo

Hi,

On May 21, 2007, at 9:54 PM, Bill Moseley wrote:


This likely falls into one of the many how do I get $c into the
model threads.

My session has the locale and timezone fetched from the user's
preferences at login.  It's not really locale, but a language tag
which is also used by Locale::Maketext, but should work for DateTime's
locale setting.

I use timestamp with time zone on my Postgresql timestamps and the
model inflates to DataTime objects.  Most if not all dates should be
localized for the user.

I'm tempted to use model class data to pass this to the model.  So at
the start of every request do something like:

My::Model-current_timezone( $c-session-{timezone} );
My::Model-current_locale( $c-session-{locale} );

And then have the model use those (if set) when inflating.

Any better ideas for dealing with this?

I ask because (besides not having that much I18N experience) I
think this is something that really belongs in the view.

[% c.local_date( user.last_updated_time ) | html %]

But, setting the locale and time_zone in the inflator would be handy
since it's all one place instead of every time I use a date in the
view.

What do you do?


I always do my model datetime stuff in UTC.

Formatting according to user prefs belongs in the view, IMHO.

I understand your wish to format in only one place, but IMHO, thats  
whar BLOCKs or PROCESSed files are for. Just do a date.tt and use it  
every where. Or write a Template::Plugin that takes in account your  
user preferences and just do [% my.date_field | user_pref_date %]


Best regards,
--
Pedro Melo
Blog: http://www.simplicidade.org/notes/
Jabber ID: [EMAIL PROTECTED]
Use Jabber!



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


Re: [Catalyst] Setting time zone and locale on dates.

2007-05-22 Thread Chisel Wright
On Tue, May 22, 2007 at 10:20:26AM +0100, Pedro Melo wrote:
 I always do my model datetime stuff in UTC.

After many years of painful date-work thanks to decisions made by
others, this is how I prefer to work.
Store everything in UTC (with time zome, just to be clear).

After that, formatting and TZ tweaking is just eye candy in the
template

-- 
Chisel Wright
e: [EMAIL PROTECTED]
w: http://www.herlpacker.co.uk/

  Atheism is a religion, provided you also accept that
  NOT collecting stamps is a hobby.

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


[Catalyst] Setting time zone and locale on dates.

2007-05-21 Thread Bill Moseley
This likely falls into one of the many how do I get $c into the
model threads.

My session has the locale and timezone fetched from the user's
preferences at login.  It's not really locale, but a language tag
which is also used by Locale::Maketext, but should work for DateTime's
locale setting.

I use timestamp with time zone on my Postgresql timestamps and the
model inflates to DataTime objects.  Most if not all dates should be
localized for the user.

I'm tempted to use model class data to pass this to the model.  So at
the start of every request do something like:

My::Model-current_timezone( $c-session-{timezone} );
My::Model-current_locale( $c-session-{locale} );

And then have the model use those (if set) when inflating.

Any better ideas for dealing with this?

I ask because (besides not having that much I18N experience) I
think this is something that really belongs in the view.

[% c.local_date( user.last_updated_time ) | html %]

But, setting the locale and time_zone in the inflator would be handy
since it's all one place instead of every time I use a date in the
view.

What do you do?


-- 
Bill Moseley
[EMAIL PROTECTED]


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


Re: [Catalyst] Setting time zone and locale on dates.

2007-05-21 Thread Chisel Wright
On Mon, May 21, 2007 at 01:54:54PM -0700, Bill Moseley wrote:
 What do you do?

I inflate all my dates to DateTime objects:

  foreach my $datecol (qw/created/) {
__PACKAGE__-inflate_column($datecol, {
  inflate = sub { DateTime::Format::Pg-parse_datetime(shift); },
  deflate = sub { DateTime::Format::Pg-format_datetime(shift); },
});
  }

Then to display dates, I pass them through my somewhat scruffy looking
nicedate() TT macro:

http://svn.berlios.de/svnroot/repos/parley/trunk/root/base/shared/useful_tt_stuff

There might be nicer ways, but the overall method seems to be working
really well for me so far.

I'm not sure if/how locale would tie into this though.

Chisel
-- 
Chisel Wright
e: [EMAIL PROTECTED]
w: http://www.herlpacker.co.uk/

  SELECT message FROM signatures ORDER BY RANDOM() LIMIT 1;

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


Re: [Catalyst] Setting time zone and locale on dates.

2007-05-21 Thread Matt S Trout
On Mon, May 21, 2007 at 10:58:34PM +0100, Chisel Wright wrote:
 On Mon, May 21, 2007 at 01:54:54PM -0700, Bill Moseley wrote:
  What do you do?
 
 I inflate all my dates to DateTime objects:
 
   foreach my $datecol (qw/created/) {
 __PACKAGE__-inflate_column($datecol, {
   inflate = sub { DateTime::Format::Pg-parse_datetime(shift); },
   deflate = sub { DateTime::Format::Pg-format_datetime(shift); },
 });
   }

DBIx::Class::InflateColumn::DateTime will do this part for you these days.

-- 
  Matt S Trout   Need help with your Catalyst or DBIx::Class project?
   Technical DirectorWant a managed development or deployment platform?
 Shadowcat Systems Ltd.  Contact mst (at) shadowcatsystems.co.uk for a quote
http://chainsawblues.vox.com/ http://www.shadowcatsystems.co.uk/ 

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