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

NAME

6       Time::Tiny - A time object, with as little code as possible
7

VERSION

9       version 1.08
10

SYNOPSIS

12         # Create a time manually
13         $christmas = Time::Tiny->new(
14             hour   => 10,
15             minute => 45,
16             second => 0,
17             );
18
19         # Show the current time
20         $now = Time::Tiny->now;
21         print "Hour   : " . $now->hour   . "\n";
22         print "Minute : " . $now->minute . "\n";
23         print "Second : " . $now->second . "\n";
24

DESCRIPTION

26       Time::Tiny is a member of the DateTime::Tiny suite of time modules.
27
28       It implements an extremely lightweight object that represents a time,
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, Time::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 Time::Tiny
76       module can be inflated into the equivalent DateTime as needed, loading
77       DateTime on the fly if necessary.
78
79       For the purposes of date/time logic, all Time::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 locale 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         # Create a Time::Tiny object for midnight
98         my $midnight = Time::Tiny->new(
99             hour   => 0,
100             minute => 0,
101             second => 0,
102         );
103
104       The "new" constructor creates a new Time::Tiny object.
105
106       It takes three named parameters. "hour" should be the hour of the day
107       (0-23), "minute" should be the minute of the hour (0-59), and "second"
108       should be the second of the minute (0-59).
109
110       These are the only parameters accepted.
111
112       Returns a new Time::Tiny object.
113
114   now
115         my $current_time = Time::Tiny->now;
116
117       The "now" method creates a new date object for the current time.
118
119       The time created will be based on localtime, despite the fact that the
120       time is created in the floating time zone.
121
122       This means that the time created by "now" is somewhat lossy, but since
123       the primary purpose of Time::Tiny is for small transient time objects,
124       and not for use in calculations and comparisons, this is considered
125       acceptable for now.
126
127       Returns a new Time::Tiny object.
128
129   hour
130       The "hour" accessor returns the hour component of the time as an
131       integer from zero to twenty-three (0-23) in line with 24-hour time.
132
133   minute
134       The "minute" accessor returns the minute component of the time as an
135       integer from zero to fifty-nine (0-59).
136
137   second
138       The "second" accessor returns the second component of the time as an
139       integer from zero to fifty-nine (0-59).
140
141   from_string
142       The "from_string" method creates a new Time::Tiny object from a string.
143
144       The string is expected to be an "hh:mm:ss" type ISO 8601 time string.
145
146         my $almost_midnight = Time::Tiny->from_string( '23:59:59' );
147
148       Returns a new Time::Tiny object, or throws an exception on error.
149
150   as_string
151       The "as_string" method converts the time object to an ISO 8601 time
152       string, with separators (see example in "from_string").
153
154       Returns a string.
155
156   DateTime
157       The "DateTime" method is used to create a DateTime object that is
158       equivalent to the Time::Tiny object, for use in conversions and
159       calculations.
160
161       As mentioned earlier, the object will be set to the 'C' locate, and the
162       'floating' time zone.
163
164       If installed, the DateTime module will be loaded automatically.
165
166       Returns a DateTime object, or throws an exception if DateTime is not
167       installed on the current host.
168

HISTORY

170       This module was written by Adam Kennedy in 2006.  In 2016, David Golden
171       adopted it as a caretaker maintainer.
172

SEE ALSO

174       DateTime, DateTime::Tiny, Time::Tiny, Config::Tiny, ali.as
175

SUPPORT

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

AUTHORS

191       •   Adam Kennedy <adamk@cpan.org>
192
193       •   David Golden <dagolden@cpan.org>
194

CONTRIBUTOR

196       Tim Heaney <oylenshpeegul@gmail.com>
197
199       This software is copyright (c) 2006 by Adam Kennedy.
200
201       This is free software; you can redistribute it and/or modify it under
202       the same terms as the Perl 5 programming language system itself.
203
204
205
206perl v5.36.0                      2023-01-20                     Time::Tiny(3)
Impressum