Time::Tiny(3pm)
π Time::Tiny π
okay bestie, so this is a page from the User Contributed Perl Documentation section of the manual β and it's about Time::Tiny, one of those precious little modules that does a small thing extremely well. say hi to your new tiny time object πβ¨
β¨ VERSION β¨
this is version 1.08, and yes she's still thriving π
πΈ SYNOPSIS πΈ
# Create a time manually
$christmas = Time::Tiny->new(
hour => 10,
minute => 45,
second => 0,
);
# Show the current time
$now = Time::Tiny->now;
print "Hour : " . $now->hour . "\n";
print "Minute : " . $now->minute . "\n";
print "Second : " . $now->second . "\n";
like, look at how cute and short that is. no cap, that's the whole vibe π
π¦ DESCRIPTION π¦
Time::Tiny is a member of the DateTime::Tiny suite of time modules. she runs with a whole friend group π
what she does: implements an extremely lightweight object that represents a time, without any time data. yes literally, that's the concept, hold on, we'll get there.
π The Tiny Mandate π
so here's the tea. a LOT of CPAN modules that give you the best implementation of a concept are, like, huge. and for some reason β and this is so real β it generally seems to be about 3 megabyte of ram usage just to load the module. π
and here's the thing: in a lot of situations where these big comprehensive implementations exist, some people only need a small fraction of the functionality, or they only need it in an ancillary role. like, girly just needs a crumb of the features.
the aim of the Tiny modules is to implement an alternative to the large module that implements a subset of the functionality, using as little code as possible.
typically that means a module implementing between 50% and 80% of the features of the larger module, but using only 100 kilobytes of code, which is about 1/30th of the larger module. tiny queen behavior π
π The Concept of Tiny Date and Time π
due to the inherent complexity, Date and Time is intrinsically very difficult to implement properly. it's giving final boss energy.
the arguably only module to implement it completely correct is DateTime. however β and this is the tradeoff β to implement it properly, DateTime is quite slow and requires 3-4 megabytes of memory to load.
so the challenge in implementing a Tiny equivalent to DateTime is to do it without making the functionality critically flawed, and to carefully select the subset of functionality to implement. choices were made, and they were made with intention β¨
now, if you look at where the main complexity and cost exists, you'll find that it's relatively cheap to represent a date or time as an object, but much much more expensive to modify or convert the object.
as a result, Time::Tiny provides the functionality required to represent a date as an object, to stringify the date and to parse it back in β but does not allow you to modify the dates. she's immutable, she's low maintenance, she's at peace π§
the purpose of all this is to allow for date object representations in situations like log parsing and fast real-time work.
the problem with this is that having no ability to modify date limits the usefulness greatly. yeah. acknowledged. π
to make up for this: if you have DateTime installed, any Time::Tiny module can be inflated into the equivalent DateTime as needed, loading DateTime on the fly if necessary. glow-up available on demand π«
for the purposes of date/time logic, all Time::Tiny objects exist in the "C" locale, and the "floating" time zone (although obviously, in a pure date context, the time zone largely doesn't matter). when converting up to full DateTime objects, these locale and time zone settings will be applied (although an ability is provided to override this).
plus, the implementation is strictly correct and is intended to be very easily to sub-class for specific purposes of your own. go off, subclass it, make it yours π«Ά
π USAGE π
in general, the intent is that the API be as close as possible to the API for DateTime. except, of course, that this module implements less of it. same energy, smaller purse π
π METHODS π
π new
# Create a Time::Tiny object for midnight
my $midnight = Time::Tiny->new(
hour => 0,
minute => 0,
second => 0,
);
the new constructor creates a new Time::Tiny object. it's literally the birth of a time.
it takes three named parameters. hour should be the hour of the day (0-23), minute should be the minute of the hour (0-59), and second should be the second of the minute (0-59).
these are the only parameters accepted. don't try to sneak anything else in there, she will not entertain it π
returns a new Time::Tiny object.
π now
my $current_time = Time::Tiny->now;
the now method creates a new date object for the current time.
the time created will be based on localtime, despite the fact that the time is created in the floating time zone. yes this is a little contradictory, we know, stay with us.
this means that the time created by now is somewhat lossy, but since the primary purpose of Time::Tiny is for small transient time objects, and not for use in calculations and comparisons, this is considered acceptable for now. it's giving "good enough, we move" π
returns a new Time::Tiny object.
π hour
the hour accessor returns the hour component of the time as an integer from zero to twenty-three (0-23), in line with 24-hour time.
π minute
the minute accessor returns the minute component of the time as an integer from zero to fifty-nine (0-59).
π second
the second accessor returns the second component of the time as an integer from zero to fifty-nine (0-59).
π from_string
the from_string method creates a new Time::Tiny object from a string. it's the parser girlie of the bunch π
the string is expected to be an "hh:mm:ss" type ISO 8601 time string.
my $almost_midnight = Time::Tiny->from_string( '23:59:59' );
returns a new Time::Tiny object, or throws an exception on error. bestie will not silently swallow your typo π
π as_string
the as_string method converts the time object to an ISO 8601 time string, with separators (see example in from_string).
returns a string.
π DateTime
the DateTime method is used to create a DateTime object that is equivalent to the Time::Tiny object, for use in conversions and calculations. it's the glow-up method, the main character transformation arc π
as mentioned earlier, the object will be set to the 'C' locale, and the 'floating' time zone.
if installed, the DateTime module will be loaded automatically.
returns a DateTime object, or throws an exception if DateTime is not installed on the current host. no DateTime, no conversion, sorry babe π
π HISTORY π
this module was written by Adam Kennedy in 2006. in 2016, David Golden adopted it as a caretaker maintainer. legacy maintained, we love to see it π«Ά
π SEE ALSO π
DateTime, DateTime::Tiny, Time::Tiny, Config::Tiny, ali.as
π SUPPORT π
π Bugs / Feature Requests π
please report any bugs or feature requests through the issue tracker at <https://github.com/dagolden/Time-Tiny/issues>. you will be notified automatically of any progress on your issue. they'll keep you posted fr fr π¬
π¦ Source Code π¦
this is open source software. the code repository is available for public review and contribution under the terms of the license.
<https://github.com/dagolden/Time-Tiny>
git clone https://github.com/dagolden/Time-Tiny.git
go clone her, she's right there π
π AUTHORS π
- Adam Kennedy
<adamk@cpan.org> - David Golden
<dagolden@cpan.org>
π¦ CONTRIBUTOR π¦
Tim Heaney <oylenshpeegul@gmail.com>
π COPYRIGHT AND LICENSE π
this software is copyright (c) 2006 by Adam Kennedy.
this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
that's the whole page, bestie!! no sections skipped, no options dropped, she's complete and she's iconic π β¨
this little legend lives in the User Contributed Perl Documentation crew, she's stepping out with perl v5.36.0, and her page was dated 2022-10-13. now go make a tiny time object and be free π¦π
π¦ where this page comes from
- ubuntu noble: libtime-tiny-perl 1.08-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libtime-tiny-perl 1.08-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libtime-tiny-perl 1.08-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms