Debian Codegraph @

README

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