$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

date_day_before_month.patch (928 Bytes)

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 :slight_smile:

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 :slight_smile:

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 :wink:

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

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 :slight_smile:

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 :wink:

Thought, I prefer to stay consistent with current output formaters which
supports this :wink:

datetime_locale.patch (4.14 KB)

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 :slight_smile:

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 :slight_smile:

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 :wink:

Thought, I prefer to stay consistent with current output formaters which
supports this :wink:

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 and C which may contains date and
+time format as specified in DateTime::Locale (default to full_date_format and
+medium_time_format), C and C 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::frowning: 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.


List info: The rt-devel Archives

That seems fairly reasonable. If it had tests, it would be incredibly
reasonable :wink:

I just commited those reasonable things :wink: