Debian Codegraph @

lib/Date/Format.pm

raw
1 # Copyright (c) 1995-2009 Graham Barr. This program is free
2 # software; you can redistribute it and/or modify it under the same terms
3 # as Perl itself.
4
5 package Date::Format;
6
7 use strict;
8 require Exporter;
9
10 our $VERSION = '2.35'; # VERSION: generated
11 # ABSTRACT: Date formatting subroutines
12
13 use Date::Format::Generic;
14
15 our @ISA = qw(Exporter);
16 our @EXPORT = qw(time2str strftime ctime asctime);
17
18 sub time2str ($;$$$)
19 {
20 my ($fmt, $time, $zone, $lang) = @_;
21 my $pkg = defined $lang
22 ? do { require Date::Language; Date::Language->new($lang) }
23 : 'Date::Format::Generic';
24 $pkg->time2str($fmt, $time, $zone);
25 }
26
27 sub strftime ($\@;$)
28 {
29 Date::Format::Generic->strftime(@_);
30 }
31
32 sub ctime ($;$)
33 {
34 my ($t,$tz) = @_;
35 Date::Format::Generic->time2str("%a %b %e %T %Y\n", $t, $tz);
36 }
37
38 sub asctime (\@;$)
39 {
40 my ($t,$tz) = @_;
41 Date::Format::Generic->strftime("%a %b %e %T %Y\n", $t, $tz);
42 }
43
44 1;
45
46 __END__
47
48 =pod
49
50 =encoding UTF-8
51
52 =head1 NAME
53
54 Date::Format - Date formatting subroutines
55
56 =head1 VERSION
57
58 version 2.35
59
60 =head1 SYNOPSIS
61
62 use Date::Format;
63
64 my @lt = localtime(time);
65
66 my $template = "....";
67
68 print time2str($template, time);
69 print strftime($template, @lt);
70
71 my $zone;
72 print time2str($template, time, $zone);
73 print strftime($template, @lt, $zone);
74
75 print ctime(time);
76 print asctime(@lt);
77
78 print ctime(time, $zone);
79 print asctime(@lt, $zone);
80
81 =head1 DESCRIPTION
82
83 This module provides routines to format dates into ASCII strings. They
84 correspond to the C library routines C<strftime> and C<ctime>.
85
86 =over 4
87
88 =item time2str(TEMPLATE, TIME [, ZONE [, LANGUAGE]])
89
90 C<time2str> converts C<TIME> into an ASCII string using the conversion
91 specification given in C<TEMPLATE>. C<ZONE> if given specifies the zone
92 which the output is required to be in, C<ZONE> defaults to your current zone.
93 C<LANGUAGE> if given specifies the language for day and month names
94 (e.g. C<'German'>, C<'French'>); defaults to C<'English'>.
95
96 =item strftime(TEMPLATE, TIME [, ZONE])
97
98 C<strftime> is similar to C<time2str> with the exception that the time is
99 passed as an array, such as the array returned by C<localtime>.
100
101 =item ctime(TIME [, ZONE])
102
103 C<ctime> calls C<time2str> with the given arguments using the
104 conversion specification C<"%a %b %e %T %Y\n">
105
106 =item asctime(TIME [, ZONE])
107
108 C<asctime> calls C<time2str> with the given arguments using the
109 conversion specification C<"%a %b %e %T %Y\n">
110
111 =back
112
113 =head1 NAME
114
115 Date::Format - Date formatting subroutines
116
117 =head1 MULTI-LANGUAGE SUPPORT
118
119 Date::Format is capable of formatting into several languages. You can
120 pass an optional language name directly to C<time2str>:
121
122 time2str("%a %b %e %T %Y\n", time, undef, 'German');
123 time2str("%a %b %e %T %Y\n", time, 'GMT', 'French');
124
125 Alternatively, create a language-specific object and call methods on it,
126 see L<Date::Language>:
127
128 my $lang = Date::Language->new('German');
129 $lang->time2str("%a %b %e %T %Y\n", time);
130
131 =head1 CONVERSION SPECIFICATION
132
133 Each conversion specification is replaced by appropriate
134 characters as described in the following list. The
135 appropriate characters are determined by the LC_TIME
136 category of the program's locale.
137
138 %% PERCENT
139 %a day of the week abbr
140 %A day of the week
141 %b month abbr
142 %B month
143 %c MM/DD/YY HH:MM:SS
144 %C ctime format: Sat Nov 19 21:05:57 1994
145 %d numeric day of the month, with leading zeros (eg 01..31)
146 %e like %d, but a leading zero is replaced by a space (eg 1..32)
147 %D MM/DD/YY
148 %G GPS week number (weeks since January 6, 1980)
149 %h month abbr
150 %H hour, 24 hour clock, leading 0's)
151 %I hour, 12 hour clock, leading 0's)
152 %j day of the year
153 %k hour
154 %l hour, 12 hour clock
155 %L month number, starting with 1
156 %m month number, starting with 01
157 %M minute, leading 0's
158 %n NEWLINE
159 %o ornate day of month -- "1st", "2nd", "25th", etc.
160 %p AM or PM
161 %P am or pm (Yes %p and %P are backwards :)
162 %q Quarter number, starting with 1
163 %r time format: 09:05:57 PM
164 %R time format: 21:05
165 %s seconds since the Epoch, UCT
166 %S seconds, leading 0's
167 %t TAB
168 %T time format: 21:05:57
169 %U week number, Sunday as first day of week
170 %w day of the week, numerically, Sunday == 0
171 %W week number, Monday as first day of week
172 %x date format: 11/19/94
173 %X time format: 21:05:57
174 %y year (2 digits)
175 %Y year (4 digits)
176 %Z timezone in ascii. eg: PST
177 %z timezone in format -/+0000
178
179 C<%d>, C<%e>, C<%H>, C<%I>, C<%j>, C<%k>, C<%l>, C<%m>, C<%M>, C<%q>,
180 C<%y> and C<%Y> can be output in Roman numerals by prefixing the letter
181 with C<O>, e.g. C<%OY> will output the year as roman numerals.
182
183 =head1 LIMITATION
184
185 The functions in this module are limited to the time range that can be
186 represented by the time_t data type, i.e. 1901-12-13 20:45:53 GMT to
187 2038-01-19 03:14:07 GMT.
188
189 =head1 AUTHOR
190
191 Graham Barr <[email protected]>
192
193 =head1 COPYRIGHT
194
195 Copyright (c) 1995-2009 Graham Barr. This program is free
196 software; you can redistribute it and/or modify it under the same terms
197 as Perl itself.
198
199 =head1 AUTHOR
200
201 Graham <[email protected]>
202
203 =head1 COPYRIGHT AND LICENSE
204
205 This software is copyright (c) 2020 by Graham Barr.
206
207 This is free software; you can redistribute it and/or modify it under
208 the same terms as the Perl 5 programming language system itself.
209
210 =cut