1Template::Plugin::Date(U3s)er Contributed Perl DocumentatTieomnplate::Plugin::Date(3)
2
3
4

NAME

6       Template::Plugin::Date - Plugin to generate formatted date strings
7

SYNOPSIS

9           [% USE date %]
10
11           # use current time and default format
12           [% date.format %]
13
14           # specify time as seconds since epoch or 'h:m:s d-m-y' string
15           [% date.format(960973980) %]
16           [% date.format('4:20:36 21/12/2000') %]
17
18           # specify format
19           [% date.format(mytime, '%H:%M:%S') %]
20
21           # specify locale
22           [% date.format(date.now, '%a %d %b %y', 'en_GB') %]
23
24           # named parameters
25           [% date.format(mytime, format = '%H:%M:%S') %]
26           [% date.format(locale = 'en_GB') %]
27           [% date.format(time   = date.now,
28                          format = '%H:%M:%S',
29                          locale = 'en_GB) %]
30
31           # specify default format to plugin
32           [% USE date(format = '%H:%M:%S', locale = 'de_DE') %]
33
34           [% date.format %]
35           ...
36

DESCRIPTION

38       The Date plugin provides an easy way to generate formatted time and
39       date strings by delegating to the POSIX strftime() routine.
40
41       The plugin can be loaded via the familiar USE directive.
42
43           [% USE date %]
44
45       This creates a plugin object with the default name of 'date'.  An
46       alternate name can be specified as such:
47
48           [% USE myname = date %]
49
50       The plugin provides the format() method which accepts a time value, a
51       format string and a locale name.  All of these parameters are optional
52       with the current system time, default format ('%H:%M:%S %d-%b-%Y') and
53       current locale being used respectively, if undefined.  Default values
54       for the time, format and/or locale may be specified as named parameters
55       in the USE directive.
56
57           [% USE date(format = '%a %d-%b-%Y', locale = 'fr_FR') %]
58
59       When called without any parameters, the format() method returns a
60       string representing the current system time, formatted by strftime()
61       according to the default format and for the default locale (which may
62       not be the current one, if locale is set in the USE directive).
63
64           [% date.format %]
65
66       The plugin allows a time/date to be specified as seconds since the
67       epoch, as is returned by time().
68
69           File last modified: [% date.format(filemod_time) %]
70
71       The time/date can also be specified as a string of the form 'h:m:s
72       d/m/y'.  Any of the characters : / - or space may be used to delimit
73       fields.
74
75           [% USE day = date(format => '%A', locale => 'en_GB') %]
76           [% day.format('4:20:00 9-13-2000') %]
77
78       Output:
79
80           Tuesday
81
82       A format string can also be passed to the format() method, and a locale
83       specification may follow that.
84
85           [% date.format(filemod, '%d-%b-%Y') %]
86           [% date.format(filemod, '%d-%b-%Y', 'en_GB') %]
87
88       A fourth parameter allows you to force output in GMT, in the case of
89       seconds-since-the-epoch input:
90
91           [% date.format(filemod, '%d-%b-%Y', 'en_GB', 1) %]
92
93       Note that in this case, if the local time is not GMT, then also speci‐
94       fying '%Z' (time zone) in the format parameter will lead to an
95       extremely misleading result.
96
97       Any or all of these parameters may be named.  Positional parameters
98       should always be in the order ($time, $format, $locale).
99
100           [% date.format(format => '%H:%M:%S') %]
101           [% date.format(time => filemod, format => '%H:%M:%S') %]
102           [% date.format(mytime, format => '%H:%M:%S') %]
103           [% date.format(mytime, format => '%H:%M:%S', locale => 'fr_FR') %]
104           [% date.format(mytime, format => '%H:%M:%S', gmt => 1) %]
105           ...etc...
106
107       The now() method returns the current system time in seconds since the
108       epoch.
109
110           [% date.format(date.now, '%A') %]
111
112       The calc() method can be used to create an interface to the Date::Calc
113       module (if installed on your system).
114
115           [% calc = date.calc %]
116           [% calc.Monday_of_Week(22, 2001).join('/') %]
117
118       The manip() method can be used to create an interface to the
119       Date::Manip module (if installed on your system).
120
121           [% manip = date.manip %]
122           [% manip.UnixDate("Noon Yesterday","%Y %b %d %H:%M") %]
123

AUTHORS

125       Thierry-Michel Barral <kktos@electron-libre.com> wrote the original
126       plugin.
127
128       Andy Wardley <abw@cre.canon.co.uk> provided some minor fixups/enhance‐
129       ments, a test script and documentation.
130
131       Mark D. Mills <mark@hostile.org> cloned Date::Manip from the cute
132       Date::Calc sub-plugin.
133

VERSION

135       2.77, distributed as part of the Template Toolkit version 2.18,
136       released on 09 February 2007.
137
139       Copyright (C) 2000 Thierry-Michel Barral, Andy Wardley.
140
141       This module is free software; you can redistribute it and/or modify it
142       under the same terms as Perl itself.
143

SEE ALSO

145       Template::Plugin, POSIX
146
147
148
149perl v5.8.8                       2007-02-09         Template::Plugin::Date(3)
Impressum