Templa...teTime(3pm)
π Template::Plugin::DateTime β the Template::Plugin::DateTime page, bestie edition π
okay so this is Template::Plugin::DateTime, a little gem from the User Contributed Perl Documentation corner of your perldoc, and it's literally your VIP pass to using DateTime objects inside your Template Toolkit templates. no more squinting at Perl in your .tt files, we're doing this in-template now π
β¨ NAME β¨
Template::Plugin::DateTime β a Template Plugin To Use DateTime Objects π¦
β¨ SYNOPSIS β¨
the vibe: you USE the plugin, you get a date object, you go absolutely feral with it.
[% USE date = DateTime(year = 2004, month = 4, day = 1) %]
[% USE date = DateTime(today = 1) %]
Today is [% date.year %]/[% date.month %]/[% date.day %].
[% date.add(days => 32) %]
32 days from today is [% date.year %]/[% date.month %]/[% date.day %].
see how easy?? build a date, print its bits, add 32 days, print it again. slay β¨
β¨ DESCRIPTION β¨
so the basic idea of using a DateTime plugin is, like, this:
USE date = DateTime(year = 2004, month = 4, day = 1);
-OR- (bestie we have options, obviously)
by passing a pattern to parse a date by string using DateTime::Format::Strptime:
USE date = DateTime(from_string => '2008-05-30 00:00:00', pattern => '%Y-%m-%d %H:%M:%S', time_zone => 'America/New_York');
literally that's the whole concept. you pick how the date gets born, the plugin handles the rest. πΈ
β¨ METHODS β¨
π new
this is used internally. You won't be using it from your templates. <em>hands off, girl, it's not for you π</em>
β¨ CONSTRUCTOR β¨
the constructor is exactly the same as that of Datetime.pm, except β plot twist β you can pass optional parameters to it to toggle between different underlying DateTime constructors. pick your fighter: π
from_epochβ Creates a Datetime object by callingDateTime::from_epoch(). The value for thefrom_epochparameter must be a number representing UNIX epoch.
[% epoch = ... %]
[% USE date = DateTime(from_epoch = epoch) %]
nowβ Creates a DateTime object by callingDateTime::now(). The value for thenowparameter is a boolean value.
[% USE date = DateTime(now = 1) %]
[% USE date = Datetime(now = 1, time_zone => 'Asia/Tokyo') %]
todayβ Creates a DateTime object by callingDateTime::today(). The value for thetodayparameter is a boolean value.
[% USE date = DateTime(today = 1) %]
from_objectβ Creates a DateTime object by callingDateTime::from_object(). The value for thefrom_objectmust be an object implementing theutc_rd_values()method, as described inDateTime.pm.
[% USE date = DateTime(from_object = other_date) %]
last_day_of_monthβ Creates a DateTime object by callingDateTime::last_day_of_month(). The value for thelast_day_of_monthparameter is a boolean value, and"year"and"month"parameters must be specified.
[% USE date = DateTime(last_day_of_month = 1, year = 2004, month = 4 ) %]
from_stringβ Creates a DateTime object by callingDateTime::Format::Strptime. The value for thefrom_stringparameter is a string value, and the"pattern"parameter is optional and defaults to'%Y-%m-%d %H:%M:%S'. SeeDateTime::Format::Strptimefor other optional parameters. π§
[% USE date = DateTime(from_string => '2008-05-30 10:00:00', pattern => '%Y-%m-%d %H:%M:%S') %]
β¨ SEE ALSO β¨
DateTime DateTime::Format::Strptime Template β the whole friend group π«Ά
β¨ AUTHOR β¨
Copyright (c) 2004-2007 Daisuke Maki <daisuke@endeworks.jp>. respect the icon π
β¨ LICENSE β¨
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
See http://www.perl.com/perl/misc/Artistic.html
and that's the whole page, bestie π this one's running on perl v5.34.0 and the docs are dated 2022-06-17 β old but iconic, no cap. go build some dates, you're gonna eat πβ¨
π¦ where this page comes from
- debian bookworm: libtemplate-plugin-datetime-perl 0.06002-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libtemplate-plugin-datetime-perl 0.06002-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libtemplate-plugin-datetime-perl 0.06002-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtemplate-plugin-datetime-perl 0.06002-2 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtemplate-plugin-datetime-perl 0.06002-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