App-Dapper
view release on metacpan or search on metacpan
representing the current system time, formatted by strftime() according to the
default format and for the default locale (which may not be the current one, if
locale is set in the use directive).
[% date.format %]
The plugin allows a time/date to be specified as seconds since the epoch, as is
returned by time().
File last modified: [% date.format(filemod_time) %]
The time/date can also be specified as a string of the form `h:m:s d/m/y` or
`y/m/d h:m:s`. Any of the characters `:` `/` `-` or space may be used to delimit
fields.
[% use day = date(format => '%A', locale => 'en_GB') %]
[% day.format('4:20:00 9-13-2000') %]
Output:
Tuesday
A format string can also be passed to the format() method, and a locale
specification may follow that.
[% date.format(filemod, '%d-%b-%Y') %]
[% date.format(filemod, '%d-%b-%Y', 'en_GB') %]
A fourth parameter allows you to force output in GMT, in the case of seconds-
since-the-epoch input:
[% date.format(filemod, '%d-%b-%Y', 'en_GB', 1) %]
Note that in this case, if the local time is not GMT, then also specifying '%Z'
(time zone) in the format parameter will lead to an extremely misleading result.
Any or all of these parameters may be named. Positional parameters should always
be in the order ($time, $format, $locale).
[% date.format(format => '%H:%M:%S') %]
[% date.format(time => filemod, format => '%H:%M:%S') %]
[% date.format(mytime, format => '%H:%M:%S') %]
[% date.format(mytime, format => '%H:%M:%S', locale => 'fr_FR') %]
[% date.format(mytime, format => '%H:%M:%S', gmt => 1) %]
...etc...
The now() method returns the current system time in seconds since the epoch.
[% date.format(date.now, '%A') %]
The calc() method can be used to create an interface to the Date::Calc module (if
installed on your system).
[% calc = date.calc %]
[% calc.Monday_of_Week(22, 2001).join('/') %]
The manip() method can be used to create an interface to the Date::Manip module
(if installed on your system).
[% manip = date.manip %]
[% manip.UnixDate("Noon Yesterday","%Y %b %d %H:%M") %]
## Chomping
When using directives in templates, it can help to add whitespace around
the directives to make them more readable. However, adding this whitespace
can make the resulting output unreadable. To help with this, special uses of
the `+`, `-`, `=`, and `~` characters can be used to pre- and post-chomp
the whitespace as follows:
#### [%+ Chomp None +%]
Don't do any chomping.
```
Quick.
[%+ "Brown." +%]
Fox.
```
Result:
```
Quick.
Brown.
Fox.
```
#### [%- Chomp One -%]
Delete any whitespace up to the adjacent newline.
```
Quick.
[%- "Brown." -%]
Fox.
```
Result:
```
Quick.
Brown.
Fox.
```
#### [%= Chomp Collapse =%]
Collapse adjacent whitespace to a single space.
```
Quick.
[%= "Brown." =%]
( run in 3.225 seconds using v1.01-cache-2.11-cpan-64ef6c95b5d )