Debian Codegraph @

README

raw
1 NAME
2 Time::Tiny - A time object, with as little code as possible
3
4 VERSION
5 version 1.08
6
7 SYNOPSIS
8 # Create a time manually
9 $christmas = Time::Tiny->new(
10 hour => 10,
11 minute => 45,
12 second => 0,
13 );
14
15 # Show the current time
16 $now = Time::Tiny->now;
17 print "Hour : " . $now->hour . "\n";
18 print "Minute : " . $now->minute . "\n";
19 print "Second : " . $now->second . "\n";
20
21 DESCRIPTION
22 Time::Tiny is a member of the DateTime::Tiny suite of time modules.
23
24 It implements an extremely lightweight object that represents a time,
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, Time::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 Time::Tiny
71 module can be inflated into the equivalent DateTime as needed, loading
72 DateTime on the fly if necessary.
73
74 For the purposes of date/time logic, all Time::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 locale 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 # Create a Time::Tiny object for midnight
93 my $midnight = Time::Tiny->new(
94 hour => 0,
95 minute => 0,
96 second => 0,
97 );
98
99 The "new" constructor creates a new Time::Tiny object.
100
101 It takes three named parameters. "hour" should be the hour of the day
102 (0-23), "minute" should be the minute of the hour (0-59), and "second"
103 should be the second of the minute (0-59).
104
105 These are the only parameters accepted.
106
107 Returns a new Time::Tiny object.
108
109 now
110 my $current_time = Time::Tiny->now;
111
112 The "now" method creates a new date object for the current time.
113
114 The time created will be based on localtime, despite the fact that the
115 time is created in the floating time zone.
116
117 This means that the time created by "now" is somewhat lossy, but since
118 the primary purpose of Time::Tiny is for small transient time objects,
119 and not for use in calculations and comparisons, this is considered
120 acceptable for now.
121
122 Returns a new Time::Tiny object.
123
124 hour
125 The "hour" accessor returns the hour component of the time as an integer
126 from zero to twenty-three (0-23) in line with 24-hour time.
127
128 minute
129 The "minute" accessor returns the minute component of the time as an
130 integer from zero to fifty-nine (0-59).
131
132 second
133 The "second" accessor returns the second component of the time as an
134 integer from zero to fifty-nine (0-59).
135
136 from_string
137 The "from_string" method creates a new Time::Tiny object from a string.
138
139 The string is expected to be an "hh:mm:ss" type ISO 8601 time string.
140
141 my $almost_midnight = Time::Tiny->from_string( '23:59:59' );
142
143 Returns a new Time::Tiny object, or throws an exception on error.
144
145 as_string
146 The "as_string" method converts the time object to an ISO 8601 time
147 string, with separators (see example in "from_string").
148
149 Returns a string.
150
151 DateTime
152 The "DateTime" method is used to create a DateTime object that is
153 equivalent to the Time::Tiny object, for use in conversions and
154 calculations.
155
156 As mentioned earlier, the object will be set to the 'C' locate, and the
157 'floating' time zone.
158
159 If installed, the DateTime module will be loaded automatically.
160
161 Returns a DateTime object, or throws an exception if DateTime is not
162 installed on the current host.
163
164 HISTORY
165 This module was written by Adam Kennedy in 2006. In 2016, David Golden
166 adopted it as a caretaker maintainer.
167
168 SEE ALSO
169 DateTime, DateTime::Tiny, Time::Tiny, Config::Tiny, ali.as
170
171 SUPPORT
172 Bugs / Feature Requests
173 Please report any bugs or feature requests through the issue tracker at
174 <https://github.com/dagolden/Time-Tiny/issues>. You will be notified
175 automatically of any progress on your issue.
176
177 Source Code
178 This is open source software. The code repository is available for
179 public review and contribution under the terms of the license.
180
181 <https://github.com/dagolden/Time-Tiny>
182
183 git clone https://github.com/dagolden/Time-Tiny.git
184
185 AUTHORS
186 * Adam Kennedy <[email protected]>
187
188 * David Golden <[email protected]>
189
190 CONTRIBUTOR
191 Tim Heaney <[email protected]>
192
193 COPYRIGHT AND LICENSE
194 This software is copyright (c) 2006 by Adam Kennedy.
195
196 This is free software; you can redistribute it and/or modify it under
197 the same terms as the Perl 5 programming language system itself.
198