POSIX:...ompiler(3pm)

πŸ’… NAME

POSIX::strftime::Compiler β€” GNU C library compatible strftime for loggers and servers πŸŽ€

(also hi, you're reading the POSIX:...ompiler page from the User Contributed Perl Documentation, welcome bestie 🌸)

✨ SYNOPSIS

use POSIX::strftime::Compiler qw/strftime/;

say strftime('%a, %d %b %Y %T %z',localtime):

my $fmt = '%a, %d %b %Y %T %z';
my $psc = POSIX::strftime::Compiler->new($fmt);
say $psc->to_string(localtime);

πŸ¦‹ DESCRIPTION

So POSIX::strftime::Compiler gives you a GNU C library compatible strftime(3). But here's the slay part: this module will not be affected by the system locale πŸ‘‘. That's literally the whole point β€” it's so useful when you want to write loggers, servers, and portable applications.

To generate the same result strings on any locale, POSIX::strftime::Compiler wraps POSIX::strftime and converts some format characters to perl code. Iconic behavior, no cap πŸ’…


πŸ”₯ FUNCTION

strftime($fmt:String, @time)

Generate a formatted string from a format and a time. That's it, that's the vibe ✨

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
strftime('%d/%b/%Y:%T %z',$sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst):
Heads up bestie 🫢: compiled codes are stored in %POSIX::strftime::Compiler::STRFTIME. Also this function is not exported by default β€” you gotta ask for it.

🧚 METHODS

new($fmt)

Creates an instance of POSIX::strftime::Compiler. Main character energy πŸ’œ

to_string(@time)

Generate a formatted string from a time. Go off, honestly 🌟

🌈 FORMAT CHARACTERS

POSIX::strftime::Compiler supports almost all the characters that GNU strftime(3) supports πŸ“ But β€” and this is the catch β€” %E[cCxXyY] and %O[deHImMSuUVwWy] are not supported. Just remove the E and O prefix, that's the whole workaround 😭

πŸ’– A RECOMMEND MODULE

  • Time::TZOffset β€” if Time::TZOffset is available, P::s::Compiler uses it for a more faster time zone offset calculation ⚑ I strongly recommend you install this if you use %z.

πŸ’€ PERFORMANCE ISSUES ON WINDOWS

Windows and Cygwin and some systems may not support %z and %Z πŸ™ˆ For these systems, POSIX::strftime::Compiler calculates the time zone offset and finds the zone name. This is not fast β€” like, not me waiting πŸ’€ If you need performance on Windows and Cygwin, please install Time::TZOffset.

πŸŽ€ SEE ALSO

  • POSIX::strftime::GNU β€” POSIX::strftime::Compiler is built on POSIX::strftime::GNU::PP code
  • POSIX
  • Apache::LogFormat::Compiler

πŸ‘‘ LICENSE

Copyright (C) Masahiro Nagano.

Format specification is based on the strftime(3) manual page which is a part of the Linux man-pages project.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Periodt 🫢

⭐ AUTHOR

Masahiro Nagano <kazeburo@gmail.com>


okay bye bestie, go format some timestamps πŸ’…βœ¨πŸ¦‹ β€” this was perl v5.42.0, dated 2024-03-08, from the POSIX:...ompiler(3pm) page. mwah πŸŽ€

πŸ“¦ where this page comes from