Debian Codegraph @

README

raw
1 NAME
2 DateTime::Tiny - A date object, with as little code as possible
3
4 VERSION
5 version 1.08
6
7 SYNOPSIS
8 # Create a date manually
9 $christmas = DateTime::Tiny->new(
10 year => 2006,
11 month => 12,
12 day => 25,
13 hour => 10,
14 minute => 45,
15 second => 0,
16 );
17
18 # Show the current date
19 my $now = DateTime::Tiny->now;
20 print "Year : " . $now->year . "\n";
21 print "Month : " . $now->month . "\n";
22 print "Day : " . $now->day . "\n";
23 print "Hour : " . $now->hour . "\n";
24 print "Minute : " . $now->minute . "\n";
25 print "Second : " . $now->second . "\n";
26
27 DESCRIPTION
28 DateTime::Tiny is a most prominent member of the DateTime::Tiny suite of
29 time modules.
30
31 It implements an extremely lightweight object that represents a
32 datetime.
33
34 The Tiny Mandate
35 Many CPAN modules which provide the best implementation of a certain
36 concepts are very large. For some reason, this generally seems to be
37 about 3 megabyte of ram usage to load the module.
38
39 For a lot of the situations in which these large and comprehensive
40 implementations exist, some people will only need a small fraction of
41 the functionality, or only need this functionality in an ancillary role.
42
43 The aim of the Tiny modules is to implement an alternative to the large
44 module that implements a useful subset of their functionality, using as
45 little code as possible.
46
47 Typically, this means a module that implements between 50% and 80% of
48 the features of the larger module (although this is just a guideline),
49 but using only 100 kilobytes of code, which is about 1/30th of the
50 larger module.
51
52 The Concept of Tiny Date and Time
53 Due to the inherent complexity, Date and Time is intrinsically very
54 difficult to implement properly.
55
56 The arguably only module to implement it completely correct is DateTime.
57 However, to implement it properly DateTime is quite slow and requires
58 3-4 megabytes of memory to load.
59
60 The challenge in implementing a Tiny equivalent to DateTime is to do so
61 without making the functionality critically flawed, and to carefully
62 select the subset of functionality to implement.
63
64 If you look at where the main complexity and cost exists, you will find
65 that it is relatively cheap to represent a date or time as an object,
66 but much much more expensive to modify, manipulate or convert the
67 object.
68
69 As a result, DateTime::Tiny provides the functionality required to
70 represent a date as an object, to stringify the date and to parse it
71 back in, but does not allow you to modify the dates.
72
73 The purpose of this is to allow for date object representations in
74 situations like log parsing and fast real-time type work.
75
76 The problem with this is that having no ability to modify date limits
77 the usefulness greatly.
78
79 To make up for this, if you have DateTime installed, any DateTime::Tiny
80 module can be inflated into the equivalent DateTime as needing, loading
81 DateTime on the fly if necessary.
82
83 This is somewhat similar to DateTime::LazyInit, but unlike that module
84 DateTime::Tiny objects are not modifiable.
85
86 For the purposes of date/time logic, all DateTime::Tiny objects exist in
87 the "C" locale, and the "floating" time zone. This may be improved in
88 the future if a suitably tiny way of handling timezones is found.
89
90 When converting up to full DateTime objects, these locale and time zone
91 settings will be applied (although an ability is provided to override
92 this).
93
94 In addition, the implementation is strictly correct and is intended to
95 be very easily to sub-class for specific purposes of your own.
96
97 USAGE
98 In general, the intent is that the API be as close as possible to the
99 API for DateTime. Except, of course, that this module implements less of
100 it.
101
102 METHODS
103 new
104 my $date = DateTime::Tiny->new(
105 year => 2006,
106 month => 12,
107 day => 31,
108 hour => 10,
109 minute => 45,
110 second => 32,
111 );
112
113 The "new" constructor creates a new DateTime::Tiny object.
114
115 It takes six named parameters. "day" should be the day of the month
116 (1-31), "month" should be the month of the year (1-12), "year" as a 4
117 digit year. "hour" should be the hour of the day (0-23), "minute" should
118 be the minute of the hour (0-59) and "second" should be the second of
119 the minute (0-59).
120
121 These are the only parameters accepted.
122
123 Returns a new DateTime::Tiny object.
124
125 now
126 my $current_date = DateTime::Tiny->now;
127
128 The "now" method creates a new date object for the current date.
129
130 The date created will be based on localtime, despite the fact that the
131 date is created in the floating time zone.
132
133 Returns a new DateTime::Tiny object.
134
135 year
136 The "year" accessor returns the 4-digit year for the date.
137
138 month
139 The "month" accessor returns the 1-12 month of the year for the date.
140
141 day
142 The "day" accessor returns the 1-31 day of the month for the date.
143
144 hour
145 The "hour" accessor returns the hour component of the time as an integer
146 from zero to twenty-three (0-23) in line with 24-hour time.
147
148 minute
149 The "minute" accessor returns the minute component of the time as an
150 integer from zero to fifty-nine (0-59).
151
152 second
153 The "second" accessor returns the second component of the time as an
154 integer from zero to fifty-nine (0-59).
155
156 ymdhms
157 The "ymdhms" method returns the most common and accurate stringified
158 date format, which returns in the form "2006-04-12T23:59:59".
159
160 from_string
161 The "from_string" method creates a new DateTime::Tiny object from a
162 string.
163
164 The string is expected to be an ISO 8601 combined date and time, with
165 separators (including the 'T' separator) and no time zone designator. No
166 other ISO 8601 formats are supported.
167
168 my $almost_midnight = DateTime::Tiny->from_string( '2006-12-20T23:59:59' );
169
170 Returns a new DateTime::Tiny object, or throws an exception on error.
171
172 as_string
173 The "as_string" method converts the date to the default string, which at
174 present is the same as that returned by the "ymdhms" method above.
175
176 This string conforms to the ISO 8601 standard for the encoding of a
177 combined date and time as a string, without time-zone designator.
178
179 DateTime
180 The "DateTime" method is used to create a DateTime object that is
181 equivalent to the DateTime::Tiny object, for use in conversions and
182 calculations.
183
184 As mentioned earlier, the object will be set to the 'C' locale, and the
185 'floating' time zone.
186
187 If installed, the DateTime module will be loaded automatically.
188
189 Returns a DateTime object, or throws an exception if DateTime is not
190 installed on the current host.
191
192 HISTORY
193 This module was written by Adam Kennedy in 2006. In 2016, David Golden
194 adopted it as a caretaker maintainer.
195
196 SEE ALSO
197 DateTime, Date::Tiny, Time::Tiny, Config::Tiny, ali.as
198
199 SUPPORT
200 Bugs / Feature Requests
201 Please report any bugs or feature requests through the issue tracker at
202 <https://github.com/dagolden/DateTime-Tiny/issues>. You will be notified
203 automatically of any progress on your issue.
204
205 Source Code
206 This is open source software. The code repository is available for
207 public review and contribution under the terms of the license.
208
209 <https://github.com/dagolden/DateTime-Tiny>
210
211 git clone https://github.com/dagolden/DateTime-Tiny.git
212
213 AUTHORS
214 * Adam Kennedy <[email protected]>
215
216 * David Golden <[email protected]>
217
218 CONTRIBUTORS
219 * Ken Williams <[email protected]>
220
221 * Nigel Gregoire <[email protected]>
222
223 * Ovid <[email protected]>
224
225 COPYRIGHT AND LICENSE
226 This software is copyright (c) 2006 by Adam Kennedy.
227
228 This is free software; you can redistribute it and/or modify it under
229 the same terms as the Perl 5 programming language system itself.
230