Mailing List Archive

date formatting
Hi,

I am writing an RSS template that would produce rss output for a
category and date formatting is killing me. Any way that $story->get_publish_date
return date in RFC-822 format. Is date formating left on users?

Zdravko
Re: date formatting [ In reply to ]
> return date in RFC-822 format. Is date formating left on users?

To make things worse, my strftime keeps saying that today is Sunday!?

:(
Zdravko
Re: date formatting [ In reply to ]
Hi,

What do you need that the documentation on the Bric::Util::Time module
didn't show you ? I'll be happy to improve the documentation.

regards,

Paul

Zdravko Balorda wrote:
>
> Hi,
>
> I am writing an RSS template that would produce rss output for a
> category and date formatting is killing me. Any way that
> $story->get_publish_date
> return date in RFC-822 format. Is date formating left on users?
>
> Zdravko
>
>
Re: date formatting [ In reply to ]
On Feb 9, 2010, at 2:26 AM, Zdravko Balorda wrote:

> I am writing an RSS template that would produce rss output for a
> category and date formatting is killing me. Any way that $story->get_publish_date
> return date in RFC-822 format. Is date formating left on users?

Something like:

$story->get_publish_date('%a, %d %b %Y %H:%M:%S %z');

`perldoc DateTime` for more on the supported strftime formats.

Best,

David
Re: date formatting [ In reply to ]
> What do you need that the documentation on the Bric::Util::Time module
> didn't show you ? I'll be happy to improve the documentation.
>


Beside that it's my first time using any Bric::Util package,
% use Bric::Util::Time ’:all’;
fails to include saying (bricolage 1.10.4. Do upgrade, I know. :):
Error during compilation of <anonymous component>: Unrecognized character \xE2 at (eval 78998) line 11, <GEN2844> line 637. Stack:
[/usr/local/lib/perl5/site_perl/5.8.8/HTML/Mason/Interp.pm:631] [/usr/local/lib/perl5/site_perl/5.8.8/Bric/Util/Burner/Mason.pm:355]
[/usr/local/lib/perl5/site_perl/5.8.8/Bric/Util/Burner.pm:1523]
[/usr/local/lib/perl5/site_perl/5.8.8/Bric/App/Callback/Profile/Template.pm:567]
[/usr/local/lib/perl5/site_perl/5.8.8/Bric/App/Callback/Profile/Template.pm:98]
[/usr/local/lib/perl5/site_perl/5.8.8/Params/CallbackRequest.pm:296]
[/usr/local/lib/perl5/site_perl/5.8.8/MasonX/Interp/WithCallbacks.pm:119]
[/usr/local/lib/perl5/site_perl/5.8.8/HTML/Mason/ApacheHandler.pm:868]
[/usr/local/lib/perl5/site_perl/5.8.8/HTML/Mason/ApacheHandler.pm:822]
[/usr/local/lib/perl5/site_perl/5.8.8/Bric/App/Handler.pm:314] [/dev/null:0]

Regards, Zdravko.

ps. I've missed that $story->get_publish_date accepts format as argument.
This fixes all of my problems. :)
Re: date formatting [ In reply to ]
On Feb 9, 2010, at 11:36 PM, Zdravko Balorda wrote:

>
>> What do you need that the documentation on the Bric::Util::Time module didn't show you ? I'll be happy to improve the documentation.
>
>
> Beside that it's my first time using any Bric::Util package,
> % use Bric::Util::Time ’:all’;

Don't use smart quotes there.

> ps. I've missed that $story->get_publish_date accepts format as argument.
> This fixes all of my problems. :)

Great!

Best,

David
Re: date formatting [ In reply to ]
Hi,

I am having a bit of trouble setting LC_ALL:
% use POSIX;
% use locale;
% setlocale(LC_ALL, "sl_SI.UTF-8");

works ok, (I've checked it in perl) but
Bricolage construct
<% $story->get_cover_date($datef) %> locale <% setlocale(LC_ALL) %>
seems to ignore it and keeps writing English dates.

Any hint?
Regards, Zdravko
Re: date formatting [ In reply to ]
Hi Zdravko,


I've always used DateTime directly to format dates, like this:

$date = DateTime->from_epoch( epoch => $story->get_cover_date('%s'),
locale => $locale );

Then output $date with the format of your choice.:

<% $date->strftime($format) %>

Hope this helps,

Bret


On Thu, 2010-06-10 at 08:34 +0200, Zdravko Balorda wrote:
>
> Hi,
>
> I am having a bit of trouble setting LC_ALL:
> % use POSIX;
> % use locale;
> % setlocale(LC_ALL, "sl_SI.UTF-8");
>
> works ok, (I've checked it in perl) but
> Bricolage construct
> <% $story->get_cover_date($datef) %> locale <% setlocale(LC_ALL) %>
> seems to ignore it and keeps writing English dates.
>
> Any hint?
> Regards, Zdravko
>
>


--
Bret Dawson
Producer
Pectopah Productions Inc.
(416) 895-7635
bret@pectopah.com
www.pectopah.com
Re: date formatting [ In reply to ]
On Jun 9, 2010, at 11:34 PM, Zdravko Balorda wrote:

> I am having a bit of trouble setting LC_ALL:
> % use POSIX;
> % use locale;
> % setlocale(LC_ALL, "sl_SI.UTF-8");
>
> works ok, (I've checked it in perl) but
> Bricolage construct
> <% $story->get_cover_date($datef) %> locale <% setlocale(LC_ALL) %>
> seems to ignore it and keeps writing English dates.

From the DateTime documentation:

> Locales
> All the object methods which return names or abbreviations return data
> based on a locale. This is done by setting the locale when
> constructing a DateTime object. There is also a "DefaultLocale()"
> class method which may be used to set the default locale for all
> DateTime objects created. If this is not set, then "en_US" is used.

So I imagine you want to call `DateTime->DefaultLocale('sl_SI')` in the <%init> block of your root-level autohandler, and then set it back to "en_US" in a <%cleanup> block. Or if you just need the dates in non-English in one place, scope more appropriately.

Best,

David
Re: date formatting [ In reply to ]
> So I imagine you want to call `DateTime->DefaultLocale('sl_SI')` in the <%init> block of your root-level autohandler, and then set it back to "en_US" in a <%cleanup> block. Or if you just need the dates in non-English in one place, scope more appropriately.
>

Thank you. It works. :)

Regards, Zdravko