DateTimeX::strftimeq - POSIX::strftime() with support for embedded perl code in %(...)q
This document describes version 0.002 of DateTimeX::strftimeq (from Perl distribution DateTimeX-strftimeq), released on 2019-11-19.
use DateTimeX::strftime; # by default exports strftimeq() my @time = localtime(); print strftimeq '<%6Y-%m-%d>', @time; # <002019-11-19> print strftimeq '<%6Y-%m-%d%( $_->day_of_week eq 7 ? "sun" : "" )q>', @time; # <002019-11-19> print strftimeq '<%6Y-%m-%d%( $_->day_of_week eq 2 ? "tue" : "" )q>', @time; # <002019-11-19tue>
You can also pass DateTime object instead of ($second, $minute, $hour, $day, $month, $year):
print strftimeq '<%6Y-%m-%d>', $dt; # <002019-11-19>
This module provides strftimeq() which extends POSIX's strftime() with a conversion: %(...)q. Inside the parenthesis, you can specify Perl code. The Perl code will receive a hash argument (%args) with the following keys: time (arrayref, the arguments passed to strftimeq() except for the first), dt (DateTime object). For convenience, $_ will also be locally set to the DateTime object.
strftimeq()
strftime()
%(...)q
%args
time
dt
$_
Usage:
$str = strftimeq $fmt, $sec, $min, $hour, $mday, $mon, $year; $str = strftimeq $fmt, $dt;
Please visit the project's homepage at https://metacpan.org/release/DateTimeX-strftimeq.
Source repository is at https://github.com/perlancar/perl-DateTimeX-strftimeq.
Please report any bugs or feature requests on the bugtracker website https://rt.cpan.org/Public/Dist/Display.html?Name=DateTimeX-strftimeq
When submitting a bug or request, please include a test-file or a patch to an existing test-file that illustrates the bug or desired feature.
POSIX's strftime()
DateTime
perlancar <perlancar@cpan.org>
This software is copyright (c) 2019 by perlancar@cpan.org.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install DateTimeX::strftimeq, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DateTimeX::strftimeq
CPAN shell
perl -MCPAN -e shell install DateTimeX::strftimeq
For more information on module installation, please visit the detailed CPAN module installation guide.