[rt-users] Still Can't Figured Out DateTimeFormat
Kevin Falcone
falcone at bestpractical.com
Fri Apr 4 11:28:17 EDT 2014
On Thu, Apr 03, 2014 at 03:12:13PM -0700, Tim Gustafson wrote:
> I'm still struggling with setting a custom date/time format in RT 4.2.
You've forgotten to say what format you want, except obliquely in the
code below.
> I've tried man different variants of the following to no avail:
>
> Set(
> $DateTimeFormat,
> {
> "Format" => "LocalizedDateTime",
> "DateFormat" => "MM/dd/yyyy",
> "TimeFormat" => "hh:mm a"
> }
> );
> Returns date and time as string, with user localization.
I believe you're misunderstanding 'localization' in this context.
The feature you're using is intended to say "If a user's RT Language
is set to french, attempt to use what DateTime::Locale knows about
french dates/times to format their date". This is a highly technical
definition of 'localization', but is related to RT's support for many
languages.
> Supports arguments: DateFormat and TimeFormat which may contains date
> and time format as specified in DateTime::Locale (default to
> date_format_full and time_format_medium), AbbrDayand AbbrMonth which
> may be set to 0 if you want full Day/Month names instead of
> abbreviated ones.
The docs imply to read the DateTime::Locale docs
https://metacpan.org/pod/DateTime::Locale
and to give it a Date formatting method and a Time formatting method
as understood by DateTime::Locale. DateTime::Locale will then use
what you input (such as time_format_medium) to calculate what the
user's language indicates it should display. In particular,
time_format_medium for a swedish user may be different than
time_format_medium for a british user.
There is no arbitrary input of time format strings available through
this interface. Arbitrary format strings would defeat the purpose of
allowing a localized date and time display based on the user's
language.
You could however construct an arbitrary date using DateTime::Locale's
formatting method and passing it arbitrary format strings, but at that
point you've done a lot of work to reimplement POSIX::strftime
> However, when I set this option in my RT_SiteConfig.pm, the system
> defaults back to the default date/time format.
Actually, as an english speaker, with your configuration, I see
Sun, Mar 16, 2014 3:53:14 PM
which is quite different from
Sun Mar 16 15:53:14 2014
the RT system standard.
And if I was Swedish, I would see
sön 16 mar 2014 15.53.14
You'll note that it knows to put the day before the month and to use
.s instead of :s
> I feel as though this ought to be an easy thing to change, and yet
> none of the documentation describes how to do it. I have asked this
> question before and never received a satisfactory answer.
You didn't reply to my previous answer explaining or asking for
clarification.
> You don't need a custom module to set the time zone, so why should you
> need one to set the date/time format?
I believe you misunderstand the complexity of date output formats.
Timezones are actually easier in many ways.
> Is there really no simple configuration option that I can set to
> format the date and time in an arbitrary way?
Arbitrary? Write the 4 lines of code I showed you when you asked this
question originally. Or, as I replied to your previous email, instead of
attempting to use LocalizedDateTime, pick the RT built-in which is
*already* close to your time format and see if you can pass arguments
(things such as the default RT format allow you to pass Seconds => 0
for example). Or read the DateTime::Locale docs and hope there's a
format close enough to the one you need, however a quick perusal of
their code makes that doubtful.
Faced with a date format as specific as yours and far from any built
in RT formats, I would look to see if your format has an RFC name, see
if there is a perl module to do the heavy lifting and then write the
trivial piece of code. It would probably have taken less time than
you've spent wrestling with LocalizedDateTime at this point.
-kevin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 235 bytes
Desc: not available
URL: <http://lists.bestpractical.com/pipermail/rt-users/attachments/20140404/953efceb/attachment.sig>
More information about the rt-users
mailing list