1Template::Plugin::Date(U3s)er Contributed Perl DocumentatTieomnplate::Plugin::Date(3)
2
3
4
6 Template::Plugin::Date - Plugin to generate formatted date strings
7
9 [% USE date %]
10
11 # use current time and default format
12 [% date.format %]
13
14 # specify time as seconds since epoch
15 # or as a 'h:m:s d-m-y' or 'y-m-d h:m:s' string
16 [% date.format(960973980) %]
17 [% date.format('4:20:36 21/12/2000') %]
18 [% date.format('2000/12/21 4:20:36') %]
19
20 # specify format
21 [% date.format(mytime, '%H:%M:%S') %]
22
23 # specify locale
24 [% date.format(date.now, '%a %d %b %y', 'en_GB') %]
25
26 # named parameters
27 [% date.format(mytime, format = '%H:%M:%S') %]
28 [% date.format(locale = 'en_GB') %]
29 [% date.format(time = date.now,
30 format = '%H:%M:%S',
31 locale = 'en_GB) %]
32
33 # specify default format to plugin
34 [% USE date(format = '%H:%M:%S', locale = 'de_DE') %]
35
36 [% date.format %]
37 ...
38
40 The "Date" plugin provides an easy way to generate formatted time and
41 date strings by delegating to the "POSIX" "strftime()" routine.
42
43 The plugin can be loaded via the familiar USE directive.
44
45 [% USE date %]
46
47 This creates a plugin object with the default name of '"date"'. An
48 alternate name can be specified as such:
49
50 [% USE myname = date %]
51
52 The plugin provides the "format()" method which accepts a time value, a
53 format string and a locale name. All of these parameters are optional
54 with the current system time, default format ('"%H:%M:%S %d-%b-%Y"')
55 and current locale being used respectively, if undefined. Default
56 values for the time, format and/or locale may be specified as named
57 parameters in the "USE" directive.
58
59 [% USE date(format = '%a %d-%b-%Y', locale = 'fr_FR') %]
60
61 When called without any parameters, the "format()" method returns a
62 string representing the current system time, formatted by "strftime()"
63 according to the default format and for the default locale (which may
64 not be the current one, if locale is set in the "USE" directive).
65
66 [% date.format %]
67
68 The plugin allows a time/date to be specified as seconds since the
69 epoch, as is returned by "time()".
70
71 File last modified: [% date.format(filemod_time) %]
72
73 The time/date can also be specified as a string of the form "h:m:s
74 d/m/y" or "y/m/d h:m:s". Any of the characters : / - or space may be
75 used to delimit fields.
76
77 [% USE day = date(format => '%A', locale => 'en_GB') %]
78 [% day.format('4:20:00 9-13-2000') %]
79
80 Output:
81
82 Tuesday
83
84 A format string can also be passed to the "format()" method, and a
85 locale specification may follow that.
86
87 [% date.format(filemod, '%d-%b-%Y') %]
88 [% date.format(filemod, '%d-%b-%Y', 'en_GB') %]
89
90 A fourth parameter allows you to force output in GMT, in the case of
91 seconds-since-the-epoch input:
92
93 [% date.format(filemod, '%d-%b-%Y', 'en_GB', 1) %]
94
95 Note that in this case, if the local time is not GMT, then also
96 specifying '%Z' (time zone) in the format parameter will lead to an
97 extremely misleading result.
98
99 Any or all of these parameters may be named. Positional parameters
100 should always be in the order "($time, $format, $locale)".
101
102 [% date.format(format => '%H:%M:%S') %]
103 [% date.format(time => filemod, format => '%H:%M:%S') %]
104 [% date.format(mytime, format => '%H:%M:%S') %]
105 [% date.format(mytime, format => '%H:%M:%S', locale => 'fr_FR') %]
106 [% date.format(mytime, format => '%H:%M:%S', gmt => 1) %]
107 ...etc...
108
109 The "now()" method returns the current system time in seconds since the
110 epoch.
111
112 [% date.format(date.now, '%A') %]
113
114 The "calc()" method can be used to create an interface to the
115 "Date::Calc" module (if installed on your system).
116
117 [% calc = date.calc %]
118 [% calc.Monday_of_Week(22, 2001).join('/') %]
119
120 The "manip()" method can be used to create an interface to the
121 "Date::Manip" module (if installed on your system).
122
123 [% manip = date.manip %]
124 [% manip.UnixDate("Noon Yesterday","%Y %b %d %H:%M") %]
125
127 Thierry-Michel Barral wrote the original plugin.
128
129 Andy Wardley provided some minor fixups/enhancements, a test script and
130 documentation.
131
132 Mark D. Mills cloned "Date::Manip" from the "Date::Calc" sub-plugin.
133
135 Copyright (C) 2000-2007 Thierry-Michel Barral, Andy Wardley.
136
137 This module is free software; you can redistribute it and/or modify it
138 under the same terms as Perl itself.
139
141 Template::Plugin, POSIX
142
143
144
145perl v5.16.3 2012-01-13 Template::Plugin::Date(3)