Build.PL100644000765000024 45513714171362 17422 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44# ========================================================================= # THIS FILE IS AUTOMATICALLY GENERATED BY MINILLA. # DO NOT EDIT DIRECTLY. # ========================================================================= use 5.008_001; use strict; use Module::Build::Tiny 0.035; Build_PL(); Changes100644000765000024 325513714171362 17442 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44Revision history for Perl extension POSIX-strftime-Compiler 0.44 2020-08-10T07:10:35Z - Check tzdata before test 0.43 2020-07-26T07:23:50Z - Test issues with space in perl path name #9 - microoptimization: check for invalid number of parameters later #5 0.42 2016-07-11T10:04:37Z - import musl patch 0.41 2015-01-05T03:25:28Z - fixed synopsis 0.40 2014-08-21T01:25:32Z - fix test. accept ACST as Australia/Darwin's timezone Because Australian eastern time zone abbr changed in tzdata 2014f ref http://mm.icann.org/pipermail/tz-announce/2014-August/000023.html 0.32 2014-06-09T01:53:19Z - change perl version requirements to 5.8.1 0.31 2014-02-24T06:27:11Z - bugfix on solaris. Solaris does not have %s. 0.30 2014-01-25T16:46:06Z - not require int(sec), improve performance 0.13 2014-01-24T01:12:31Z - bugfix on cygwin. osname is cygwin. not Cygwin. 0.12 2014-01-23T08:21:39Z - fix bug around %s on windows. require "(" ")" 0.11 2014-01-23T06:18:58Z - Escape unkown characters with '%%' - fix '%' escaping - maybe test fixed on netbsd. six arguments required for '%Z'? 0.10 2014-01-21T01:41:51Z - release as non-trial version - use sprintf if format only has simple characters - add benchmark_tz.pl 0.06 2014-01-20T02:26:07Z - add GNU compatibility for Windows 0.05 2014-01-17T06:03:45Z - behave as POSIX::strftime wrapper. faster than use POSIX::strftime with setlocale 0.04 2014-01-15T15:19:20Z - suppress warnings in test 0.03 2014-01-15T15:11:57Z - use POSIX::tzname for trial 0.02 2014-01-15T01:45:07Z - update documents 0.01 2014-01-15T01:24:31Z - original version LICENSE100644000765000024 4376213714171362 17203 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44This software is copyright (c) 2014 by Masahiro Nagano . This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Terms of the Perl programming language system itself a) the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version, or b) the "Artistic License" --- The GNU General Public License, Version 1, February 1989 --- This software is Copyright (c) 2014 by Masahiro Nagano . This is free software, licensed under: The GNU General Public License, Version 1, February 1989 GNU GENERAL PUBLIC LICENSE Version 1, February 1989 Copyright (C) 1989 Free Software Foundation, Inc. 51 Franklin St, Suite 500, Boston, MA 02110-1335 USA Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble The license agreements of most software companies try to keep users at the mercy of those companies. By contrast, our General Public License is intended to guarantee your freedom to share and change free software--to make sure the software is free for all its users. The General Public License applies to the Free Software Foundation's software and to any other program whose authors commit to using it. You can use it for your programs, too. When we speak of free software, we are referring to freedom, not price. Specifically, the General Public License is designed to make sure that you have the freedom to give away or sell copies of free software, that you receive source code or can get it if you want it, that you can change the software or use pieces of it in new free programs; and that you know you can do these things. To protect your rights, we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights. These restrictions translate to certain responsibilities for you if you distribute copies of the software, or if you modify it. For example, if you distribute copies of a such a program, whether gratis or for a fee, you must give the recipients all the rights that you have. You must make sure that they, too, receive or can get the source code. And you must tell them their rights. We protect your rights with two steps: (1) copyright the software, and (2) offer you this license which gives you legal permission to copy, distribute and/or modify the software. Also, for each author's protection and ours, we want to make certain that everyone understands that there is no warranty for this free software. If the software is modified by someone else and passed on, we want its recipients to know that what they have is not the original, so that any problems introduced by others will not reflect on the original authors' reputations. The precise terms and conditions for copying, distribution and modification follow. GNU GENERAL PUBLIC LICENSE TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION 0. This License Agreement applies to any program or other work which contains a notice placed by the copyright holder saying it may be distributed under the terms of this General Public License. The "Program", below, refers to any such program or work, and a "work based on the Program" means either the Program or any work containing the Program or a portion of it, either verbatim or with modifications. Each licensee is addressed as "you". 1. You may copy and distribute verbatim copies of the Program's source code as you receive it, in any medium, provided that you conspicuously and appropriately publish on each copy an appropriate copyright notice and disclaimer of warranty; keep intact all the notices that refer to this General Public License and to the absence of any warranty; and give any other recipients of the Program a copy of this General Public License along with the Program. You may charge a fee for the physical act of transferring a copy. 2. You may modify your copy or copies of the Program or any portion of it, and copy and distribute such modifications under the terms of Paragraph 1 above, provided that you also do the following: a) cause the modified files to carry prominent notices stating that you changed the files and the date of any change; and b) cause the whole of any work that you distribute or publish, that in whole or in part contains the Program or any part thereof, either with or without modifications, to be licensed at no charge to all third parties under the terms of this General Public License (except that you may choose to grant warranty protection to some or all third parties, at your option). c) If the modified program normally reads commands interactively when run, you must cause it, when started running for such interactive use in the simplest and most usual way, to print or display an announcement including an appropriate copyright notice and a notice that there is no warranty (or else, saying that you provide a warranty) and that users may redistribute the program under these conditions, and telling the user how to view a copy of this General Public License. d) You may charge a fee for the physical act of transferring a copy, and you may at your option offer warranty protection in exchange for a fee. Mere aggregation of another independent work with the Program (or its derivative) on a volume of a storage or distribution medium does not bring the other work under the scope of these terms. 3. You may copy and distribute the Program (or a portion or derivative of it, under Paragraph 2) in object code or executable form under the terms of Paragraphs 1 and 2 above provided that you also do one of the following: a) accompany it with the complete corresponding machine-readable source code, which must be distributed under the terms of Paragraphs 1 and 2 above; or, b) accompany it with a written offer, valid for at least three years, to give any third party free (except for a nominal charge for the cost of distribution) a complete machine-readable copy of the corresponding source code, to be distributed under the terms of Paragraphs 1 and 2 above; or, c) accompany it with the information you received as to where the corresponding source code may be obtained. (This alternative is allowed only for noncommercial distribution and only if you received the program in object code or executable form alone.) Source code for a work means the preferred form of the work for making modifications to it. For an executable file, complete source code means all the source code for all modules it contains; but, as a special exception, it need not include source code for modules which are standard libraries that accompany the operating system on which the executable file runs, or for standard header files or definitions files that accompany that operating system. 4. You may not copy, modify, sublicense, distribute or transfer the Program except as expressly provided under this General Public License. Any attempt otherwise to copy, modify, sublicense, distribute or transfer the Program is void, and will automatically terminate your rights to use the Program under this License. However, parties who have received copies, or rights to use copies, from you under this General Public License will not have their licenses terminated so long as such parties remain in full compliance. 5. By copying, distributing or modifying the Program (or any work based on the Program) you indicate your acceptance of this license to do so, and all its terms and conditions. 6. Each time you redistribute the Program (or any work based on the Program), the recipient automatically receives a license from the original licensor to copy, distribute or modify the Program subject to these terms and conditions. You may not impose any further restrictions on the recipients' exercise of the rights granted herein. 7. The Free Software Foundation may publish revised and/or new versions of the General Public License from time to time. Such new versions will be similar in spirit to the present version, but may differ in detail to address new problems or concerns. Each version is given a distinguishing version number. If the Program specifies a version number of the license which applies to it and "any later version", you have the option of following the terms and conditions either of that version or of any later version published by the Free Software Foundation. If the Program does not specify a version number of the license, you may choose any version ever published by the Free Software Foundation. 8. If you wish to incorporate parts of the Program into other free programs whose distribution conditions are different, write to the author to ask for permission. For software which is copyrighted by the Free Software Foundation, write to the Free Software Foundation; we sometimes make exceptions for this. Our decision will be guided by the two goals of preserving the free status of all derivatives of our free software and of promoting the sharing and reuse of software generally. NO WARRANTY 9. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 10. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. END OF TERMS AND CONDITIONS Appendix: How to Apply These Terms to Your New Programs If you develop a new program, and you want it to be of the greatest possible use to humanity, the best way to achieve this is to make it free software which everyone can redistribute and change under these terms. To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. Copyright (C) 19yy This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA Also add information on how to contact you by electronic and paper mail. If the program is interactive, make it output a short notice like this when it starts in an interactive mode: Gnomovision version 69, Copyright (C) 19xx name of author Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. This is free software, and you are welcome to redistribute it under certain conditions; type `show c' for details. The hypothetical commands `show w' and `show c' should show the appropriate parts of the General Public License. Of course, the commands you use may be called something other than `show w' and `show c'; they could even be mouse-clicks or menu items--whatever suits your program. You should also get your employer (if you work as a programmer) or your school, if any, to sign a "copyright disclaimer" for the program, if necessary. Here a sample; alter the names: Yoyodyne, Inc., hereby disclaims all copyright interest in the program `Gnomovision' (a program to direct compilers to make passes at assemblers) written by James Hacker. , 1 April 1989 Ty Coon, President of Vice That's all there is to it! --- The Artistic License 1.0 --- This software is Copyright (c) 2014 by Masahiro Nagano . This is free software, licensed under: The Artistic License 1.0 The Artistic License Preamble The intent of this document is to state the conditions under which a Package may be copied, such that the Copyright Holder maintains some semblance of artistic control over the development of the package, while giving the users of the package the right to use and distribute the Package in a more-or-less customary fashion, plus the right to make reasonable modifications. Definitions: - "Package" refers to the collection of files distributed by the Copyright Holder, and derivatives of that collection of files created through textual modification. - "Standard Version" refers to such a Package if it has not been modified, or has been modified in accordance with the wishes of the Copyright Holder. - "Copyright Holder" is whoever is named in the copyright or copyrights for the package. - "You" is you, if you're thinking about copying or distributing this Package. - "Reasonable copying fee" is whatever you can justify on the basis of media cost, duplication charges, time of people involved, and so on. (You will not be required to justify it to the Copyright Holder, but only to the computing community at large as a market that must bear the fee.) - "Freely Available" means that no fee is charged for the item itself, though there may be fees involved in handling the item. It also means that recipients of the item may redistribute it under the same conditions they received it. 1. You may make and give away verbatim copies of the source form of the Standard Version of this Package without restriction, provided that you duplicate all of the original copyright notices and associated disclaimers. 2. You may apply bug fixes, portability fixes and other modifications derived from the Public Domain or from the Copyright Holder. A Package modified in such a way shall still be considered the Standard Version. 3. You may otherwise modify your copy of this Package in any way, provided that you insert a prominent notice in each changed file stating how and when you changed that file, and provided that you do at least ONE of the following: a) place your modifications in the Public Domain or otherwise make them Freely Available, such as by posting said modifications to Usenet or an equivalent medium, or placing the modifications on a major archive site such as ftp.uu.net, or by allowing the Copyright Holder to include your modifications in the Standard Version of the Package. b) use the modified Package only within your corporation or organization. c) rename any non-standard executables so the names do not conflict with standard executables, which must also be provided, and provide a separate manual page for each non-standard executable that clearly documents how it differs from the Standard Version. d) make other distribution arrangements with the Copyright Holder. 4. You may distribute the programs of this Package in object code or executable form, provided that you do at least ONE of the following: a) distribute a Standard Version of the executables and library files, together with instructions (in the manual page or equivalent) on where to get the Standard Version. b) accompany the distribution with the machine-readable source of the Package with your modifications. c) accompany any non-standard executables with their corresponding Standard Version executables, giving the non-standard executables non-standard names, and clearly documenting the differences in manual pages (or equivalent), together with instructions on where to get the Standard Version. d) make other distribution arrangements with the Copyright Holder. 5. You may charge a reasonable copying fee for any distribution of this Package. You may charge any fee you choose for support of this Package. You may not charge a fee for this Package itself. However, you may distribute this Package in aggregate with other (possibly commercial) programs as part of a larger (possibly commercial) software distribution provided that you do not advertise this Package as a product of your own. 6. The scripts and library files supplied as input to or produced as output from the programs of this Package do not automatically fall under the copyright of this Package, but belong to whomever generated them, and may be sold commercially, and may be aggregated with this Package. 7. C or perl subroutines supplied by you and linked into this Package shall not be considered part of this Package. 8. The name of the Copyright Holder may not be used to endorse or promote products derived from this software without specific prior written permission. 9. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. The End META.json100644000765000024 426013714171362 17565 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44{ "abstract" : "GNU C library compatible strftime for loggers and servers", "author" : [ "Masahiro Nagano " ], "dynamic_config" : 0, "generated_by" : "Minilla/v3.1.10", "license" : [ "perl_5" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : "2" }, "name" : "POSIX-strftime-Compiler", "no_index" : { "directory" : [ "t", "xt", "inc", "share", "eg", "examples", "author", "builder" ] }, "prereqs" : { "configure" : { "requires" : { "Module::Build::Tiny" : "0.035" } }, "develop" : { "requires" : { "Test::CPAN::Meta" : "0", "Test::MinimumVersion::Fast" : "0.04", "Test::PAUSE::Permissions" : "0.07", "Test::Pod" : "1.41", "Test::Spellunker" : "v0.2.7" } }, "runtime" : { "requires" : { "Carp" : "0", "Exporter" : "0", "POSIX" : "0", "Time::Local" : "0", "perl" : "5.008001" }, "suggests" : { "Time::TZOffset" : "0" } }, "test" : { "requires" : { "Test::More" : "0.98" } } }, "provides" : { "POSIX::strftime::Compiler" : { "file" : "lib/POSIX/strftime/Compiler.pm", "version" : "0.44" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/kazeburo/POSIX-strftime-Compiler/issues" }, "homepage" : "https://github.com/kazeburo/POSIX-strftime-Compiler", "repository" : { "url" : "git://github.com/kazeburo/POSIX-strftime-Compiler.git", "web" : "https://github.com/kazeburo/POSIX-strftime-Compiler" } }, "version" : "0.44", "x_contributors" : [ "Piotr Roszatycki ", "Slaven Rezic ", "Tom Bloor " ], "x_serialization_backend" : "JSON::PP version 4.04", "x_static_install" : 1 } README.md100644000765000024 541713714171362 17430 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44[![Build Status](https://travis-ci.org/kazeburo/POSIX-strftime-Compiler.svg?branch=master)](https://travis-ci.org/kazeburo/POSIX-strftime-Compiler) # NAME POSIX::strftime::Compiler - GNU C library compatible strftime for loggers and servers # 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 POSIX::strftime::Compiler provides GNU C library compatible strftime(3). But this module will not affected by the system locale. This feature is useful when you want to write loggers, servers and portable applications. For generate same result strings on any locale, POSIX::strftime::Compiler wraps POSIX::strftime and converts some format characters to perl code # FUNCTION - strftime($fmt:String, @time) Generate formatted string from a format and time. 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): Compiled codes are stored in `%POSIX::strftime::Compiler::STRFTIME`. This function is not exported by default. # METHODS - new($fmt) create instance of POSIX::strftime::Compiler - to\_string(@time) Generate formatted string from time. # FORMAT CHARACTERS POSIX::strftime::Compiler supports almost all characters that GNU strftime(3) supports. But `%E[cCxXyY]` and `%O[deHImMSuUVwWy]` are not supported, just remove E and O prefix. # A RECOMMEND MODULE - [Time::TZOffset](https://metacpan.org/pod/Time%3A%3ATZOffset) If [Time::TZOffset](https://metacpan.org/pod/Time%3A%3ATZOffset) is available, P::s::Compiler use it for more faster time zone offset calculation. I strongly recommend you to install this if you use `%z`. # PERFORMANCE ISSUES ON WINDOWS Windows and Cygwin and some system may not support `%z` and `%Z`. For these system, POSIX::strftime::Compiler calculate time zone offset and find zone name. This is not fast. If you need performance on Windows and Cygwin, please install [Time::TZOffset](https://metacpan.org/pod/Time%3A%3ATZOffset) # SEE ALSO - [POSIX::strftime::GNU](https://metacpan.org/pod/POSIX%3A%3Astrftime%3A%3AGNU) POSIX::strftime::Compiler is built on POSIX::strftime::GNU::PP code - [POSIX](https://metacpan.org/pod/POSIX) - [Apache::LogFormat::Compiler](https://metacpan.org/pod/Apache%3A%3ALogFormat%3A%3ACompiler) # LICENSE Copyright (C) Masahiro Nagano. Format specification is based on 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. # AUTHOR Masahiro Nagano cpanfile100644000765000024 30413714171362 17623 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44requires 'perl', '5.008001'; requires 'Carp'; requires 'Time::Local'; requires 'POSIX'; requires 'Exporter'; suggests 'Time::TZOffset'; on 'test' => sub { requires 'Test::More', '0.98'; }; benchmark.pl100644000765000024 365413714171362 21034 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44/eguse Benchmark qw/:all/; use POSIX qw//; use POSIX::strftime::Compiler; my $fmt = '%d/%b/%Y:%T'; my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my $t = time; my @lt = localtime($t); sub with_sprintf { sprintf '%02d/%s/%04d:%02d:%02d:%02d', $_[3], $abbr[$_[4]], $_[5]+1900, $_[2], $_[1], $_[0]; } my $psc = POSIX::strftime::Compiler->new($fmt); cmpthese(timethese(-1, { 'compiler' => sub { $psc->to_string(@lt); }, 'compiler_function' => sub { POSIX::strftime::Compiler::strftime($fmt, @lt); }, 'posix_and_locale' => sub { my $old_locale = POSIX::setlocale(&POSIX::LC_ALL); POSIX::setlocale(&POSIX::LC_ALL, 'C'); POSIX::strftime($fmt,@lt); POSIX::setlocale(&POSIX::LC_ALL, $old_locale); }, 'posix' => sub { POSIX::strftime($fmt,@lt); }, # 'compiler_wo_cache' => sub { # my $compiler2 = POSIX::strftime::Compiler->new($fmt); # $compiler2->to_string(localtime($t)); # }, 'sprintf' => sub { with_sprintf(@lt); }, })); __END__ Benchmark: running compiler, compiler_function, posix_and_locale, sprintf for at least 1 CPU seconds... compiler: 2 wallclock secs ( 1.01 usr + 0.00 sys = 1.01 CPU) @ 454208.91/s (n=458751) compiler_function: 2 wallclock secs ( 1.14 usr + 0.00 sys = 1.14 CPU) @ 431157.02/s (n=491519) posix_and_locale: 1 wallclock secs ( 1.11 usr + 0.00 sys = 1.11 CPU) @ 70446.85/s (n=78196) sprintf: 1 wallclock secs ( 1.06 usr + 0.00 sys = 1.06 CPU) @ 618264.15/s (n=655360) Rate posix_and_locale compiler_function compiler sprintf posix_and_locale 70447/s -- -84% -84% -89% compiler_function 431157/s 512% -- -5% -30% compiler 454209/s 545% 5% -- -27% sprintf 618264/s 778% 43% 36% -- benchmark_args.pl100644000765000024 133213714171362 22037 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44/eguse Benchmark qw/:all/; use POSIX qw//; use POSIX::strftime::Compiler; my $fmt = $ARGV[0] || '%d/%b/%Y:%T'; my $t = time; my @lt = localtime($t); my $psc = POSIX::strftime::Compiler->new($fmt); print "sample: " . $psc->to_string(@lt) ."\n"; cmpthese(timethese(-1, { 'compiler' => sub { $psc->to_string(@lt); }, 'compiler_function' => sub { POSIX::strftime::Compiler::strftime($fmt, @lt); }, 'posix_and_locale' => sub { my $old_locale = POSIX::setlocale(&POSIX::LC_ALL); POSIX::setlocale(&POSIX::LC_ALL, 'C'); POSIX::strftime($fmt,@lt); POSIX::setlocale(&POSIX::LC_ALL, $old_locale); }, 'posix' => sub { POSIX::strftime($fmt,@lt); }, })); benchmark_tz.pl100644000765000024 344313714171362 21545 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44/eguse Benchmark qw/:all/; use POSIX qw//; use POSIX::strftime::Compiler; use Time::TZOffset; my $fmt = '%d/%b/%Y:%T %z'; my @abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); my $t = time; my @lt = localtime($t); sub with_sprintf { sprintf '%02d/%s/%04d:%02d:%02d:%02d %s', $_[3], $abbr[$_[4]], $_[5]+1900, $_[2], $_[1], $_[0], Time::TZOffset::tzoffset(@_); } my $psc = POSIX::strftime::Compiler->new($fmt); cmpthese(timethese(-1, { 'compiler' => sub { $psc->to_string(@lt); }, 'compiler_function' => sub { POSIX::strftime::Compiler::strftime($fmt, @lt); }, 'posix' => sub { POSIX::strftime($fmt,@lt); }, 'posix_and_locale' => sub { my $old_locale = POSIX::setlocale(&POSIX::LC_ALL); POSIX::setlocale(&POSIX::LC_ALL, 'C'); POSIX::strftime($fmt,@lt); POSIX::setlocale(&POSIX::LC_ALL, $old_locale); }, # 'compiler_wo_cache' => sub { # my $compiler2 = POSIX::strftime::Compiler->new($fmt); # $compiler2->to_string(localtime($t)); # }, 'sprintf' => sub { with_sprintf(@lt); }, })); __END__ compiler_function: 1 wallclock secs ( 1.04 usr + 0.00 sys = 1.04 CPU) @ 183794.23/s (n=191146) posix_and_locale: 1 wallclock secs ( 1.05 usr + 0.00 sys = 1.05 CPU) @ 68265.71/s (n=71679) sprintf: 1 wallclock secs ( 1.03 usr + 0.00 sys = 1.03 CPU) @ 208775.73/s (n=215039) Rate posix_and_locale compiler_function compiler sprintf posix_and_locale 68266/s -- -63% -64% -67% compiler_function 183794/s 169% -- -3% -12% compiler 189253/s 177% 3% -- -9% sprintf 208776/s 206% 14% 10% -- Compiler.pm100644000765000024 3505613714171362 23610 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44/lib/POSIX/strftimepackage POSIX::strftime::Compiler; use 5.008001; use strict; use warnings; use Carp; use Time::Local qw//; use POSIX qw//; use base qw/Exporter/; our $VERSION = "0.44"; our @EXPORT_OK = qw/strftime/; use constant { SEC => 0, MIN => 1, HOUR => 2, DAY => 3, MONTH => 4, YEAR => 5, WDAY => 6, YDAY => 7, ISDST => 8, ISO_WEEK_START_WDAY => 1, # Monday ISO_WEEK1_WDAY => 4, # Thursday YDAY_MINIMUM => -366, }; BEGIN { *tzoffset = \&_tzoffset; *tzname = \&_tzname; if (eval { require Time::TZOffset; 1; }) { no warnings 'redefine'; *tzoffset = \&Time::TZOffset::tzoffset; } } # copy from POSIX/strftime/GNU/PP.pm and modify my @offset2zone = qw( -1100 0 SST -1100 0 SST -1000 0 HAST -0900 1 HADT -1000 0 HST -1000 0 HST -0930 0 MART -0930 0 MART -0900 0 AKST -0800 1 AKDT -0900 0 GAMT -0900 0 GAMT -0800 0 PST -0700 1 PDT -0800 0 PST -0800 0 PST -0700 0 MST -0600 1 MDT -0700 0 MST -0700 0 MST -0600 0 CST -0500 1 CDT -0600 0 GALT -0600 0 GALT -0500 0 ECT -0500 0 ECT -0500 0 EST -0400 1 EDT -0500 1 EASST -0600 0 EAST -0430 0 VET -0430 0 VET -0400 0 AMT -0400 0 AMT -0400 0 AST -0300 1 ADT -0330 0 NST -0230 1 NDT -0300 0 ART -0300 0 ART -0300 0 PMST -0200 1 PMDT -0300 1 AMST -0400 0 AMT -0300 1 WARST -0300 1 WARST -0200 0 FNT -0200 0 FNT -0200 1 UYST -0300 0 UYT -0100 0 AZOT +0000 1 AZOST -0100 0 CVT -0100 0 CVT +0000 0 GMT +0000 0 GMT +0000 0 WET +0100 1 WEST +0100 0 CET +0200 1 CEST +0100 0 WAT +0100 0 WAT +0200 0 EET +0200 0 EET +0200 0 IST +0300 1 IDT +0200 1 WAST +0100 0 WAT +0300 0 FET +0300 0 FET +030704 0 zzz +030704 0 zzz +0330 0 IRST +0430 1 IRDT +0400 0 AZT +0500 1 AZST +0400 0 GST +0400 0 GST +0430 0 AFT +0430 0 AFT +0500 0 DAVT +0700 0 DAVT +0500 0 MVT +0500 0 MVT +0530 0 IST +0530 0 IST +0545 0 NPT +0545 0 NPT +0600 0 BDT +0600 0 BDT +0630 0 CCT +0630 0 CCT +0700 0 ICT +0700 0 ICT +0800 0 HKT +0800 0 HKT +0845 0 CWST +0845 0 CWST +0900 0 JST +0900 0 JST +0930 0 CST +0930 0 CST +1000 0 PGT +1000 0 PGT +1030 1 CST +0930 0 CST +1100 0 CAST +0800 0 WST +1100 0 NCT +1100 0 NCT +1100 1 EST +1000 0 EST +1100 1 LHST +1030 0 LHST +1130 0 NFT +1130 0 NFT +1200 0 FJT +1200 0 FJT +1300 0 TKT +1300 0 TKT +1300 1 NZDT +1200 0 NZST +1345 1 CHADT +1245 0 CHAST +1400 0 LINT +1400 0 LINT +1400 1 WSDT +1300 0 WST ); sub _tzoffset { my $diff = (exists $ENV{TZ} and $ENV{TZ} =~ m!^(?:GMT|UTC)$!) ? 0 : Time::Local::timegm(@_) - Time::Local::timelocal(@_); sprintf '%+03d%02u', $diff/60/60, $diff/60%60; } sub _tzname { return $ENV{TZ} if exists $ENV{TZ} and $ENV{TZ} =~ m!^(?:GMT|UTC)$!; my $diff = tzoffset(@_); my @t1 = my @t2 = @_; @t1[3,4] = (1, 1); # winter my $diff1 = tzoffset(@t1); @t2[3,4] = (1, 7); # summer my $diff2 = tzoffset(@t2); for (my $i=0; $i < @offset2zone; $i += 6) { next unless $offset2zone[$i] eq $diff1 and $offset2zone[$i+3] eq $diff2; return $diff2 eq $diff ? $offset2zone[$i+5] : $offset2zone[$i+2]; } if ($diff =~ /^([+-])(\d\d)$/) { return sprintf 'GMT%s%d', $1 eq '-' ? '+' : '-', $2; }; return 'Etc'; } sub iso_week_days { my ($yday, $wday) = @_; # Add enough to the first operand of % to make it nonnegative. my $big_enough_multiple_of_7 = (int(- YDAY_MINIMUM / 7) + 2) * 7; return ($yday - ($yday - $wday + ISO_WEEK1_WDAY + $big_enough_multiple_of_7) % 7 + ISO_WEEK1_WDAY - ISO_WEEK_START_WDAY); } sub isleap { my $year = shift; return ($year % 4 == 0 && ($year % 100 != 0 || $year % 400 == 0)) ? 1 : 0 } sub isodaysnum { my @t = @_; my $year = ($t[YEAR] + ($t[YEAR] < 0 ? 1900 % 400 : 1900 % 400 - 400)); my $year_adjust = 0; my $days = iso_week_days($t[YDAY], $t[WDAY]); if ($days < 0) { # This ISO week belongs to the previous year. $year_adjust = -1; $days = iso_week_days($t[YDAY] + (365 + isleap($year -1)), $t[WDAY]); } else { my $d = iso_week_days($t[YDAY] - (365 + isleap($year)), $t[WDAY]); if ($d >= 0) { # This ISO week belongs to the next year. */ $year_adjust = 1; $days = $d; } } return ($days, $year_adjust); } sub isoyearnum { my ($days, $year_adjust) = isodaysnum(@_); return $_[YEAR] + 1900 + $year_adjust; } sub isoweeknum { my ($days, $year_adjust) = isodaysnum(@_); return int($days / 7) + 1; } our %FORMAT_CHARS = map { $_ => 1 } split //, q!%aAbBcCdDeFGghHIjklmMnNpPrRsStTuUVwWxXyYzZ!; our %SPRINTF_CHARS = ( '%' => [q!%s!, q!%!], 'a' => [q!%s!, q!$weekday_abbr[$_[WDAY]]!], 'A' => [q!%s!, q!$weekday_name[$_[WDAY]]!], 'b' => [q!%s!, q!$month_abbr[$_[MONTH]]!], 'B' => [q!%s!, q!$month_name[$_[MONTH]]!], 'c' => [q!%s %s %2d %02d:%02d:%02d %04d!, q!$weekday_abbr[$_[WDAY]], $month_abbr[$_[MONTH]], $_[DAY], $_[HOUR], $_[MIN], $_[SEC], $_[YEAR]+1900!], 'C' => [q!%02d!, q!($_[YEAR]+1900)/100!], 'd' => [q!%02d!, q!$_[DAY]!], 'D' => [q!%02d/%02d/%02d!, q!$_[MONTH]+1,$_[DAY],$_[YEAR]%100!], 'e' => [q!%2d!, q!$_[DAY]!], 'F' => [q!%04d-%02d-%02d!, q!$_[YEAR]+1900,$_[MONTH]+1,$_[DAY]!], 'h' => [q!%s!, q!$month_abbr[$_[MONTH]]!], 'H' => [q!%02d!, q!$_[HOUR]!], 'I' => [q!%02d!, q!$_[HOUR]%12 || 1!], 'j' => [q!%03d!, q!$_[YDAY]+1!], 'k' => [q!%2d!, q!$_[HOUR]!], 'l' => [q!%2d!, q!$_[HOUR]%12 || 1!], 'm' => [q!%02d!, q!$_[MONTH]+1!], 'M' => [q!%02d!, q!$_[MIN]!], 'n' => [q!%s!, q!"\n"!], 'N' => [q!%s!, q!substr(sprintf('%.9f', $_[SEC] - int $_[SEC]), 2)!], 'p' => [q!%s!, q!$_[HOUR] > 0 && $_[HOUR] < 13 ? "AM" : "PM"!], 'P' => [q!%s!, q!$_[HOUR] > 0 && $_[HOUR] < 13 ? "am" : "pm"!], 'r' => [q!%02d:%02d:%02d %s!, q!$_[HOUR]%12 || 1, $_[MIN], $_[SEC], $_[HOUR] > 0 && $_[HOUR] < 13 ? "AM" : "PM"!], 'R' => [q!%02d:%02d!, q!$_[HOUR], $_[MIN]!], 'S' => [q!%02d!, q!$_[SEC]!], 't' => [q!%s!, q!"\t"!], 'T' => [q!%02d:%02d:%02d!, q!$_[HOUR], $_[MIN], $_[SEC]!], 'u' => [q!%d!, q!$_[WDAY] || 7!], 'w' => [q!%d!, q!$_[WDAY]!], 'x' => [q!%02d/%02d/%02d!, q!$_[MONTH]+1,$_[DAY],$_[YEAR]%100!], 'X' => [q!%02d:%02d:%02d!, q!$_[HOUR], $_[MIN], $_[SEC]!], 'y' => [q!%02d!, q!$_[YEAR]%100!], 'Y' => [q!%02d!, q!$_[YEAR]+1900!], '%' => [q!%s!, q!'%'!], ); if ( eval { require Time::TZOffset; 1 } ) { $SPRINTF_CHARS{z} = [q!%s!,q!Time::TZOffset::tzoffset(@_)!]; } our %LOCALE_CHARS = ( '%' => [q!'%%'!], 'a' => [q!$weekday_abbr[$_[WDAY]]!,1], 'A' => [q!$weekday_name[$_[WDAY]]!,1], 'b' => [q!$month_abbr[$_[MONTH]]!], 'B' => [q!$month_name[$_[MONTH]]!], 'c' => [q!$weekday_abbr[$_[WDAY]] . ' ' . $month_abbr[$_[MONTH]] . ' ' . substr(' '.$_[DAY],-2) . ' %H:%M:%S %Y'!,1], 'C' => [q!substr('0'.int(($_[YEAR]+1900)/100), -2)!], #century 'h' => [q!$month_abbr[$_[MONTH]]!], 'k' => [q!substr(' '.$_[HOUR],-2)!], 'l' => [q!substr(' '.($_[HOUR]%12 || 1),-2)!], 'N' => [q!substr(sprintf('%.9f', $_[SEC] - int $_[SEC]), 2)!], 'n' => [q!"\n"!], 'p' => [q!$_[HOUR] > 0 && $_[HOUR] < 13 ? "AM" : "PM"!], 'P' => [q!$_[HOUR] > 0 && $_[HOUR] < 13 ? "am" : "pm"!], 'r' => [q!sprintf('%02d:%02d:%02d %s',$_[HOUR]%12 || 1, $_[MIN], $_[SEC], $_[HOUR] > 0 && $_[HOUR] < 13 ? "AM" : "PM")!], 't' => [q!"\t"!], 'x' => [q!'%m/%d/%y'!], 'X' => [q!'%H:%M:%S'!], 'z' => [q!'%z'!,1], 'Z' => [q!'%Z'!,1], ); if ( $^O =~ m!^(MSWin32|cygwin)$!i ) { %LOCALE_CHARS = ( %LOCALE_CHARS, 'D' => [q!'%m/%d/%y'!], 'F' => [q!'%Y-%m-%d'!], 'G' => [q!substr('0000'. isoyearnum(@_), -4)!,1], 'R' => [q!'%H:%M'!], 'T' => [q!'%H:%M:%S'!], 'V' => [q!substr('0'.isoweeknum(@_),-2)!,1], 'e' => [q!substr(' '.$_[DAY],-2)!], 'g' => [q!substr('0'.isoyearnum(@_)%100,-2)!,1], 's' => [q!int(Time::Local::timegm(@_))!,1], 'u' => [q!$_[WDAY] || 7!,1], 'z' => [q!tzoffset(@_)!,1], 'Z' => [q!tzname(@_)!,1], ); } elsif ( $^O =~ m!^solaris$!i ) { $LOCALE_CHARS{s} = [q!int(Time::Local::timegm(@_))!,1]; } my $sprintf_char_handler = sub { my ($char,$args) = @_; return q|! . '%%' .q!| if $char eq ''; #last % return q|! . '%%| . $char . q|' . q!| if ! exists $FORMAT_CHARS{$char}; #escape %% my ($format, $code) = @{$SPRINTF_CHARS{$char}}; push @$args, $code; return $format; }; my $char_handler = sub { my ($char,$need9char_ref) = @_; return q|! . '%%' .q!| if $char eq ''; #last % return q|! . '%%| . $char . q|' . q!| if ! exists $FORMAT_CHARS{$char}; #escape %% return q|! . '%| . $char . q|' . q!| if ! exists $LOCALE_CHARS{$char}; #stay my ($code,$flag) = @{$LOCALE_CHARS{$char}}; $$need9char_ref++ if $flag; q|! . | . $code . q| . q!|; }; sub compile { my ($fmt) = @_; my @weekday_name = qw(Sunday Monday Tuesday Wednesday Thursday Friday Saturday); my @weekday_abbr = qw(Sun Mon Tue Wed Thu Fri Sat); my @month_name = qw(January February March April May June July August September October November December); my @month_abbr = qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec); $fmt =~ s/!/\\!/g; $fmt =~ s!\%E([cCxXyY])!%$1!g; $fmt =~ s!\%O([deHImMSuUVwWy])!%$1!g; my $sprintf_fmt = $fmt; my $disable_sprintf=0; my $sprintf_code = ''; while ( $sprintf_fmt =~ m~ (?:\%([\%\+a-zA-Z])) ~gx ) { if ( exists $FORMAT_CHARS{$1} && ! exists $SPRINTF_CHARS{$1} ) { $disable_sprintf++ } } if ( !$disable_sprintf ) { my @args; $sprintf_fmt =~ s! (?: \%([\%\+a-zA-Z]|$) ) ! $sprintf_char_handler->($1,\@args) !egx; $sprintf_code = q~if ( @_ == 9 ) { return sprintf(q!~ . $sprintf_fmt . q~!,~ . join(",", @args) . q~); }~; } my $posix_fmt = $fmt; my $need9char=0; $posix_fmt =~ s! (?: \%([\%\+a-zA-Z]|$) ) ! $char_handler->($1,\$need9char) !egx; my $need9char_code=''; if ( $need9char ) { $need9char_code = q~if ( @_ == 6 ) { my $sec = $_[0]; @_ = gmtime Time::Local::timegm(@_); $_[0] = $sec; }~; } my $code = q~sub { ~ . $sprintf_code . q~ ~ . $need9char_code . q~ if ( @_ != 9 && @_ != 6 ) { Carp::croak 'Usage: strftime(sec, min, hour, mday, mon, year, wday = -1, yday = -1, isdst = -1)'; } POSIX::strftime(q!~ . $posix_fmt . q~!,@_); }~; my $sub = eval $code; ## no critic die $@ ."\n=====\n".$code."\n=====\n" if $@; wantarray ? ($sub,$code) : $sub; } my %STRFTIME; sub strftime { my $fmt = shift; ($STRFTIME{$fmt} ||= compile($fmt))->(@_); } sub new { my $class = shift; my $fmt = shift; my ($sub,$code) = compile($fmt); bless [$sub,$code], $class; } sub to_string { my $self = shift; $self->[0]->(@_); } sub code_ref { my $self = shift; $self->[0]; } 1; __END__ =encoding utf-8 =head1 NAME POSIX::strftime::Compiler - GNU C library compatible strftime for loggers and servers =head1 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); =head1 DESCRIPTION POSIX::strftime::Compiler provides GNU C library compatible strftime(3). But this module will not affected by the system locale. This feature is useful when you want to write loggers, servers and portable applications. For generate same result strings on any locale, POSIX::strftime::Compiler wraps POSIX::strftime and converts some format characters to perl code =head1 FUNCTION =over 4 =item strftime($fmt:String, @time) Generate formatted string from a format and time. 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): Compiled codes are stored in C<%POSIX::strftime::Compiler::STRFTIME>. This function is not exported by default. =back =head1 METHODS =over 4 =item new($fmt) create instance of POSIX::strftime::Compiler =item to_string(@time) Generate formatted string from time. =back =head1 FORMAT CHARACTERS POSIX::strftime::Compiler supports almost all characters that GNU strftime(3) supports. But C<%E[cCxXyY]> and C<%O[deHImMSuUVwWy]> are not supported, just remove E and O prefix. =head1 A RECOMMEND MODULE =over =item L If L is available, P::s::Compiler use it for more faster time zone offset calculation. I strongly recommend you to install this if you use C<%z>. =back =head1 PERFORMANCE ISSUES ON WINDOWS Windows and Cygwin and some system may not support C<%z> and C<%Z>. For these system, POSIX::strftime::Compiler calculate time zone offset and find zone name. This is not fast. If you need performance on Windows and Cygwin, please install L =head1 SEE ALSO =over 4 =item L POSIX::strftime::Compiler is built on POSIX::strftime::GNU::PP code =item L =item L =back =head1 LICENSE Copyright (C) Masahiro Nagano. Format specification is based on 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. =head1 AUTHOR Masahiro Nagano Ekazeburo@gmail.comE =cut minil.toml100644000765000024 6513714171362 20110 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44name = "POSIX-strftime-Compiler" badges = ["travis"] 00_compile.t100644000765000024 14013714171362 20474 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44/tuse strict; use Test::More; use_ok $_ for qw( POSIX::strftime::Compiler ); done_testing; 01_basic.t100644000765000024 553213714171362 20160 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44/tuse strict; use warnings; BEGIN { # Windows can't change timezone inside Perl script if (($ENV{TZ}||'') ne 'GMT') { $ENV{TZ} = 'GMT'; exec $^X (map { "-I\"$_\"" } @INC), $0; }; } use Test::More; use POSIX::strftime::Compiler; use Time::Local; my %format = ( a => 'Sun', A => 'Sunday', b => 'Jul', B => 'July', c => 'Sun Jul 6 21:03:54 2008', C => '20', d => '06', D => '07/06/08', e => ' 6', EC => '20', Ex => '07/06/08', EX => '21:03:54', EY => '2008', Ey => '08', F => '2008-07-06', G => '2008', g => '08', h => 'Jul', H => '21', I => '09', j => '188', k => '21', l => ' 9', m => '07', M => '03', n => "\n", N => '123456000', Od => '06', Oe => ' 6', OH => '21', OI => '09', Om => '07', OM => '03', OS => '54', Ou => '7', OU => '27', OV => '27', Ow => '0', Oy => '08', p => 'PM', P => 'pm', r => '09:03:54 PM', R => '21:03', s => '1215378234', S => '54', t => "\t", T => '21:03:54', u => '7', U => '27', V => '27', w => '0', W => '26', x => '07/06/08', X => '21:03:54', y => '08', Y => '2008', z => '+0000', Z => qr/^(GMT|UTC)$/, '%' => '%', Q => '%Q', #unknown q => '%q', #unknown ); my @t = localtime timelocal(54, 3, 21, 6, 6, 108); $t[0] += 0.123456; foreach my $f (sort keys %format) { if ( ref $format{$f} ) { like( POSIX::strftime::Compiler::strftime('%'.$f,@t), $format{$f}, '%'.$f); } else { is( POSIX::strftime::Compiler::strftime('%'.$f,@t), $format{$f}, '%'.$f); is( POSIX::strftime::Compiler::strftime('%'.$f.'foo',@t), $format{$f}.'foo', '%'.$f); is( POSIX::strftime::Compiler::strftime('%'.$f.' foo',@t), $format{$f}.' foo', '%'.$f); } } @t = (54.123456, 3, 21, 6, 6, 108); foreach my $f (sort keys %format) { if ( ref $format{$f} ) { like( POSIX::strftime::Compiler::strftime('%'.$f,@t), $format{$f}, '%'.$f.'=6'); } else { is( POSIX::strftime::Compiler::strftime('%'.$f,@t), $format{$f}, '%'.$f. '=6'); is( POSIX::strftime::Compiler::strftime('%'.$f.'foo',@t), $format{$f}.'foo', '%'.$f.'foo=6'); is( POSIX::strftime::Compiler::strftime('%'.$f.' foo',@t), $format{$f}.' foo', '%'.$f.' foo=6'); } } #last single % is( POSIX::strftime::Compiler::strftime('foo %',@t), 'foo %', 'last %'); #last single % is( POSIX::strftime::Compiler::strftime('foo %',(54.123456, 3, 21, 6, 6, 108)), 'foo %', 'last % =6'); done_testing(); 02_timezone.pl100644000765000024 65413714171362 21062 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44/t#!/usr/bin/perl use strict; use warnings; BEGIN { # Windows can't change timezone inside Perl script if ($ENV{TEST_TZ}) { $ENV{TZ} = delete $ENV{TEST_TZ}; exec $^X (map { "-I\"$_\"" } @INC), $0, @ARGV; }; } use Time::Local; use POSIX::strftime::Compiler; my $fmt = shift @ARGV || '%z'; my @t = @ARGV ? localtime timelocal(@ARGV) : localtime; print POSIX::strftime::Compiler::strftime($fmt,@t); 02_timezone.t100644000765000024 141613714171362 20727 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44/tuse strict; use warnings; use Test::More; use POSIX::strftime::Compiler; use File::Basename; my $inc = join ' ', map { "-I\"$_\"" } @INC; my $dir = dirname(__FILE__); $ENV{TEST_TZ} = 'CET-1CEST'; eval { my $d = `"$^X" $inc $dir/02_timezone.pl %z 0 0 0 1 7 112`; if ($d !~ m!^\+0200!) { die "tzdada is not enough: $d"; } }; if ( $@ ) { plan skip_all => $@; } my @t1 = (0, 0, 0, 1, 1, 112); my @t2 = (0, 0, 0, 1, 7, 112); is `"$^X" $inc $dir/02_timezone.pl %z @t1`, '+0100', "tmzone1($ENV{TEST_TZ})"; is `"$^X" $inc $dir/02_timezone.pl %Z @t1`, 'CET', "tmname1($ENV{TEST_TZ})"; is `"$^X" $inc $dir/02_timezone.pl %z @t2`, '+0200', "tmzone2($ENV{TEST_TZ})"; is `"$^X" $inc $dir/02_timezone.pl %Z @t2`, 'CEST', "tmname2($ENV{TEST_TZ})"; done_testing();03_isoweek.t100644000765000024 124013714171362 20537 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44/tuse strict; use warnings; use Test::More; use POSIX::strftime::Compiler; is( POSIX::strftime::Compiler::strftime('%gW%V',(0, 0, 0, 31, 11, 111)), '11W52', '2011-12-31'); is( POSIX::strftime::Compiler::strftime('%gW%V',(0, 0, 0, 1, 0, 112)), '11W52', '2012-01-01'); is( POSIX::strftime::Compiler::strftime('%gW%V',(0, 0, 0, 2, 0, 112)), '12W01', '2012-01-02'); is( POSIX::strftime::Compiler::strftime('%gW%V',(0, 0, 0, 30, 11, 112)), '12W52', '2012-12-30'); is( POSIX::strftime::Compiler::strftime('%gW%V',(0, 0, 0, 31, 11, 112)), '13W01', '2012-12-31'); is( POSIX::strftime::Compiler::strftime('%gW%V',(0, 0, 0, 1, 0, 113)), '13W01', '2013-01-01'); done_testing; 04_tzset.t100644000765000024 473613714171362 20260 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44/tuse strict; use warnings; use Test::More; use POSIX qw//; use Time::Local; use POSIX::strftime::Compiler qw/strftime/; use File::Basename; my $inc = join ' ', map { "-I\"$_\"" } @INC; my $dir = dirname(__FILE__); eval { POSIX::tzset; die q!tzset is implemented on this ! . $^O .q!. But Windows can't change tz inside script! if $^O =~ m/^(MSWin32|cygwin)$/i; }; if ( $@ ) { plan skip_all => $@; } eval { local $ENV{TEST_TZ} = 'Australia/Darwin'; my $d = `"$^X" $inc $dir/02_timezone.pl %z 0 0 0 10 0 113`; if ($d !~ m!^\+0930!) { die "tzdada is not enough: $d"; } }; if ( $@ ) { plan skip_all => $@; } my @timezones = ( ['Australia/Darwin','+0930','+0930','+0930','+0930',qr/A?CST/,qr/A?CST/,qr/A?CST/,qr/A?CST/ ], ['Asia/Tokyo', '+0900','+0900','+0900','+0900', 'JST','JST','JST','JST'], ['UTC', '+0000','+0000','+0000','+0000','UTC','UTC','UTC','UTC'], ['Europe/London', '+0000','+0100','+0100','+0000',qr/(GMT|WET)/,qr/(BST|WEST)/,qr/(BST|WEST)/,qr/(GMT|WET|)/], ['Europe/Paris', '+0100','+0200','+0200','+0100','CET','CEST','CEST','CET'], ['America/New_York','-0500', '-0400', '-0400', '-0500','EST','EDT','EDT','EST'] ); for my $timezones (@timezones) { my ($timezone, @tz) = @$timezones; local $ENV{TZ} = $timezone; POSIX::tzset; subtest "$timezone" => sub { my $i=0; for my $date ( ([10,1,2013], [10,5,2013], [15,8,2013], [15,11,2013]) ) { my ($day,$month,$year) = @$date; my $str = strftime('%z',localtime(timelocal(0, 45, 12, $day, $month - 1, $year))); is $str, $tz[$i]; my $str2 = strftime('%Z',localtime(timelocal(0, 45, 12, $day, $month - 1, $year))); if ( ref $tz[$i+4] ) { like $str2, $tz[$i+4], "$timezone / $year-$month-$day => $str2"; } else { is $str2, $tz[$i+4], "$timezone / $year-$month-$day => $str2"; } my $str3 = POSIX::strftime::Compiler::_tzoffset(localtime(timelocal(0, 45, 12, $day, $month - 1, $year))); is $str3, $tz[$i]; my $str4 = POSIX::strftime::Compiler::_tzname(localtime(timelocal(0, 45, 12, $day, $month - 1, $year))); if ( ref $tz[$i+4] ) { like $str4, $tz[$i+4], "$timezone / $year-$month-$day => $str4"; } else { is $str4, $tz[$i+4], "$timezone / $year-$month-$day => $str4"; } $i++; } }; } done_testing(); META.yml100644000765000024 226013714171362 17413 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44--- abstract: 'GNU C library compatible strftime for loggers and servers' author: - 'Masahiro Nagano ' build_requires: Test::More: '0.98' configure_requires: Module::Build::Tiny: '0.035' dynamic_config: 0 generated_by: 'Minilla/v3.1.10, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: POSIX-strftime-Compiler no_index: directory: - t - xt - inc - share - eg - examples - author - builder provides: POSIX::strftime::Compiler: file: lib/POSIX/strftime/Compiler.pm version: '0.44' requires: Carp: '0' Exporter: '0' POSIX: '0' Time::Local: '0' perl: '5.008001' resources: bugtracker: https://github.com/kazeburo/POSIX-strftime-Compiler/issues homepage: https://github.com/kazeburo/POSIX-strftime-Compiler repository: git://github.com/kazeburo/POSIX-strftime-Compiler.git version: '0.44' x_contributors: - 'Piotr Roszatycki ' - 'Slaven Rezic ' - 'Tom Bloor ' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' x_static_install: 1 MANIFEST100644000765000024 40213714171362 17247 0ustar00kazeburostaff000000000000POSIX-strftime-Compiler-0.44Build.PL Changes LICENSE META.json README.md cpanfile eg/benchmark.pl eg/benchmark_args.pl eg/benchmark_tz.pl lib/POSIX/strftime/Compiler.pm minil.toml t/00_compile.t t/01_basic.t t/02_timezone.pl t/02_timezone.t t/03_isoweek.t t/04_tzset.t META.yml MANIFEST