Date::Tiny(3pm)

πŸ“¦
version 1.07 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

Date::Tiny β€” it's a date object, bestie, and it's got, like, the least code possible πŸ’– (this is the Date::Tiny(3pm) page, in case the vibe check needed a name tag)

πŸŽ€ VERSION πŸŽ€

version 1.07 β€” yes she's serving numbers, no she's not updating

πŸ’… SYNOPSIS πŸ’…

# Create a date manually
$christmas = Date::Tiny->new(
    year  => 2006,
    month => 12,
    day   => 25,
    );

# Show the current date
$today = Date::Tiny->now;
print "Year : " . $today->year  . "\n";
print "Month: " . $today->month . "\n";
print "Day  : " . $today->day   . "\n";

okay so that's the whole vibe. tiny little object, three numbers, done. πŸ¦‹

🌸 DESCRIPTION 🌸

Date::Tiny is a member of the DateTime::Tiny suite of time modules. she's part of the family, she's the date-only sibling.

What she implements: an extremely lightweight object that represents a date. And that's it β€” no time data, not a single hour, not one lil minute. periodt. πŸ’€

πŸ’– The Tiny Mandate πŸ’–

ngl, a lot of CPAN modules that give you the best implementation of a concept are absolutely enormous. and like... for some reason it's always roughly 3 megabytes of ram usage just to load the thing?? 😭

so here's the situation: for a LOT of the cases where those big comprehensive implementations exist, some people only need a tiny fraction of the functionality. or they only need it in an ancillary role, like a little side character in the plot.

The aim of the Tiny modules is to be the alternative to the big module: implement 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. slay. ✨

πŸ¦‹ The Concept of Tiny Date and Time πŸ¦‹

so here's the tea: Date and Time is intrinsically very difficult to implement properly, because of the inherent complexity. it's giving "chaotic by nature".

The arguably only module to implement it completely correct is DateTime. but to implement it properly, DateTime is quite slow and requires 3-4 megabytes of memory to load. iconic but heavy. πŸ‘‘

So the challenge in making a Tiny equivalent to DateTime is doing it without making the functionality critically flawed, and carefully selecting which subset of functionality to implement. no pressure or anything.

And if you look at where the main complexity and cost actually lives, you'll find 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, Date::Tiny provides the functionality required to:

  • represent a date as an object
  • stringify the date
  • parse it back in

but does not allow you to modify the dates. nope. not happening. πŸ™ˆ

The purpose of 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. we know. πŸ’€

To make up for this: if you have DateTime installed, any Date::Tiny module can be inflated into the equivalent DateTime as needing, loading DateTime on the fly if necessary. magic. ✨

For the purposes of date/time logic, all Date::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 local and time zone settings will be applied (although an ability is provided to override this).

In addition, the implementation is strictly correct and is intended to be very easily to sub-class for specific purposes of your own. go off, subclass her. 🫢

🌈 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. iykyk.

πŸ‘‘ METHODS πŸ‘‘

πŸ’œ new

my $date = Date::Tiny->new(
    year  => 2006,
    month => 12,
    day   => 31,
    );

The "new" constructor creates a new Date::Tiny object. baby's first date object.

It takes three named parameters:

  • day should be the day of the month (1-31)
  • month should be the month of the year (1-12)
  • year as a 4 digit year

These are the only parameters accepted. don't try to sneak anything else in there bestie, she will not accept it. 🚫

Returns a new Date::Tiny object.

🌸 now

my $current_date = Date::Tiny->now;

The "now" method creates a new date object for the current date.

The date created will be based on localtime, despite the fact that the date is created in the floating time zone. (yes that's a little weird. no we're not explaining further. it's in the source. πŸ’€)

Returns a new Date::Tiny object.

⭐ year

The "year" accessor returns the 4-digit year for the date.

⭐ month

The "month" accessor returns the 1-12 month of the year for the date.

⭐ day

The "day" accessor returns the 1-31 day of the month for the date.

πŸŽ€ ymd

The "ymd" method returns the most common and accurate stringified date format, which returns in the form "2006-04-12". chef's kiss, no notes. πŸ’…

πŸŽ€ as_string

The "as_string" method converts the date to the default string, which at present is the same as that returned by the "ymd" method above.

This string matches the ISO 8601 standard for the encoding of a date as a string. certified standard-compliant queen. πŸ‘‘

πŸ¦‹ from_string

The "from_string" method creates a new Date::Tiny object from a string.

The string is expected to be a "yyyy-mm-dd" ISO 8601 time string.

my $almost_christmas = Date::Tiny->from_string( '2006-12-23' );

Returns a new Date::Tiny object, or throws an exception on error. so like, wrap it or whatever. 😭

πŸ’– DateTime

The "DateTime" method is used to create a DateTime object that is equivalent to the Date::Tiny object, for use in conversions and calculations.

As mentioned earlier, the object will be set to the 'C' locate, and the 'floating' time zone.

If installed, the DateTime module will be loaded automatically. no manual labor required. ✨

Returns a DateTime object, or throws an exception if DateTime is not installed on the current host. (so like... install DateTime. or don't. but then don't come crying to me. πŸ™ˆ)

πŸ“œ HISTORY πŸ“œ

This module was written by Adam Kennedy in 2006. In 2016, David Golden adopted it as a caretaker maintainer. glow-up arc complete. πŸ’œ

πŸ”₯ 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/Date-Tiny/issues>. You will be notified automatically of any progress on your issue. bestie will 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/Date-Tiny>

git clone https://github.com/dagolden/Date-Tiny.git

🌟 AUTHORS 🌟

  • Adam Kennedy <adamk@cpan.org>
  • David Golden <dagolden@cpan.org>

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.


okay and that's the whole page bestie πŸŽ€ she was built on perl v5.32.1 and dated 2021-11-04, which is genuinely so long ago but she still ate. mwah πŸ’‹

πŸ“¦ where this page comes from