Templa...Format(3pm)
π NAME π
Template::Plugin::DateTime::Format β ok so bestie, this one lets you format DateTime objects from inside TT, using DateTime::Format-style formatters. It's giving "finally, my dates can be pretty." β¨
πΈ SYNOPSIS πΈ
[% USE f = DateTime::Format('DateTime::Format::Strptime', { pattern => "%T" }) %]
[% f.format(datetime_object) %]
π¦ DESCRIPTION π¦
So like, imagine you have a DateTime object and you wanna render it in your template. Sounds cute right? WRONG. Because the default rendering is 2008-01-01T01:23:45 and honestly? it's giving ugly. π
The usual fix is formatting that DateTime with a DateTime::Format object β totally valid β but the problem is there's usually no nice place to put the formatting code. Nowhere. Not a vibe.
This plugin solves that. π You can create a formatter object from within TT and then use that object to format DateTime objects. Main character behavior, fr fr.
π CREATING AN OBJECT π
Creating a formatter instance is done in the usual TT way:
[% USE varname = DateTime::Format( ... args ... ) %]
This creates a new formatter and calls it varname. Cute name, congrats. π«Ά
The constructor takes up to three arguments. Let's break it down:
- First argument β the name of the formatter class. It is required, and the named class must follow the
DateTime::FormatAPI. An exception will be thrown if the class cannot be loaded. No cap. - Second argument β a reference to pass to the formatter's constructor. If it's an array reference, the array gets dereferenced before being passed to
newas@_. Otherwise, the single reference is passed to the constructor. Simple as. - Third argument β optional! It's the rest of
@_to pass toformat_datetimeafter the DateTime object. And listen, the original author literally says: "I don't know if this is actually allowed by the API, but I figured it might come in handy." So likeβ¦ we're passing along that honesty verbatim. π
π FORMATTING DATES π
Once you've created the object, invoke the format method with the DateTime object you'd like to format. The result of format_datetime is returned. That's it. That's the whole thing. Slay. β¨
π METHODS π
new
Called by TT to create a new formatter. That's its whole job and it does it gorgeously.
format($datetime)
Formats $datetime. Iconic. No notes. π
π REPOSITORY π
<https://github.com/neilbowers/Template-Plugin-DateTime-Format>
(go star it, bestie β)
π§ AUTHOR π§
Jonathan Rockway "<jrockway@cpan.org>"
π COPYRIGHT AND LICENSE π
Copyright (c) 2008 Jonathan Rockway.
This module is free software. You may redistribute it under the same terms as perl itself. π«Ά
btw this whole page came from the User Contributed Perl Documentation section,perl v5.34.0, dated2022-06-17.
That's the tea, bestie β go format some dates and make them β¨beautifulβ¨. π
π¦ where this page comes from
- debian bookworm: libtemplate-plugin-datetime-format-perl 0.03-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtemplate-plugin-datetime-format-perl 0.03-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtemplate-plugin-datetime-format-perl 0.03-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtemplate-plugin-datetime-format-perl 0.03-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtemplate-plugin-datetime-format-perl 0.03-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms