1DateTime::Tiny(3)     User Contributed Perl Documentation    DateTime::Tiny(3)
2
3
4

NAME

6       DateTime::Tiny - A date object, with as little code as possible
7

VERSION

9       version 1.07
10

SYNOPSIS

12         # Create a date manually
13         $christmas = DateTime::Tiny->new(
14             year   => 2006,
15             month  => 12,
16             day    => 25,
17             hour   => 10,
18             minute => 45,
19             second => 0,
20             );
21
22         # Show the current date
23         my $now = DateTime::Tiny->now;
24         print "Year   : " . $now->year   . "\n";
25         print "Month  : " . $now->month  . "\n";
26         print "Day    : " . $now->day    . "\n";
27         print "Hour   : " . $now->hour   . "\n";
28         print "Minute : " . $now->minute . "\n";
29         print "Second : " . $now->second . "\n";
30

DESCRIPTION

32       DateTime::Tiny is a most prominent member of the DateTime::Tiny suite
33       of time modules.
34
35       It implements an extremely lightweight object that represents a
36       datetime.
37
38   The Tiny Mandate
39       Many CPAN modules which provide the best implementation of a certain
40       concepts are very large. For some reason, this generally seems to be
41       about 3 megabyte of ram usage to load the module.
42
43       For a lot of the situations in which these large and comprehensive
44       implementations exist, some people will only need a small fraction of
45       the functionality, or only need this functionality in an ancillary
46       role.
47
48       The aim of the Tiny modules is to implement an alternative to the large
49       module that implements a useful subset of their functionality, using as
50       little code as possible.
51
52       Typically, this means a module that implements between 50% and 80% of
53       the features of the larger module (although this is just a guideline),
54       but using only 100 kilobytes of code, which is about 1/30th of the
55       larger module.
56
57   The Concept of Tiny Date and Time
58       Due to the inherent complexity, Date and Time is intrinsically very
59       difficult to implement properly.
60
61       The arguably only module to implement it completely correct is
62       DateTime. However, to implement it properly DateTime is quite slow and
63       requires 3-4 megabytes of memory to load.
64
65       The challenge in implementing a Tiny equivalent to DateTime is to do so
66       without making the functionality critically flawed, and to carefully
67       select the subset of functionality to implement.
68
69       If you look at where the main complexity and cost exists, you will find
70       that it is relatively cheap to represent a date or time as an object,
71       but much much more expensive to modify, manipulate or convert the
72       object.
73
74       As a result, DateTime::Tiny provides the functionality required to
75       represent a date as an object, to stringify the date and to parse it
76       back in, but does not allow you to modify the dates.
77
78       The purpose of this is to allow for date object representations in
79       situations like log parsing and fast real-time type work.
80
81       The problem with this is that having no ability to modify date limits
82       the usefulness greatly.
83
84       To make up for this, if you have DateTime installed, any DateTime::Tiny
85       module can be inflated into the equivalent DateTime as needing, loading
86       DateTime on the fly if necessary.
87
88       This is somewhat similar to DateTime::LazyInit, but unlike that module
89       DateTime::Tiny objects are not modifiable.
90
91       For the purposes of date/time logic, all DateTime::Tiny objects exist
92       in the "C" locale, and the "floating" time zone. This may be improved
93       in the future if a suitably tiny way of handling timezones is found.
94
95       When converting up to full DateTime objects, these locale and time zone
96       settings will be applied (although an ability is provided to override
97       this).
98
99       In addition, the implementation is strictly correct and is intended to
100       be very easily to sub-class for specific purposes of your own.
101

USAGE

103       In general, the intent is that the API be as close as possible to the
104       API for DateTime. Except, of course, that this module implements less
105       of it.
106

METHODS

108   new
109         my $date = DateTime::Tiny->new(
110             year   => 2006,
111             month  => 12,
112             day    => 31,
113             hour   => 10,
114             minute => 45,
115             second => 32,
116             );
117
118       The "new" constructor creates a new DateTime::Tiny object.
119
120       It takes six named parameters. "day" should be the day of the month
121       (1-31), "month" should be the month of the year (1-12), "year" as a 4
122       digit year.  "hour" should be the hour of the day (0-23), "minute"
123       should be the minute of the hour (0-59) and "second" should be the
124       second of the minute (0-59).
125
126       These are the only parameters accepted.
127
128       Returns a new DateTime::Tiny object.
129
130   now
131         my $current_date = DateTime::Tiny->now;
132
133       The "now" method creates a new date object for the current date.
134
135       The date created will be based on localtime, despite the fact that the
136       date is created in the floating time zone.
137
138       Returns a new DateTime::Tiny object.
139
140   year
141       The "year" accessor returns the 4-digit year for the date.
142
143   month
144       The "month" accessor returns the 1-12 month of the year for the date.
145
146   day
147       The "day" accessor returns the 1-31 day of the month for the date.
148
149   hour
150       The "hour" accessor returns the hour component of the time as an
151       integer from zero to twenty-three (0-23) in line with 24-hour time.
152
153   minute
154       The "minute" accessor returns the minute component of the time as an
155       integer from zero to fifty-nine (0-59).
156
157   second
158       The "second" accessor returns the second component of the time as an
159       integer from zero to fifty-nine (0-59).
160
161   ymdhms
162       The "ymdhms" method returns the most common and accurate stringified
163       date format, which returns in the form "2006-04-12T23:59:59".
164
165   from_string
166       The "from_string" method creates a new DateTime::Tiny object from a
167       string.
168
169       The string is expected to be an ISO 8601 combined date and time, with
170       separators (including the 'T' separator) and no time zone designator.
171       No other ISO 8601 formats are supported.
172
173         my $almost_midnight = DateTime::Tiny->from_string( '2006-12-20T23:59:59' );
174
175       Returns a new DateTime::Tiny object, or throws an exception on error.
176
177   as_string
178       The "as_string" method converts the date to the default string, which
179       at present is the same as that returned by the "ymdhms" method above.
180
181       This string conforms to the ISO 8601 standard for the encoding of a
182       combined date and time as a string, without time-zone designator.
183
184   DateTime
185       The "DateTime" method is used to create a DateTime object that is
186       equivalent to the DateTime::Tiny object, for use in conversions and
187       calculations.
188
189       As mentioned earlier, the object will be set to the 'C' locale, and the
190       'floating' time zone.
191
192       If installed, the DateTime module will be loaded automatically.
193
194       Returns a DateTime object, or throws an exception if DateTime is not
195       installed on the current host.
196

HISTORY

198       This module was written by Adam Kennedy in 2006.  In 2016, David Golden
199       adopted it as a caretaker maintainer.
200

SEE ALSO

202       DateTime, Date::Tiny, Time::Tiny, Config::Tiny, ali.as
203

SUPPORT

205   Bugs / Feature Requests
206       Please report any bugs or feature requests through the issue tracker at
207       <https://github.com/dagolden/DateTime-Tiny/issues>.  You will be
208       notified automatically of any progress on your issue.
209
210   Source Code
211       This is open source software.  The code repository is available for
212       public review and contribution under the terms of the license.
213
214       <https://github.com/dagolden/DateTime-Tiny>
215
216         git clone https://github.com/dagolden/DateTime-Tiny.git
217

AUTHORS

219       •   Adam Kennedy <adamk@cpan.org>
220
221       •   David Golden <dagolden@cpan.org>
222

CONTRIBUTORS

224       •   Ken Williams <Ken.Williams@WindLogics.com>
225
226       •   Nigel Gregoire <nigelg@airg.com>
227
228       •   Ovid <curtis_ovid_poe@yahoo.com>
229
231       This software is copyright (c) 2006 by Adam Kennedy.
232
233       This is free software; you can redistribute it and/or modify it under
234       the same terms as the Perl 5 programming language system itself.
235
236
237
238perl v5.32.1                      2021-01-27                 DateTime::Tiny(3)
Impressum