Templa...teTime(3pm)

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

πŸŽ€ 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 calling DateTime::from_epoch(). The value for the from_epoch parameter must be a number representing UNIX epoch.
  [% epoch = ...  %]
  [% USE date = DateTime(from_epoch = epoch) %]
  • now β€” Creates a DateTime object by calling DateTime::now(). The value for the now parameter is a boolean value.
  [% USE date = DateTime(now = 1) %]
  [% USE date = Datetime(now = 1, time_zone => 'Asia/Tokyo') %]
  • today β€” Creates a DateTime object by calling DateTime::today(). The value for the today parameter is a boolean value.
  [% USE date = DateTime(today = 1) %]
  • from_object β€” Creates a DateTime object by calling DateTime::from_object(). The value for the from_object must be an object implementing the utc_rd_values() method, as described in DateTime.pm.
  [% USE date = DateTime(from_object = other_date) %]
  • last_day_of_month β€” Creates a DateTime object by calling DateTime::last_day_of_month(). The value for the last_day_of_month parameter 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 calling DateTime::Format::Strptime. The value for the from_string parameter is a string value, and the "pattern" parameter is optional and defaults to '%Y-%m-%d %H:%M:%S'. See DateTime::Format::Strptime for 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