[Catalyst] Changing format of date field
Hartmaier Alexander
alexander.hartmaier at t-systems.at
Wed Jan 8 18:14:43 GMT 2014
On 2014-01-08 18:56, Adam Witney wrote:
>
>
> On 8. 1. 2014 17:31, Hartmaier Alexander wrote:
>> On 2014-01-08 18:19, Adam Witney wrote:
>>>
>>>
>>> On 7. 1. 2014 9:55, neil.lunn wrote:
>>>
>>>> 3. You *Are* going to get back a string in the raw params. So what you
>>>> need to do is parse that format into a DateTime object again when
>>>> submitting back to model or wherever else you want to use it as an
>>>> object.
>>>
>>> Thanks guys for the various suggestions, I think I will follow this
>>> approach above and leave the format to the view as suggested!
>>>
>>> Thanks again
>>>
>>> Adam
>> I have various format_ methods in my view class that are exposed to TT
>> using View::TT's expose_methods config option including format_date,
>> format_datetime and format_datetime_ajax.
>
> Thanks Alexander, could you possibly send me an example of the
> format_datetime? I am trying to figure exactly where and how to put it
> in.
>
> Thanks
>
> Adam
>
package NAC::Web::NAC::View::HTML;
use strict;
use warnings;
use Safe::Isa;
use parent 'Catalyst::View::TT';
__PACKAGE__->config(
TEMPLATE_EXTENSION => '.tt',
render_die => 1,
CONSTANTS => { version => $NAC::Web::NAC::VERSION, },
ENCODING => 'utf-8',
expose_methods => [
qw( format_bps format_bytes format_datetime format_date
format_datetime_ajax format_int_speed format_int_speed_real )
],
);
=head1 NAME
NAC::Web::NAC::View::HTML - TT View for NAC::Web::NAC
=head1 DESCRIPTION
TT View for NAC::Web::NAC.
=over
=item format_datetime
Returns a scalar from a DateTime object stringified to %Y-%m-%d %H:%M %z.
=cut
sub format_datetime {
my ( $self, $c, $datetime ) = @_;
if ( $datetime->$_isa('DateTime') ) {
# FIXME: yes that's ugly, but else we'd need to get the users
timezone or format client-side
return $datetime->clone->set_time_zone('Europe/Vienna')
->strftime('%Y-%m-%d %H:%M %z');
}
return;
}
1;
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
T-Systems Austria GesmbH Rennweg 97-99, 1030 Wien
Handelsgericht Wien, FN 79340b
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
Notice: This e-mail contains information that is confidential and may be privileged.
If you are not the intended recipient, please notify the sender and then
delete this e-mail immediately.
*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*"*
More information about the Catalyst
mailing list