Templa...Format(3pm)

πŸ“¦
version 0.03 Β· 2 versions
  • 0.03 Β· debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking (latest)
  • 0.03 Β· ubuntu jammy
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– 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::Format API. 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 new as @_. Otherwise, the single reference is passed to the constructor. Simple as.
  • Third argument β€” optional! It's the rest of @_ to pass to format_datetime after 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 (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, dated 2022-06-17.

That's the tea, bestie β€” go format some dates and make them ✨beautiful✨. πŸ’–

πŸ“¦ where this page comes from