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

NAME

6       Date::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 = Date::Tiny->new(
14             year  => 2006,
15             month => 12,
16             day   => 25,
17             );
18
19         # Show the current date
20         $today = Date::Tiny->now;
21         print "Year : " . $today->year  . "\n";
22         print "Month: " . $today->month . "\n";
23         print "Day  : " . $today->day   . "\n";
24

DESCRIPTION

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

USAGE

91       In general, the intent is that the API be as close as possible to the
92       API for DateTime. Except, of course, that this module implements less
93       of it.
94

METHODS

96   new
97         my $date = Date::Tiny->new(
98             year  => 2006,
99             month => 12,
100             day   => 31,
101             );
102
103       The "new" constructor creates a new Date::Tiny object.
104
105       It takes three named parameters. "day" should be the day of the month
106       (1-31), "month" should be the month of the year (1-12), "year" as a 4
107       digit year.
108
109       These are the only parameters accepted.
110
111       Returns a new Date::Tiny object.
112
113   now
114         my $current_date = Date::Tiny->now;
115
116       The "now" method creates a new date object for the current date.
117
118       The date created will be based on localtime, despite the fact that the
119       date is created in the floating time zone.
120
121       Returns a new Date::Tiny object.
122
123   year
124       The "year" accessor returns the 4-digit year for the date.
125
126   month
127       The "month" accessor returns the 1-12 month of the year for the date.
128
129   day
130       The "day" accessor returns the 1-31 day of the month for the date.
131
132   ymd
133       The "ymd" method returns the most common and accurate stringified date
134       format, which returns in the form "2006-04-12".
135
136   as_string
137       The "as_string" method converts the date to the default string, which
138       at present is the same as that returned by the "ymd" method above.
139
140       This string matches the ISO 8601 standard for the encoding of a date as
141       a string.
142
143   from_string
144       The "from_string" method creates a new Date::Tiny object from a string.
145
146       The string is expected to be a "yyyy-mm-dd" ISO 8601 time string.
147
148         my $almost_christmas = Date::Tiny->from_string( '2006-12-23' );
149
150       Returns a new Date::Tiny object, or throws an exception on error.
151
152   DateTime
153       The "DateTime" method is used to create a DateTime object that is
154       equivalent to the Date::Tiny object, for use in conversions and
155       calculations.
156
157       As mentioned earlier, the object will be set to the 'C' locate, and the
158       'floating' time zone.
159
160       If installed, the DateTime module will be loaded automatically.
161
162       Returns a DateTime object, or throws an exception if DateTime is not
163       installed on the current host.
164

HISTORY

166       This module was written by Adam Kennedy in 2006.  In 2016, David Golden
167       adopted it as a caretaker maintainer.
168

SEE ALSO

170       DateTime, DateTime::Tiny, Time::Tiny, Config::Tiny, ali.as
171

SUPPORT

173   Bugs / Feature Requests
174       Please report any bugs or feature requests through the issue tracker at
175       <https://github.com/dagolden/Date-Tiny/issues>.  You will be notified
176       automatically of any progress on your issue.
177
178   Source Code
179       This is open source software.  The code repository is available for
180       public review and contribution under the terms of the license.
181
182       <https://github.com/dagolden/Date-Tiny>
183
184         git clone https://github.com/dagolden/Date-Tiny.git
185

AUTHORS

187       •   Adam Kennedy <adamk@cpan.org>
188
189       •   David Golden <dagolden@cpan.org>
190
192       This software is copyright (c) 2006 by Adam Kennedy.
193
194       This is free software; you can redistribute it and/or modify it under
195       the same terms as the Perl 5 programming language system itself.
196
197
198
199perl v5.38.0                      2023-07-20                     Date::Tiny(3)
Impressum