Time::localtime(3perl)
π Time::localtime β bestie's by-name interface to Perl's built-in localtime() π
okay so this is Time::localtime(3perl), straight out of the Perl Programmers Reference Guide, and it's genuinely one of those tiny modules that makes your life sooo much nicer, no cap. Let's get into it π«Ά
β¨ NAME β¨
Time::localtime β a by-name interface to Perl's built-in localtime() function. it's giving "stop counting array indexes, bestie" π
πΈ SYNOPSIS πΈ
use Time::localtime;
printf "Year is %d\n", localtime->year() + 1900;
$now = ctime();
use Time::localtime;
use File::stat;
$date_string = ctime(stat($file)->mtime);
look at her β clean, readable, no mysterious [5] in sight. periodt β¨
π¦ DESCRIPTION π¦
So here's the tea β: this module's default exports override the core localtime() function, swapping it out for a version that hands you back Time::tm objects instead. iconic behavior, honestly.
That object has methods, and each method returns the similarly named structure field name from the C's tm structure out of time.h. The whole squad is:
secminhourmdaymonyearwdayydayisdst
You can also import all the structure fields directly into your namespace as regular variables using the :FIELDS import tag. π
Heads up bestie: this still overrides your core functions. That part doesn't go away. π
You access these fields as variables named with a preceding tm_ in front of their method names. So the way that $tm_obj->mday() corresponds to $tm_mday if you import the fields β yeah. that's the pattern. iykyk π
The ctime() function provides a way of getting at the scalar sense of the original CORE::localtime() function. so if you want the plain old string vibes back, ctime() is your girl π
Wanna access this functionality without the core overrides? no problem! Just pass the use an empty import list, and then access function functions with their full qualified names. π§
On the other hand, the built-ins are still available via the CORE:: pseudo-package. so you're never actually stranded, bestie π
π NOTE π
While this class is currently implemented using the Class::Struct module to build a struct-like class, you shouldn't rely upon this. like, it works, but do not build your whole personality on it, okay? π
π AUTHOR π
Tom Christiansen β the moment, the legend, the main character π
and that's the whole page, bestie!! π this was perl v5.44.0, dated 2026-10-17, and yeah β it's officially Time::localtime(3perl). go forth and use named fields like the icon you are π
β¨π¦
π¦ where this page comes from
- arch rolling: perl 5.44.0-1 Β· Artistic-1.0-Perl AND 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