Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Request Tracker: Devel

$DateDayBeforeMonth in DefaultFormat and enhance of date/time display

 

 

Request Tracker devel RSS feed   Index | Next | Previous | View Threaded


elacour at easter-eggs

Jan 9, 2009, 6:13 AM

Post #1 of 5 (1016 views)
Permalink
$DateDayBeforeMonth in DefaultFormat and enhance of date/time display

Dear RT hackers,

current display of date in RT is not correct for french speakers at
least, because mday is before month in Date::DefaultFormat.

so I think it would be good to use $DateDayBeforeMonth here like the
attached patch.

But maybe we would better make use of DateTime::Locale for displaying
date/times to be sure to cover most languages.

Here is an example of DateTime::Locale usage (as I understand this
module):

use DateTime;
use DateTime::Locale;

my $loc = DateTime::Locale->load('fr');
my $format = 'full_date_format';

my $dt = DateTime->from_epoch( locale => 'fr',
epoch => time,
time_zone => 'Europe/Paris',
);

print $dt->strftime($loc->$format);


Output: vendredi 9 janvier 2009


We can still present the different format available in user preferences
and in global config:

full_date_format: vendredi 9 janvier 2009
long_date_format: 9 janvier 2009
medium_date_format: 9 jan 2009
short_date_format: 09/01/09
full_time_format: 12:55:57 v
long_time_format: 12:55:57 Europe/Paris
medium_time_format: 12:55:57
short_time_format: 12:55
full_datetime_format: vendredi 9 janvier 2009 12:55:57 v
long_datetime_format: 9 janvier 2009 12:55:57 Europe/Paris
medium_datetime_format: 9 jan 2009 12:55:57
short_datetime_format: 09/01/09 12:55
Attachments: date_day_before_month.patch (0.91 KB)


jesse at bestpractical

Jan 9, 2009, 9:23 AM

Post #2 of 5 (952 views)
Permalink
Re: $DateDayBeforeMonth in DefaultFormat and enhance of date/time display [In reply to]

On Fri 9.Jan'09 at 15:13:11 +0100, Emmanuel Lacour wrote:
> Dear RT hackers,
>
> current display of date in RT is not correct for french speakers at
> least, because mday is before month in Date::DefaultFormat.
>
> so I think it would be good to use $DateDayBeforeMonth here like the
> attached patch.

Hm. This makes me a little twitchy. I'd really rather keep it
parsing-only. I like your suggestion below :)


>
> But maybe we would better make use of DateTime::Locale for displaying
> date/times to be sure to cover most languages.

I like this plan better :)

> Here is an example of DateTime::Locale usage (as I understand this
> module):
>

Cool. Can we make it depend on DateTime::Locale only if it's installed?

Also, I'd probably only offer the datetime formats, since only-date and
only-time formats don't make a whole lot of sense in RT ;)

> use DateTime;
> use DateTime::Locale;
>
> my $loc = DateTime::Locale->load('fr');
> my $format = 'full_date_format';
>
> my $dt = DateTime->from_epoch( locale => 'fr',
> epoch => time,
> time_zone => 'Europe/Paris',
> );
>
> print $dt->strftime($loc->$format);
>
>
> Output: vendredi 9 janvier 2009
>
>
> We can still present the different format available in user preferences
> and in global config:
>
> full_date_format: vendredi 9 janvier 2009
> long_date_format: 9 janvier 2009
> medium_date_format: 9 jan 2009
> short_date_format: 09/01/09
> full_time_format: 12:55:57 v
> long_time_format: 12:55:57 Europe/Paris
> medium_time_format: 12:55:57
> short_time_format: 12:55
> full_datetime_format: vendredi 9 janvier 2009 12:55:57 v
> long_datetime_format: 9 janvier 2009 12:55:57 Europe/Paris
> medium_datetime_format: 9 jan 2009 12:55:57
> short_datetime_format: 09/01/09 12:55
>
>


> _______________________________________________
> List info: http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel


--


elacour at easter-eggs

Jan 12, 2009, 1:28 AM

Post #3 of 5 (938 views)
Permalink
Re: $DateDayBeforeMonth in DefaultFormat and enhance of date/time display [In reply to]

On Fri, Jan 09, 2009 at 12:23:15PM -0500, Jesse Vincent wrote:
>
> Hm. This makes me a little twitchy. I'd really rather keep it
> parsing-only. I like your suggestion below :)
>

I agree, I just modified a bit the description in RT_Config.pm.in to
say that it's only for parsing.

>
> >
> > But maybe we would better make use of DateTime::Locale for displaying
> > date/times to be sure to cover most languages.
>
> I like this plan better :)
>
> > Here is an example of DateTime::Locale usage (as I understand this
> > module):
> >
>
> Cool. Can we make it depend on DateTime::Locale only if it's installed?
>

See attached patch.

> Also, I'd probably only offer the datetime formats, since only-date and
> only-time formats don't make a whole lot of sense in RT ;)
>

Thought, I prefer to stay consistent with current output formaters which
supports this ;)
Attachments: datetime_locale.patch (4.14 KB)


jesse at bestpractical

Jan 12, 2009, 5:34 AM

Post #4 of 5 (930 views)
Permalink
Re: $DateDayBeforeMonth in DefaultFormat and enhance of date/time display [In reply to]

That seems fairly reasonable. If it had tests, it would be incredibly
reasonable ;)


On Mon, Jan 12, 2009 at 10:28:40AM +0100, Emmanuel Lacour wrote:
> On Fri, Jan 09, 2009 at 12:23:15PM -0500, Jesse Vincent wrote:
> >
> > Hm. This makes me a little twitchy. I'd really rather keep it
> > parsing-only. I like your suggestion below :)
> >
>
> I agree, I just modified a bit the description in RT_Config.pm.in to
> say that it's only for parsing.
>
> >
> > >
> > > But maybe we would better make use of DateTime::Locale for displaying
> > > date/times to be sure to cover most languages.
> >
> > I like this plan better :)
> >
> > > Here is an example of DateTime::Locale usage (as I understand this
> > > module):
> > >
> >
> > Cool. Can we make it depend on DateTime::Locale only if it's installed?
> >
>
> See attached patch.
>
> > Also, I'd probably only offer the datetime formats, since only-date and
> > only-time formats don't make a whole lot of sense in RT ;)
> >
>
> Thought, I prefer to stay consistent with current output formaters which
> supports this ;)
>

> diff --git a/etc/RT_Config.pm.in b/etc/RT_Config.pm.in
> index 0ac4a30..9bc0c2e 100755
> --- a/etc/RT_Config.pm.in
> +++ b/etc/RT_Config.pm.in
> @@ -1284,6 +1284,7 @@ section in perldoc F<lib/RT/Date.pm> for more options. This option can
> be overridden by users in their preferences.
> Some examples:
>
> +C<Set($DateTimeFormat, 'LocalizedDateTime');>
> C<Set($DateTimeFormat, { Format => 'ISO', Seconds => 0 });>
> C<Set($DateTimeFormat, 'RFC2822');>
> C<Set($DateTimeFormat, { Format => 'RFC2822', Seconds => 0, DayOfWeek => 0 });>
> diff --git a/lib/RT/Config.pm b/lib/RT/Config.pm
> index 0027656..710a2c9 100644
> --- a/lib/RT/Config.pm
> +++ b/lib/RT/Config.pm
> @@ -275,7 +275,11 @@ our %META = (
> Callback => sub { my $ret = { Values => [], ValuesLabel => {}};
> my $date = new RT::Date($HTML::Mason::Commands::session{'CurrentUser'});
> $date->Set;
> - foreach my $value (qw(DefaultFormat RFC2822 ISO W3CDTF)) { #loc_qw
> + my @formats = qw(DefaultFormat RFC2822 ISO W3CDTF); #loc_qw
> + if ( eval 'use DateTime qw(); 1;' && eval 'use DateTime::Locale qw(); 1;' ) {
> + push @formats, 'LocalizedDateTime'; #loc
> + }
> + foreach my $value (@formats) {
> push @{$ret->{Values}}, $value;
> $ret->{ValuesLabel}{$value} = $date->$value();
> }
> diff --git a/lib/RT/Date.pm b/lib/RT/Date.pm
> index c1354b7..b03f8a1 100755
> --- a/lib/RT/Date.pm
> +++ b/lib/RT/Date.pm
> @@ -586,6 +586,72 @@ sub DefaultFormat
> }
> }
>
> +=head3 LocalizedDateTime
> +
> +Returns date and time as string, with user localization.
> +
> +Supports arguments: C<DateFormat> and C<TimeFormat> which may contains date and
> +time format as specified in DateTime::Locale (default to full_date_format and
> +medium_time_format), C<AbbrDay> and C<AbbrMonth> which may be set to 0 if
> +you want full Day/Month names instead of abbreviated ones.
> +
> +Require optionnal DateTime::Locale module.
> +
> +=cut
> +
> +sub LocalizedDateTime
> +{
> + my $self = shift;
> + my %args = ( Date => 1,
> + Time => 1,
> + Timezone => '',
> + DateFormat => 'full_date_format',
> + TimeFormat => 'medium_time_format',
> + AbbrDay => 1,
> + AbbrMonth => 1,
> + @_,
> + );
> +
> + return $self->loc("DateTime module missing") unless ( eval 'use DateTime qw(); 1;' );
> + return $self->loc("DateTime::Locale module missing") unless ( eval 'use DateTime::Locale qw(); 1;' );
> + my $date_format = $args{'DateFormat'};
> + my $time_format = $args{'TimeFormat'};
> +
> + my $lang = $self->CurrentUser->UserObj->Lang || 'en';
> +
> + my $formatter = DateTime::Locale->load($lang);
> + $date_format = $formatter->$date_format;
> + $time_format = $formatter->$time_format;
> + $date_format =~ s/\%A/\%a/g if ( $args{'AbbrDay'} );
> + $date_format =~ s/\%B/\%b/g if ( $args{'AbbrMonth'} );
> +
> + my ($sec,$min,$hour,$mday,$mon,$year,$wday,$ydaym,$isdst,$offset) =
> + $self->Localtime($args{'Timezone'});
> + $mon++;
> + my $tz = $self->Timezone($args{'Timezone'});
> +
> + # FIXME : another way to call this module without conflict with local
> + # DateTime method?
> + my $dt = new DateTime::( locale => $lang,
> + time_zone => $tz,
> + year => $year,
> + month => $mon,
> + day => $mday,
> + hour => $hour,
> + minute => $min,
> + second => $sec,
> + nanosecond => 0,
> + );
> +
> + if ( $args{'Date'} && !$args{'Time'} ) {
> + return $dt->strftime($date_format);
> + } elsif ( !$args{'Date'} && $args{'Time'} ) {
> + return $dt->strftime($time_format);
> + } else {
> + return $dt->strftime($date_format) . " " . $dt->strftime($time_format);
> + }
> +}
> +
> =head3 ISO
>
> Returns the object's date in ISO format C<YYYY-MM-DD mm:hh:ss>.

> _______________________________________________
> List info: http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel


--
_______________________________________________
List info: http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel


elacour at easter-eggs

Jan 13, 2009, 11:09 AM

Post #5 of 5 (928 views)
Permalink
Re: $DateDayBeforeMonth in DefaultFormat and enhance of date/time display [In reply to]

On Mon, Jan 12, 2009 at 08:34:36AM -0500, Jesse Vincent wrote:
> That seems fairly reasonable. If it had tests, it would be incredibly
> reasonable ;)
>

I just commited those reasonable things ;)

_______________________________________________
List info: http://lists.bestpractical.com/cgi-bin/mailman/listinfo/rt-devel

Request Tracker devel RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.