Time-Moment-0.44/000755 000765 000024 00000000000 13274643625 014372 5ustar00chansenstaff000000 000000 Time-Moment-0.44/.travis.yml000644 000765 000024 00000000647 13022651233 016473 0ustar00chansenstaff000000 000000 language: perl perl: - "5.24" - "5.22" - "5.20" - "5.18" - "5.16" - "5.14" - "5.12" - "5.10" before_install: - "cpanm Module::Install" - "cpanm Module::Install::XSUtil" - "cpanm Module::Install::ReadmeFromPod" - "cpanm Test::More" - "cpanm Test::Fatal" - "cpanm Test::Requires" - "cpanm Test::Number::Delta" - "cpanm Sereal" - "cpanm Params::Coerce" script: "perl Makefile.PL; make test" Time-Moment-0.44/Changes000644 000765 000024 00000026315 13274643251 015667 0ustar00chansenstaff000000 000000 0.44 2018-05-09 - Bug fix in Time::Moment::Adjusters that prevented the exportation of OrthodoxEasterSunday(). Reported by David Romano (unobe) #29. - Bug fix in Time::Moment::Adjusters, the PreviousDayOfWeek() routine computed an incorrect value, fix by Simon Shine (sshine) and tests by Julien Fiegehenn (simbabque) and Simon Shine #31 and PR #32. 0.43 2018-03-08 - Correct commification of epoch seconds in documentation. PR #26, by Tim Heaney (oylenshpeegul). - The macro test around the inclusion of stdbool.h was too broad and didn't account for compiler abilities. PR #28 by Dale Ghent (daleghent). 0.42 2017-04-10 - Avoid relying on current working directory being in @INC 0.41 2016-12-10 - Time::Moment - Documented the precision value returned by ->precision() - Documented the optional precision value in ->compare() - Time::Moment::Adjusters - Corrected the NearestMinuteInterval example - Increased and documented the accepted values for NearestMinuteInterval 0.40 2016-11-26 - Correct forward function declaration to include interpreter context Bug fix for #22, compilation with threaded perls. Reported by Slaven Rezić (eserte). 0.39 2016-11-25 - Added following methods to Time::Moment: - precision - with_precision - Added following adjusters to Time::Moment::Adjusters: - WesternEasterSunday() - OthodoxEasterSunday() - NearestMinuteInterval($interval) - Added following examples to eg/ - eg/se_bank_holidays.pl 0.38 2016-01-22 - Added following methods to the API: - is_leap_year - Added following examples to eg/ - eg/age.pl 0.37 2015-12-18 - Added following methods to the API: - with_quarter - Clarified parts of documentation 0.36 2015-10-11 - Applied patch from Vitaliy V. Tokarev (issue #15) which addresses build issues on Solaris with Sun Compiler. 0.35 2015-10-10 - Added support for named parameters in from_epoch - Fix a compiler issue related to PERL_UNUSED_VAR(), reported by CPAN smokers, . 0.34 2015-10-10 - This release has no code changes. Re-released without object files. 0.33 2015-10-10 - Fixed a bug in from_rd, from_jd and from_mjd when Perl is compiled with long double. Reported by Slaven Rezić (SREZIC), issue #19. 0.32 2015-10-09 - Added Test::Number::Delta v1.06 as a test prerequisite - Increased test coverage - Added following methods to the API: - from_rd 0.31 2015-09-28 - Added following methods to the API: - delta_years - delta_months - delta_weeks - delta_days 0.30 2015-09-23 - Fixed a bug in the delta methods that where added in previous release. The result should be negative if the other time is before the time of the invocant. - Added two examples to eg/ - eg/ago.pl - eg/beat.pl 0.29 2015-09-17 - Changed the fractional second precision in from_epoch() when invoked with a floating point value from nanosecond precision to microsecond precision. - Changed the exception message in ->from_string(), from "Cannot parse ..." to "Could not parse ...". - Added following methods to the API: - delta_hours - delta_minutes - delta_seconds - delta_milliseconds - delta_microseconds - delta_nanoseconds - microsecond_of_day - nanosecond_of_day - with_microsecond_of_day - with_nanosecond_of_day 0.28 2015-09-12 - Changed the lenient mode in ->from_string to be more lenient. The string representation may now consist of a mixture of the basic format and the extended format. e.g. the date may be in the basic format, while the time of day is in the extended format, 20121224T12:15:30Z. - Changed the fractional second precision in ->jd, ->mjd and ->rd from nanosecond to millisecond, higher precision can be returned by providing the optional named parameter precision. - Applied pull request by Gareth Harper (GHARPER) which fixes test issues, due to changes in Test::More (pull request #17). 0.27 2015-09-02 - Added ->with method - Added Time::Moment::Adjusters - Added following examples to eg/ - eg/cal.pl - eg/excel.pl - eg/us_federal_holidays.pl 0.26 2015-08-28 - The optional epoch date in ->from_jd and ->from_mjd has changed from 0001-01-01T00Z to 0000-12-31T00Z (Rata Die). - Applied patch from Vitaliy V. Tokarev (issue #15) which addresses builds on Solaris. - Added following methods to the API: - minutes_of_day - with_minutes_of_day - millisecond_of_day - with_millisecond_of_day - Internals has been refactored to ease maintainability - Added more test cases 0.25 2015-07-07 - Added following methods to the API: - from_jd - from_mjd - rd 0.24 2015-05-20 Bug fix for when Perl is compiled with threads. - Bug introduced in 60591ef (0.23) fixes issue #13, reported by Dmytro Zagashev (ZDM). 0.23 2015-05-19 - Added following methods to the API: - at_midnight - at_noon - at_last_day_of_year - at_last_day_of_quarter - at_last_day_of_month - with_second_of_day 0.22 2015-02-14 - Fixed issue #12. Redefinition of bool with Visual Studio 2013 C compiler, reported by A. Sinan Ünür (NANIS). - Added following method: - second_of_day 0.21 2014-11-23 - Added following methods to increase consistency in the API: - with_week - with_day_of_week - length_of_week_year 0.20 2014-11-04 - Reduced the required accuracy in ISO 8601 representations, previously the time of day where required to include hour and minute, the required accuracy has now been reduced to hour. - Documented the %w conversion specification in ->srtftime, reported by Peter Isaksson. - Minor documentation tweaks. 0.19 2014-10-08 - Fixed Makefile.PL to only check if Module::Install is missing, should make it possible to install using cpanm. - Added accessors for Julian Date (->jd) and Modified Julian Date (->mjd). 0.18 2014-09-09 - Ensure that the referenced object has a SvREFCNT of 1 before trying to reuse the invocant, fixes issue #7. Reported by Tomohiro Hosaka (bokutin). - Added accessor method ->utc_year, used by DateTime::TimeZone for dates far into the future, fixes issue #6. Reported by Karl Lohner (klohner). 0.17 2014-08-07 - Ensure that the SvREFCNT is 1 before trying to reuse the invocant in chained method calls (leont++). - Require Test::Fatal v0.006 or higher, fixes issue #5. Reported by Doug Bell (preaction). - Removed the "early preview release" warning from the documentation. 0.16 2014-03-18 - Fixed the Storable thaw method to account for negative offsets - Corrected documentation for length_of_{year,quarter,month} methods - Added following methods to increase consistency in the API: - with_day_of_quarter() - with_millisecond() - with_microsecond() - plus_milliseconds() - plus_microseconds() - minus_milliseconds() - minus_microseconds() 0.15 2014-02-23 - Changed API in to_string() to use named parameters instead of boolean to make the API more consistent. - Added three new methods: - length_of_year() - length_of_quarter() - length_of_month() - Corrected typedef declaration in dt_config.h, should now hopefully compile correctly on Windows when using MSC. 0.14 2014-01-26 - Changed now() to use the reentrant localtime_r() if provided by libc - Added support for the literal strings 'UTC' and 'GMT' as UTC designator in from_string() when lenient is true. - Sereal is now a supported serializer, documented and tested. Added an examample of usage, eg/sereal.pl 0.13 2014-01-04 - Implemented ->with_offset_same_local() - Renamed the method ->with_offset to ->with_offset_same_instant, the old method name is aliased. - Added a new section to the documentation "TIME ZONES" which shows how to convert between time zones using DateTime::TimeZone. - Added more tests 0.12 2013-12-29 - Implemented support for lenient parsing in ->from_string, should be capable of parsing most ISO 8601 profiles, including non conformant ISO 8601 representations such as ISO 9075. - Implemented support for generic FREEZE / THAW serialization, upcomming Sereal will support these callbacks. - Implemented ->new - Refactored test suite and added more tests - Implemented support for GNU's '_', '-' and '0' flags in ->strftime() - Added eg/strftime.pl 0.11 2013-12-15 - Added support for date/time arithmethics - Added support for altering the components of the date/time - Changed ->from_epoch to only accept seconds and nanosecond parameters - Added POD section with example format strings - Documentation improvements 0.10 2013-12-07 - Added support for fractional seconds in the constructor ->from_epoch - Added serialization support for: - Storable - JSON - CBOR - Changed the method ->to_string to return the same string representation as stringification. - Optimized the usage of chained method calls from constructors. - Added eg/cbor.pl and eg/json.pl 0.09 2013-12-05 - Added new constructor method, ->now_utc - Added two extended conversion specifications, %k and %l. Both common in GNU, BSD and perl implementations of strftime() - The extended %f conversion specification now accepts an optional maximum field width - Documented remaining methods and overloaded operators - Added the now_utc constructor to dev/bench.pl 0.08 2013-12-04 - Changed resolution from microsecond to nanosecond - Implemented ->with_nanosecond() - Documentation improvements - Fixed strftime() to preserve the SvUTF8 flag if the given format string has the SvUTF8 flag set. - Overhauled strftime() conversion specifications to better confirm to IEEE Std 1003.1. Extended conversion specifications is now documented as such. 0.07 2013-12-02 - Documented most of the API. - Implemented ->to_string(). - Changed stringification to only include fractional seconds in output if present. 0.06 2013-11-31 - Added more docs. 0.05 2013-11-30 - Renamed internal variable pow10 to prevent symbol clashes 0.04 2013-11-30 - Added accessor for week of the year, ->week - Implemented support for parsing of any ISO 8601 date and time of day in both extended and basic format. For example: - 0001-01-01T00:00:00Z (Calender date, extended format) - 00010101T000000Z (Calender date, basic format) - 0001-W01-1T00:00:00Z (Week date, extended format) - 0001W011T000000Z (Week date, basic format) - 0001-001T00:00:00Z (Ordinal date, extended format) - 0001001T000000Z (Ordinal date, basic format) - Added localtime() and POSIX::strftime() to benchmark, invoking Time::Moment->now is ~ 70% faster than invoking localtime(). 0.03 2013-11-28 - Renamed variable 'sun' to 'sunday' to prevent conflict on Solaris operating system which defines a macro named 'sun'. (leont++) 0.02 2013-11-25 - Implemented ->from_string() in C - Implemented ->now() in C if the system supports gettimeofday(2) - Added dev/sizeof.pl - Added Time::Piece to dev/bench.pl 0.01 2013-11-24 - Initial CPAN preview release. Time-Moment-0.44/dev/000755 000765 000024 00000000000 13274643625 015150 5ustar00chansenstaff000000 000000 Time-Moment-0.44/eg/000755 000765 000024 00000000000 13274643625 014765 5ustar00chansenstaff000000 000000 Time-Moment-0.44/inc/000755 000765 000024 00000000000 13274643625 015143 5ustar00chansenstaff000000 000000 Time-Moment-0.44/lib/000755 000765 000024 00000000000 13274643625 015140 5ustar00chansenstaff000000 000000 Time-Moment-0.44/Makefile.PL000644 000765 000024 00000002544 13072622406 016337 0ustar00chansenstaff000000 000000 use lib '.'; use strict; use warnings; BEGIN { unshift @INC, 'inc'; my @required = ( 'inc::Module::Install' => '1.00', 'Module::Install::XSUtil' => '0.36', 'Module::Install::ReadmeFromPod' => '0', ); my @missing; while(my($module, $version) = splice(@required, 0, 2)) { eval qq{use $module $version (); 1} or push @missing, $module; } if(@missing) { print qq{# The following modules are not available.\n}; print qq{# `perl $0 | cpanm` will install them:\n}; s/\A inc:: //x for @missing; print $_, "\n" for @missing; exit 1; } } use inc::Module::Install; name 'Time-Moment'; perl_version '5.008001'; all_from 'lib/Time/Moment.pm'; repository 'https://github.com/chansen/p5-time-moment'; bugtracker 'https://github.com/chansen/p5-time-moment/issues'; readme_from 'lib/Time/Moment.pod'; requires 'Carp' => '0'; requires 'XSLoader' => '0'; requires 'Time::HiRes' => '0'; test_requires 'Test::More' => '0.88'; test_requires 'Test::Fatal' => '0.006'; test_requires 'Test::Requires' => '0'; test_requires 'Test::Number::Delta' => '1.06'; cc_warnings; cc_include_paths 'src'; cc_src_paths '.'; ppport; requires_external_cc; WriteAll; Time-Moment-0.44/MANIFEST000644 000765 000024 00000003131 13274643622 015516 0ustar00chansenstaff000000 000000 .travis.yml Changes dev/bench.pl dev/sizeof.pl eg/age.pl eg/ago.pl eg/beat.pl eg/cal.pl eg/cbor.pl eg/clocks.pl eg/excel.pl eg/json.pl eg/se_bank_holidays.pl eg/sereal.pl eg/strftime.pl eg/us_federal_holidays.pl inc/Module/Install.pm inc/Module/Install/Base.pm inc/Module/Install/Can.pm inc/Module/Install/Compiler.pm inc/Module/Install/External.pm inc/Module/Install/Fetch.pm inc/Module/Install/Makefile.pm inc/Module/Install/Metadata.pm inc/Module/Install/ReadmeFromPod.pm inc/Module/Install/Win32.pm inc/Module/Install/WriteAll.pm inc/Module/Install/XSUtil.pm lib/Time/Moment.pm lib/Time/Moment.pod lib/Time/Moment/Adjusters.pm lib/Time/Moment/Adjusters.pod Makefile.PL MANIFEST This list of files MANIFEST.SKIP META.yml Moment.xs ppport.h README src/dt_accessor.c src/dt_accessor.h src/dt_arithmetic.c src/dt_arithmetic.h src/dt_config.h src/dt_core.c src/dt_core.h src/dt_easter.c src/dt_easter.h src/dt_length.c src/dt_length.h src/dt_parse_iso.c src/dt_parse_iso.h src/dt_util.c src/dt_util.h src/dt_valid.c src/dt_valid.h src/moment.c src/moment.h src/moment_fmt.c src/moment_fmt.h src/moment_parse.c src/moment_parse.h t/000_load.t t/100_basic.t t/110_now.t t/120_now_utc.t t/130_from_epoch.t t/140_from_object.t t/145_from_object_tp.t t/150_from_object_dt.t t/180_from_string.t t/190_rd.t t/191_jd.t t/192_mjd.t t/200_compare.t t/300_strftime.t t/400_with.t t/410_with_offset.t t/411_with_adjusters.t t/415_precision.t t/420_at.t t/430_length.t t/450_delta_time.t t/455_delta_date.t t/500_storable.t t/510_json.t t/520_cbor.t t/530_sereal.t t/600_coerce_dt.t t/610_coerce_tp.t t/900_bug_reuse.t t/Util.pm typemap Time-Moment-0.44/MANIFEST.SKIP000644 000765 000024 00000001467 12403511176 016264 0ustar00chansenstaff000000 000000 # Avoid version control files. \bRCS\b \bCVS\b \bSCCS\b ,v$ \B\.svn\b \B\.git\b \B\.gitignore\b \b_darcs\b \B\.cvsignore$ # Avoid VMS specific MakeMaker generated files \bDescrip.MMS$ \bDESCRIP.MMS$ \bdescrip.mms$ # Avoid Makemaker generated and utility files. \bMANIFEST\.bak \bMakefile$ \bblib/ \bMakeMaker-\d \bpm_to_blib\.ts$ \bpm_to_blib$ \bblibdirs\.ts$ # 6.18 through 6.25 generated this # Avoid Module::Build generated and utility files. \bBuild$ \b_build/ \bBuild.bat$ \bBuild.COM$ \bBUILD.COM$ \bbuild.com$ # Avoid temp and backup files. ~$ \.old$ \#$ \b\.# \.bak$ \.tmp$ \.# \.rej$ # Avoid OS-specific files/dirs # Mac OSX metadata \B\.DS_Store # Mac OSX SMB mount metadata files \B\._ # Avoid Devel::Cover and Devel::CoverX::Covered files. \bcover_db\b \bcovered\b # Avoid MYMETA files ^MYMETA\. Time-Moment-0.44/META.yml000644 000765 000024 00000001513 13274643622 015640 0ustar00chansenstaff000000 000000 --- abstract: 'Represents a date and time of day with an offset from UTC' author: - 'Christian Hansen C' build_requires: ExtUtils::MakeMaker: 6.59 Test::Fatal: '0.006' Test::More: '0.88' Test::Number::Delta: '1.06' Test::Requires: 0 configure_requires: ExtUtils::MakeMaker: 6.59 ExtUtils::ParseXS: 3.18 distribution_type: module dynamic_config: 1 generated_by: 'Module::Install version 1.16' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 name: Time-Moment no_index: directory: - inc - t requires: Carp: 0 Time::HiRes: 0 XSLoader: 0.02 perl: 5.8.1 resources: bugtracker: https://github.com/chansen/p5-time-moment/issues license: http://dev.perl.org/licenses/ repository: https://github.com/chansen/p5-time-moment version: '0.44' Time-Moment-0.44/Moment.xs000644 000765 000024 00000070164 13015663457 016213 0ustar00chansenstaff000000 000000 #define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "XSUB.h" #include "ppport.h" #include "moment.h" #include "moment_fmt.h" #include "moment_parse.h" typedef enum { MOMENT_PARAM_UNKNOWN=0, MOMENT_PARAM_YEAR, MOMENT_PARAM_MONTH, MOMENT_PARAM_DAY, MOMENT_PARAM_HOUR, MOMENT_PARAM_MINUTE, MOMENT_PARAM_SECOND, MOMENT_PARAM_NANOSECOND, MOMENT_PARAM_OFFSET, MOMENT_PARAM_LENIENT, MOMENT_PARAM_REDUCED, MOMENT_PARAM_EPOCH, MOMENT_PARAM_PRECISION, } moment_param_t; typedef int64_t I64V; #if IVSIZE >= 8 # define SvI64V(sv) (I64V)SvIV(sv) # define newSVi64v(i64) newSViv((IV)i64) # define XSRETURN_I64V(i64) XSRETURN_IV((IV)i64) #else # define SvI64V(sv) (I64V)SvNV(sv) # define newSVi64v(i64) newSVnv((NV)i64) # define XSRETURN_I64V(i64) XSRETURN_NV((NV)i64) #endif #ifndef STR_WITH_LEN #define STR_WITH_LEN(s) ("" s ""), (sizeof(s)-1) #endif #ifndef gv_stashpvs #define gv_stashpvs(s, flags) gv_stashpvn(STR_WITH_LEN(s), flags) #endif #ifndef XSRETURN_BOOL #define XSRETURN_BOOL(v) STMT_START { ST(0) = boolSV(v); XSRETURN(1); } STMT_END #endif #ifndef XSRETURN_SV #define XSRETURN_SV(sv) STMT_START { ST(0) = sv; XSRETURN(1); } STMT_END #endif #ifndef cBOOL #define cBOOL(cbool) ((cbool) ? (bool)1 : (bool)0) #endif #ifndef PERL_UNUSED_VAR # define PERL_UNUSED_VAR(x) ((void)x) #endif #define MY_CXT_KEY "Time::Moment::_guts" XS_VERSION typedef struct { HV *stash; } my_cxt_t; START_MY_CXT static void setup_my_cxt(pTHX_ pMY_CXT) { MY_CXT.stash = gv_stashpvs("Time::Moment", GV_ADD); } static moment_param_t moment_param(const char *s, const STRLEN len) { switch (len) { case 3: if (memEQ(s, "day", 3)) return MOMENT_PARAM_DAY; break; case 4: if (memEQ(s, "year", 4)) return MOMENT_PARAM_YEAR; if (memEQ(s, "hour", 4)) return MOMENT_PARAM_HOUR; break; case 5: if (memEQ(s, "month", 5)) return MOMENT_PARAM_MONTH; if (memEQ(s, "epoch", 5)) return MOMENT_PARAM_EPOCH; break; case 6: if (memEQ(s, "minute", 6)) return MOMENT_PARAM_MINUTE; if (memEQ(s, "second", 6)) return MOMENT_PARAM_SECOND; if (memEQ(s, "offset", 6)) return MOMENT_PARAM_OFFSET; break; case 7: if (memEQ(s, "lenient", 7)) return MOMENT_PARAM_LENIENT; if (memEQ(s, "reduced", 7)) return MOMENT_PARAM_REDUCED; break; case 9: if (memEQ(s, "precision", 9)) return MOMENT_PARAM_PRECISION; break; case 10: if (memEQ(s, "nanosecond", 10)) return MOMENT_PARAM_NANOSECOND; break; } return MOMENT_PARAM_UNKNOWN; } static moment_param_t THX_sv_moment_param(pTHX_ SV *sv) { const char *str; STRLEN len; str = SvPV_const(sv, len); return moment_param(str, len); } static SV * THX_sv_as_object(pTHX_ SV *sv, const char *name) { dSP; SV *rv; GV *method; int count; if (!SvROK(sv)) return NULL; rv = SvRV(sv); if (!SvOBJECT(rv) || !SvSTASH(rv)) return NULL; if (!(method = gv_fetchmethod(SvSTASH(rv), name))) return NULL; ENTER; SAVETMPS; PUSHMARK(SP); XPUSHs(sv); PUTBACK; count = call_sv((SV *)method, G_SCALAR); SPAGAIN; if (count != 1) croak("method call returned %d values, 1 expected", count); rv = newSVsv(POPs); PUTBACK; FREETMPS; LEAVE; return sv_2mortal(rv); } static SV * THX_sv_2neat(pTHX_ SV *sv) { if (sv_isobject(sv)) { SV * const rv = SvRV(sv); const char *name = sv_reftype(rv, 1); const char *type = sv_reftype(rv, 0); sv = sv_newmortal(); sv_setpvf(sv, "%s=%s(0x%p)", name, type, rv); } return sv; } static void THX_croak_cmp(pTHX_ SV *sv1, SV *sv2, const bool swap, const char *name) { if (swap) { SV * const tmp = sv1; sv1 = sv2; sv2 = tmp; } croak("A %s object can only be compared to another %s object ('%"SVf"', '%"SVf"')", name, name, THX_sv_2neat(aTHX_ sv1), THX_sv_2neat(aTHX_ sv2)); } static SV * THX_newSVmoment(pTHX_ const moment_t *m, HV *stash) { SV *pv = newSVpvn((const char *)m, sizeof(moment_t)); SV *sv = newRV_noinc(pv); sv_bless(sv, stash); return sv; } static SV * THX_sv_set_moment(pTHX_ SV *sv, const moment_t *m) { if (!SvROK(sv)) croak("panic: sv_set_moment called with nonreference"); sv_setpvn_mg(SvRV(sv), (const char *)m, sizeof(moment_t)); SvTEMP_off(sv); return sv; } static bool THX_sv_isa_stash(pTHX_ SV *sv, const char *klass, HV *stash, size_t size) { SV *rv; SvGETMAGIC(sv); if (!SvROK(sv)) return FALSE; rv = SvRV(sv); if (!(SvOBJECT(rv) && SvSTASH(rv) && SvPOKp(rv) && SvCUR(rv) == size)) return FALSE; return (SvSTASH(rv) == stash || sv_derived_from(sv, klass)); } static HV * THX_stash_constructor(pTHX_ SV *sv, const char *name, STRLEN namelen, HV *stash) { const char *pv; STRLEN len; SvGETMAGIC(sv); if (SvROK(sv)) { SV * const rv = SvRV(sv); if (SvOBJECT(rv) && SvSTASH(rv)) return SvSTASH(rv); } pv = SvPV_nomg_const(sv, len); if (len == namelen && memEQ(pv, name, namelen)) return stash; return gv_stashpvn(pv, len, GV_ADD); } static bool THX_sv_isa_moment(pTHX_ SV *sv) { dMY_CXT; return THX_sv_isa_stash(aTHX_ sv, "Time::Moment", MY_CXT.stash, sizeof(moment_t)); } static moment_t * THX_sv_2moment_ptr(pTHX_ SV *sv, const char *name) { if (!THX_sv_isa_moment(aTHX_ sv)) croak("%s is not an instance of Time::Moment", name); return (moment_t *)SvPVX_const(SvRV(sv)); } static moment_t THX_sv_2moment(pTHX_ SV *sv, const char *name) { return *THX_sv_2moment_ptr(aTHX_ sv, name); } static SV * THX_sv_2moment_coerce_sv(pTHX_ SV *sv) { SV *res; if (THX_sv_isa_moment(aTHX_ sv)) return sv; res = THX_sv_as_object(aTHX_ sv, "__as_Time_Moment"); if(!res || !THX_sv_isa_moment(aTHX_ res)) croak("Cannot coerce object of type %"SVf" to Time::Moment", THX_sv_2neat(aTHX_ sv)); return res; } #define dSTASH_CONSTRUCTOR(sv, name, dstash) \ HV * const stash = THX_stash_constructor(aTHX_ sv, STR_WITH_LEN(name), dstash) #define dSTASH_INVOCANT \ HV * const stash = SvSTASH(SvRV(ST(0))) #define dSTASH_CONSTRUCTOR_MOMENT(sv) \ dMY_CXT; \ dSTASH_CONSTRUCTOR(sv, "Time::Moment", MY_CXT.stash) #define newSVmoment(m, stash) \ THX_newSVmoment(aTHX_ m, stash) #define sv_set_moment(sv, m) \ THX_sv_set_moment(aTHX_ sv, m); #define sv_2moment_ptr(sv, name) \ THX_sv_2moment_ptr(aTHX_ sv, name) #define sv_2moment(sv, name) \ THX_sv_2moment(aTHX_ sv, name) #define sv_2moment_coerce_sv(sv) \ THX_sv_2moment_coerce_sv(aTHX_ sv) #define sv_isa_moment(sv) \ THX_sv_isa_moment(aTHX_ sv) #define croak_cmp(sv1, sv2, swap, name) \ THX_croak_cmp(aTHX_ sv1, sv2, swap, name) #define sv_moment_param(sv) \ THX_sv_moment_param(aTHX_ sv) #define sv_reusable(sv) \ (SvTEMP(sv) && SvREFCNT(sv) == 1 && SvROK(sv) && SvREFCNT(SvRV(sv)) == 1) XS(XS_Time_Moment_nil) { dVAR; dXSARGS; PERL_UNUSED_VAR(items); XSRETURN_EMPTY; } XS(XS_Time_Moment_stringify) { dVAR; dXSARGS; if (items < 1) croak("Wrong number of arguments to Time::Moment::(\"\""); ST(0) = moment_to_string(sv_2moment_ptr(ST(0), "self"), FALSE); XSRETURN(1); } XS(XS_Time_Moment_ncmp) { dVAR; dXSARGS; const moment_t *m1, *m2; bool swap; SV *svm1, *svm2; if (items < 3) croak("Wrong number of arguments to Time::Moment::(<=>"); svm1 = ST(0); svm2 = ST(1); swap = cBOOL(SvTRUE(ST(2))); if (!sv_isa_moment(svm2)) croak_cmp(svm1, svm2, swap, "Time::Moment"); m1 = sv_2moment_ptr(svm1, "self"); m2 = sv_2moment_ptr(svm2, "other"); if (swap) { const moment_t *tmp = m1; m1 = m2; m2 = tmp; } XSRETURN_IV(moment_compare_instant(m1, m2)); } #ifdef HAS_GETTIMEOFDAY static moment_t THX_moment_now(pTHX_ bool utc) { struct timeval tv; IV off, sec; gettimeofday(&tv, NULL); if (utc) off = 0; else { const time_t when = tv.tv_sec; struct tm *tm; #ifdef HAS_LOCALTIME_R struct tm tmbuf; #ifdef LOCALTIME_R_NEEDS_TZSET tzset(); #endif tm = localtime_r(&when, &tmbuf); #else tm = localtime(&when); #endif if (tm == NULL) croak("localtime() failed: %s", Strerror(errno)); sec = ((1461 * (tm->tm_year - 1) >> 2) + tm->tm_yday - 25202) * 86400 + tm->tm_hour * 3600 + tm->tm_min * 60 + tm->tm_sec; off = (sec - tv.tv_sec) / 60; } return moment_from_epoch(tv.tv_sec, tv.tv_usec * 1000, off); } #endif MODULE = Time::Moment PACKAGE = Time::Moment PROTOTYPES: DISABLE BOOT: { MY_CXT_INIT; setup_my_cxt(aTHX_ aMY_CXT); #if (PERL_REVISION == 5 && PERL_VERSION < 9) PL_amagic_generation++; #endif sv_setsv(get_sv("Time::Moment::()", GV_ADD), &PL_sv_yes); newXS("Time::Moment::()", XS_Time_Moment_nil, file); newXS("Time::Moment::(\"\"", XS_Time_Moment_stringify, file); newXS("Time::Moment::(<=>", XS_Time_Moment_ncmp, file); } #ifdef USE_ITHREADS void CLONE(...) CODE: { MY_CXT_CLONE; setup_my_cxt(aTHX_ aMY_CXT); PERL_UNUSED_VAR(items); } #endif moment_t new(klass, ...) SV *klass PREINIT: dSTASH_CONSTRUCTOR_MOMENT(klass); IV year = 1, month = 1, day = 1; IV hour = 0, minute = 0, second = 0, ns = 0, offset = 0; I32 i; CODE: if (((items - 1) % 2) != 0) croak("Odd number of elements in call to constructor when named parameters were expected"); for (i = 1; i < items; i += 2) { switch (sv_moment_param(ST(i))) { case MOMENT_PARAM_YEAR: year = SvIV(ST(i+1)); break; case MOMENT_PARAM_MONTH: month = SvIV(ST(i+1)); break; case MOMENT_PARAM_DAY: day = SvIV(ST(i+1)); break; case MOMENT_PARAM_HOUR: hour = SvIV(ST(i+1)); break; case MOMENT_PARAM_MINUTE: minute = SvIV(ST(i+1)); break; case MOMENT_PARAM_SECOND: second = SvIV(ST(i+1)); break; case MOMENT_PARAM_NANOSECOND: ns = SvIV(ST(i+1)); break; case MOMENT_PARAM_OFFSET: offset = SvIV(ST(i+1)); break; default: croak("Unrecognised parameter: '%"SVf"'", ST(i)); } } RETVAL = moment_new(year, month, day, hour, minute, second, ns, offset); OUTPUT: RETVAL #ifdef HAS_GETTIMEOFDAY moment_t now(klass) SV *klass ALIAS: Time::Moment::now = 0 Time::Moment::now_utc = 1 PREINIT: dSTASH_CONSTRUCTOR_MOMENT(klass); CODE: RETVAL = THX_moment_now(aTHX_ !!ix); OUTPUT: RETVAL #endif moment_t from_epoch(klass, seconds, ...) SV *klass SV *seconds PREINIT: dSTASH_CONSTRUCTOR_MOMENT(klass); IV precision = 6; CODE: if (items == 2) { if (SvIOK(seconds)) RETVAL = moment_from_epoch(SvI64V(seconds), 0, 0); else RETVAL = moment_from_epoch_nv(SvNV(seconds), precision); } else if (items == 3) { RETVAL = moment_from_epoch(SvI64V(seconds), SvIV(ST(2)), 0); } else { SV *nanosecond = NULL; I32 i; if ((items % 2) != 0) croak("Odd number of elements in named parameters"); for (i = 2; i < items; i += 2) { switch (sv_moment_param(ST(i))) { case MOMENT_PARAM_NANOSECOND: nanosecond = ST(i+1); break; case MOMENT_PARAM_PRECISION: precision = SvIV(ST(i+1)); break; default: croak("Unrecognised parameter: '%"SVf"'", ST(i)); } } if (nanosecond) RETVAL = moment_from_epoch(SvI64V(seconds), SvIV(nanosecond), 0); else { if (SvIOK(seconds)) RETVAL = moment_from_epoch(SvI64V(seconds), 0, 0); else RETVAL = moment_from_epoch_nv(SvNV(seconds), precision); } } OUTPUT: RETVAL moment_t from_string(klass, string, ...) SV *klass SV *string PREINIT: dSTASH_CONSTRUCTOR_MOMENT(klass); bool lenient; const char *str; STRLEN len; I32 i; CODE: if ((items % 2) != 0) croak("Odd number of elements in named parameters"); lenient = FALSE; for (i = 2; i < items; i += 2) { switch (sv_moment_param(ST(i))) { case MOMENT_PARAM_LENIENT: lenient = cBOOL(SvTRUE((ST(i+1)))); break; default: croak("Unrecognised parameter: '%"SVf"'", ST(i)); } } str = SvPV_const(string, len); RETVAL = moment_from_string(str, len, lenient); OUTPUT: RETVAL moment_t from_rd(klass, jd, ...) SV *klass NV jd PREINIT: dSTASH_CONSTRUCTOR_MOMENT(klass); NV epoch = 0; IV precision = 3; IV offset = 0; I32 i; ALIAS: Time::Moment::from_rd = 0 Time::Moment::from_jd = 1 Time::Moment::from_mjd = 2 CODE: if ((items % 2) != 0) croak("Odd number of elements in named parameters"); switch (ix) { case 1: epoch = -1721424.5; break; case 2: epoch = 678576; break; } for (i = 2; i < items; i += 2) { switch (sv_moment_param(ST(i))) { case MOMENT_PARAM_PRECISION: precision = SvIV(ST(i+1)); break; case MOMENT_PARAM_EPOCH: epoch = SvNV(ST(i+1)); break; case MOMENT_PARAM_OFFSET: if (ix == 0) { offset = SvIV(ST(i+1)); break; } /* FALLTROUGH */ default: croak("Unrecognised parameter: '%"SVf"'", ST(i)); } } if (ix == 0) RETVAL = moment_from_rd(jd, epoch, precision, offset); else if (ix == 1) RETVAL = moment_from_jd(jd, epoch, precision); else RETVAL = moment_from_mjd(jd, epoch, precision); OUTPUT: RETVAL void from_object(klass, object) SV *klass SV *object PREINIT: dSTASH_CONSTRUCTOR_MOMENT(klass); CODE: /* PERL_UNUSED_VAR() fails on certain compilers because HV * const stash */ if (0) { HV * dummy = stash; PERL_UNUSED_VAR(dummy); } XSRETURN_SV(sv_2moment_coerce_sv(object)); moment_t at_utc(self) const moment_t *self PREINIT: dSTASH_INVOCANT; ALIAS: Time::Moment::at_utc = 0 Time::Moment::at_midnight = 1 Time::Moment::at_noon = 2 Time::Moment::at_last_day_of_year = 3 Time::Moment::at_last_day_of_quarter = 4 Time::Moment::at_last_day_of_month = 5 CODE: switch (ix) { case 0: RETVAL = moment_at_utc(self); break; case 1: RETVAL = moment_at_midnight(self); break; case 2: RETVAL = moment_at_noon(self); break; case 3: RETVAL = moment_at_last_day_of_year(self); break; case 4: RETVAL = moment_at_last_day_of_quarter(self); break; case 5: RETVAL = moment_at_last_day_of_month(self); break; } if (moment_equals(self, &RETVAL)) XSRETURN(1); if (sv_reusable(ST(0))) { sv_set_moment(ST(0), &RETVAL); XSRETURN(1); } OUTPUT: RETVAL moment_t plus_seconds(self, value) const moment_t *self I64V value PREINIT: dSTASH_INVOCANT; ALIAS: Time::Moment::plus_years = MOMENT_UNIT_YEARS Time::Moment::plus_months = MOMENT_UNIT_MONTHS Time::Moment::plus_weeks = MOMENT_UNIT_WEEKS Time::Moment::plus_days = MOMENT_UNIT_DAYS Time::Moment::plus_hours = MOMENT_UNIT_HOURS Time::Moment::plus_minutes = MOMENT_UNIT_MINUTES Time::Moment::plus_seconds = MOMENT_UNIT_SECONDS Time::Moment::plus_milliseconds = MOMENT_UNIT_MILLIS Time::Moment::plus_microseconds = MOMENT_UNIT_MICROS Time::Moment::plus_nanoseconds = MOMENT_UNIT_NANOS CODE: if (value == 0) XSRETURN(1); RETVAL = moment_plus_unit(self, (moment_unit_t)ix, value); if (sv_reusable(ST(0))) { sv_set_moment(ST(0), &RETVAL); XSRETURN(1); } OUTPUT: RETVAL moment_t minus_seconds(self, value) const moment_t *self I64V value PREINIT: dSTASH_INVOCANT; ALIAS: Time::Moment::minus_years = MOMENT_UNIT_YEARS Time::Moment::minus_months = MOMENT_UNIT_MONTHS Time::Moment::minus_weeks = MOMENT_UNIT_WEEKS Time::Moment::minus_days = MOMENT_UNIT_DAYS Time::Moment::minus_hours = MOMENT_UNIT_HOURS Time::Moment::minus_minutes = MOMENT_UNIT_MINUTES Time::Moment::minus_seconds = MOMENT_UNIT_SECONDS Time::Moment::minus_milliseconds = MOMENT_UNIT_MILLIS Time::Moment::minus_microseconds = MOMENT_UNIT_MICROS Time::Moment::minus_nanoseconds = MOMENT_UNIT_NANOS CODE: if (value == 0) XSRETURN(1); RETVAL = moment_minus_unit(self, (moment_unit_t)ix, value); if (sv_reusable(ST(0))) { sv_set_moment(ST(0), &RETVAL); XSRETURN(1); } OUTPUT: RETVAL void delta_years(self, other) const moment_t *self const moment_t *other PREINIT: int64_t delta; ALIAS: Time::Moment::delta_years = MOMENT_UNIT_YEARS Time::Moment::delta_months = MOMENT_UNIT_MONTHS Time::Moment::delta_weeks = MOMENT_UNIT_WEEKS Time::Moment::delta_days = MOMENT_UNIT_DAYS Time::Moment::delta_hours = MOMENT_UNIT_HOURS Time::Moment::delta_minutes = MOMENT_UNIT_MINUTES Time::Moment::delta_seconds = MOMENT_UNIT_SECONDS Time::Moment::delta_milliseconds = MOMENT_UNIT_MILLIS Time::Moment::delta_microseconds = MOMENT_UNIT_MICROS Time::Moment::delta_nanoseconds = MOMENT_UNIT_NANOS PPCODE: delta = moment_delta_unit(self, other, (moment_unit_t)ix); XSRETURN_I64V(delta); void with(self, adjuster) const moment_t *self SV *adjuster PREINIT: I32 count; PERL_UNUSED_VAR(self); PPCODE: SvGETMAGIC(adjuster); if (SvROK(adjuster)) adjuster = SvRV(adjuster); if (SvTYPE(adjuster) != SVt_PVCV || SvOBJECT(adjuster)) croak("Parameter: 'adjuster' is not a CODE reference"); PUSHMARK(SP); SP += 1; PUTBACK; count = call_sv(adjuster, G_SCALAR); if (count != 1) croak("Expected one return value from adjuster, got %d elements", count); if (!sv_isa_moment(ST(0))) croak("Expected an instance of Time::Moment from adjuster, got '%"SVf"'", THX_sv_2neat(aTHX_ ST(0))); SPAGAIN; moment_t with_year(self, value) const moment_t *self I64V value PREINIT: dSTASH_INVOCANT; ALIAS: Time::Moment::with_year = MOMENT_FIELD_YEAR Time::Moment::with_quarter = MOMENT_FIELD_QUARTER_OF_YEAR Time::Moment::with_month = MOMENT_FIELD_MONTH_OF_YEAR Time::Moment::with_week = MOMENT_FIELD_WEEK_OF_YEAR Time::Moment::with_day_of_year = MOMENT_FIELD_DAY_OF_YEAR Time::Moment::with_day_of_quarter = MOMENT_FIELD_DAY_OF_QUARTER Time::Moment::with_day_of_month = MOMENT_FIELD_DAY_OF_MONTH Time::Moment::with_day_of_week = MOMENT_FIELD_DAY_OF_WEEK Time::Moment::with_hour = MOMENT_FIELD_HOUR_OF_DAY Time::Moment::with_minute = MOMENT_FIELD_MINUTE_OF_HOUR Time::Moment::with_minute_of_day = MOMENT_FIELD_MINUTE_OF_DAY Time::Moment::with_second = MOMENT_FIELD_SECOND_OF_MINUTE Time::Moment::with_second_of_day = MOMENT_FIELD_SECOND_OF_DAY Time::Moment::with_millisecond = MOMENT_FIELD_MILLI_OF_SECOND Time::Moment::with_millisecond_of_day = MOMENT_FIELD_MILLI_OF_DAY Time::Moment::with_microsecond = MOMENT_FIELD_MICRO_OF_SECOND Time::Moment::with_microsecond_of_day = MOMENT_FIELD_MICRO_OF_DAY Time::Moment::with_nanosecond = MOMENT_FIELD_NANO_OF_SECOND Time::Moment::with_nanosecond_of_day = MOMENT_FIELD_NANO_OF_DAY Time::Moment::with_precision = MOMENT_FIELD_PRECISION Time::Moment::with_rdn = MOMENT_FIELD_RATA_DIE_DAY CODE: RETVAL = moment_with_field(self, (moment_component_t)ix, value); if (moment_equals(self, &RETVAL)) XSRETURN(1); if (sv_reusable(ST(0))) { sv_set_moment(ST(0), &RETVAL); XSRETURN(1); } OUTPUT: RETVAL moment_t with_offset_same_instant(self, offset) const moment_t *self IV offset PREINIT: dSTASH_INVOCANT; ALIAS: Time::Moment::with_offset_same_instant = 0 Time::Moment::with_offset_same_local = 1 CODE: if (ix == 0) RETVAL = moment_with_offset_same_instant(self, offset); else RETVAL = moment_with_offset_same_local(self, offset); if (moment_equals(self, &RETVAL)) XSRETURN(1); if (sv_reusable(ST(0))) { sv_set_moment(ST(0), &RETVAL); XSRETURN(1); } OUTPUT: RETVAL void year(self) const moment_t *self ALIAS: Time::Moment::year = 0 Time::Moment::quarter = 1 Time::Moment::month = 2 Time::Moment::week = 3 Time::Moment::day_of_year = 4 Time::Moment::day_of_quarter = 5 Time::Moment::day_of_month = 6 Time::Moment::day_of_week = 7 Time::Moment::hour = 8 Time::Moment::minute = 9 Time::Moment::minute_of_day = 10 Time::Moment::second = 11 Time::Moment::second_of_day = 12 Time::Moment::millisecond = 13 Time::Moment::millisecond_of_day = 14 Time::Moment::microsecond = 15 Time::Moment::nanosecond = 16 Time::Moment::offset = 17 Time::Moment::precision = 18 Time::Moment::rdn = 19 PREINIT: IV v = 0; PPCODE: switch (ix) { case 0: v = moment_year(self); break; case 1: v = moment_quarter(self); break; case 2: v = moment_month(self); break; case 3: v = moment_week(self); break; case 4: v = moment_day_of_year(self); break; case 5: v = moment_day_of_quarter(self); break; case 6: v = moment_day_of_month(self); break; case 7: v = moment_day_of_week(self); break; case 8: v = moment_hour(self); break; case 9: v = moment_minute(self); break; case 10: v = moment_minute_of_day(self); break; case 11: v = moment_second(self); break; case 12: v = moment_second_of_day(self); break; case 13: v = moment_millisecond(self); break; case 14: v = moment_millisecond_of_day(self); break; case 15: v = moment_microsecond(self); break; case 16: v = moment_nanosecond(self); break; case 17: v = moment_offset(self); break; case 18: v = moment_precision(self); break; case 19: v = moment_rata_die_day(self); break; } XSRETURN_IV(v); void epoch(self) const moment_t *self ALIAS: Time::Moment::epoch = 0 Time::Moment::utc_rd_as_seconds = 1 Time::Moment::local_rd_as_seconds = 2 Time::Moment::microsecond_of_day = 3 Time::Moment::nanosecond_of_day = 4 PREINIT: int64_t v = 0; PPCODE: switch (ix) { case 0: v = moment_epoch(self); break; case 1: v = moment_instant_rd_seconds(self); break; case 2: v = moment_local_rd_seconds(self); break; case 3: v = moment_microsecond_of_day(self); break; case 4: v = moment_nanosecond_of_day(self); break; } XSRETURN_I64V(v); void jd(self, ...) const moment_t *self ALIAS: Time::Moment::jd = 0 Time::Moment::mjd = 1 Time::Moment::rd = 2 PREINIT: NV v = 0; IV precision = 3; moment_t adjusted; I32 i; PPCODE: if (((items - 1) % 2) != 0) croak("Odd number of elements in named parameters"); for (i = 1; i < items; i += 2) { switch (sv_moment_param(ST(i))) { case MOMENT_PARAM_PRECISION: precision = SvIV(ST(i+1)); break; default: croak("Unrecognised parameter: '%"SVf"'", ST(i)); } } adjusted = moment_with_precision(self, precision); switch (ix) { case 0: v = moment_jd(&adjusted); break; case 1: v = moment_mjd(&adjusted); break; case 2: v = moment_rd(&adjusted); break; } XSRETURN_NV(v); void length_of_year(self) const moment_t *self ALIAS: Time::Moment::length_of_year = 0 Time::Moment::length_of_quarter = 1 Time::Moment::length_of_month = 2 Time::Moment::length_of_week_year = 3 PREINIT: IV v = 0; PPCODE: switch (ix) { case 0: v = moment_length_of_year(self); break; case 1: v = moment_length_of_quarter(self); break; case 2: v = moment_length_of_month(self); break; case 3: v = moment_length_of_week_year(self); break; } XSRETURN_IV(v); void utc_rd_values(self) const moment_t *self ALIAS: Time::Moment::utc_rd_values = 0 Time::Moment::local_rd_values = 1 PREINIT: IV rdn, sod, nos; PPCODE: if (ix == 0) moment_to_instant_rd_values(self, &rdn, &sod, &nos); else moment_to_local_rd_values(self, &rdn, &sod, &nos); EXTEND(SP, 3); mPUSHi(rdn); mPUSHi(sod); mPUSHi(nos); XSRETURN(3); void compare(self, other, ...) const moment_t *self const moment_t *other PREINIT: IV precision = 9; I32 i; IV r; PPCODE: if ((items % 2) != 0) croak("Odd number of elements in named parameters"); for (i = 2; i < items; i += 2) { switch (sv_moment_param(ST(i))) { case MOMENT_PARAM_PRECISION: precision = SvIV(ST(i+1)); break; default: croak("Unrecognised parameter: '%"SVf"'", ST(i)); } } if (precision == 9) r = moment_compare_instant(self, other); else r = moment_compare_precision(self, other, precision); XSRETURN_IV(r); void is_equal(self, other) const moment_t *self const moment_t *other ALIAS: Time::Moment::is_equal = 0 Time::Moment::is_before = 1 Time::Moment::is_after = 2 PREINIT: bool v = FALSE; PPCODE: switch (ix) { case 0: v = moment_compare_instant(self, other) == 0; break; case 1: v = moment_compare_instant(self, other) < 0; break; case 2: v = moment_compare_instant(self, other) > 0; break; } XSRETURN_BOOL(v); void is_leap_year(self) const moment_t *self PPCODE: XSRETURN_BOOL(moment_is_leap_year(self)); void strftime(self, format) const moment_t *self SV *format PREINIT: STRLEN len; const char *str; SV *ret; PPCODE: str = SvPV_const(format, len); ret = moment_strftime(self, str, len); if (SvUTF8(format)) SvUTF8_on(ret); XSRETURN_SV(ret); void to_string(self, ...) const moment_t *self PREINIT: bool reduced; I32 i; PPCODE: if (((items - 1) % 2) != 0) croak("Odd number of elements in named parameters"); reduced = FALSE; for (i = 1; i < items; i += 2) { switch (sv_moment_param(ST(i))) { case MOMENT_PARAM_REDUCED: reduced = cBOOL(SvTRUE((ST(i+1)))); break; default: croak("Unrecognised parameter: '%"SVf"'", ST(i)); } } XSRETURN_SV(moment_to_string(self, reduced)); MODULE = Time::Moment PACKAGE = Time::Moment::Internal PROTOTYPES: DISABLE void western_easter_sunday(year) IV year PPCODE: XSRETURN_IV(moment_internal_western_easter(year)); void orthodox_easter_sunday(year) IV year PPCODE: XSRETURN_IV(moment_internal_orthodox_easter(year)); Time-Moment-0.44/ppport.h000644 000765 000024 00000575616 13274643622 016110 0ustar00chansenstaff000000 000000 #if 0 <<'SKIP'; #endif /* ---------------------------------------------------------------------- ppport.h -- Perl/Pollution/Portability Version 3.32 Automatically created by Devel::PPPort running under perl 5.014004. Do NOT edit this file directly! -- Edit PPPort_pm.PL and the includes in parts/inc/ instead. Use 'perldoc ppport.h' to view the documentation below. ---------------------------------------------------------------------- SKIP =pod =head1 NAME ppport.h - Perl/Pollution/Portability version 3.32 =head1 SYNOPSIS perl ppport.h [options] [source files] Searches current directory for files if no [source files] are given --help show short help --version show version --patch=file write one patch file with changes --copy=suffix write changed copies with suffix --diff=program use diff program and options --compat-version=version provide compatibility with Perl version --cplusplus accept C++ comments --quiet don't output anything except fatal errors --nodiag don't show diagnostics --nohints don't show hints --nochanges don't suggest changes --nofilter don't filter input files --strip strip all script and doc functionality from ppport.h --list-provided list provided API --list-unsupported list unsupported API --api-info=name show Perl API portability information =head1 COMPATIBILITY This version of F is designed to support operation with Perl installations back to 5.003, and has been tested up to 5.20. =head1 OPTIONS =head2 --help Display a brief usage summary. =head2 --version Display the version of F. =head2 --patch=I If this option is given, a single patch file will be created if any changes are suggested. This requires a working diff program to be installed on your system. =head2 --copy=I If this option is given, a copy of each file will be saved with the given suffix that contains the suggested changes. This does not require any external programs. Note that this does not automagically add a dot between the original filename and the suffix. If you want the dot, you have to include it in the option argument. If neither C<--patch> or C<--copy> are given, the default is to simply print the diffs for each file. This requires either C or a C program to be installed. =head2 --diff=I Manually set the diff program and options to use. The default is to use C, when installed, and output unified context diffs. =head2 --compat-version=I Tell F to check for compatibility with the given Perl version. The default is to check for compatibility with Perl version 5.003. You can use this option to reduce the output of F if you intend to be backward compatible only down to a certain Perl version. =head2 --cplusplus Usually, F will detect C++ style comments and replace them with C style comments for portability reasons. Using this option instructs F to leave C++ comments untouched. =head2 --quiet Be quiet. Don't print anything except fatal errors. =head2 --nodiag Don't output any diagnostic messages. Only portability alerts will be printed. =head2 --nohints Don't output any hints. Hints often contain useful portability notes. Warnings will still be displayed. =head2 --nochanges Don't suggest any changes. Only give diagnostic output and hints unless these are also deactivated. =head2 --nofilter Don't filter the list of input files. By default, files not looking like source code (i.e. not *.xs, *.c, *.cc, *.cpp or *.h) are skipped. =head2 --strip Strip all script and documentation functionality from F. This reduces the size of F dramatically and may be useful if you want to include F in smaller modules without increasing their distribution size too much. The stripped F will have a C<--unstrip> option that allows you to undo the stripping, but only if an appropriate C module is installed. =head2 --list-provided Lists the API elements for which compatibility is provided by F. Also lists if it must be explicitly requested, if it has dependencies, and if there are hints or warnings for it. =head2 --list-unsupported Lists the API elements that are known not to be supported by F and below which version of Perl they probably won't be available or work. =head2 --api-info=I Show portability information for API elements matching I. If I is surrounded by slashes, it is interpreted as a regular expression. =head1 DESCRIPTION In order for a Perl extension (XS) module to be as portable as possible across differing versions of Perl itself, certain steps need to be taken. =over 4 =item * Including this header is the first major one. This alone will give you access to a large part of the Perl API that hasn't been available in earlier Perl releases. Use perl ppport.h --list-provided to see which API elements are provided by ppport.h. =item * You should avoid using deprecated parts of the API. For example, using global Perl variables without the C prefix is deprecated. Also, some API functions used to have a C prefix. Using this form is also deprecated. You can safely use the supported API, as F will provide wrappers for older Perl versions. =item * If you use one of a few functions or variables that were not present in earlier versions of Perl, and that can't be provided using a macro, you have to explicitly request support for these functions by adding one or more C<#define>s in your source code before the inclusion of F. These functions or variables will be marked C in the list shown by C<--list-provided>. Depending on whether you module has a single or multiple files that use such functions or variables, you want either C or global variants. For a C function or variable (used only in a single source file), use: #define NEED_function #define NEED_variable For a global function or variable (used in multiple source files), use: #define NEED_function_GLOBAL #define NEED_variable_GLOBAL Note that you mustn't have more than one global request for the same function or variable in your project. Function / Variable Static Request Global Request ----------------------------------------------------------------------------------------- PL_parser NEED_PL_parser NEED_PL_parser_GLOBAL PL_signals NEED_PL_signals NEED_PL_signals_GLOBAL caller_cx() NEED_caller_cx NEED_caller_cx_GLOBAL eval_pv() NEED_eval_pv NEED_eval_pv_GLOBAL grok_bin() NEED_grok_bin NEED_grok_bin_GLOBAL grok_hex() NEED_grok_hex NEED_grok_hex_GLOBAL grok_number() NEED_grok_number NEED_grok_number_GLOBAL grok_numeric_radix() NEED_grok_numeric_radix NEED_grok_numeric_radix_GLOBAL grok_oct() NEED_grok_oct NEED_grok_oct_GLOBAL load_module() NEED_load_module NEED_load_module_GLOBAL mg_findext() NEED_mg_findext NEED_mg_findext_GLOBAL my_snprintf() NEED_my_snprintf NEED_my_snprintf_GLOBAL my_sprintf() NEED_my_sprintf NEED_my_sprintf_GLOBAL my_strlcat() NEED_my_strlcat NEED_my_strlcat_GLOBAL my_strlcpy() NEED_my_strlcpy NEED_my_strlcpy_GLOBAL newCONSTSUB() NEED_newCONSTSUB NEED_newCONSTSUB_GLOBAL newRV_noinc() NEED_newRV_noinc NEED_newRV_noinc_GLOBAL newSV_type() NEED_newSV_type NEED_newSV_type_GLOBAL newSVpvn_flags() NEED_newSVpvn_flags NEED_newSVpvn_flags_GLOBAL newSVpvn_share() NEED_newSVpvn_share NEED_newSVpvn_share_GLOBAL pv_display() NEED_pv_display NEED_pv_display_GLOBAL pv_escape() NEED_pv_escape NEED_pv_escape_GLOBAL pv_pretty() NEED_pv_pretty NEED_pv_pretty_GLOBAL sv_2pv_flags() NEED_sv_2pv_flags NEED_sv_2pv_flags_GLOBAL sv_2pvbyte() NEED_sv_2pvbyte NEED_sv_2pvbyte_GLOBAL sv_catpvf_mg() NEED_sv_catpvf_mg NEED_sv_catpvf_mg_GLOBAL sv_catpvf_mg_nocontext() NEED_sv_catpvf_mg_nocontext NEED_sv_catpvf_mg_nocontext_GLOBAL sv_pvn_force_flags() NEED_sv_pvn_force_flags NEED_sv_pvn_force_flags_GLOBAL sv_setpvf_mg() NEED_sv_setpvf_mg NEED_sv_setpvf_mg_GLOBAL sv_setpvf_mg_nocontext() NEED_sv_setpvf_mg_nocontext NEED_sv_setpvf_mg_nocontext_GLOBAL sv_unmagicext() NEED_sv_unmagicext NEED_sv_unmagicext_GLOBAL vload_module() NEED_vload_module NEED_vload_module_GLOBAL vnewSVpvf() NEED_vnewSVpvf NEED_vnewSVpvf_GLOBAL warner() NEED_warner NEED_warner_GLOBAL To avoid namespace conflicts, you can change the namespace of the explicitly exported functions / variables using the C macro. Just C<#define> the macro before including C: #define DPPP_NAMESPACE MyOwnNamespace_ #include "ppport.h" The default namespace is C. =back The good thing is that most of the above can be checked by running F on your source code. See the next section for details. =head1 EXAMPLES To verify whether F is needed for your module, whether you should make any changes to your code, and whether any special defines should be used, F can be run as a Perl script to check your source code. Simply say: perl ppport.h The result will usually be a list of patches suggesting changes that should at least be acceptable, if not necessarily the most efficient solution, or a fix for all possible problems. If you know that your XS module uses features only available in newer Perl releases, if you're aware that it uses C++ comments, and if you want all suggestions as a single patch file, you could use something like this: perl ppport.h --compat-version=5.6.0 --cplusplus --patch=test.diff If you only want your code to be scanned without any suggestions for changes, use: perl ppport.h --nochanges You can specify a different C program or options, using the C<--diff> option: perl ppport.h --diff='diff -C 10' This would output context diffs with 10 lines of context. If you want to create patched copies of your files instead, use: perl ppport.h --copy=.new To display portability information for the C function, use: perl ppport.h --api-info=newSVpvn Since the argument to C<--api-info> can be a regular expression, you can use perl ppport.h --api-info=/_nomg$/ to display portability information for all C<_nomg> functions or perl ppport.h --api-info=/./ to display information for all known API elements. =head1 BUGS If this version of F is causing failure during the compilation of this module, please check if newer versions of either this module or C are available on CPAN before sending a bug report. If F was generated using the latest version of C and is causing failure of this module, please file a bug report here: L Please include the following information: =over 4 =item 1. The complete output from running "perl -V" =item 2. This file. =item 3. The name and version of the module you were trying to build. =item 4. A full log of the build that failed. =item 5. Any other information that you think could be relevant. =back For the latest version of this code, please get the C module from CPAN. =head1 COPYRIGHT Version 3.x, Copyright (c) 2004-2013, Marcus Holland-Moritz. Version 2.x, Copyright (C) 2001, Paul Marquess. Version 1.x, Copyright (C) 1999, Kenneth Albanowski. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =head1 SEE ALSO See L. =cut use strict; # Disable broken TRIE-optimization BEGIN { eval '${^RE_TRIE_MAXBUF} = -1' if $] >= 5.009004 && $] <= 5.009005 } my $VERSION = 3.32; my %opt = ( quiet => 0, diag => 1, hints => 1, changes => 1, cplusplus => 0, filter => 1, strip => 0, version => 0, ); my($ppport) = $0 =~ /([\w.]+)$/; my $LF = '(?:\r\n|[\r\n])'; # line feed my $HS = "[ \t]"; # horizontal whitespace # Never use C comments in this file! my $ccs = '/'.'*'; my $cce = '*'.'/'; my $rccs = quotemeta $ccs; my $rcce = quotemeta $cce; eval { require Getopt::Long; Getopt::Long::GetOptions(\%opt, qw( help quiet diag! filter! hints! changes! cplusplus strip version patch=s copy=s diff=s compat-version=s list-provided list-unsupported api-info=s )) or usage(); }; if ($@ and grep /^-/, @ARGV) { usage() if "@ARGV" =~ /^--?h(?:elp)?$/; die "Getopt::Long not found. Please don't use any options.\n"; } if ($opt{version}) { print "This is $0 $VERSION.\n"; exit 0; } usage() if $opt{help}; strip() if $opt{strip}; if (exists $opt{'compat-version'}) { my($r,$v,$s) = eval { parse_version($opt{'compat-version'}) }; if ($@) { die "Invalid version number format: '$opt{'compat-version'}'\n"; } die "Only Perl 5 is supported\n" if $r != 5; die "Invalid version number: $opt{'compat-version'}\n" if $v >= 1000 || $s >= 1000; $opt{'compat-version'} = sprintf "%d.%03d%03d", $r, $v, $s; } else { $opt{'compat-version'} = 5; } my %API = map { /^(\w+)\|([^|]*)\|([^|]*)\|(\w*)$/ ? ( $1 => { ($2 ? ( base => $2 ) : ()), ($3 ? ( todo => $3 ) : ()), (index($4, 'v') >= 0 ? ( varargs => 1 ) : ()), (index($4, 'p') >= 0 ? ( provided => 1 ) : ()), (index($4, 'n') >= 0 ? ( nothxarg => 1 ) : ()), } ) : die "invalid spec: $_" } qw( ASCII_TO_NEED||5.007001|n AvFILLp|5.004050||p AvFILL||| BhkDISABLE||5.021008| BhkENABLE||5.021008| BhkENTRY_set||5.021008| BhkENTRY||| BhkFLAGS||| CALL_BLOCK_HOOKS||| CLASS|||n CPERLscope|5.005000||p CX_CURPAD_SAVE||| CX_CURPAD_SV||| CopFILEAV|5.006000||p CopFILEGV_set|5.006000||p CopFILEGV|5.006000||p CopFILESV|5.006000||p CopFILE_set|5.006000||p CopFILE|5.006000||p CopSTASHPV_set|5.006000||p CopSTASHPV|5.006000||p CopSTASH_eq|5.006000||p CopSTASH_set|5.006000||p CopSTASH|5.006000||p CopyD|5.009002|5.004050|p Copy||| CvPADLIST||5.008001| CvSTASH||| CvWEAKOUTSIDE||| DEFSV_set|5.010001||p DEFSV|5.004050||p END_EXTERN_C|5.005000||p ENTER||| ERRSV|5.004050||p EXTEND||| EXTERN_C|5.005000||p F0convert|||n FREETMPS||| GIMME_V||5.004000|n GIMME|||n GROK_NUMERIC_RADIX|5.007002||p G_ARRAY||| G_DISCARD||| G_EVAL||| G_METHOD|5.006001||p G_NOARGS||| G_SCALAR||| G_VOID||5.004000| GetVars||| GvAV||| GvCV||| GvHV||| GvSVn|5.009003||p GvSV||| Gv_AMupdate||5.011000| HEf_SVKEY|5.003070||p HeHASH||5.003070| HeKEY||5.003070| HeKLEN||5.003070| HePV||5.004000| HeSVKEY_force||5.003070| HeSVKEY_set||5.004000| HeSVKEY||5.003070| HeUTF8|5.010001|5.008000|p HeVAL||5.003070| HvENAMELEN||5.015004| HvENAMEUTF8||5.015004| HvENAME||5.013007| HvNAMELEN_get|5.009003||p HvNAMELEN||5.015004| HvNAMEUTF8||5.015004| HvNAME_get|5.009003||p HvNAME||| INT2PTR|5.006000||p IN_LOCALE_COMPILETIME|5.007002||p IN_LOCALE_RUNTIME|5.007002||p IN_LOCALE|5.007002||p IN_PERL_COMPILETIME|5.008001||p IS_NUMBER_GREATER_THAN_UV_MAX|5.007002||p IS_NUMBER_INFINITY|5.007002||p IS_NUMBER_IN_UV|5.007002||p IS_NUMBER_NAN|5.007003||p IS_NUMBER_NEG|5.007002||p IS_NUMBER_NOT_INT|5.007002||p IVSIZE|5.006000||p IVTYPE|5.006000||p IVdf|5.006000||p LEAVE||| LINKLIST||5.013006| LVRET||| MARK||| MULTICALL||5.021008| MUTABLE_PTR|5.010001||p MUTABLE_SV|5.010001||p MY_CXT_CLONE|5.009002||p MY_CXT_INIT|5.007003||p MY_CXT|5.007003||p MoveD|5.009002|5.004050|p Move||| NATIVE_TO_NEED||5.007001|n NOOP|5.005000||p NUM2PTR|5.006000||p NVTYPE|5.006000||p NVef|5.006001||p NVff|5.006001||p NVgf|5.006001||p Newxc|5.009003||p Newxz|5.009003||p Newx|5.009003||p Nullav||| Nullch||| Nullcv||| Nullhv||| Nullsv||| OP_CLASS||5.013007| OP_DESC||5.007003| OP_NAME||5.007003| OP_TYPE_IS_OR_WAS||5.019010| OP_TYPE_IS||5.019007| ORIGMARK||| OpHAS_SIBLING||5.021007| OpSIBLING_set||5.021007| OpSIBLING||5.021007| PAD_BASE_SV||| PAD_CLONE_VARS||| PAD_COMPNAME_FLAGS||| PAD_COMPNAME_GEN_set||| PAD_COMPNAME_GEN||| PAD_COMPNAME_OURSTASH||| PAD_COMPNAME_PV||| PAD_COMPNAME_TYPE||| PAD_RESTORE_LOCAL||| PAD_SAVE_LOCAL||| PAD_SAVE_SETNULLPAD||| PAD_SETSV||| PAD_SET_CUR_NOSAVE||| PAD_SET_CUR||| PAD_SVl||| PAD_SV||| PERLIO_FUNCS_CAST|5.009003||p PERLIO_FUNCS_DECL|5.009003||p PERL_ABS|5.008001||p PERL_BCDVERSION|5.021008||p PERL_GCC_BRACE_GROUPS_FORBIDDEN|5.008001||p PERL_HASH|5.003070||p PERL_INT_MAX|5.003070||p PERL_INT_MIN|5.003070||p PERL_LONG_MAX|5.003070||p PERL_LONG_MIN|5.003070||p PERL_MAGIC_arylen|5.007002||p PERL_MAGIC_backref|5.007002||p PERL_MAGIC_bm|5.007002||p PERL_MAGIC_collxfrm|5.007002||p PERL_MAGIC_dbfile|5.007002||p PERL_MAGIC_dbline|5.007002||p PERL_MAGIC_defelem|5.007002||p PERL_MAGIC_envelem|5.007002||p PERL_MAGIC_env|5.007002||p PERL_MAGIC_ext|5.007002||p PERL_MAGIC_fm|5.007002||p PERL_MAGIC_glob|5.021008||p PERL_MAGIC_isaelem|5.007002||p PERL_MAGIC_isa|5.007002||p PERL_MAGIC_mutex|5.021008||p PERL_MAGIC_nkeys|5.007002||p PERL_MAGIC_overload_elem|5.021008||p PERL_MAGIC_overload_table|5.007002||p PERL_MAGIC_overload|5.021008||p PERL_MAGIC_pos|5.007002||p PERL_MAGIC_qr|5.007002||p PERL_MAGIC_regdata|5.007002||p PERL_MAGIC_regdatum|5.007002||p PERL_MAGIC_regex_global|5.007002||p PERL_MAGIC_shared_scalar|5.007003||p PERL_MAGIC_shared|5.007003||p PERL_MAGIC_sigelem|5.007002||p PERL_MAGIC_sig|5.007002||p PERL_MAGIC_substr|5.007002||p PERL_MAGIC_sv|5.007002||p PERL_MAGIC_taint|5.007002||p PERL_MAGIC_tiedelem|5.007002||p PERL_MAGIC_tiedscalar|5.007002||p PERL_MAGIC_tied|5.007002||p PERL_MAGIC_utf8|5.008001||p PERL_MAGIC_uvar_elem|5.007003||p PERL_MAGIC_uvar|5.007002||p PERL_MAGIC_vec|5.007002||p PERL_MAGIC_vstring|5.008001||p PERL_PV_ESCAPE_ALL|5.009004||p PERL_PV_ESCAPE_FIRSTCHAR|5.009004||p PERL_PV_ESCAPE_NOBACKSLASH|5.009004||p PERL_PV_ESCAPE_NOCLEAR|5.009004||p PERL_PV_ESCAPE_QUOTE|5.009004||p PERL_PV_ESCAPE_RE|5.009005||p PERL_PV_ESCAPE_UNI_DETECT|5.009004||p PERL_PV_ESCAPE_UNI|5.009004||p PERL_PV_PRETTY_DUMP|5.009004||p PERL_PV_PRETTY_ELLIPSES|5.010000||p PERL_PV_PRETTY_LTGT|5.009004||p PERL_PV_PRETTY_NOCLEAR|5.010000||p PERL_PV_PRETTY_QUOTE|5.009004||p PERL_PV_PRETTY_REGPROP|5.009004||p PERL_QUAD_MAX|5.003070||p PERL_QUAD_MIN|5.003070||p PERL_REVISION|5.006000||p PERL_SCAN_ALLOW_UNDERSCORES|5.007003||p PERL_SCAN_DISALLOW_PREFIX|5.007003||p PERL_SCAN_GREATER_THAN_UV_MAX|5.007003||p PERL_SCAN_SILENT_ILLDIGIT|5.008001||p PERL_SHORT_MAX|5.003070||p PERL_SHORT_MIN|5.003070||p PERL_SIGNALS_UNSAFE_FLAG|5.008001||p PERL_SUBVERSION|5.006000||p PERL_SYS_INIT3||5.006000| PERL_SYS_INIT||| PERL_SYS_TERM||5.021008| PERL_UCHAR_MAX|5.003070||p PERL_UCHAR_MIN|5.003070||p PERL_UINT_MAX|5.003070||p PERL_UINT_MIN|5.003070||p PERL_ULONG_MAX|5.003070||p PERL_ULONG_MIN|5.003070||p PERL_UNUSED_ARG|5.009003||p PERL_UNUSED_CONTEXT|5.009004||p PERL_UNUSED_DECL|5.007002||p PERL_UNUSED_VAR|5.007002||p PERL_UQUAD_MAX|5.003070||p PERL_UQUAD_MIN|5.003070||p PERL_USE_GCC_BRACE_GROUPS|5.009004||p PERL_USHORT_MAX|5.003070||p PERL_USHORT_MIN|5.003070||p PERL_VERSION|5.006000||p PL_DBsignal|5.005000||p PL_DBsingle|||pn PL_DBsub|||pn PL_DBtrace|||pn PL_Sv|5.005000||p PL_bufend|5.021008||p PL_bufptr|5.021008||p PL_check||5.006000| PL_compiling|5.004050||p PL_comppad_name||5.017004| PL_comppad||5.008001| PL_copline|5.021008||p PL_curcop|5.004050||p PL_curpad||5.005000| PL_curstash|5.004050||p PL_debstash|5.004050||p PL_defgv|5.004050||p PL_diehook|5.004050||p PL_dirty|5.004050||p PL_dowarn|||pn PL_errgv|5.004050||p PL_error_count|5.021008||p PL_expect|5.021008||p PL_hexdigit|5.005000||p PL_hints|5.005000||p PL_in_my_stash|5.021008||p PL_in_my|5.021008||p PL_keyword_plugin||5.011002| PL_last_in_gv|||n PL_laststatval|5.005000||p PL_lex_state|5.021008||p PL_lex_stuff|5.021008||p PL_linestr|5.021008||p PL_modglobal||5.005000|n PL_na|5.004050||pn PL_no_modify|5.006000||p PL_ofsgv|||n PL_opfreehook||5.011000|n PL_parser|5.009005||p PL_peepp||5.007003|n PL_perl_destruct_level|5.004050||p PL_perldb|5.004050||p PL_ppaddr|5.006000||p PL_rpeepp||5.013005|n PL_rsfp_filters|5.021008||p PL_rsfp|5.021008||p PL_rs|||n PL_signals|5.008001||p PL_stack_base|5.004050||p PL_stack_sp|5.004050||p PL_statcache|5.005000||p PL_stdingv|5.004050||p PL_sv_arenaroot|5.004050||p PL_sv_no|5.004050||pn PL_sv_undef|5.004050||pn PL_sv_yes|5.004050||pn PL_tainted|5.004050||p PL_tainting|5.004050||p PL_tokenbuf|5.021008||p POP_MULTICALL||5.021008| POPi|||n POPl|||n POPn|||n POPpbytex||5.007001|n POPpx||5.005030|n POPp|||n POPs|||n PTR2IV|5.006000||p PTR2NV|5.006000||p PTR2UV|5.006000||p PTR2nat|5.009003||p PTR2ul|5.007001||p PTRV|5.006000||p PUSHMARK||| PUSH_MULTICALL||5.021008| PUSHi||| PUSHmortal|5.009002||p PUSHn||| PUSHp||| PUSHs||| PUSHu|5.004000||p PUTBACK||| PadARRAY||5.021008| PadMAX||5.021008| PadlistARRAY||5.021008| PadlistMAX||5.021008| PadlistNAMESARRAY||5.021008| PadlistNAMESMAX||5.021008| PadlistNAMES||5.021008| PadlistREFCNT||5.017004| PadnameIsOUR||| PadnameIsSTATE||| PadnameLEN||5.021008| PadnameOURSTASH||| PadnameOUTER||| PadnamePV||5.021008| PadnameREFCNT_dec||5.021008| PadnameREFCNT||5.021008| PadnameSV||5.021008| PadnameTYPE||| PadnameUTF8||5.021007| PadnamelistARRAY||5.021008| PadnamelistMAX||5.021008| PadnamelistREFCNT_dec||5.021008| PadnamelistREFCNT||5.021008| PerlIO_clearerr||5.007003| PerlIO_close||5.007003| PerlIO_context_layers||5.009004| PerlIO_eof||5.007003| PerlIO_error||5.007003| PerlIO_fileno||5.007003| PerlIO_fill||5.007003| PerlIO_flush||5.007003| PerlIO_get_base||5.007003| PerlIO_get_bufsiz||5.007003| PerlIO_get_cnt||5.007003| PerlIO_get_ptr||5.007003| PerlIO_read||5.007003| PerlIO_restore_errno||| PerlIO_save_errno||| PerlIO_seek||5.007003| PerlIO_set_cnt||5.007003| PerlIO_set_ptrcnt||5.007003| PerlIO_setlinebuf||5.007003| PerlIO_stderr||5.007003| PerlIO_stdin||5.007003| PerlIO_stdout||5.007003| PerlIO_tell||5.007003| PerlIO_unread||5.007003| PerlIO_write||5.007003| Perl_signbit||5.009005|n PoisonFree|5.009004||p PoisonNew|5.009004||p PoisonWith|5.009004||p Poison|5.008000||p READ_XDIGIT||5.017006| RETVAL|||n Renewc||| Renew||| SAVECLEARSV||| SAVECOMPPAD||| SAVEPADSV||| SAVETMPS||| SAVE_DEFSV|5.004050||p SPAGAIN||| SP||| START_EXTERN_C|5.005000||p START_MY_CXT|5.007003||p STMT_END|||p STMT_START|||p STR_WITH_LEN|5.009003||p ST||| SV_CONST_RETURN|5.009003||p SV_COW_DROP_PV|5.008001||p SV_COW_SHARED_HASH_KEYS|5.009005||p SV_GMAGIC|5.007002||p SV_HAS_TRAILING_NUL|5.009004||p SV_IMMEDIATE_UNREF|5.007001||p SV_MUTABLE_RETURN|5.009003||p SV_NOSTEAL|5.009002||p SV_SMAGIC|5.009003||p SV_UTF8_NO_ENCODING|5.008001||p SVfARG|5.009005||p SVf_UTF8|5.006000||p SVf|5.006000||p SVt_INVLIST||5.019002| SVt_IV||| SVt_NULL||| SVt_NV||| SVt_PVAV||| SVt_PVCV||| SVt_PVFM||| SVt_PVGV||| SVt_PVHV||| SVt_PVIO||| SVt_PVIV||| SVt_PVLV||| SVt_PVMG||| SVt_PVNV||| SVt_PV||| SVt_REGEXP||5.011000| Safefree||| Slab_Alloc||| Slab_Free||| Slab_to_ro||| Slab_to_rw||| StructCopy||| SvCUR_set||| SvCUR||| SvEND||| SvGAMAGIC||5.006001| SvGETMAGIC|5.004050||p SvGROW||| SvIOK_UV||5.006000| SvIOK_notUV||5.006000| SvIOK_off||| SvIOK_only_UV||5.006000| SvIOK_only||| SvIOK_on||| SvIOKp||| SvIOK||| SvIVX||| SvIV_nomg|5.009001||p SvIV_set||| SvIVx||| SvIV||| SvIsCOW_shared_hash||5.008003| SvIsCOW||5.008003| SvLEN_set||| SvLEN||| SvLOCK||5.007003| SvMAGIC_set|5.009003||p SvNIOK_off||| SvNIOKp||| SvNIOK||| SvNOK_off||| SvNOK_only||| SvNOK_on||| SvNOKp||| SvNOK||| SvNVX||| SvNV_nomg||5.013002| SvNV_set||| SvNVx||| SvNV||| SvOK||| SvOOK_offset||5.011000| SvOOK||| SvPOK_off||| SvPOK_only_UTF8||5.006000| SvPOK_only||| SvPOK_on||| SvPOKp||| SvPOK||| SvPVX_const|5.009003||p SvPVX_mutable|5.009003||p SvPVX||| SvPV_const|5.009003||p SvPV_flags_const_nolen|5.009003||p SvPV_flags_const|5.009003||p SvPV_flags_mutable|5.009003||p SvPV_flags|5.007002||p SvPV_force_flags_mutable|5.009003||p SvPV_force_flags_nolen|5.009003||p SvPV_force_flags|5.007002||p SvPV_force_mutable|5.009003||p SvPV_force_nolen|5.009003||p SvPV_force_nomg_nolen|5.009003||p SvPV_force_nomg|5.007002||p SvPV_force|||p SvPV_mutable|5.009003||p SvPV_nolen_const|5.009003||p SvPV_nolen|5.006000||p SvPV_nomg_const_nolen|5.009003||p SvPV_nomg_const|5.009003||p SvPV_nomg_nolen|5.013007||p SvPV_nomg|5.007002||p SvPV_renew|5.009003||p SvPV_set||| SvPVbyte_force||5.009002| SvPVbyte_nolen||5.006000| SvPVbytex_force||5.006000| SvPVbytex||5.006000| SvPVbyte|5.006000||p SvPVutf8_force||5.006000| SvPVutf8_nolen||5.006000| SvPVutf8x_force||5.006000| SvPVutf8x||5.006000| SvPVutf8||5.006000| SvPVx||| SvPV||| SvREFCNT_dec_NN||5.017007| SvREFCNT_dec||| SvREFCNT_inc_NN|5.009004||p SvREFCNT_inc_simple_NN|5.009004||p SvREFCNT_inc_simple_void_NN|5.009004||p SvREFCNT_inc_simple_void|5.009004||p SvREFCNT_inc_simple|5.009004||p SvREFCNT_inc_void_NN|5.009004||p SvREFCNT_inc_void|5.009004||p SvREFCNT_inc|||p SvREFCNT||| SvROK_off||| SvROK_on||| SvROK||| SvRV_set|5.009003||p SvRV||| SvRXOK||5.009005| SvRX||5.009005| SvSETMAGIC||| SvSHARED_HASH|5.009003||p SvSHARE||5.007003| SvSTASH_set|5.009003||p SvSTASH||| SvSetMagicSV_nosteal||5.004000| SvSetMagicSV||5.004000| SvSetSV_nosteal||5.004000| SvSetSV||| SvTAINTED_off||5.004000| SvTAINTED_on||5.004000| SvTAINTED||5.004000| SvTAINT||| SvTHINKFIRST||| SvTRUE_nomg||5.013006| SvTRUE||| SvTYPE||| SvUNLOCK||5.007003| SvUOK|5.007001|5.006000|p SvUPGRADE||| SvUTF8_off||5.006000| SvUTF8_on||5.006000| SvUTF8||5.006000| SvUVXx|5.004000||p SvUVX|5.004000||p SvUV_nomg|5.009001||p SvUV_set|5.009003||p SvUVx|5.004000||p SvUV|5.004000||p SvVOK||5.008001| SvVSTRING_mg|5.009004||p THIS|||n UNDERBAR|5.009002||p UTF8_MAXBYTES|5.009002||p UVSIZE|5.006000||p UVTYPE|5.006000||p UVXf|5.007001||p UVof|5.006000||p UVuf|5.006000||p UVxf|5.006000||p WARN_ALL|5.006000||p WARN_AMBIGUOUS|5.006000||p WARN_ASSERTIONS|5.021008||p WARN_BAREWORD|5.006000||p WARN_CLOSED|5.006000||p WARN_CLOSURE|5.006000||p WARN_DEBUGGING|5.006000||p WARN_DEPRECATED|5.006000||p WARN_DIGIT|5.006000||p WARN_EXEC|5.006000||p WARN_EXITING|5.006000||p WARN_GLOB|5.006000||p WARN_INPLACE|5.006000||p WARN_INTERNAL|5.006000||p WARN_IO|5.006000||p WARN_LAYER|5.008000||p WARN_MALLOC|5.006000||p WARN_MISC|5.006000||p WARN_NEWLINE|5.006000||p WARN_NUMERIC|5.006000||p WARN_ONCE|5.006000||p WARN_OVERFLOW|5.006000||p WARN_PACK|5.006000||p WARN_PARENTHESIS|5.006000||p WARN_PIPE|5.006000||p WARN_PORTABLE|5.006000||p WARN_PRECEDENCE|5.006000||p WARN_PRINTF|5.006000||p WARN_PROTOTYPE|5.006000||p WARN_QW|5.006000||p WARN_RECURSION|5.006000||p WARN_REDEFINE|5.006000||p WARN_REGEXP|5.006000||p WARN_RESERVED|5.006000||p WARN_SEMICOLON|5.006000||p WARN_SEVERE|5.006000||p WARN_SIGNAL|5.006000||p WARN_SUBSTR|5.006000||p WARN_SYNTAX|5.006000||p WARN_TAINT|5.006000||p WARN_THREADS|5.008000||p WARN_UNINITIALIZED|5.006000||p WARN_UNOPENED|5.006000||p WARN_UNPACK|5.006000||p WARN_UNTIE|5.006000||p WARN_UTF8|5.006000||p WARN_VOID|5.006000||p WIDEST_UTYPE|5.015004||p XCPT_CATCH|5.009002||p XCPT_RETHROW|5.009002||p XCPT_TRY_END|5.009002||p XCPT_TRY_START|5.009002||p XPUSHi||| XPUSHmortal|5.009002||p XPUSHn||| XPUSHp||| XPUSHs||| XPUSHu|5.004000||p XSPROTO|5.010000||p XSRETURN_EMPTY||| XSRETURN_IV||| XSRETURN_NO||| XSRETURN_NV||| XSRETURN_PV||| XSRETURN_UNDEF||| XSRETURN_UV|5.008001||p XSRETURN_YES||| XSRETURN|||p XST_mIV||| XST_mNO||| XST_mNV||| XST_mPV||| XST_mUNDEF||| XST_mUV|5.008001||p XST_mYES||| XS_APIVERSION_BOOTCHECK||5.021008| XS_EXTERNAL||5.021008| XS_INTERNAL||5.021008| XS_VERSION_BOOTCHECK||5.021008| XS_VERSION||| XSprePUSH|5.006000||p XS||| XopDISABLE||5.021008| XopENABLE||5.021008| XopENTRYCUSTOM||5.021008| XopENTRY_set||5.021008| XopENTRY||5.021008| XopFLAGS||5.013007| ZeroD|5.009002||p Zero||| _aMY_CXT|5.007003||p _add_range_to_invlist||| _append_range_to_invlist||| _core_swash_init||| _get_encoding||| _get_regclass_nonbitmap_data||| _get_swash_invlist||| _invlist_array_init|||n _invlist_contains_cp|||n _invlist_contents||| _invlist_dump||| _invlist_intersection_maybe_complement_2nd||| _invlist_intersection||| _invlist_invert||| _invlist_len|||n _invlist_populate_swatch|||n _invlist_search|||n _invlist_subtract||| _invlist_union_maybe_complement_2nd||| _invlist_union||| _is_cur_LC_category_utf8||| _is_in_locale_category||5.021001| _is_uni_FOO||5.017008| _is_uni_perl_idcont||5.017008| _is_uni_perl_idstart||5.017007| _is_utf8_FOO||5.017008| _is_utf8_char_slow||5.021001|n _is_utf8_idcont||5.021001| _is_utf8_idstart||5.021001| _is_utf8_mark||5.017008| _is_utf8_perl_idcont||5.017008| _is_utf8_perl_idstart||5.017007| _is_utf8_xidcont||5.021001| _is_utf8_xidstart||5.021001| _load_PL_utf8_foldclosures||| _make_exactf_invlist||| _new_invlist_C_array||| _new_invlist||| _pMY_CXT|5.007003||p _setup_canned_invlist||| _swash_inversion_hash||| _swash_to_invlist||| _to_fold_latin1||| _to_uni_fold_flags||5.014000| _to_upper_title_latin1||| _to_utf8_fold_flags||5.019009| _to_utf8_lower_flags||5.019009| _to_utf8_title_flags||5.019009| _to_utf8_upper_flags||5.019009| _warn_problematic_locale|||n aMY_CXT_|5.007003||p aMY_CXT|5.007003||p aTHXR_|5.021008||p aTHXR|5.021008||p aTHX_|5.006000||p aTHX|5.006000||p aassign_common_vars||| add_above_Latin1_folds||| add_cp_to_invlist||| add_data|||n add_multi_match||| add_utf16_textfilter||| adjust_size_and_find_bucket|||n advance_one_SB||| advance_one_WB||| alloc_maybe_populate_EXACT||| alloccopstash||| allocmy||| amagic_call||| amagic_cmp_locale||| amagic_cmp||| amagic_deref_call||5.013007| amagic_i_ncmp||| amagic_is_enabled||| amagic_ncmp||| anonymise_cv_maybe||| any_dup||| ao||| append_utf8_from_native_byte||5.019004|n apply_attrs_my||| apply_attrs_string||5.006001| apply_attrs||| apply||| assert_uft8_cache_coherent||| assignment_type||| atfork_lock||5.007003|n atfork_unlock||5.007003|n av_arylen_p||5.009003| av_clear||| av_create_and_push||5.009005| av_create_and_unshift_one||5.009005| av_delete||5.006000| av_exists||5.006000| av_extend_guts||| av_extend||| av_fetch||| av_fill||| av_iter_p||5.011000| av_len||| av_make||| av_pop||| av_push||| av_reify||| av_shift||| av_store||| av_tindex||5.017009| av_top_index||5.017009| av_undef||| av_unshift||| ax|||n backup_one_SB||| backup_one_WB||| bad_type_gv||| bad_type_pv||| bind_match||| block_end||5.004000| block_gimme||5.004000| block_start||5.004000| blockhook_register||5.013003| boolSV|5.004000||p boot_core_PerlIO||| boot_core_UNIVERSAL||| boot_core_mro||| bytes_cmp_utf8||5.013007| bytes_from_utf8||5.007001| bytes_to_utf8||5.006001| call_argv|5.006000||p call_atexit||5.006000| call_list||5.004000| call_method|5.006000||p call_pv|5.006000||p call_sv|5.006000||p caller_cx|5.013005|5.006000|p calloc||5.007002|n cando||| cast_i32||5.006000|n cast_iv||5.006000|n cast_ulong||5.006000|n cast_uv||5.006000|n check_locale_boundary_crossing||| check_type_and_open||| check_uni||| check_utf8_print||| checkcomma||| ckWARN|5.006000||p ck_entersub_args_core||| ck_entersub_args_list||5.013006| ck_entersub_args_proto_or_list||5.013006| ck_entersub_args_proto||5.013006| ck_warner_d||5.011001|v ck_warner||5.011001|v ckwarn_common||| ckwarn_d||5.009003| ckwarn||5.009003| clear_placeholders||| clear_special_blocks||| clone_params_del|||n clone_params_new|||n closest_cop||| cntrl_to_mnemonic|||n compute_EXACTish|||n construct_ahocorasick_from_trie||| cop_fetch_label||5.015001| cop_free||| cop_hints_2hv||5.013007| cop_hints_fetch_pvn||5.013007| cop_hints_fetch_pvs||5.013007| cop_hints_fetch_pv||5.013007| cop_hints_fetch_sv||5.013007| cop_store_label||5.015001| cophh_2hv||5.013007| cophh_copy||5.013007| cophh_delete_pvn||5.013007| cophh_delete_pvs||5.013007| cophh_delete_pv||5.013007| cophh_delete_sv||5.013007| cophh_fetch_pvn||5.013007| cophh_fetch_pvs||5.013007| cophh_fetch_pv||5.013007| cophh_fetch_sv||5.013007| cophh_free||5.013007| cophh_new_empty||5.021008| cophh_store_pvn||5.013007| cophh_store_pvs||5.013007| cophh_store_pv||5.013007| cophh_store_sv||5.013007| core_prototype||| coresub_op||| could_it_be_a_POSIX_class|||n cr_textfilter||| create_eval_scope||| croak_memory_wrap||5.019003|n croak_no_mem|||n croak_no_modify||5.013003|n croak_nocontext|||vn croak_popstack|||n croak_sv||5.013001| croak_xs_usage||5.010001|n croak|||v csighandler||5.009003|n current_re_engine||| curse||| custom_op_desc||5.007003| custom_op_get_field||| custom_op_name||5.007003| custom_op_register||5.013007| custom_op_xop||5.013007| cv_ckproto_len_flags||| cv_clone_into||| cv_clone||| cv_const_sv_or_av|||n cv_const_sv||5.003070|n cv_dump||| cv_forget_slab||| cv_get_call_checker||5.013006| cv_name||5.021005| cv_set_call_checker_flags||5.021004| cv_set_call_checker||5.013006| cv_undef_flags||| cv_undef||| cvgv_from_hek||| cvgv_set||| cvstash_set||| cx_dump||5.005000| cx_dup||| cxinc||| dAXMARK|5.009003||p dAX|5.007002||p dITEMS|5.007002||p dMARK||| dMULTICALL||5.009003| dMY_CXT_SV|5.007003||p dMY_CXT|5.007003||p dNOOP|5.006000||p dORIGMARK||| dSP||| dTHR|5.004050||p dTHXR|5.021008||p dTHXa|5.006000||p dTHXoa|5.006000||p dTHX|5.006000||p dUNDERBAR|5.009002||p dVAR|5.009003||p dXCPT|5.009002||p dXSARGS||| dXSI32||| dXSTARG|5.006000||p deb_curcv||| deb_nocontext|||vn deb_stack_all||| deb_stack_n||| debop||5.005000| debprofdump||5.005000| debprof||| debstackptrs||5.007003| debstack||5.007003| debug_start_match||| deb||5.007003|v defelem_target||| del_sv||| delete_eval_scope||| delimcpy||5.004000|n deprecate_commaless_var_list||| despatch_signals||5.007001| destroy_matcher||| die_nocontext|||vn die_sv||5.013001| die_unwind||| die|||v dirp_dup||| div128||| djSP||| do_aexec5||| do_aexec||| do_aspawn||| do_binmode||5.004050| do_chomp||| do_close||| do_delete_local||| do_dump_pad||| do_eof||| do_exec3||| do_execfree||| do_exec||| do_gv_dump||5.006000| do_gvgv_dump||5.006000| do_hv_dump||5.006000| do_ipcctl||| do_ipcget||| do_join||| do_magic_dump||5.006000| do_msgrcv||| do_msgsnd||| do_ncmp||| do_oddball||| do_op_dump||5.006000| do_open6||| do_open9||5.006000| do_open_raw||| do_openn||5.007001| do_open||5.003070| do_pmop_dump||5.006000| do_print||| do_readline||| do_seek||| do_semop||| do_shmio||| do_smartmatch||| do_spawn_nowait||| do_spawn||| do_sprintf||| do_sv_dump||5.006000| do_sysseek||| do_tell||| do_trans_complex_utf8||| do_trans_complex||| do_trans_count_utf8||| do_trans_count||| do_trans_simple_utf8||| do_trans_simple||| do_trans||| do_vecget||| do_vecset||| do_vop||| docatch||| doeval||| dofile||| dofindlabel||| doform||| doing_taint||5.008001|n dooneliner||| doopen_pm||| doparseform||| dopoptoeval||| dopoptogiven||| dopoptolabel||| dopoptoloop||| dopoptosub_at||| dopoptowhen||| doref||5.009003| dounwind||| dowantarray||| drand48_init_r|||n drand48_r|||n dump_all_perl||| dump_all||5.006000| dump_c_backtrace||| dump_eval||5.006000| dump_exec_pos||| dump_form||5.006000| dump_indent||5.006000|v dump_mstats||| dump_packsubs_perl||| dump_packsubs||5.006000| dump_sub_perl||| dump_sub||5.006000| dump_sv_child||| dump_trie_interim_list||| dump_trie_interim_table||| dump_trie||| dump_vindent||5.006000| dumpuntil||| dup_attrlist||| emulate_cop_io||| eval_pv|5.006000||p eval_sv|5.006000||p exec_failed||| expect_number||| fbm_compile||5.005000| fbm_instr||5.005000| feature_is_enabled||| filter_add||| filter_del||| filter_gets||| filter_read||| finalize_optree||| finalize_op||| find_and_forget_pmops||| find_array_subscript||| find_beginning||| find_byclass||| find_default_stash||| find_hash_subscript||| find_in_my_stash||| find_lexical_cv||| find_runcv_where||| find_runcv||5.008001| find_rundefsv2||| find_rundefsvoffset||5.009002| find_rundefsv||5.013002| find_script||| find_uninit_var||| first_symbol|||n fixup_errno_string||| foldEQ_latin1||5.013008|n foldEQ_locale||5.013002|n foldEQ_utf8_flags||5.013010| foldEQ_utf8||5.013002| foldEQ||5.013002|n fold_constants||| forbid_setid||| force_ident_maybe_lex||| force_ident||| force_list||| force_next||| force_strict_version||| force_version||| force_word||| forget_pmop||| form_nocontext|||vn form_short_octal_warning||| form||5.004000|v fp_dup||| fprintf_nocontext|||vn free_c_backtrace||| free_global_struct||| free_tied_hv_pool||| free_tmps||| gen_constant_list||| get_ANYOF_cp_list_for_ssc||| get_and_check_backslash_N_name||| get_aux_mg||| get_av|5.006000||p get_c_backtrace_dump||| get_c_backtrace||| get_context||5.006000|n get_cvn_flags|5.009005||p get_cvs|5.011000||p get_cv|5.006000||p get_db_sub||| get_debug_opts||| get_hash_seed||| get_hv|5.006000||p get_invlist_iter_addr|||n get_invlist_offset_addr|||n get_invlist_previous_index_addr|||n get_mstats||| get_no_modify||| get_num||| get_op_descs||5.005000| get_op_names||5.005000| get_opargs||| get_ppaddr||5.006000| get_re_arg||| get_sv|5.006000||p get_vtbl||5.005030| getcwd_sv||5.007002| getenv_len||| glob_2number||| glob_assign_glob||| gp_dup||| gp_free||| gp_ref||| grok_atoUV|||n grok_bin|5.007003||p grok_bslash_N||| grok_bslash_c||| grok_bslash_o||| grok_bslash_x||| grok_hex|5.007003||p grok_infnan||5.021004| grok_number_flags||5.021002| grok_number|5.007002||p grok_numeric_radix|5.007002||p grok_oct|5.007003||p group_end||| gv_AVadd||| gv_HVadd||| gv_IOadd||| gv_SVadd||| gv_add_by_type||5.011000| gv_autoload4||5.004000| gv_autoload_pvn||5.015004| gv_autoload_pv||5.015004| gv_autoload_sv||5.015004| gv_check||| gv_const_sv||5.009003| gv_dump||5.006000| gv_efullname3||5.003070| gv_efullname4||5.006001| gv_efullname||| gv_fetchfile_flags||5.009005| gv_fetchfile||| gv_fetchmeth_autoload||5.007003| gv_fetchmeth_internal||| gv_fetchmeth_pv_autoload||5.015004| gv_fetchmeth_pvn_autoload||5.015004| gv_fetchmeth_pvn||5.015004| gv_fetchmeth_pv||5.015004| gv_fetchmeth_sv_autoload||5.015004| gv_fetchmeth_sv||5.015004| gv_fetchmethod_autoload||5.004000| gv_fetchmethod_pv_flags||5.015004| gv_fetchmethod_pvn_flags||5.015004| gv_fetchmethod_sv_flags||5.015004| gv_fetchmethod||| gv_fetchmeth||| gv_fetchpvn_flags|5.009002||p gv_fetchpvs|5.009004||p gv_fetchpv||| gv_fetchsv|5.009002||p gv_fullname3||5.003070| gv_fullname4||5.006001| gv_fullname||| gv_handler||5.007001| gv_init_pvn||5.015004| gv_init_pv||5.015004| gv_init_svtype||| gv_init_sv||5.015004| gv_init||| gv_is_in_main||| gv_magicalize_isa||| gv_magicalize||| gv_name_set||5.009004| gv_override||| gv_setref||| gv_stashpvn_internal||| gv_stashpvn|5.003070||p gv_stashpvs|5.009003||p gv_stashpv||| gv_stashsvpvn_cached||| gv_stashsv||| gv_try_downgrade||| handle_regex_sets||| he_dup||| hek_dup||| hfree_next_entry||| hfreeentries||| hsplit||| hv_assert||| hv_auxinit_internal|||n hv_auxinit||| hv_backreferences_p||| hv_clear_placeholders||5.009001| hv_clear||| hv_common_key_len||5.010000| hv_common||5.010000| hv_copy_hints_hv||5.009004| hv_delayfree_ent||5.004000| hv_delete_common||| hv_delete_ent||5.003070| hv_delete||| hv_eiter_p||5.009003| hv_eiter_set||5.009003| hv_ename_add||| hv_ename_delete||| hv_exists_ent||5.003070| hv_exists||| hv_fetch_ent||5.003070| hv_fetchs|5.009003||p hv_fetch||| hv_fill||5.013002| hv_free_ent_ret||| hv_free_ent||5.004000| hv_iterinit||| hv_iterkeysv||5.003070| hv_iterkey||| hv_iternext_flags||5.008000| hv_iternextsv||| hv_iternext||| hv_iterval||| hv_kill_backrefs||| hv_ksplit||5.003070| hv_magic_check|||n hv_magic||| hv_name_set||5.009003| hv_notallowed||| hv_placeholders_get||5.009003| hv_placeholders_p||| hv_placeholders_set||5.009003| hv_rand_set||5.018000| hv_riter_p||5.009003| hv_riter_set||5.009003| hv_scalar||5.009001| hv_store_ent||5.003070| hv_store_flags||5.008000| hv_stores|5.009004||p hv_store||| hv_undef_flags||| hv_undef||| ibcmp_locale||5.004000| ibcmp_utf8||5.007003| ibcmp||| incline||| incpush_if_exists||| incpush_use_sep||| incpush||| ingroup||| init_argv_symbols||| init_constants||| init_dbargs||| init_debugger||| init_global_struct||| init_i18nl10n||5.006000| init_i18nl14n||5.006000| init_ids||| init_interp||| init_main_stash||| init_perllib||| init_postdump_symbols||| init_predump_symbols||| init_stacks||5.005000| init_tm||5.007002| inplace_aassign||| instr|||n intro_my||5.004000| intuit_method||| intuit_more||| invert||| invlist_array|||n invlist_clone||| invlist_extend||| invlist_highest|||n invlist_is_iterating|||n invlist_iterfinish|||n invlist_iterinit|||n invlist_iternext|||n invlist_max|||n invlist_previous_index|||n invlist_set_len||| invlist_set_previous_index|||n invlist_trim|||n invoke_exception_hook||| io_close||| isALNUMC|5.006000||p isALNUM_lazy||5.021001| isALPHANUMERIC||5.017008| isALPHA||| isASCII|5.006000||p isBLANK|5.006001||p isCNTRL|5.006000||p isDIGIT||| isFOO_lc||| isFOO_utf8_lc||| isGCB|||n isGRAPH|5.006000||p isGV_with_GP|5.009004||p isIDCONT||5.017008| isIDFIRST_lazy||5.021001| isIDFIRST||| isLOWER||| isOCTAL||5.013005| isPRINT|5.004000||p isPSXSPC|5.006001||p isPUNCT|5.006000||p isSB||| isSPACE||| isUPPER||| isUTF8_CHAR||5.021001| isWB||| isWORDCHAR||5.013006| isXDIGIT|5.006000||p is_an_int||| is_ascii_string||5.011000| is_handle_constructor|||n is_invariant_string||5.021007|n is_lvalue_sub||5.007001| is_safe_syscall||5.019004| is_ssc_worth_it|||n is_uni_alnum_lc||5.006000| is_uni_alnumc_lc||5.017007| is_uni_alnumc||5.017007| is_uni_alnum||5.006000| is_uni_alpha_lc||5.006000| is_uni_alpha||5.006000| is_uni_ascii_lc||5.006000| is_uni_ascii||5.006000| is_uni_blank_lc||5.017002| is_uni_blank||5.017002| is_uni_cntrl_lc||5.006000| is_uni_cntrl||5.006000| is_uni_digit_lc||5.006000| is_uni_digit||5.006000| is_uni_graph_lc||5.006000| is_uni_graph||5.006000| is_uni_idfirst_lc||5.006000| is_uni_idfirst||5.006000| is_uni_lower_lc||5.006000| is_uni_lower||5.006000| is_uni_print_lc||5.006000| is_uni_print||5.006000| is_uni_punct_lc||5.006000| is_uni_punct||5.006000| is_uni_space_lc||5.006000| is_uni_space||5.006000| is_uni_upper_lc||5.006000| is_uni_upper||5.006000| is_uni_xdigit_lc||5.006000| is_uni_xdigit||5.006000| is_utf8_alnumc||5.017007| is_utf8_alnum||5.006000| is_utf8_alpha||5.006000| is_utf8_ascii||5.006000| is_utf8_blank||5.017002| is_utf8_char_buf||5.015008|n is_utf8_char||5.006000|n is_utf8_cntrl||5.006000| is_utf8_common||| is_utf8_digit||5.006000| is_utf8_graph||5.006000| is_utf8_idcont||5.008000| is_utf8_idfirst||5.006000| is_utf8_lower||5.006000| is_utf8_mark||5.006000| is_utf8_perl_space||5.011001| is_utf8_perl_word||5.011001| is_utf8_posix_digit||5.011001| is_utf8_print||5.006000| is_utf8_punct||5.006000| is_utf8_space||5.006000| is_utf8_string_loclen||5.009003|n is_utf8_string_loc||5.008001|n is_utf8_string||5.006001|n is_utf8_upper||5.006000| is_utf8_xdigit||5.006000| is_utf8_xidcont||5.013010| is_utf8_xidfirst||5.013010| isa_lookup||| isinfnansv||| isinfnan||5.021004|n items|||n ix|||n jmaybe||| join_exact||| keyword_plugin_standard||| keyword||| leave_common||| leave_scope||| lex_bufutf8||5.011002| lex_discard_to||5.011002| lex_grow_linestr||5.011002| lex_next_chunk||5.011002| lex_peek_unichar||5.011002| lex_read_space||5.011002| lex_read_to||5.011002| lex_read_unichar||5.011002| lex_start||5.009005| lex_stuff_pvn||5.011002| lex_stuff_pvs||5.013005| lex_stuff_pv||5.013006| lex_stuff_sv||5.011002| lex_unstuff||5.011002| listkids||| list||| load_module_nocontext|||vn load_module|5.006000||pv localize||| looks_like_bool||| looks_like_number||| lop||| mPUSHi|5.009002||p mPUSHn|5.009002||p mPUSHp|5.009002||p mPUSHs|5.010001||p mPUSHu|5.009002||p mXPUSHi|5.009002||p mXPUSHn|5.009002||p mXPUSHp|5.009002||p mXPUSHs|5.010001||p mXPUSHu|5.009002||p magic_clear_all_env||| magic_cleararylen_p||| magic_clearenv||| magic_clearhints||| magic_clearhint||| magic_clearisa||| magic_clearpack||| magic_clearsig||| magic_copycallchecker||| magic_dump||5.006000| magic_existspack||| magic_freearylen_p||| magic_freeovrld||| magic_getarylen||| magic_getdebugvar||| magic_getdefelem||| magic_getnkeys||| magic_getpack||| magic_getpos||| magic_getsig||| magic_getsubstr||| magic_gettaint||| magic_getuvar||| magic_getvec||| magic_get||| magic_killbackrefs||| magic_methcall1||| magic_methcall|||v magic_methpack||| magic_nextpack||| magic_regdata_cnt||| magic_regdatum_get||| magic_regdatum_set||| magic_scalarpack||| magic_set_all_env||| magic_setarylen||| magic_setcollxfrm||| magic_setdbline||| magic_setdebugvar||| magic_setdefelem||| magic_setenv||| magic_sethint||| magic_setisa||| magic_setlvref||| magic_setmglob||| magic_setnkeys||| magic_setpack||| magic_setpos||| magic_setregexp||| magic_setsig||| magic_setsubstr||| magic_settaint||| magic_setutf8||| magic_setuvar||| magic_setvec||| magic_set||| magic_sizepack||| magic_wipepack||| make_matcher||| make_trie||| malloc_good_size|||n malloced_size|||n malloc||5.007002|n markstack_grow||5.021001| matcher_matches_sv||| maybe_multimagic_gv||| mayberelocate||| measure_struct||| memEQs|5.009005||p memEQ|5.004000||p memNEs|5.009005||p memNE|5.004000||p mem_collxfrm||| mem_log_common|||n mess_alloc||| mess_nocontext|||vn mess_sv||5.013001| mess||5.006000|v mfree||5.007002|n mg_clear||| mg_copy||| mg_dup||| mg_find_mglob||| mg_findext|5.013008||pn mg_find|||n mg_free_type||5.013006| mg_free||| mg_get||| mg_length||5.005000| mg_localize||| mg_magical|||n mg_set||| mg_size||5.005000| mini_mktime||5.007002|n minus_v||| missingterm||| mode_from_discipline||| modkids||| more_bodies||| more_sv||| moreswitches||| move_proto_attr||| mro_clean_isarev||| mro_gather_and_rename||| mro_get_from_name||5.010001| mro_get_linear_isa_dfs||| mro_get_linear_isa||5.009005| mro_get_private_data||5.010001| mro_isa_changed_in||| mro_meta_dup||| mro_meta_init||| mro_method_changed_in||5.009005| mro_package_moved||| mro_register||5.010001| mro_set_mro||5.010001| mro_set_private_data||5.010001| mul128||| mulexp10|||n multideref_stringify||| my_atof2||5.007002| my_atof||5.006000| my_attrs||| my_bcopy|||n my_bytes_to_utf8|||n my_bzero|||n my_chsize||| my_clearenv||| my_cxt_index||| my_cxt_init||| my_dirfd||5.009005|n my_exit_jump||| my_exit||| my_failure_exit||5.004000| my_fflush_all||5.006000| my_fork||5.007003|n my_kid||| my_lstat_flags||| my_lstat||5.021008| my_memcmp|||n my_memset|||n my_pclose||5.003070| my_popen_list||5.007001| my_popen||5.003070| my_setenv||| my_setlocale||| my_snprintf|5.009004||pvn my_socketpair||5.007003|n my_sprintf|5.009003||pvn my_stat_flags||| my_stat||5.021008| my_strerror||5.021001| my_strftime||5.007002| my_strlcat|5.009004||pn my_strlcpy|5.009004||pn my_unexec||| my_vsnprintf||5.009004|n need_utf8|||n newANONATTRSUB||5.006000| newANONHASH||| newANONLIST||| newANONSUB||| newASSIGNOP||| newATTRSUB_x||| newATTRSUB||5.006000| newAVREF||| newAV||| newBINOP||| newCONDOP||| newCONSTSUB_flags||5.015006| newCONSTSUB|5.004050||p newCVREF||| newDEFSVOP||5.021006| newFORM||| newFOROP||5.013007| newGIVENOP||5.009003| newGIVWHENOP||| newGP||| newGVOP||| newGVREF||| newGVgen_flags||5.015004| newGVgen||| newHVREF||| newHVhv||5.005000| newHV||| newIO||| newLISTOP||| newLOGOP||| newLOOPEX||| newLOOPOP||| newMETHOP_internal||| newMETHOP_named||5.021005| newMETHOP||5.021005| newMYSUB||5.017004| newNULLLIST||| newOP||| newPADNAMELIST||5.021007|n newPADNAMEouter||5.021007|n newPADNAMEpvn||5.021007|n newPADOP||| newPMOP||| newPROG||| newPVOP||| newRANGE||| newRV_inc|5.004000||p newRV_noinc|5.004000||p newRV||| newSLICEOP||| newSTATEOP||| newSTUB||| newSUB||| newSVOP||| newSVREF||| newSV_type|5.009005||p newSVavdefelem||| newSVhek||5.009003| newSViv||| newSVnv||| newSVpadname||5.017004| newSVpv_share||5.013006| newSVpvf_nocontext|||vn newSVpvf||5.004000|v newSVpvn_flags|5.010001||p newSVpvn_share|5.007001||p newSVpvn_utf8|5.010001||p newSVpvn|5.004050||p newSVpvs_flags|5.010001||p newSVpvs_share|5.009003||p newSVpvs|5.009003||p newSVpv||| newSVrv||| newSVsv||| newSVuv|5.006000||p newSV||| newUNOP_AUX||5.021007| newUNOP||| newWHENOP||5.009003| newWHILEOP||5.013007| newXS_deffile||| newXS_flags||5.009004| newXS_len_flags||| newXSproto||5.006000| newXS||5.006000| new_collate||5.006000| new_constant||| new_ctype||5.006000| new_he||| new_logop||| new_numeric||5.006000| new_stackinfo||5.005000| new_version||5.009000| new_warnings_bitfield||| next_symbol||| nextargv||| nextchar||| ninstr|||n no_bareword_allowed||| no_fh_allowed||| no_op||| noperl_die|||vn not_a_number||| not_incrementable||| nothreadhook||5.008000| nuke_stacks||| num_overflow|||n oopsAV||| oopsHV||| op_append_elem||5.013006| op_append_list||5.013006| op_clear||| op_contextualize||5.013006| op_convert_list||5.021006| op_dump||5.006000| op_free||| op_integerize||| op_linklist||5.013006| op_lvalue_flags||| op_lvalue||5.013007| op_null||5.007002| op_parent||5.021002|n op_prepend_elem||5.013006| op_refcnt_dec||| op_refcnt_inc||| op_refcnt_lock||5.009002| op_refcnt_unlock||5.009002| op_relocate_sv||| op_scope||5.013007| op_sibling_splice||5.021002|n op_std_init||| op_unscope||| open_script||| openn_cleanup||| openn_setup||| opmethod_stash||| opslab_force_free||| opslab_free_nopad||| opslab_free||| pMY_CXT_|5.007003||p pMY_CXT|5.007003||p pTHX_|5.006000||p pTHX|5.006000||p packWARN|5.007003||p pack_cat||5.007003| pack_rec||| package_version||| package||| packlist||5.008001| pad_add_anon||5.008001| pad_add_name_pvn||5.015001| pad_add_name_pvs||5.015001| pad_add_name_pv||5.015001| pad_add_name_sv||5.015001| pad_add_weakref||| pad_alloc_name||| pad_alloc||| pad_block_start||| pad_check_dup||| pad_compname_type||5.009003| pad_findlex||| pad_findmy_pvn||5.015001| pad_findmy_pvs||5.015001| pad_findmy_pv||5.015001| pad_findmy_sv||5.015001| pad_fixup_inner_anons||| pad_free||| pad_leavemy||| pad_new||5.008001| pad_push||| pad_reset||| pad_setsv||| pad_sv||| pad_swipe||| pad_tidy||5.008001| padlist_dup||| padlist_store||| padname_dup||| padname_free||| padnamelist_dup||| padnamelist_fetch||5.021007|n padnamelist_free||| padnamelist_store||5.021007| parse_arithexpr||5.013008| parse_barestmt||5.013007| parse_block||5.013007| parse_body||| parse_fullexpr||5.013008| parse_fullstmt||5.013005| parse_gv_stash_name||| parse_ident||| parse_label||5.013007| parse_listexpr||5.013008| parse_lparen_question_flags||| parse_stmtseq||5.013006| parse_subsignature||| parse_termexpr||5.013008| parse_unicode_opts||| parser_dup||| parser_free_nexttoke_ops||| parser_free||| path_is_searchable|||n peep||| pending_ident||| perl_alloc_using|||n perl_alloc|||n perl_clone_using|||n perl_clone|||n perl_construct|||n perl_destruct||5.007003|n perl_free|||n perl_parse||5.006000|n perl_run|||n pidgone||| pm_description||| pmop_dump||5.006000| pmruntime||| pmtrans||| pop_scope||| populate_ANYOF_from_invlist||| populate_isa|||v pregcomp||5.009005| pregexec||| pregfree2||5.011000| pregfree||| prescan_version||5.011004| printbuf||| printf_nocontext|||vn process_special_blocks||| ptr_hash|||n ptr_table_clear||5.009005| ptr_table_fetch||5.009005| ptr_table_find|||n ptr_table_free||5.009005| ptr_table_new||5.009005| ptr_table_split||5.009005| ptr_table_store||5.009005| push_scope||| put_charclass_bitmap_innards||| put_code_point||| put_range||| pv_display|5.006000||p pv_escape|5.009004||p pv_pretty|5.009004||p pv_uni_display||5.007003| qerror||| qsortsvu||| quadmath_format_needed|||n quadmath_format_single|||n re_compile||5.009005| re_croak2||| re_dup_guts||| re_intuit_start||5.019001| re_intuit_string||5.006000| re_op_compile||| realloc||5.007002|n reentrant_free||5.021008| reentrant_init||5.021008| reentrant_retry||5.021008|vn reentrant_size||5.021008| ref_array_or_hash||| refcounted_he_chain_2hv||| refcounted_he_fetch_pvn||| refcounted_he_fetch_pvs||| refcounted_he_fetch_pv||| refcounted_he_fetch_sv||| refcounted_he_free||| refcounted_he_inc||| refcounted_he_new_pvn||| refcounted_he_new_pvs||| refcounted_he_new_pv||| refcounted_he_new_sv||| refcounted_he_value||| refkids||| refto||| ref||5.021008| reg2Lanode||| reg_check_named_buff_matched|||n reg_named_buff_all||5.009005| reg_named_buff_exists||5.009005| reg_named_buff_fetch||5.009005| reg_named_buff_firstkey||5.009005| reg_named_buff_iter||| reg_named_buff_nextkey||5.009005| reg_named_buff_scalar||5.009005| reg_named_buff||| reg_node||| reg_numbered_buff_fetch||| reg_numbered_buff_length||| reg_numbered_buff_store||| reg_qr_package||| reg_recode||| reg_scan_name||| reg_skipcomment|||n reg_temp_copy||| reganode||| regatom||| regbranch||| regclass_swash||5.009004| regclass||| regcppop||| regcppush||| regcurly|||n regdump_extflags||| regdump_intflags||| regdump||5.005000| regdupe_internal||| regexec_flags||5.005000| regfree_internal||5.009005| reghop3|||n reghop4|||n reghopmaybe3|||n reginclass||| reginitcolors||5.006000| reginsert||| regmatch||| regnext||5.005000| regnode_guts||| regpatws|||n regpiece||| regpposixcc||| regprop||| regrepeat||| regtail_study||| regtail||| regtry||| reg||| repeatcpy|||n report_evil_fh||| report_redefined_cv||| report_uninit||| report_wrongway_fh||| require_pv||5.006000| require_tie_mod||| restore_magic||| rninstr|||n rpeep||| rsignal_restore||| rsignal_save||| rsignal_state||5.004000| rsignal||5.004000| run_body||| run_user_filter||| runops_debug||5.005000| runops_standard||5.005000| rv2cv_op_cv||5.013006| rvpv_dup||| rxres_free||| rxres_restore||| rxres_save||| safesyscalloc||5.006000|n safesysfree||5.006000|n safesysmalloc||5.006000|n safesysrealloc||5.006000|n same_dirent||| save_I16||5.004000| save_I32||| save_I8||5.006000| save_adelete||5.011000| save_aelem_flags||5.011000| save_aelem||5.004050| save_aliased_sv||| save_alloc||5.006000| save_aptr||| save_ary||| save_bool||5.008001| save_clearsv||| save_delete||| save_destructor_x||5.006000| save_destructor||5.006000| save_freeop||| save_freepv||| save_freesv||| save_generic_pvref||5.006001| save_generic_svref||5.005030| save_gp||5.004000| save_hash||| save_hdelete||5.011000| save_hek_flags|||n save_helem_flags||5.011000| save_helem||5.004050| save_hints||5.010001| save_hptr||| save_int||| save_item||| save_iv||5.005000| save_lines||| save_list||| save_long||| save_magic_flags||| save_mortalizesv||5.007001| save_nogv||| save_op||5.005000| save_padsv_and_mortalize||5.010001| save_pptr||| save_pushi32ptr||5.010001| save_pushptri32ptr||| save_pushptrptr||5.010001| save_pushptr||5.010001| save_re_context||5.006000| save_scalar_at||| save_scalar||| save_set_svflags||5.009000| save_shared_pvref||5.007003| save_sptr||| save_strlen||| save_svref||| save_vptr||5.006000| savepvn||| savepvs||5.009003| savepv||| savesharedpvn||5.009005| savesharedpvs||5.013006| savesharedpv||5.007003| savesharedsvpv||5.013006| savestack_grow_cnt||5.008001| savestack_grow||| savesvpv||5.009002| sawparens||| scalar_mod_type|||n scalarboolean||| scalarkids||| scalarseq||| scalarvoid||| scalar||| scan_bin||5.006000| scan_commit||| scan_const||| scan_formline||| scan_heredoc||| scan_hex||| scan_ident||| scan_inputsymbol||| scan_num||5.007001| scan_oct||| scan_pat||| scan_str||| scan_subst||| scan_trans||| scan_version||5.009001| scan_vstring||5.009005| scan_word||| search_const||| seed||5.008001| sequence_num||| set_ANYOF_arg||| set_caret_X||| set_context||5.006000|n set_numeric_local||5.006000| set_numeric_radix||5.006000| set_numeric_standard||5.006000| set_padlist|||n setdefout||| share_hek_flags||| share_hek||5.004000| should_warn_nl|||n si_dup||| sighandler|||n simplify_sort||| skipspace_flags||| softref2xv||| sortcv_stacked||| sortcv_xsub||| sortcv||| sortsv_flags||5.009003| sortsv||5.007003| space_join_names_mortal||| ss_dup||| ssc_add_range||| ssc_and||| ssc_anything||| ssc_clear_locale|||n ssc_cp_and||| ssc_finalize||| ssc_init||| ssc_intersection||| ssc_is_anything|||n ssc_is_cp_posixl_init|||n ssc_or||| ssc_union||| stack_grow||| start_glob||| start_subparse||5.004000| stdize_locale||| strEQ||| strGE||| strGT||| strLE||| strLT||| strNE||| str_to_version||5.006000| strip_return||| strnEQ||| strnNE||| study_chunk||| sub_crush_depth||| sublex_done||| sublex_push||| sublex_start||| sv_2bool_flags||5.013006| sv_2bool||| sv_2cv||| sv_2io||| sv_2iuv_common||| sv_2iuv_non_preserve||| sv_2iv_flags||5.009001| sv_2iv||| sv_2mortal||| sv_2num||| sv_2nv_flags||5.013001| sv_2pv_flags|5.007002||p sv_2pv_nolen|5.006000||p sv_2pvbyte_nolen|5.006000||p sv_2pvbyte|5.006000||p sv_2pvutf8_nolen||5.006000| sv_2pvutf8||5.006000| sv_2pv||| sv_2uv_flags||5.009001| sv_2uv|5.004000||p sv_add_arena||| sv_add_backref||| sv_backoff|||n sv_bless||| sv_buf_to_ro||| sv_buf_to_rw||| sv_cat_decode||5.008001| sv_catpv_flags||5.013006| sv_catpv_mg|5.004050||p sv_catpv_nomg||5.013006| sv_catpvf_mg_nocontext|||pvn sv_catpvf_mg|5.006000|5.004000|pv sv_catpvf_nocontext|||vn sv_catpvf||5.004000|v sv_catpvn_flags||5.007002| sv_catpvn_mg|5.004050||p sv_catpvn_nomg|5.007002||p sv_catpvn||| sv_catpvs_flags||5.013006| sv_catpvs_mg||5.013006| sv_catpvs_nomg||5.013006| sv_catpvs|5.009003||p sv_catpv||| sv_catsv_flags||5.007002| sv_catsv_mg|5.004050||p sv_catsv_nomg|5.007002||p sv_catsv||| sv_chop||| sv_clean_all||| sv_clean_objs||| sv_clear||| sv_cmp_flags||5.013006| sv_cmp_locale_flags||5.013006| sv_cmp_locale||5.004000| sv_cmp||| sv_collxfrm_flags||5.013006| sv_collxfrm||| sv_copypv_flags||5.017002| sv_copypv_nomg||5.017002| sv_copypv||| sv_dec_nomg||5.013002| sv_dec||| sv_del_backref||| sv_derived_from_pvn||5.015004| sv_derived_from_pv||5.015004| sv_derived_from_sv||5.015004| sv_derived_from||5.004000| sv_destroyable||5.010000| sv_display||| sv_does_pvn||5.015004| sv_does_pv||5.015004| sv_does_sv||5.015004| sv_does||5.009004| sv_dump||| sv_dup_common||| sv_dup_inc_multiple||| sv_dup_inc||| sv_dup||| sv_eq_flags||5.013006| sv_eq||| sv_exp_grow||| sv_force_normal_flags||5.007001| sv_force_normal||5.006000| sv_free2||| sv_free_arenas||| sv_free||| sv_get_backrefs||5.021008|n sv_gets||5.003070| sv_grow||| sv_i_ncmp||| sv_inc_nomg||5.013002| sv_inc||| sv_insert_flags||5.010001| sv_insert||| sv_isa||| sv_isobject||| sv_iv||5.005000| sv_kill_backrefs||| sv_len_utf8_nomg||| sv_len_utf8||5.006000| sv_len||| sv_magic_portable|5.021008|5.004000|p sv_magicext_mglob||| sv_magicext||5.007003| sv_magic||| sv_mortalcopy_flags||| sv_mortalcopy||| sv_ncmp||| sv_newmortal||| sv_newref||| sv_nolocking||5.007003| sv_nosharing||5.007003| sv_nounlocking||| sv_nv||5.005000| sv_only_taint_gmagic|||n sv_or_pv_pos_u2b||| sv_peek||5.005000| sv_pos_b2u_flags||5.019003| sv_pos_b2u_midway||| sv_pos_b2u||5.006000| sv_pos_u2b_cached||| sv_pos_u2b_flags||5.011005| sv_pos_u2b_forwards|||n sv_pos_u2b_midway|||n sv_pos_u2b||5.006000| sv_pvbyten_force||5.006000| sv_pvbyten||5.006000| sv_pvbyte||5.006000| sv_pvn_force_flags|5.007002||p sv_pvn_force||| sv_pvn_nomg|5.007003|5.005000|p sv_pvn||5.005000| sv_pvutf8n_force||5.006000| sv_pvutf8n||5.006000| sv_pvutf8||5.006000| sv_pv||5.006000| sv_recode_to_utf8||5.007003| sv_reftype||| sv_ref||| sv_release_COW||| sv_replace||| sv_report_used||| sv_resetpvn||| sv_reset||| sv_rvweaken||5.006000| sv_sethek||| sv_setiv_mg|5.004050||p sv_setiv||| sv_setnv_mg|5.006000||p sv_setnv||| sv_setpv_mg|5.004050||p sv_setpvf_mg_nocontext|||pvn sv_setpvf_mg|5.006000|5.004000|pv sv_setpvf_nocontext|||vn sv_setpvf||5.004000|v sv_setpviv_mg||5.008001| sv_setpviv||5.008001| sv_setpvn_mg|5.004050||p sv_setpvn||| sv_setpvs_mg||5.013006| sv_setpvs|5.009004||p sv_setpv||| sv_setref_iv||| sv_setref_nv||| sv_setref_pvn||| sv_setref_pvs||5.021008| sv_setref_pv||| sv_setref_uv||5.007001| sv_setsv_cow||| sv_setsv_flags||5.007002| sv_setsv_mg|5.004050||p sv_setsv_nomg|5.007002||p sv_setsv||| sv_setuv_mg|5.004050||p sv_setuv|5.004000||p sv_tainted||5.004000| sv_taint||5.004000| sv_true||5.005000| sv_unglob||| sv_uni_display||5.007003| sv_unmagicext|5.013008||p sv_unmagic||| sv_unref_flags||5.007001| sv_unref||| sv_untaint||5.004000| sv_upgrade||| sv_usepvn_flags||5.009004| sv_usepvn_mg|5.004050||p sv_usepvn||| sv_utf8_decode||5.006000| sv_utf8_downgrade||5.006000| sv_utf8_encode||5.006000| sv_utf8_upgrade_flags_grow||5.011000| sv_utf8_upgrade_flags||5.007002| sv_utf8_upgrade_nomg||5.007002| sv_utf8_upgrade||5.007001| sv_uv|5.005000||p sv_vcatpvf_mg|5.006000|5.004000|p sv_vcatpvfn_flags||5.017002| sv_vcatpvfn||5.004000| sv_vcatpvf|5.006000|5.004000|p sv_vsetpvf_mg|5.006000|5.004000|p sv_vsetpvfn||5.004000| sv_vsetpvf|5.006000|5.004000|p svtype||| swallow_bom||| swash_fetch||5.007002| swash_init||5.006000| swash_scan_list_line||| swatch_get||| sync_locale||5.021004| sys_init3||5.010000|n sys_init||5.010000|n sys_intern_clear||| sys_intern_dup||| sys_intern_init||| sys_term||5.010000|n taint_env||| taint_proper||| tied_method|||v tmps_grow_p||| toFOLD_uni||5.007003| toFOLD_utf8||5.019001| toFOLD||5.019001| toLOWER_L1||5.019001| toLOWER_LC||5.004000| toLOWER_uni||5.007003| toLOWER_utf8||5.015007| toLOWER||| toTITLE_uni||5.007003| toTITLE_utf8||5.015007| toTITLE||5.019001| toUPPER_uni||5.007003| toUPPER_utf8||5.015007| toUPPER||| to_byte_substr||| to_lower_latin1|||n to_uni_fold||5.007003| to_uni_lower_lc||5.006000| to_uni_lower||5.007003| to_uni_title_lc||5.006000| to_uni_title||5.007003| to_uni_upper_lc||5.006000| to_uni_upper||5.007003| to_utf8_case||5.007003| to_utf8_fold||5.015007| to_utf8_lower||5.015007| to_utf8_substr||| to_utf8_title||5.015007| to_utf8_upper||5.015007| tokenize_use||| tokeq||| tokereport||| too_few_arguments_pv||| too_many_arguments_pv||| translate_substr_offsets|||n try_amagic_bin||| try_amagic_un||| uiv_2buf|||n unlnk||| unpack_rec||| unpack_str||5.007003| unpackstring||5.008001| unreferenced_to_tmp_stack||| unshare_hek_or_pvn||| unshare_hek||| unsharepvn||5.003070| unwind_handler_stack||| update_debugger_info||| upg_version||5.009005| usage||| utf16_textfilter||| utf16_to_utf8_reversed||5.006001| utf16_to_utf8||5.006001| utf8_distance||5.006000| utf8_hop||5.006000|n utf8_length||5.007001| utf8_mg_len_cache_update||| utf8_mg_pos_cache_update||| utf8_to_bytes||5.006001| utf8_to_uvchr_buf||5.015009| utf8_to_uvchr||5.007001| utf8_to_uvuni_buf||5.015009| utf8_to_uvuni||5.007001| utf8n_to_uvchr||5.007001| utf8n_to_uvuni||5.007001| utilize||| uvchr_to_utf8_flags||5.007003| uvchr_to_utf8||5.007001| uvoffuni_to_utf8_flags||5.019004| uvuni_to_utf8_flags||5.007003| uvuni_to_utf8||5.007001| valid_utf8_to_uvchr||5.015009| valid_utf8_to_uvuni||5.015009| validate_proto||| validate_suid||| varname||| vcmp||5.009000| vcroak||5.006000| vdeb||5.007003| vform||5.006000| visit||| vivify_defelem||| vivify_ref||| vload_module|5.006000||p vmess||5.006000| vnewSVpvf|5.006000|5.004000|p vnormal||5.009002| vnumify||5.009000| vstringify||5.009000| vverify||5.009003| vwarner||5.006000| vwarn||5.006000| wait4pid||| warn_nocontext|||vn warn_sv||5.013001| warner_nocontext|||vn warner|5.006000|5.004000|pv warn|||v was_lvalue_sub||| watch||| whichsig_pvn||5.015004| whichsig_pv||5.015004| whichsig_sv||5.015004| whichsig||| win32_croak_not_implemented|||n with_queued_errors||| wrap_op_checker||5.015008| write_to_stderr||| xs_boot_epilog||| xs_handshake|||vn xs_version_bootcheck||| yyerror_pvn||| yyerror_pv||| yyerror||| yylex||| yyparse||| yyunlex||| yywarn||| ); if (exists $opt{'list-unsupported'}) { my $f; for $f (sort { lc $a cmp lc $b } keys %API) { next unless $API{$f}{todo}; print "$f ", '.'x(40-length($f)), " ", format_version($API{$f}{todo}), "\n"; } exit 0; } # Scan for possible replacement candidates my(%replace, %need, %hints, %warnings, %depends); my $replace = 0; my($hint, $define, $function); sub find_api { my $code = shift; $code =~ s{ / (?: \*[^*]*\*+(?:[^$ccs][^*]*\*+)* / | /[^\r\n]*) | "[^"\\]*(?:\\.[^"\\]*)*" | '[^'\\]*(?:\\.[^'\\]*)*' }{}egsx; grep { exists $API{$_} } $code =~ /(\w+)/mg; } while () { if ($hint) { my $h = $hint->[0] eq 'Hint' ? \%hints : \%warnings; if (m{^\s*\*\s(.*?)\s*$}) { for (@{$hint->[1]}) { $h->{$_} ||= ''; # suppress warning with older perls $h->{$_} .= "$1\n"; } } else { undef $hint } } $hint = [$1, [split /,?\s+/, $2]] if m{^\s*$rccs\s+(Hint|Warning):\s+(\w+(?:,?\s+\w+)*)\s*$}; if ($define) { if ($define->[1] =~ /\\$/) { $define->[1] .= $_; } else { if (exists $API{$define->[0]} && $define->[1] !~ /^DPPP_\(/) { my @n = find_api($define->[1]); push @{$depends{$define->[0]}}, @n if @n } undef $define; } } $define = [$1, $2] if m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(.*)}; if ($function) { if (/^}/) { if (exists $API{$function->[0]}) { my @n = find_api($function->[1]); push @{$depends{$function->[0]}}, @n if @n } undef $function; } else { $function->[1] .= $_; } } $function = [$1, ''] if m{^DPPP_\(my_(\w+)\)}; $replace = $1 if m{^\s*$rccs\s+Replace:\s+(\d+)\s+$rcce\s*$}; $replace{$2} = $1 if $replace and m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(\w+)}; $replace{$2} = $1 if m{^\s*#\s*define\s+(\w+)(?:\([^)]*\))?\s+(\w+).*$rccs\s+Replace\s+$rcce}; $replace{$1} = $2 if m{^\s*$rccs\s+Replace (\w+) with (\w+)\s+$rcce\s*$}; if (m{^\s*$rccs\s+(\w+(\s*,\s*\w+)*)\s+depends\s+on\s+(\w+(\s*,\s*\w+)*)\s+$rcce\s*$}) { my @deps = map { s/\s+//g; $_ } split /,/, $3; my $d; for $d (map { s/\s+//g; $_ } split /,/, $1) { push @{$depends{$d}}, @deps; } } $need{$1} = 1 if m{^#if\s+defined\(NEED_(\w+)(?:_GLOBAL)?\)}; } for (values %depends) { my %s; $_ = [sort grep !$s{$_}++, @$_]; } if (exists $opt{'api-info'}) { my $f; my $count = 0; my $match = $opt{'api-info'} =~ m!^/(.*)/$! ? $1 : "^\Q$opt{'api-info'}\E\$"; for $f (sort { lc $a cmp lc $b } keys %API) { next unless $f =~ /$match/; print "\n=== $f ===\n\n"; my $info = 0; if ($API{$f}{base} || $API{$f}{todo}) { my $base = format_version($API{$f}{base} || $API{$f}{todo}); print "Supported at least starting from perl-$base.\n"; $info++; } if ($API{$f}{provided}) { my $todo = $API{$f}{todo} ? format_version($API{$f}{todo}) : "5.003"; print "Support by $ppport provided back to perl-$todo.\n"; print "Support needs to be explicitly requested by NEED_$f.\n" if exists $need{$f}; print "Depends on: ", join(', ', @{$depends{$f}}), ".\n" if exists $depends{$f}; print "\n$hints{$f}" if exists $hints{$f}; print "\nWARNING:\n$warnings{$f}" if exists $warnings{$f}; $info++; } print "No portability information available.\n" unless $info; $count++; } $count or print "Found no API matching '$opt{'api-info'}'."; print "\n"; exit 0; } if (exists $opt{'list-provided'}) { my $f; for $f (sort { lc $a cmp lc $b } keys %API) { next unless $API{$f}{provided}; my @flags; push @flags, 'explicit' if exists $need{$f}; push @flags, 'depend' if exists $depends{$f}; push @flags, 'hint' if exists $hints{$f}; push @flags, 'warning' if exists $warnings{$f}; my $flags = @flags ? ' ['.join(', ', @flags).']' : ''; print "$f$flags\n"; } exit 0; } my @files; my @srcext = qw( .xs .c .h .cc .cpp -c.inc -xs.inc ); my $srcext = join '|', map { quotemeta $_ } @srcext; if (@ARGV) { my %seen; for (@ARGV) { if (-e) { if (-f) { push @files, $_ unless $seen{$_}++; } else { warn "'$_' is not a file.\n" } } else { my @new = grep { -f } glob $_ or warn "'$_' does not exist.\n"; push @files, grep { !$seen{$_}++ } @new; } } } else { eval { require File::Find; File::Find::find(sub { $File::Find::name =~ /($srcext)$/i and push @files, $File::Find::name; }, '.'); }; if ($@) { @files = map { glob "*$_" } @srcext; } } if (!@ARGV || $opt{filter}) { my(@in, @out); my %xsc = map { /(.*)\.xs$/ ? ("$1.c" => 1, "$1.cc" => 1) : () } @files; for (@files) { my $out = exists $xsc{$_} || /\b\Q$ppport\E$/i || !/($srcext)$/i; push @{ $out ? \@out : \@in }, $_; } if (@ARGV && @out) { warning("Skipping the following files (use --nofilter to avoid this):\n| ", join "\n| ", @out); } @files = @in; } die "No input files given!\n" unless @files; my(%files, %global, %revreplace); %revreplace = reverse %replace; my $filename; my $patch_opened = 0; for $filename (@files) { unless (open IN, "<$filename") { warn "Unable to read from $filename: $!\n"; next; } info("Scanning $filename ..."); my $c = do { local $/; }; close IN; my %file = (orig => $c, changes => 0); # Temporarily remove C/XS comments and strings from the code my @ccom; $c =~ s{ ( ^$HS*\#$HS*include\b[^\r\n]+\b(?:\Q$ppport\E|XSUB\.h)\b[^\r\n]* | ^$HS*\#$HS*(?:define|elif|if(?:def)?)\b[^\r\n]* ) | ( ^$HS*\#[^\r\n]* | "[^"\\]*(?:\\.[^"\\]*)*" | '[^'\\]*(?:\\.[^'\\]*)*' | / (?: \*[^*]*\*+(?:[^$ccs][^*]*\*+)* / | /[^\r\n]* ) ) }{ defined $2 and push @ccom, $2; defined $1 ? $1 : "$ccs$#ccom$cce" }mgsex; $file{ccom} = \@ccom; $file{code} = $c; $file{has_inc_ppport} = $c =~ /^$HS*#$HS*include[^\r\n]+\b\Q$ppport\E\b/m; my $func; for $func (keys %API) { my $match = $func; $match .= "|$revreplace{$func}" if exists $revreplace{$func}; if ($c =~ /\b(?:Perl_)?($match)\b/) { $file{uses_replace}{$1}++ if exists $revreplace{$func} && $1 eq $revreplace{$func}; $file{uses_Perl}{$func}++ if $c =~ /\bPerl_$func\b/; if (exists $API{$func}{provided}) { $file{uses_provided}{$func}++; if (!exists $API{$func}{base} || $API{$func}{base} > $opt{'compat-version'}) { $file{uses}{$func}++; my @deps = rec_depend($func); if (@deps) { $file{uses_deps}{$func} = \@deps; for (@deps) { $file{uses}{$_} = 0 unless exists $file{uses}{$_}; } } for ($func, @deps) { $file{needs}{$_} = 'static' if exists $need{$_}; } } } if (exists $API{$func}{todo} && $API{$func}{todo} > $opt{'compat-version'}) { if ($c =~ /\b$func\b/) { $file{uses_todo}{$func}++; } } } } while ($c =~ /^$HS*#$HS*define$HS+(NEED_(\w+?)(_GLOBAL)?)\b/mg) { if (exists $need{$2}) { $file{defined $3 ? 'needed_global' : 'needed_static'}{$2}++; } else { warning("Possibly wrong #define $1 in $filename") } } for (qw(uses needs uses_todo needed_global needed_static)) { for $func (keys %{$file{$_}}) { push @{$global{$_}{$func}}, $filename; } } $files{$filename} = \%file; } # Globally resolve NEED_'s my $need; for $need (keys %{$global{needs}}) { if (@{$global{needs}{$need}} > 1) { my @targets = @{$global{needs}{$need}}; my @t = grep $files{$_}{needed_global}{$need}, @targets; @targets = @t if @t; @t = grep /\.xs$/i, @targets; @targets = @t if @t; my $target = shift @targets; $files{$target}{needs}{$need} = 'global'; for (@{$global{needs}{$need}}) { $files{$_}{needs}{$need} = 'extern' if $_ ne $target; } } } for $filename (@files) { exists $files{$filename} or next; info("=== Analyzing $filename ==="); my %file = %{$files{$filename}}; my $func; my $c = $file{code}; my $warnings = 0; for $func (sort keys %{$file{uses_Perl}}) { if ($API{$func}{varargs}) { unless ($API{$func}{nothxarg}) { my $changes = ($c =~ s{\b(Perl_$func\s*\(\s*)(?!aTHX_?)(\)|[^\s)]*\))} { $1 . ($2 eq ')' ? 'aTHX' : 'aTHX_ ') . $2 }ge); if ($changes) { warning("Doesn't pass interpreter argument aTHX to Perl_$func"); $file{changes} += $changes; } } } else { warning("Uses Perl_$func instead of $func"); $file{changes} += ($c =~ s{\bPerl_$func(\s*)\((\s*aTHX_?)?\s*} {$func$1(}g); } } for $func (sort keys %{$file{uses_replace}}) { warning("Uses $func instead of $replace{$func}"); $file{changes} += ($c =~ s/\b$func\b/$replace{$func}/g); } for $func (sort keys %{$file{uses_provided}}) { if ($file{uses}{$func}) { if (exists $file{uses_deps}{$func}) { diag("Uses $func, which depends on ", join(', ', @{$file{uses_deps}{$func}})); } else { diag("Uses $func"); } } $warnings += hint($func); } unless ($opt{quiet}) { for $func (sort keys %{$file{uses_todo}}) { print "*** WARNING: Uses $func, which may not be portable below perl ", format_version($API{$func}{todo}), ", even with '$ppport'\n"; $warnings++; } } for $func (sort keys %{$file{needed_static}}) { my $message = ''; if (not exists $file{uses}{$func}) { $message = "No need to define NEED_$func if $func is never used"; } elsif (exists $file{needs}{$func} && $file{needs}{$func} ne 'static') { $message = "No need to define NEED_$func when already needed globally"; } if ($message) { diag($message); $file{changes} += ($c =~ s/^$HS*#$HS*define$HS+NEED_$func\b.*$LF//mg); } } for $func (sort keys %{$file{needed_global}}) { my $message = ''; if (not exists $global{uses}{$func}) { $message = "No need to define NEED_${func}_GLOBAL if $func is never used"; } elsif (exists $file{needs}{$func}) { if ($file{needs}{$func} eq 'extern') { $message = "No need to define NEED_${func}_GLOBAL when already needed globally"; } elsif ($file{needs}{$func} eq 'static') { $message = "No need to define NEED_${func}_GLOBAL when only used in this file"; } } if ($message) { diag($message); $file{changes} += ($c =~ s/^$HS*#$HS*define$HS+NEED_${func}_GLOBAL\b.*$LF//mg); } } $file{needs_inc_ppport} = keys %{$file{uses}}; if ($file{needs_inc_ppport}) { my $pp = ''; for $func (sort keys %{$file{needs}}) { my $type = $file{needs}{$func}; next if $type eq 'extern'; my $suffix = $type eq 'global' ? '_GLOBAL' : ''; unless (exists $file{"needed_$type"}{$func}) { if ($type eq 'global') { diag("Files [@{$global{needs}{$func}}] need $func, adding global request"); } else { diag("File needs $func, adding static request"); } $pp .= "#define NEED_$func$suffix\n"; } } if ($pp && ($c =~ s/^(?=$HS*#$HS*define$HS+NEED_\w+)/$pp/m)) { $pp = ''; $file{changes}++; } unless ($file{has_inc_ppport}) { diag("Needs to include '$ppport'"); $pp .= qq(#include "$ppport"\n) } if ($pp) { $file{changes} += ($c =~ s/^($HS*#$HS*define$HS+NEED_\w+.*?)^/$1$pp/ms) || ($c =~ s/^(?=$HS*#$HS*include.*\Q$ppport\E)/$pp/m) || ($c =~ s/^($HS*#$HS*include.*XSUB.*\s*?)^/$1$pp/m) || ($c =~ s/^/$pp/); } } else { if ($file{has_inc_ppport}) { diag("No need to include '$ppport'"); $file{changes} += ($c =~ s/^$HS*?#$HS*include.*\Q$ppport\E.*?$LF//m); } } # put back in our C comments my $ix; my $cppc = 0; my @ccom = @{$file{ccom}}; for $ix (0 .. $#ccom) { if (!$opt{cplusplus} && $ccom[$ix] =~ s!^//!!) { $cppc++; $file{changes} += $c =~ s/$rccs$ix$rcce/$ccs$ccom[$ix] $cce/; } else { $c =~ s/$rccs$ix$rcce/$ccom[$ix]/; } } if ($cppc) { my $s = $cppc != 1 ? 's' : ''; warning("Uses $cppc C++ style comment$s, which is not portable"); } my $s = $warnings != 1 ? 's' : ''; my $warn = $warnings ? " ($warnings warning$s)" : ''; info("Analysis completed$warn"); if ($file{changes}) { if (exists $opt{copy}) { my $newfile = "$filename$opt{copy}"; if (-e $newfile) { error("'$newfile' already exists, refusing to write copy of '$filename'"); } else { local *F; if (open F, ">$newfile") { info("Writing copy of '$filename' with changes to '$newfile'"); print F $c; close F; } else { error("Cannot open '$newfile' for writing: $!"); } } } elsif (exists $opt{patch} || $opt{changes}) { if (exists $opt{patch}) { unless ($patch_opened) { if (open PATCH, ">$opt{patch}") { $patch_opened = 1; } else { error("Cannot open '$opt{patch}' for writing: $!"); delete $opt{patch}; $opt{changes} = 1; goto fallback; } } mydiff(\*PATCH, $filename, $c); } else { fallback: info("Suggested changes:"); mydiff(\*STDOUT, $filename, $c); } } else { my $s = $file{changes} == 1 ? '' : 's'; info("$file{changes} potentially required change$s detected"); } } else { info("Looks good"); } } close PATCH if $patch_opened; exit 0; sub try_use { eval "use @_;"; return $@ eq '' } sub mydiff { local *F = shift; my($file, $str) = @_; my $diff; if (exists $opt{diff}) { $diff = run_diff($opt{diff}, $file, $str); } if (!defined $diff and try_use('Text::Diff')) { $diff = Text::Diff::diff($file, \$str, { STYLE => 'Unified' }); $diff = <
$tmp") { print F $str; close F; if (open F, "$prog $file $tmp |") { while () { s/\Q$tmp\E/$file.patched/; $diff .= $_; } close F; unlink $tmp; return $diff; } unlink $tmp; } else { error("Cannot open '$tmp' for writing: $!"); } return undef; } sub rec_depend { my($func, $seen) = @_; return () unless exists $depends{$func}; $seen = {%{$seen||{}}}; return () if $seen->{$func}++; my %s; grep !$s{$_}++, map { ($_, rec_depend($_, $seen)) } @{$depends{$func}}; } sub parse_version { my $ver = shift; if ($ver =~ /^(\d+)\.(\d+)\.(\d+)$/) { return ($1, $2, $3); } elsif ($ver !~ /^\d+\.[\d_]+$/) { die "cannot parse version '$ver'\n"; } $ver =~ s/_//g; $ver =~ s/$/000000/; my($r,$v,$s) = $ver =~ /(\d+)\.(\d{3})(\d{3})/; $v = int $v; $s = int $s; if ($r < 5 || ($r == 5 && $v < 6)) { if ($s % 10) { die "cannot parse version '$ver'\n"; } } return ($r, $v, $s); } sub format_version { my $ver = shift; $ver =~ s/$/000000/; my($r,$v,$s) = $ver =~ /(\d+)\.(\d{3})(\d{3})/; $v = int $v; $s = int $s; if ($r < 5 || ($r == 5 && $v < 6)) { if ($s % 10) { die "invalid version '$ver'\n"; } $s /= 10; $ver = sprintf "%d.%03d", $r, $v; $s > 0 and $ver .= sprintf "_%02d", $s; return $ver; } return sprintf "%d.%d.%d", $r, $v, $s; } sub info { $opt{quiet} and return; print @_, "\n"; } sub diag { $opt{quiet} and return; $opt{diag} and print @_, "\n"; } sub warning { $opt{quiet} and return; print "*** ", @_, "\n"; } sub error { print "*** ERROR: ", @_, "\n"; } my %given_hints; my %given_warnings; sub hint { $opt{quiet} and return; my $func = shift; my $rv = 0; if (exists $warnings{$func} && !$given_warnings{$func}++) { my $warn = $warnings{$func}; $warn =~ s!^!*** !mg; print "*** WARNING: $func\n", $warn; $rv++; } if ($opt{hints} && exists $hints{$func} && !$given_hints{$func}++) { my $hint = $hints{$func}; $hint =~ s/^/ /mg; print " --- hint for $func ---\n", $hint; } $rv; } sub usage { my($usage) = do { local(@ARGV,$/)=($0); <> } =~ /^=head\d$HS+SYNOPSIS\s*^(.*?)\s*^=/ms; my %M = ( 'I' => '*' ); $usage =~ s/^\s*perl\s+\S+/$^X $0/; $usage =~ s/([A-Z])<([^>]+)>/$M{$1}$2$M{$1}/g; print < }; my($copy) = $self =~ /^=head\d\s+COPYRIGHT\s*^(.*?)^=\w+/ms; $copy =~ s/^(?=\S+)/ /gms; $self =~ s/^$HS+Do NOT edit.*?(?=^-)/$copy/ms; $self =~ s/^SKIP.*(?=^__DATA__)/SKIP if (\@ARGV && \$ARGV[0] eq '--unstrip') { eval { require Devel::PPPort }; \$@ and die "Cannot require Devel::PPPort, please install.\\n"; if (eval \$Devel::PPPort::VERSION < $VERSION) { die "$0 was originally generated with Devel::PPPort $VERSION.\\n" . "Your Devel::PPPort is only version \$Devel::PPPort::VERSION.\\n" . "Please install a newer version, or --unstrip will not work.\\n"; } Devel::PPPort::WriteFile(\$0); exit 0; } print <$0" or die "cannot strip $0: $!\n"; print OUT "$pl$c\n"; exit 0; } __DATA__ */ #ifndef _P_P_PORTABILITY_H_ #define _P_P_PORTABILITY_H_ #ifndef DPPP_NAMESPACE # define DPPP_NAMESPACE DPPP_ #endif #define DPPP_CAT2(x,y) CAT2(x,y) #define DPPP_(name) DPPP_CAT2(DPPP_NAMESPACE, name) #ifndef PERL_REVISION # if !defined(__PATCHLEVEL_H_INCLUDED__) && !(defined(PATCHLEVEL) && defined(SUBVERSION)) # define PERL_PATCHLEVEL_H_IMPLICIT # include # endif # if !(defined(PERL_VERSION) || (defined(SUBVERSION) && defined(PATCHLEVEL))) # include # endif # ifndef PERL_REVISION # define PERL_REVISION (5) /* Replace: 1 */ # define PERL_VERSION PATCHLEVEL # define PERL_SUBVERSION SUBVERSION /* Replace PERL_PATCHLEVEL with PERL_VERSION */ /* Replace: 0 */ # endif #endif #define _dpppDEC2BCD(dec) ((((dec)/100)<<8)|((((dec)%100)/10)<<4)|((dec)%10)) #define PERL_BCDVERSION ((_dpppDEC2BCD(PERL_REVISION)<<24)|(_dpppDEC2BCD(PERL_VERSION)<<12)|_dpppDEC2BCD(PERL_SUBVERSION)) /* It is very unlikely that anyone will try to use this with Perl 6 (or greater), but who knows. */ #if PERL_REVISION != 5 # error ppport.h only works with Perl version 5 #endif /* PERL_REVISION != 5 */ #ifndef dTHR # define dTHR dNOOP #endif #ifndef dTHX # define dTHX dNOOP #endif #ifndef dTHXa # define dTHXa(x) dNOOP #endif #ifndef pTHX # define pTHX void #endif #ifndef pTHX_ # define pTHX_ #endif #ifndef aTHX # define aTHX #endif #ifndef aTHX_ # define aTHX_ #endif #if (PERL_BCDVERSION < 0x5006000) # ifdef USE_THREADS # define aTHXR thr # define aTHXR_ thr, # else # define aTHXR # define aTHXR_ # endif # define dTHXR dTHR #else # define aTHXR aTHX # define aTHXR_ aTHX_ # define dTHXR dTHX #endif #ifndef dTHXoa # define dTHXoa(x) dTHXa(x) #endif #ifdef I_LIMITS # include #endif #ifndef PERL_UCHAR_MIN # define PERL_UCHAR_MIN ((unsigned char)0) #endif #ifndef PERL_UCHAR_MAX # ifdef UCHAR_MAX # define PERL_UCHAR_MAX ((unsigned char)UCHAR_MAX) # else # ifdef MAXUCHAR # define PERL_UCHAR_MAX ((unsigned char)MAXUCHAR) # else # define PERL_UCHAR_MAX ((unsigned char)~(unsigned)0) # endif # endif #endif #ifndef PERL_USHORT_MIN # define PERL_USHORT_MIN ((unsigned short)0) #endif #ifndef PERL_USHORT_MAX # ifdef USHORT_MAX # define PERL_USHORT_MAX ((unsigned short)USHORT_MAX) # else # ifdef MAXUSHORT # define PERL_USHORT_MAX ((unsigned short)MAXUSHORT) # else # ifdef USHRT_MAX # define PERL_USHORT_MAX ((unsigned short)USHRT_MAX) # else # define PERL_USHORT_MAX ((unsigned short)~(unsigned)0) # endif # endif # endif #endif #ifndef PERL_SHORT_MAX # ifdef SHORT_MAX # define PERL_SHORT_MAX ((short)SHORT_MAX) # else # ifdef MAXSHORT /* Often used in */ # define PERL_SHORT_MAX ((short)MAXSHORT) # else # ifdef SHRT_MAX # define PERL_SHORT_MAX ((short)SHRT_MAX) # else # define PERL_SHORT_MAX ((short) (PERL_USHORT_MAX >> 1)) # endif # endif # endif #endif #ifndef PERL_SHORT_MIN # ifdef SHORT_MIN # define PERL_SHORT_MIN ((short)SHORT_MIN) # else # ifdef MINSHORT # define PERL_SHORT_MIN ((short)MINSHORT) # else # ifdef SHRT_MIN # define PERL_SHORT_MIN ((short)SHRT_MIN) # else # define PERL_SHORT_MIN (-PERL_SHORT_MAX - ((3 & -1) == 3)) # endif # endif # endif #endif #ifndef PERL_UINT_MAX # ifdef UINT_MAX # define PERL_UINT_MAX ((unsigned int)UINT_MAX) # else # ifdef MAXUINT # define PERL_UINT_MAX ((unsigned int)MAXUINT) # else # define PERL_UINT_MAX (~(unsigned int)0) # endif # endif #endif #ifndef PERL_UINT_MIN # define PERL_UINT_MIN ((unsigned int)0) #endif #ifndef PERL_INT_MAX # ifdef INT_MAX # define PERL_INT_MAX ((int)INT_MAX) # else # ifdef MAXINT /* Often used in */ # define PERL_INT_MAX ((int)MAXINT) # else # define PERL_INT_MAX ((int)(PERL_UINT_MAX >> 1)) # endif # endif #endif #ifndef PERL_INT_MIN # ifdef INT_MIN # define PERL_INT_MIN ((int)INT_MIN) # else # ifdef MININT # define PERL_INT_MIN ((int)MININT) # else # define PERL_INT_MIN (-PERL_INT_MAX - ((3 & -1) == 3)) # endif # endif #endif #ifndef PERL_ULONG_MAX # ifdef ULONG_MAX # define PERL_ULONG_MAX ((unsigned long)ULONG_MAX) # else # ifdef MAXULONG # define PERL_ULONG_MAX ((unsigned long)MAXULONG) # else # define PERL_ULONG_MAX (~(unsigned long)0) # endif # endif #endif #ifndef PERL_ULONG_MIN # define PERL_ULONG_MIN ((unsigned long)0L) #endif #ifndef PERL_LONG_MAX # ifdef LONG_MAX # define PERL_LONG_MAX ((long)LONG_MAX) # else # ifdef MAXLONG # define PERL_LONG_MAX ((long)MAXLONG) # else # define PERL_LONG_MAX ((long) (PERL_ULONG_MAX >> 1)) # endif # endif #endif #ifndef PERL_LONG_MIN # ifdef LONG_MIN # define PERL_LONG_MIN ((long)LONG_MIN) # else # ifdef MINLONG # define PERL_LONG_MIN ((long)MINLONG) # else # define PERL_LONG_MIN (-PERL_LONG_MAX - ((3 & -1) == 3)) # endif # endif #endif #if defined(HAS_QUAD) && (defined(convex) || defined(uts)) # ifndef PERL_UQUAD_MAX # ifdef ULONGLONG_MAX # define PERL_UQUAD_MAX ((unsigned long long)ULONGLONG_MAX) # else # ifdef MAXULONGLONG # define PERL_UQUAD_MAX ((unsigned long long)MAXULONGLONG) # else # define PERL_UQUAD_MAX (~(unsigned long long)0) # endif # endif # endif # ifndef PERL_UQUAD_MIN # define PERL_UQUAD_MIN ((unsigned long long)0L) # endif # ifndef PERL_QUAD_MAX # ifdef LONGLONG_MAX # define PERL_QUAD_MAX ((long long)LONGLONG_MAX) # else # ifdef MAXLONGLONG # define PERL_QUAD_MAX ((long long)MAXLONGLONG) # else # define PERL_QUAD_MAX ((long long) (PERL_UQUAD_MAX >> 1)) # endif # endif # endif # ifndef PERL_QUAD_MIN # ifdef LONGLONG_MIN # define PERL_QUAD_MIN ((long long)LONGLONG_MIN) # else # ifdef MINLONGLONG # define PERL_QUAD_MIN ((long long)MINLONGLONG) # else # define PERL_QUAD_MIN (-PERL_QUAD_MAX - ((3 & -1) == 3)) # endif # endif # endif #endif /* This is based on code from 5.003 perl.h */ #ifdef HAS_QUAD # ifdef cray #ifndef IVTYPE # define IVTYPE int #endif #ifndef IV_MIN # define IV_MIN PERL_INT_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_INT_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_UINT_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_UINT_MAX #endif # ifdef INTSIZE #ifndef IVSIZE # define IVSIZE INTSIZE #endif # endif # else # if defined(convex) || defined(uts) #ifndef IVTYPE # define IVTYPE long long #endif #ifndef IV_MIN # define IV_MIN PERL_QUAD_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_QUAD_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_UQUAD_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_UQUAD_MAX #endif # ifdef LONGLONGSIZE #ifndef IVSIZE # define IVSIZE LONGLONGSIZE #endif # endif # else #ifndef IVTYPE # define IVTYPE long #endif #ifndef IV_MIN # define IV_MIN PERL_LONG_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_LONG_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_ULONG_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_ULONG_MAX #endif # ifdef LONGSIZE #ifndef IVSIZE # define IVSIZE LONGSIZE #endif # endif # endif # endif #ifndef IVSIZE # define IVSIZE 8 #endif #ifndef LONGSIZE # define LONGSIZE 8 #endif #ifndef PERL_QUAD_MIN # define PERL_QUAD_MIN IV_MIN #endif #ifndef PERL_QUAD_MAX # define PERL_QUAD_MAX IV_MAX #endif #ifndef PERL_UQUAD_MIN # define PERL_UQUAD_MIN UV_MIN #endif #ifndef PERL_UQUAD_MAX # define PERL_UQUAD_MAX UV_MAX #endif #else #ifndef IVTYPE # define IVTYPE long #endif #ifndef LONGSIZE # define LONGSIZE 4 #endif #ifndef IV_MIN # define IV_MIN PERL_LONG_MIN #endif #ifndef IV_MAX # define IV_MAX PERL_LONG_MAX #endif #ifndef UV_MIN # define UV_MIN PERL_ULONG_MIN #endif #ifndef UV_MAX # define UV_MAX PERL_ULONG_MAX #endif #endif #ifndef IVSIZE # ifdef LONGSIZE # define IVSIZE LONGSIZE # else # define IVSIZE 4 /* A bold guess, but the best we can make. */ # endif #endif #ifndef UVTYPE # define UVTYPE unsigned IVTYPE #endif #ifndef UVSIZE # define UVSIZE IVSIZE #endif #ifndef sv_setuv # define sv_setuv(sv, uv) \ STMT_START { \ UV TeMpUv = uv; \ if (TeMpUv <= IV_MAX) \ sv_setiv(sv, TeMpUv); \ else \ sv_setnv(sv, (double)TeMpUv); \ } STMT_END #endif #ifndef newSVuv # define newSVuv(uv) ((uv) <= IV_MAX ? newSViv((IV)uv) : newSVnv((NV)uv)) #endif #ifndef sv_2uv # define sv_2uv(sv) ((PL_Sv = (sv)), (UV) (SvNOK(PL_Sv) ? SvNV(PL_Sv) : sv_2nv(PL_Sv))) #endif #ifndef SvUVX # define SvUVX(sv) ((UV)SvIVX(sv)) #endif #ifndef SvUVXx # define SvUVXx(sv) SvUVX(sv) #endif #ifndef SvUV # define SvUV(sv) (SvIOK(sv) ? SvUVX(sv) : sv_2uv(sv)) #endif #ifndef SvUVx # define SvUVx(sv) ((PL_Sv = (sv)), SvUV(PL_Sv)) #endif /* Hint: sv_uv * Always use the SvUVx() macro instead of sv_uv(). */ #ifndef sv_uv # define sv_uv(sv) SvUVx(sv) #endif #if !defined(SvUOK) && defined(SvIOK_UV) # define SvUOK(sv) SvIOK_UV(sv) #endif #ifndef XST_mUV # define XST_mUV(i,v) (ST(i) = sv_2mortal(newSVuv(v)) ) #endif #ifndef XSRETURN_UV # define XSRETURN_UV(v) STMT_START { XST_mUV(0,v); XSRETURN(1); } STMT_END #endif #ifndef PUSHu # define PUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); PUSHTARG; } STMT_END #endif #ifndef XPUSHu # define XPUSHu(u) STMT_START { sv_setuv(TARG, (UV)(u)); XPUSHTARG; } STMT_END #endif #ifdef HAS_MEMCMP #ifndef memNE # define memNE(s1,s2,l) (memcmp(s1,s2,l)) #endif #ifndef memEQ # define memEQ(s1,s2,l) (!memcmp(s1,s2,l)) #endif #else #ifndef memNE # define memNE(s1,s2,l) (bcmp(s1,s2,l)) #endif #ifndef memEQ # define memEQ(s1,s2,l) (!bcmp(s1,s2,l)) #endif #endif #ifndef memEQs # define memEQs(s1, l, s2) \ (sizeof(s2)-1 == l && memEQ(s1, (s2 ""), (sizeof(s2)-1))) #endif #ifndef memNEs # define memNEs(s1, l, s2) !memEQs(s1, l, s2) #endif #ifndef MoveD # define MoveD(s,d,n,t) memmove((char*)(d),(char*)(s), (n) * sizeof(t)) #endif #ifndef CopyD # define CopyD(s,d,n,t) memcpy((char*)(d),(char*)(s), (n) * sizeof(t)) #endif #ifdef HAS_MEMSET #ifndef ZeroD # define ZeroD(d,n,t) memzero((char*)(d), (n) * sizeof(t)) #endif #else #ifndef ZeroD # define ZeroD(d,n,t) ((void)memzero((char*)(d), (n) * sizeof(t)), d) #endif #endif #ifndef PoisonWith # define PoisonWith(d,n,t,b) (void)memset((char*)(d), (U8)(b), (n) * sizeof(t)) #endif #ifndef PoisonNew # define PoisonNew(d,n,t) PoisonWith(d,n,t,0xAB) #endif #ifndef PoisonFree # define PoisonFree(d,n,t) PoisonWith(d,n,t,0xEF) #endif #ifndef Poison # define Poison(d,n,t) PoisonFree(d,n,t) #endif #ifndef Newx # define Newx(v,n,t) New(0,v,n,t) #endif #ifndef Newxc # define Newxc(v,n,t,c) Newc(0,v,n,t,c) #endif #ifndef Newxz # define Newxz(v,n,t) Newz(0,v,n,t) #endif #ifndef PERL_UNUSED_DECL # ifdef HASATTRIBUTE # if (defined(__GNUC__) && defined(__cplusplus)) || defined(__INTEL_COMPILER) # define PERL_UNUSED_DECL # else # define PERL_UNUSED_DECL __attribute__((unused)) # endif # else # define PERL_UNUSED_DECL # endif #endif #ifndef PERL_UNUSED_ARG # if defined(lint) && defined(S_SPLINT_S) /* www.splint.org */ # include # define PERL_UNUSED_ARG(x) NOTE(ARGUNUSED(x)) # else # define PERL_UNUSED_ARG(x) ((void)x) # endif #endif #ifndef PERL_UNUSED_VAR # define PERL_UNUSED_VAR(x) ((void)x) #endif #ifndef PERL_UNUSED_CONTEXT # ifdef USE_ITHREADS # define PERL_UNUSED_CONTEXT PERL_UNUSED_ARG(my_perl) # else # define PERL_UNUSED_CONTEXT # endif #endif #ifndef NOOP # define NOOP /*EMPTY*/(void)0 #endif #ifndef dNOOP # define dNOOP extern int /*@unused@*/ Perl___notused PERL_UNUSED_DECL #endif #ifndef NVTYPE # if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE) # define NVTYPE long double # else # define NVTYPE double # endif typedef NVTYPE NV; #endif #ifndef INT2PTR # if (IVSIZE == PTRSIZE) && (UVSIZE == PTRSIZE) # define PTRV UV # define INT2PTR(any,d) (any)(d) # else # if PTRSIZE == LONGSIZE # define PTRV unsigned long # else # define PTRV unsigned # endif # define INT2PTR(any,d) (any)(PTRV)(d) # endif #endif #ifndef PTR2ul # if PTRSIZE == LONGSIZE # define PTR2ul(p) (unsigned long)(p) # else # define PTR2ul(p) INT2PTR(unsigned long,p) # endif #endif #ifndef PTR2nat # define PTR2nat(p) (PTRV)(p) #endif #ifndef NUM2PTR # define NUM2PTR(any,d) (any)PTR2nat(d) #endif #ifndef PTR2IV # define PTR2IV(p) INT2PTR(IV,p) #endif #ifndef PTR2UV # define PTR2UV(p) INT2PTR(UV,p) #endif #ifndef PTR2NV # define PTR2NV(p) NUM2PTR(NV,p) #endif #undef START_EXTERN_C #undef END_EXTERN_C #undef EXTERN_C #ifdef __cplusplus # define START_EXTERN_C extern "C" { # define END_EXTERN_C } # define EXTERN_C extern "C" #else # define START_EXTERN_C # define END_EXTERN_C # define EXTERN_C extern #endif #if defined(PERL_GCC_PEDANTIC) # ifndef PERL_GCC_BRACE_GROUPS_FORBIDDEN # define PERL_GCC_BRACE_GROUPS_FORBIDDEN # endif #endif #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) && !defined(__cplusplus) # ifndef PERL_USE_GCC_BRACE_GROUPS # define PERL_USE_GCC_BRACE_GROUPS # endif #endif #undef STMT_START #undef STMT_END #ifdef PERL_USE_GCC_BRACE_GROUPS # define STMT_START (void)( /* gcc supports ``({ STATEMENTS; })'' */ # define STMT_END ) #else # if defined(VOIDFLAGS) && (VOIDFLAGS) && (defined(sun) || defined(__sun__)) && !defined(__GNUC__) # define STMT_START if (1) # define STMT_END else (void)0 # else # define STMT_START do # define STMT_END while (0) # endif #endif #ifndef boolSV # define boolSV(b) ((b) ? &PL_sv_yes : &PL_sv_no) #endif /* DEFSV appears first in 5.004_56 */ #ifndef DEFSV # define DEFSV GvSV(PL_defgv) #endif #ifndef SAVE_DEFSV # define SAVE_DEFSV SAVESPTR(GvSV(PL_defgv)) #endif #ifndef DEFSV_set # define DEFSV_set(sv) (DEFSV = (sv)) #endif /* Older perls (<=5.003) lack AvFILLp */ #ifndef AvFILLp # define AvFILLp AvFILL #endif #ifndef ERRSV # define ERRSV get_sv("@",FALSE) #endif /* Hint: gv_stashpvn * This function's backport doesn't support the length parameter, but * rather ignores it. Portability can only be ensured if the length * parameter is used for speed reasons, but the length can always be * correctly computed from the string argument. */ #ifndef gv_stashpvn # define gv_stashpvn(str,len,create) gv_stashpv(str,create) #endif /* Replace: 1 */ #ifndef get_cv # define get_cv perl_get_cv #endif #ifndef get_sv # define get_sv perl_get_sv #endif #ifndef get_av # define get_av perl_get_av #endif #ifndef get_hv # define get_hv perl_get_hv #endif /* Replace: 0 */ #ifndef dUNDERBAR # define dUNDERBAR dNOOP #endif #ifndef UNDERBAR # define UNDERBAR DEFSV #endif #ifndef dAX # define dAX I32 ax = MARK - PL_stack_base + 1 #endif #ifndef dITEMS # define dITEMS I32 items = SP - MARK #endif #ifndef dXSTARG # define dXSTARG SV * targ = sv_newmortal() #endif #ifndef dAXMARK # define dAXMARK I32 ax = POPMARK; \ register SV ** const mark = PL_stack_base + ax++ #endif #ifndef XSprePUSH # define XSprePUSH (sp = PL_stack_base + ax - 1) #endif #if (PERL_BCDVERSION < 0x5005000) # undef XSRETURN # define XSRETURN(off) \ STMT_START { \ PL_stack_sp = PL_stack_base + ax + ((off) - 1); \ return; \ } STMT_END #endif #ifndef XSPROTO # define XSPROTO(name) void name(pTHX_ CV* cv) #endif #ifndef SVfARG # define SVfARG(p) ((void*)(p)) #endif #ifndef PERL_ABS # define PERL_ABS(x) ((x) < 0 ? -(x) : (x)) #endif #ifndef dVAR # define dVAR dNOOP #endif #ifndef SVf # define SVf "_" #endif #ifndef UTF8_MAXBYTES # define UTF8_MAXBYTES UTF8_MAXLEN #endif #ifndef CPERLscope # define CPERLscope(x) x #endif #ifndef PERL_HASH # define PERL_HASH(hash,str,len) \ STMT_START { \ const char *s_PeRlHaSh = str; \ I32 i_PeRlHaSh = len; \ U32 hash_PeRlHaSh = 0; \ while (i_PeRlHaSh--) \ hash_PeRlHaSh = hash_PeRlHaSh * 33 + *s_PeRlHaSh++; \ (hash) = hash_PeRlHaSh; \ } STMT_END #endif #ifndef PERLIO_FUNCS_DECL # ifdef PERLIO_FUNCS_CONST # define PERLIO_FUNCS_DECL(funcs) const PerlIO_funcs funcs # define PERLIO_FUNCS_CAST(funcs) (PerlIO_funcs*)(funcs) # else # define PERLIO_FUNCS_DECL(funcs) PerlIO_funcs funcs # define PERLIO_FUNCS_CAST(funcs) (funcs) # endif #endif /* provide these typedefs for older perls */ #if (PERL_BCDVERSION < 0x5009003) # ifdef ARGSproto typedef OP* (CPERLscope(*Perl_ppaddr_t))(ARGSproto); # else typedef OP* (CPERLscope(*Perl_ppaddr_t))(pTHX); # endif typedef OP* (CPERLscope(*Perl_check_t)) (pTHX_ OP*); #endif #ifndef isPSXSPC # define isPSXSPC(c) (isSPACE(c) || (c) == '\v') #endif #ifndef isBLANK # define isBLANK(c) ((c) == ' ' || (c) == '\t') #endif #ifdef EBCDIC #ifndef isALNUMC # define isALNUMC(c) isalnum(c) #endif #ifndef isASCII # define isASCII(c) isascii(c) #endif #ifndef isCNTRL # define isCNTRL(c) iscntrl(c) #endif #ifndef isGRAPH # define isGRAPH(c) isgraph(c) #endif #ifndef isPRINT # define isPRINT(c) isprint(c) #endif #ifndef isPUNCT # define isPUNCT(c) ispunct(c) #endif #ifndef isXDIGIT # define isXDIGIT(c) isxdigit(c) #endif #else # if (PERL_BCDVERSION < 0x5010000) /* Hint: isPRINT * The implementation in older perl versions includes all of the * isSPACE() characters, which is wrong. The version provided by * Devel::PPPort always overrides a present buggy version. */ # undef isPRINT # endif #ifdef HAS_QUAD # ifdef U64TYPE # define WIDEST_UTYPE U64TYPE # else # define WIDEST_UTYPE Quad_t # endif #else # define WIDEST_UTYPE U32 #endif #ifndef isALNUMC # define isALNUMC(c) (isALPHA(c) || isDIGIT(c)) #endif #ifndef isASCII # define isASCII(c) ((WIDEST_UTYPE) (c) <= 127) #endif #ifndef isCNTRL # define isCNTRL(c) ((WIDEST_UTYPE) (c) < ' ' || (c) == 127) #endif #ifndef isGRAPH # define isGRAPH(c) (isALNUM(c) || isPUNCT(c)) #endif #ifndef isPRINT # define isPRINT(c) (((c) >= 32 && (c) < 127)) #endif #ifndef isPUNCT # define isPUNCT(c) (((c) >= 33 && (c) <= 47) || ((c) >= 58 && (c) <= 64) || ((c) >= 91 && (c) <= 96) || ((c) >= 123 && (c) <= 126)) #endif #ifndef isXDIGIT # define isXDIGIT(c) (isDIGIT(c) || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F')) #endif #endif /* Until we figure out how to support this in older perls... */ #if (PERL_BCDVERSION >= 0x5008000) #ifndef HeUTF8 # define HeUTF8(he) ((HeKLEN(he) == HEf_SVKEY) ? \ SvUTF8(HeKEY_sv(he)) : \ (U32)HeKUTF8(he)) #endif #endif #ifndef PERL_SIGNALS_UNSAFE_FLAG #define PERL_SIGNALS_UNSAFE_FLAG 0x0001 #if (PERL_BCDVERSION < 0x5008000) # define D_PPP_PERL_SIGNALS_INIT PERL_SIGNALS_UNSAFE_FLAG #else # define D_PPP_PERL_SIGNALS_INIT 0 #endif #if defined(NEED_PL_signals) static U32 DPPP_(my_PL_signals) = D_PPP_PERL_SIGNALS_INIT; #elif defined(NEED_PL_signals_GLOBAL) U32 DPPP_(my_PL_signals) = D_PPP_PERL_SIGNALS_INIT; #else extern U32 DPPP_(my_PL_signals); #endif #define PL_signals DPPP_(my_PL_signals) #endif /* Hint: PL_ppaddr * Calling an op via PL_ppaddr requires passing a context argument * for threaded builds. Since the context argument is different for * 5.005 perls, you can use aTHXR (supplied by ppport.h), which will * automatically be defined as the correct argument. */ #if (PERL_BCDVERSION <= 0x5005005) /* Replace: 1 */ # define PL_ppaddr ppaddr # define PL_no_modify no_modify /* Replace: 0 */ #endif #if (PERL_BCDVERSION <= 0x5004005) /* Replace: 1 */ # define PL_DBsignal DBsignal # define PL_DBsingle DBsingle # define PL_DBsub DBsub # define PL_DBtrace DBtrace # define PL_Sv Sv # define PL_bufend bufend # define PL_bufptr bufptr # define PL_compiling compiling # define PL_copline copline # define PL_curcop curcop # define PL_curstash curstash # define PL_debstash debstash # define PL_defgv defgv # define PL_diehook diehook # define PL_dirty dirty # define PL_dowarn dowarn # define PL_errgv errgv # define PL_error_count error_count # define PL_expect expect # define PL_hexdigit hexdigit # define PL_hints hints # define PL_in_my in_my # define PL_laststatval laststatval # define PL_lex_state lex_state # define PL_lex_stuff lex_stuff # define PL_linestr linestr # define PL_na na # define PL_perl_destruct_level perl_destruct_level # define PL_perldb perldb # define PL_rsfp_filters rsfp_filters # define PL_rsfp rsfp # define PL_stack_base stack_base # define PL_stack_sp stack_sp # define PL_statcache statcache # define PL_stdingv stdingv # define PL_sv_arenaroot sv_arenaroot # define PL_sv_no sv_no # define PL_sv_undef sv_undef # define PL_sv_yes sv_yes # define PL_tainted tainted # define PL_tainting tainting # define PL_tokenbuf tokenbuf /* Replace: 0 */ #endif /* Warning: PL_parser * For perl versions earlier than 5.9.5, this is an always * non-NULL dummy. Also, it cannot be dereferenced. Don't * use it if you can avoid is and unless you absolutely know * what you're doing. * If you always check that PL_parser is non-NULL, you can * define DPPP_PL_parser_NO_DUMMY to avoid the creation of * a dummy parser structure. */ #if (PERL_BCDVERSION >= 0x5009005) # ifdef DPPP_PL_parser_NO_DUMMY # define D_PPP_my_PL_parser_var(var) ((PL_parser ? PL_parser : \ (croak("panic: PL_parser == NULL in %s:%d", \ __FILE__, __LINE__), (yy_parser *) NULL))->var) # else # ifdef DPPP_PL_parser_NO_DUMMY_WARNING # define D_PPP_parser_dummy_warning(var) # else # define D_PPP_parser_dummy_warning(var) \ warn("warning: dummy PL_" #var " used in %s:%d", __FILE__, __LINE__), # endif # define D_PPP_my_PL_parser_var(var) ((PL_parser ? PL_parser : \ (D_PPP_parser_dummy_warning(var) &DPPP_(dummy_PL_parser)))->var) #if defined(NEED_PL_parser) static yy_parser DPPP_(dummy_PL_parser); #elif defined(NEED_PL_parser_GLOBAL) yy_parser DPPP_(dummy_PL_parser); #else extern yy_parser DPPP_(dummy_PL_parser); #endif # endif /* PL_expect, PL_copline, PL_rsfp, PL_rsfp_filters, PL_linestr, PL_bufptr, PL_bufend, PL_lex_state, PL_lex_stuff, PL_tokenbuf depends on PL_parser */ /* Warning: PL_expect, PL_copline, PL_rsfp, PL_rsfp_filters, PL_linestr, PL_bufptr, PL_bufend, PL_lex_state, PL_lex_stuff, PL_tokenbuf * Do not use this variable unless you know exactly what you're * doint. It is internal to the perl parser and may change or even * be removed in the future. As of perl 5.9.5, you have to check * for (PL_parser != NULL) for this variable to have any effect. * An always non-NULL PL_parser dummy is provided for earlier * perl versions. * If PL_parser is NULL when you try to access this variable, a * dummy is being accessed instead and a warning is issued unless * you define DPPP_PL_parser_NO_DUMMY_WARNING. * If DPPP_PL_parser_NO_DUMMY is defined, the code trying to access * this variable will croak with a panic message. */ # define PL_expect D_PPP_my_PL_parser_var(expect) # define PL_copline D_PPP_my_PL_parser_var(copline) # define PL_rsfp D_PPP_my_PL_parser_var(rsfp) # define PL_rsfp_filters D_PPP_my_PL_parser_var(rsfp_filters) # define PL_linestr D_PPP_my_PL_parser_var(linestr) # define PL_bufptr D_PPP_my_PL_parser_var(bufptr) # define PL_bufend D_PPP_my_PL_parser_var(bufend) # define PL_lex_state D_PPP_my_PL_parser_var(lex_state) # define PL_lex_stuff D_PPP_my_PL_parser_var(lex_stuff) # define PL_tokenbuf D_PPP_my_PL_parser_var(tokenbuf) # define PL_in_my D_PPP_my_PL_parser_var(in_my) # define PL_in_my_stash D_PPP_my_PL_parser_var(in_my_stash) # define PL_error_count D_PPP_my_PL_parser_var(error_count) #else /* ensure that PL_parser != NULL and cannot be dereferenced */ # define PL_parser ((void *) 1) #endif #ifndef mPUSHs # define mPUSHs(s) PUSHs(sv_2mortal(s)) #endif #ifndef PUSHmortal # define PUSHmortal PUSHs(sv_newmortal()) #endif #ifndef mPUSHp # define mPUSHp(p,l) sv_setpvn(PUSHmortal, (p), (l)) #endif #ifndef mPUSHn # define mPUSHn(n) sv_setnv(PUSHmortal, (NV)(n)) #endif #ifndef mPUSHi # define mPUSHi(i) sv_setiv(PUSHmortal, (IV)(i)) #endif #ifndef mPUSHu # define mPUSHu(u) sv_setuv(PUSHmortal, (UV)(u)) #endif #ifndef mXPUSHs # define mXPUSHs(s) XPUSHs(sv_2mortal(s)) #endif #ifndef XPUSHmortal # define XPUSHmortal XPUSHs(sv_newmortal()) #endif #ifndef mXPUSHp # define mXPUSHp(p,l) STMT_START { EXTEND(sp,1); sv_setpvn(PUSHmortal, (p), (l)); } STMT_END #endif #ifndef mXPUSHn # define mXPUSHn(n) STMT_START { EXTEND(sp,1); sv_setnv(PUSHmortal, (NV)(n)); } STMT_END #endif #ifndef mXPUSHi # define mXPUSHi(i) STMT_START { EXTEND(sp,1); sv_setiv(PUSHmortal, (IV)(i)); } STMT_END #endif #ifndef mXPUSHu # define mXPUSHu(u) STMT_START { EXTEND(sp,1); sv_setuv(PUSHmortal, (UV)(u)); } STMT_END #endif /* Replace: 1 */ #ifndef call_sv # define call_sv perl_call_sv #endif #ifndef call_pv # define call_pv perl_call_pv #endif #ifndef call_argv # define call_argv perl_call_argv #endif #ifndef call_method # define call_method perl_call_method #endif #ifndef eval_sv # define eval_sv perl_eval_sv #endif /* Replace: 0 */ #ifndef PERL_LOADMOD_DENY # define PERL_LOADMOD_DENY 0x1 #endif #ifndef PERL_LOADMOD_NOIMPORT # define PERL_LOADMOD_NOIMPORT 0x2 #endif #ifndef PERL_LOADMOD_IMPORT_OPS # define PERL_LOADMOD_IMPORT_OPS 0x4 #endif #ifndef G_METHOD # define G_METHOD 64 # ifdef call_sv # undef call_sv # endif # if (PERL_BCDVERSION < 0x5006000) # define call_sv(sv, flags) ((flags) & G_METHOD ? perl_call_method((char *) SvPV_nolen_const(sv), \ (flags) & ~G_METHOD) : perl_call_sv(sv, flags)) # else # define call_sv(sv, flags) ((flags) & G_METHOD ? Perl_call_method(aTHX_ (char *) SvPV_nolen_const(sv), \ (flags) & ~G_METHOD) : Perl_call_sv(aTHX_ sv, flags)) # endif #endif /* Replace perl_eval_pv with eval_pv */ #ifndef eval_pv #if defined(NEED_eval_pv) static SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error); static #else extern SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error); #endif #ifdef eval_pv # undef eval_pv #endif #define eval_pv(a,b) DPPP_(my_eval_pv)(aTHX_ a,b) #define Perl_eval_pv DPPP_(my_eval_pv) #if defined(NEED_eval_pv) || defined(NEED_eval_pv_GLOBAL) SV* DPPP_(my_eval_pv)(char *p, I32 croak_on_error) { dSP; SV* sv = newSVpv(p, 0); PUSHMARK(sp); eval_sv(sv, G_SCALAR); SvREFCNT_dec(sv); SPAGAIN; sv = POPs; PUTBACK; if (croak_on_error && SvTRUE(GvSV(errgv))) croak(SvPVx(GvSV(errgv), na)); return sv; } #endif #endif #ifndef vload_module #if defined(NEED_vload_module) static void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args); static #else extern void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args); #endif #ifdef vload_module # undef vload_module #endif #define vload_module(a,b,c,d) DPPP_(my_vload_module)(aTHX_ a,b,c,d) #define Perl_vload_module DPPP_(my_vload_module) #if defined(NEED_vload_module) || defined(NEED_vload_module_GLOBAL) void DPPP_(my_vload_module)(U32 flags, SV *name, SV *ver, va_list *args) { dTHR; dVAR; OP *veop, *imop; OP * const modname = newSVOP(OP_CONST, 0, name); /* 5.005 has a somewhat hacky force_normal that doesn't croak on SvREADONLY() if PL_compling is true. Current perls take care in ck_require() to correctly turn off SvREADONLY before calling force_normal_flags(). This seems a better fix than fudging PL_compling */ SvREADONLY_off(((SVOP*)modname)->op_sv); modname->op_private |= OPpCONST_BARE; if (ver) { veop = newSVOP(OP_CONST, 0, ver); } else veop = NULL; if (flags & PERL_LOADMOD_NOIMPORT) { imop = sawparens(newNULLLIST()); } else if (flags & PERL_LOADMOD_IMPORT_OPS) { imop = va_arg(*args, OP*); } else { SV *sv; imop = NULL; sv = va_arg(*args, SV*); while (sv) { imop = append_elem(OP_LIST, imop, newSVOP(OP_CONST, 0, sv)); sv = va_arg(*args, SV*); } } { const line_t ocopline = PL_copline; COP * const ocurcop = PL_curcop; const int oexpect = PL_expect; #if (PERL_BCDVERSION >= 0x5004000) utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(FALSE, 0), veop, modname, imop); #elif (PERL_BCDVERSION > 0x5003000) utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(), veop, modname, imop); #else utilize(!(flags & PERL_LOADMOD_DENY), start_subparse(), modname, imop); #endif PL_expect = oexpect; PL_copline = ocopline; PL_curcop = ocurcop; } } #endif #endif #ifndef load_module #if defined(NEED_load_module) static void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...); static #else extern void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...); #endif #ifdef load_module # undef load_module #endif #define load_module DPPP_(my_load_module) #define Perl_load_module DPPP_(my_load_module) #if defined(NEED_load_module) || defined(NEED_load_module_GLOBAL) void DPPP_(my_load_module)(U32 flags, SV *name, SV *ver, ...) { va_list args; va_start(args, ver); vload_module(flags, name, ver, &args); va_end(args); } #endif #endif #ifndef newRV_inc # define newRV_inc(sv) newRV(sv) /* Replace */ #endif #ifndef newRV_noinc #if defined(NEED_newRV_noinc) static SV * DPPP_(my_newRV_noinc)(SV *sv); static #else extern SV * DPPP_(my_newRV_noinc)(SV *sv); #endif #ifdef newRV_noinc # undef newRV_noinc #endif #define newRV_noinc(a) DPPP_(my_newRV_noinc)(aTHX_ a) #define Perl_newRV_noinc DPPP_(my_newRV_noinc) #if defined(NEED_newRV_noinc) || defined(NEED_newRV_noinc_GLOBAL) SV * DPPP_(my_newRV_noinc)(SV *sv) { SV *rv = (SV *)newRV(sv); SvREFCNT_dec(sv); return rv; } #endif #endif /* Hint: newCONSTSUB * Returns a CV* as of perl-5.7.1. This return value is not supported * by Devel::PPPort. */ /* newCONSTSUB from IO.xs is in the core starting with 5.004_63 */ #if (PERL_BCDVERSION < 0x5004063) && (PERL_BCDVERSION != 0x5004005) #if defined(NEED_newCONSTSUB) static void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv); static #else extern void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv); #endif #ifdef newCONSTSUB # undef newCONSTSUB #endif #define newCONSTSUB(a,b,c) DPPP_(my_newCONSTSUB)(aTHX_ a,b,c) #define Perl_newCONSTSUB DPPP_(my_newCONSTSUB) #if defined(NEED_newCONSTSUB) || defined(NEED_newCONSTSUB_GLOBAL) /* This is just a trick to avoid a dependency of newCONSTSUB on PL_parser */ /* (There's no PL_parser in perl < 5.005, so this is completely safe) */ #define D_PPP_PL_copline PL_copline void DPPP_(my_newCONSTSUB)(HV *stash, const char *name, SV *sv) { U32 oldhints = PL_hints; HV *old_cop_stash = PL_curcop->cop_stash; HV *old_curstash = PL_curstash; line_t oldline = PL_curcop->cop_line; PL_curcop->cop_line = D_PPP_PL_copline; PL_hints &= ~HINT_BLOCK_SCOPE; if (stash) PL_curstash = PL_curcop->cop_stash = stash; newSUB( #if (PERL_BCDVERSION < 0x5003022) start_subparse(), #elif (PERL_BCDVERSION == 0x5003022) start_subparse(0), #else /* 5.003_23 onwards */ start_subparse(FALSE, 0), #endif newSVOP(OP_CONST, 0, newSVpv((char *) name, 0)), newSVOP(OP_CONST, 0, &PL_sv_no), /* SvPV(&PL_sv_no) == "" -- GMB */ newSTATEOP(0, Nullch, newSVOP(OP_CONST, 0, sv)) ); PL_hints = oldhints; PL_curcop->cop_stash = old_cop_stash; PL_curstash = old_curstash; PL_curcop->cop_line = oldline; } #endif #endif /* * Boilerplate macros for initializing and accessing interpreter-local * data from C. All statics in extensions should be reworked to use * this, if you want to make the extension thread-safe. See ext/re/re.xs * for an example of the use of these macros. * * Code that uses these macros is responsible for the following: * 1. #define MY_CXT_KEY to a unique string, e.g. "DynaLoader_guts" * 2. Declare a typedef named my_cxt_t that is a structure that contains * all the data that needs to be interpreter-local. * 3. Use the START_MY_CXT macro after the declaration of my_cxt_t. * 4. Use the MY_CXT_INIT macro such that it is called exactly once * (typically put in the BOOT: section). * 5. Use the members of the my_cxt_t structure everywhere as * MY_CXT.member. * 6. Use the dMY_CXT macro (a declaration) in all the functions that * access MY_CXT. */ #if defined(MULTIPLICITY) || defined(PERL_OBJECT) || \ defined(PERL_CAPI) || defined(PERL_IMPLICIT_CONTEXT) #ifndef START_MY_CXT /* This must appear in all extensions that define a my_cxt_t structure, * right after the definition (i.e. at file scope). The non-threads * case below uses it to declare the data as static. */ #define START_MY_CXT #if (PERL_BCDVERSION < 0x5004068) /* Fetches the SV that keeps the per-interpreter data. */ #define dMY_CXT_SV \ SV *my_cxt_sv = get_sv(MY_CXT_KEY, FALSE) #else /* >= perl5.004_68 */ #define dMY_CXT_SV \ SV *my_cxt_sv = *hv_fetch(PL_modglobal, MY_CXT_KEY, \ sizeof(MY_CXT_KEY)-1, TRUE) #endif /* < perl5.004_68 */ /* This declaration should be used within all functions that use the * interpreter-local data. */ #define dMY_CXT \ dMY_CXT_SV; \ my_cxt_t *my_cxtp = INT2PTR(my_cxt_t*,SvUV(my_cxt_sv)) /* Creates and zeroes the per-interpreter data. * (We allocate my_cxtp in a Perl SV so that it will be released when * the interpreter goes away.) */ #define MY_CXT_INIT \ dMY_CXT_SV; \ /* newSV() allocates one more than needed */ \ my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\ Zero(my_cxtp, 1, my_cxt_t); \ sv_setuv(my_cxt_sv, PTR2UV(my_cxtp)) /* This macro must be used to access members of the my_cxt_t structure. * e.g. MYCXT.some_data */ #define MY_CXT (*my_cxtp) /* Judicious use of these macros can reduce the number of times dMY_CXT * is used. Use is similar to pTHX, aTHX etc. */ #define pMY_CXT my_cxt_t *my_cxtp #define pMY_CXT_ pMY_CXT, #define _pMY_CXT ,pMY_CXT #define aMY_CXT my_cxtp #define aMY_CXT_ aMY_CXT, #define _aMY_CXT ,aMY_CXT #endif /* START_MY_CXT */ #ifndef MY_CXT_CLONE /* Clones the per-interpreter data. */ #define MY_CXT_CLONE \ dMY_CXT_SV; \ my_cxt_t *my_cxtp = (my_cxt_t*)SvPVX(newSV(sizeof(my_cxt_t)-1));\ Copy(INT2PTR(my_cxt_t*, SvUV(my_cxt_sv)), my_cxtp, 1, my_cxt_t);\ sv_setuv(my_cxt_sv, PTR2UV(my_cxtp)) #endif #else /* single interpreter */ #ifndef START_MY_CXT #define START_MY_CXT static my_cxt_t my_cxt; #define dMY_CXT_SV dNOOP #define dMY_CXT dNOOP #define MY_CXT_INIT NOOP #define MY_CXT my_cxt #define pMY_CXT void #define pMY_CXT_ #define _pMY_CXT #define aMY_CXT #define aMY_CXT_ #define _aMY_CXT #endif /* START_MY_CXT */ #ifndef MY_CXT_CLONE #define MY_CXT_CLONE NOOP #endif #endif #ifndef IVdf # if IVSIZE == LONGSIZE # define IVdf "ld" # define UVuf "lu" # define UVof "lo" # define UVxf "lx" # define UVXf "lX" # elif IVSIZE == INTSIZE # define IVdf "d" # define UVuf "u" # define UVof "o" # define UVxf "x" # define UVXf "X" # else # error "cannot define IV/UV formats" # endif #endif #ifndef NVef # if defined(USE_LONG_DOUBLE) && defined(HAS_LONG_DOUBLE) && \ defined(PERL_PRIfldbl) && (PERL_BCDVERSION != 0x5006000) /* Not very likely, but let's try anyway. */ # define NVef PERL_PRIeldbl # define NVff PERL_PRIfldbl # define NVgf PERL_PRIgldbl # else # define NVef "e" # define NVff "f" # define NVgf "g" # endif #endif #ifndef SvREFCNT_inc # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ if (_sv) \ (SvREFCNT(_sv))++; \ _sv; \ }) # else # define SvREFCNT_inc(sv) \ ((PL_Sv=(SV*)(sv)) ? (++(SvREFCNT(PL_Sv)),PL_Sv) : NULL) # endif #endif #ifndef SvREFCNT_inc_simple # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc_simple(sv) \ ({ \ if (sv) \ (SvREFCNT(sv))++; \ (SV *)(sv); \ }) # else # define SvREFCNT_inc_simple(sv) \ ((sv) ? (SvREFCNT(sv)++,(SV*)(sv)) : NULL) # endif #endif #ifndef SvREFCNT_inc_NN # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc_NN(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ SvREFCNT(_sv)++; \ _sv; \ }) # else # define SvREFCNT_inc_NN(sv) \ (PL_Sv=(SV*)(sv),++(SvREFCNT(PL_Sv)),PL_Sv) # endif #endif #ifndef SvREFCNT_inc_void # ifdef PERL_USE_GCC_BRACE_GROUPS # define SvREFCNT_inc_void(sv) \ ({ \ SV * const _sv = (SV*)(sv); \ if (_sv) \ (void)(SvREFCNT(_sv)++); \ }) # else # define SvREFCNT_inc_void(sv) \ (void)((PL_Sv=(SV*)(sv)) ? ++(SvREFCNT(PL_Sv)) : 0) # endif #endif #ifndef SvREFCNT_inc_simple_void # define SvREFCNT_inc_simple_void(sv) STMT_START { if (sv) SvREFCNT(sv)++; } STMT_END #endif #ifndef SvREFCNT_inc_simple_NN # define SvREFCNT_inc_simple_NN(sv) (++SvREFCNT(sv), (SV*)(sv)) #endif #ifndef SvREFCNT_inc_void_NN # define SvREFCNT_inc_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) #endif #ifndef SvREFCNT_inc_simple_void_NN # define SvREFCNT_inc_simple_void_NN(sv) (void)(++SvREFCNT((SV*)(sv))) #endif #ifndef newSV_type #if defined(NEED_newSV_type) static SV* DPPP_(my_newSV_type)(pTHX_ svtype const t); static #else extern SV* DPPP_(my_newSV_type)(pTHX_ svtype const t); #endif #ifdef newSV_type # undef newSV_type #endif #define newSV_type(a) DPPP_(my_newSV_type)(aTHX_ a) #define Perl_newSV_type DPPP_(my_newSV_type) #if defined(NEED_newSV_type) || defined(NEED_newSV_type_GLOBAL) SV* DPPP_(my_newSV_type)(pTHX_ svtype const t) { SV* const sv = newSV(0); sv_upgrade(sv, t); return sv; } #endif #endif #if (PERL_BCDVERSION < 0x5006000) # define D_PPP_CONSTPV_ARG(x) ((char *) (x)) #else # define D_PPP_CONSTPV_ARG(x) (x) #endif #ifndef newSVpvn # define newSVpvn(data,len) ((data) \ ? ((len) ? newSVpv((data), (len)) : newSVpv("", 0)) \ : newSV(0)) #endif #ifndef newSVpvn_utf8 # define newSVpvn_utf8(s, len, u) newSVpvn_flags((s), (len), (u) ? SVf_UTF8 : 0) #endif #ifndef SVf_UTF8 # define SVf_UTF8 0 #endif #ifndef newSVpvn_flags #if defined(NEED_newSVpvn_flags) static SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags); static #else extern SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags); #endif #ifdef newSVpvn_flags # undef newSVpvn_flags #endif #define newSVpvn_flags(a,b,c) DPPP_(my_newSVpvn_flags)(aTHX_ a,b,c) #define Perl_newSVpvn_flags DPPP_(my_newSVpvn_flags) #if defined(NEED_newSVpvn_flags) || defined(NEED_newSVpvn_flags_GLOBAL) SV * DPPP_(my_newSVpvn_flags)(pTHX_ const char *s, STRLEN len, U32 flags) { SV *sv = newSVpvn(D_PPP_CONSTPV_ARG(s), len); SvFLAGS(sv) |= (flags & SVf_UTF8); return (flags & SVs_TEMP) ? sv_2mortal(sv) : sv; } #endif #endif /* Backwards compatibility stuff... :-( */ #if !defined(NEED_sv_2pv_flags) && defined(NEED_sv_2pv_nolen) # define NEED_sv_2pv_flags #endif #if !defined(NEED_sv_2pv_flags_GLOBAL) && defined(NEED_sv_2pv_nolen_GLOBAL) # define NEED_sv_2pv_flags_GLOBAL #endif /* Hint: sv_2pv_nolen * Use the SvPV_nolen() or SvPV_nolen_const() macros instead of sv_2pv_nolen(). */ #ifndef sv_2pv_nolen # define sv_2pv_nolen(sv) SvPV_nolen(sv) #endif #ifdef SvPVbyte /* Hint: SvPVbyte * Does not work in perl-5.6.1, ppport.h implements a version * borrowed from perl-5.7.3. */ #if (PERL_BCDVERSION < 0x5007000) #if defined(NEED_sv_2pvbyte) static char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp); static #else extern char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp); #endif #ifdef sv_2pvbyte # undef sv_2pvbyte #endif #define sv_2pvbyte(a,b) DPPP_(my_sv_2pvbyte)(aTHX_ a,b) #define Perl_sv_2pvbyte DPPP_(my_sv_2pvbyte) #if defined(NEED_sv_2pvbyte) || defined(NEED_sv_2pvbyte_GLOBAL) char * DPPP_(my_sv_2pvbyte)(pTHX_ SV *sv, STRLEN *lp) { sv_utf8_downgrade(sv,0); return SvPV(sv,*lp); } #endif /* Hint: sv_2pvbyte * Use the SvPVbyte() macro instead of sv_2pvbyte(). */ #undef SvPVbyte #define SvPVbyte(sv, lp) \ ((SvFLAGS(sv) & (SVf_POK|SVf_UTF8)) == (SVf_POK) \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pvbyte(sv, &lp)) #endif #else # define SvPVbyte SvPV # define sv_2pvbyte sv_2pv #endif #ifndef sv_2pvbyte_nolen # define sv_2pvbyte_nolen(sv) sv_2pv_nolen(sv) #endif /* Hint: sv_pvn * Always use the SvPV() macro instead of sv_pvn(). */ /* Hint: sv_pvn_force * Always use the SvPV_force() macro instead of sv_pvn_force(). */ /* If these are undefined, they're not handled by the core anyway */ #ifndef SV_IMMEDIATE_UNREF # define SV_IMMEDIATE_UNREF 0 #endif #ifndef SV_GMAGIC # define SV_GMAGIC 0 #endif #ifndef SV_COW_DROP_PV # define SV_COW_DROP_PV 0 #endif #ifndef SV_UTF8_NO_ENCODING # define SV_UTF8_NO_ENCODING 0 #endif #ifndef SV_NOSTEAL # define SV_NOSTEAL 0 #endif #ifndef SV_CONST_RETURN # define SV_CONST_RETURN 0 #endif #ifndef SV_MUTABLE_RETURN # define SV_MUTABLE_RETURN 0 #endif #ifndef SV_SMAGIC # define SV_SMAGIC 0 #endif #ifndef SV_HAS_TRAILING_NUL # define SV_HAS_TRAILING_NUL 0 #endif #ifndef SV_COW_SHARED_HASH_KEYS # define SV_COW_SHARED_HASH_KEYS 0 #endif #if (PERL_BCDVERSION < 0x5007002) #if defined(NEED_sv_2pv_flags) static char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); static #else extern char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); #endif #ifdef sv_2pv_flags # undef sv_2pv_flags #endif #define sv_2pv_flags(a,b,c) DPPP_(my_sv_2pv_flags)(aTHX_ a,b,c) #define Perl_sv_2pv_flags DPPP_(my_sv_2pv_flags) #if defined(NEED_sv_2pv_flags) || defined(NEED_sv_2pv_flags_GLOBAL) char * DPPP_(my_sv_2pv_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags) { STRLEN n_a = (STRLEN) flags; return sv_2pv(sv, lp ? lp : &n_a); } #endif #if defined(NEED_sv_pvn_force_flags) static char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); static #else extern char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags); #endif #ifdef sv_pvn_force_flags # undef sv_pvn_force_flags #endif #define sv_pvn_force_flags(a,b,c) DPPP_(my_sv_pvn_force_flags)(aTHX_ a,b,c) #define Perl_sv_pvn_force_flags DPPP_(my_sv_pvn_force_flags) #if defined(NEED_sv_pvn_force_flags) || defined(NEED_sv_pvn_force_flags_GLOBAL) char * DPPP_(my_sv_pvn_force_flags)(pTHX_ SV *sv, STRLEN *lp, I32 flags) { STRLEN n_a = (STRLEN) flags; return sv_pvn_force(sv, lp ? lp : &n_a); } #endif #endif #if (PERL_BCDVERSION < 0x5008008) || ( (PERL_BCDVERSION >= 0x5009000) && (PERL_BCDVERSION < 0x5009003) ) # define DPPP_SVPV_NOLEN_LP_ARG &PL_na #else # define DPPP_SVPV_NOLEN_LP_ARG 0 #endif #ifndef SvPV_const # define SvPV_const(sv, lp) SvPV_flags_const(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_mutable # define SvPV_mutable(sv, lp) SvPV_flags_mutable(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_flags # define SvPV_flags(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_2pv_flags(sv, &lp, flags)) #endif #ifndef SvPV_flags_const # define SvPV_flags_const(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_const(sv)) : \ (const char*) sv_2pv_flags(sv, &lp, flags|SV_CONST_RETURN)) #endif #ifndef SvPV_flags_const_nolen # define SvPV_flags_const_nolen(sv, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX_const(sv) : \ (const char*) sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, flags|SV_CONST_RETURN)) #endif #ifndef SvPV_flags_mutable # define SvPV_flags_mutable(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) : \ sv_2pv_flags(sv, &lp, flags|SV_MUTABLE_RETURN)) #endif #ifndef SvPV_force # define SvPV_force(sv, lp) SvPV_force_flags(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_force_nolen # define SvPV_force_nolen(sv) SvPV_force_flags_nolen(sv, SV_GMAGIC) #endif #ifndef SvPV_force_mutable # define SvPV_force_mutable(sv, lp) SvPV_force_flags_mutable(sv, lp, SV_GMAGIC) #endif #ifndef SvPV_force_nomg # define SvPV_force_nomg(sv, lp) SvPV_force_flags(sv, lp, 0) #endif #ifndef SvPV_force_nomg_nolen # define SvPV_force_nomg_nolen(sv) SvPV_force_flags_nolen(sv, 0) #endif #ifndef SvPV_force_flags # define SvPV_force_flags(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX(sv)) : sv_pvn_force_flags(sv, &lp, flags)) #endif #ifndef SvPV_force_flags_nolen # define SvPV_force_flags_nolen(sv, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? SvPVX(sv) : sv_pvn_force_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, flags)) #endif #ifndef SvPV_force_flags_mutable # define SvPV_force_flags_mutable(sv, lp, flags) \ ((SvFLAGS(sv) & (SVf_POK|SVf_THINKFIRST)) == SVf_POK \ ? ((lp = SvCUR(sv)), SvPVX_mutable(sv)) \ : sv_pvn_force_flags(sv, &lp, flags|SV_MUTABLE_RETURN)) #endif #ifndef SvPV_nolen # define SvPV_nolen(sv) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC)) #endif #ifndef SvPV_nolen_const # define SvPV_nolen_const(sv) \ ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX_const(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, SV_GMAGIC|SV_CONST_RETURN)) #endif #ifndef SvPV_nomg # define SvPV_nomg(sv, lp) SvPV_flags(sv, lp, 0) #endif #ifndef SvPV_nomg_const # define SvPV_nomg_const(sv, lp) SvPV_flags_const(sv, lp, 0) #endif #ifndef SvPV_nomg_const_nolen # define SvPV_nomg_const_nolen(sv) SvPV_flags_const_nolen(sv, 0) #endif #ifndef SvPV_nomg_nolen # define SvPV_nomg_nolen(sv) ((SvFLAGS(sv) & (SVf_POK)) == SVf_POK \ ? SvPVX(sv) : sv_2pv_flags(sv, DPPP_SVPV_NOLEN_LP_ARG, 0)) #endif #ifndef SvPV_renew # define SvPV_renew(sv,n) STMT_START { SvLEN_set(sv, n); \ SvPV_set((sv), (char *) saferealloc( \ (Malloc_t)SvPVX(sv), (MEM_SIZE)((n)))); \ } STMT_END #endif #ifndef SvMAGIC_set # define SvMAGIC_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \ (((XPVMG*) SvANY(sv))->xmg_magic = (val)); } STMT_END #endif #if (PERL_BCDVERSION < 0x5009003) #ifndef SvPVX_const # define SvPVX_const(sv) ((const char*) (0 + SvPVX(sv))) #endif #ifndef SvPVX_mutable # define SvPVX_mutable(sv) (0 + SvPVX(sv)) #endif #ifndef SvRV_set # define SvRV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_RV); \ (((XRV*) SvANY(sv))->xrv_rv = (val)); } STMT_END #endif #else #ifndef SvPVX_const # define SvPVX_const(sv) ((const char*)((sv)->sv_u.svu_pv)) #endif #ifndef SvPVX_mutable # define SvPVX_mutable(sv) ((sv)->sv_u.svu_pv) #endif #ifndef SvRV_set # define SvRV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_RV); \ ((sv)->sv_u.svu_rv = (val)); } STMT_END #endif #endif #ifndef SvSTASH_set # define SvSTASH_set(sv, val) \ STMT_START { assert(SvTYPE(sv) >= SVt_PVMG); \ (((XPVMG*) SvANY(sv))->xmg_stash = (val)); } STMT_END #endif #if (PERL_BCDVERSION < 0x5004000) #ifndef SvUV_set # define SvUV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ (((XPVIV*) SvANY(sv))->xiv_iv = (IV) (val)); } STMT_END #endif #else #ifndef SvUV_set # define SvUV_set(sv, val) \ STMT_START { assert(SvTYPE(sv) == SVt_IV || SvTYPE(sv) >= SVt_PVIV); \ (((XPVUV*) SvANY(sv))->xuv_uv = (val)); } STMT_END #endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(vnewSVpvf) #if defined(NEED_vnewSVpvf) static SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args); static #else extern SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args); #endif #ifdef vnewSVpvf # undef vnewSVpvf #endif #define vnewSVpvf(a,b) DPPP_(my_vnewSVpvf)(aTHX_ a,b) #define Perl_vnewSVpvf DPPP_(my_vnewSVpvf) #if defined(NEED_vnewSVpvf) || defined(NEED_vnewSVpvf_GLOBAL) SV * DPPP_(my_vnewSVpvf)(pTHX_ const char *pat, va_list *args) { register SV *sv = newSV(0); sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); return sv; } #endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vcatpvf) # define sv_vcatpvf(sv, pat, args) sv_vcatpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)) #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vsetpvf) # define sv_vsetpvf(sv, pat, args) sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)) #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_catpvf_mg) #if defined(NEED_sv_catpvf_mg) static void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...); #endif #define Perl_sv_catpvf_mg DPPP_(my_sv_catpvf_mg) #if defined(NEED_sv_catpvf_mg) || defined(NEED_sv_catpvf_mg_GLOBAL) void DPPP_(my_sv_catpvf_mg)(pTHX_ SV *sv, const char *pat, ...) { va_list args; va_start(args, pat); sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #ifdef PERL_IMPLICIT_CONTEXT #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_catpvf_mg_nocontext) #if defined(NEED_sv_catpvf_mg_nocontext) static void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...); #endif #define sv_catpvf_mg_nocontext DPPP_(my_sv_catpvf_mg_nocontext) #define Perl_sv_catpvf_mg_nocontext DPPP_(my_sv_catpvf_mg_nocontext) #if defined(NEED_sv_catpvf_mg_nocontext) || defined(NEED_sv_catpvf_mg_nocontext_GLOBAL) void DPPP_(my_sv_catpvf_mg_nocontext)(SV *sv, const char *pat, ...) { dTHX; va_list args; va_start(args, pat); sv_vcatpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #endif /* sv_catpvf_mg depends on sv_catpvf_mg_nocontext */ #ifndef sv_catpvf_mg # ifdef PERL_IMPLICIT_CONTEXT # define sv_catpvf_mg Perl_sv_catpvf_mg_nocontext # else # define sv_catpvf_mg Perl_sv_catpvf_mg # endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vcatpvf_mg) # define sv_vcatpvf_mg(sv, pat, args) \ STMT_START { \ sv_vcatpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); \ SvSETMAGIC(sv); \ } STMT_END #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_setpvf_mg) #if defined(NEED_sv_setpvf_mg) static void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...); #endif #define Perl_sv_setpvf_mg DPPP_(my_sv_setpvf_mg) #if defined(NEED_sv_setpvf_mg) || defined(NEED_sv_setpvf_mg_GLOBAL) void DPPP_(my_sv_setpvf_mg)(pTHX_ SV *sv, const char *pat, ...) { va_list args; va_start(args, pat); sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #ifdef PERL_IMPLICIT_CONTEXT #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_setpvf_mg_nocontext) #if defined(NEED_sv_setpvf_mg_nocontext) static void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...); static #else extern void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...); #endif #define sv_setpvf_mg_nocontext DPPP_(my_sv_setpvf_mg_nocontext) #define Perl_sv_setpvf_mg_nocontext DPPP_(my_sv_setpvf_mg_nocontext) #if defined(NEED_sv_setpvf_mg_nocontext) || defined(NEED_sv_setpvf_mg_nocontext_GLOBAL) void DPPP_(my_sv_setpvf_mg_nocontext)(SV *sv, const char *pat, ...) { dTHX; va_list args; va_start(args, pat); sv_vsetpvfn(sv, pat, strlen(pat), &args, Null(SV**), 0, Null(bool*)); SvSETMAGIC(sv); va_end(args); } #endif #endif #endif /* sv_setpvf_mg depends on sv_setpvf_mg_nocontext */ #ifndef sv_setpvf_mg # ifdef PERL_IMPLICIT_CONTEXT # define sv_setpvf_mg Perl_sv_setpvf_mg_nocontext # else # define sv_setpvf_mg Perl_sv_setpvf_mg # endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(sv_vsetpvf_mg) # define sv_vsetpvf_mg(sv, pat, args) \ STMT_START { \ sv_vsetpvfn(sv, pat, strlen(pat), args, Null(SV**), 0, Null(bool*)); \ SvSETMAGIC(sv); \ } STMT_END #endif /* Hint: newSVpvn_share * The SVs created by this function only mimic the behaviour of * shared PVs without really being shared. Only use if you know * what you're doing. */ #ifndef newSVpvn_share #if defined(NEED_newSVpvn_share) static SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash); static #else extern SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash); #endif #ifdef newSVpvn_share # undef newSVpvn_share #endif #define newSVpvn_share(a,b,c) DPPP_(my_newSVpvn_share)(aTHX_ a,b,c) #define Perl_newSVpvn_share DPPP_(my_newSVpvn_share) #if defined(NEED_newSVpvn_share) || defined(NEED_newSVpvn_share_GLOBAL) SV * DPPP_(my_newSVpvn_share)(pTHX_ const char *src, I32 len, U32 hash) { SV *sv; if (len < 0) len = -len; if (!hash) PERL_HASH(hash, (char*) src, len); sv = newSVpvn((char *) src, len); sv_upgrade(sv, SVt_PVIV); SvIVX(sv) = hash; SvREADONLY_on(sv); SvPOK_on(sv); return sv; } #endif #endif #ifndef SvSHARED_HASH # define SvSHARED_HASH(sv) (0 + SvUVX(sv)) #endif #ifndef HvNAME_get # define HvNAME_get(hv) HvNAME(hv) #endif #ifndef HvNAMELEN_get # define HvNAMELEN_get(hv) (HvNAME_get(hv) ? (I32)strlen(HvNAME_get(hv)) : 0) #endif #ifndef GvSVn # define GvSVn(gv) GvSV(gv) #endif #ifndef isGV_with_GP # define isGV_with_GP(gv) isGV(gv) #endif #ifndef gv_fetchpvn_flags # define gv_fetchpvn_flags(name, len, flags, svt) gv_fetchpv(name, flags, svt) #endif #ifndef gv_fetchsv # define gv_fetchsv(name, flags, svt) gv_fetchpv(SvPV_nolen_const(name), flags, svt) #endif #ifndef get_cvn_flags # define get_cvn_flags(name, namelen, flags) get_cv(name, flags) #endif #ifndef WARN_ALL # define WARN_ALL 0 #endif #ifndef WARN_CLOSURE # define WARN_CLOSURE 1 #endif #ifndef WARN_DEPRECATED # define WARN_DEPRECATED 2 #endif #ifndef WARN_EXITING # define WARN_EXITING 3 #endif #ifndef WARN_GLOB # define WARN_GLOB 4 #endif #ifndef WARN_IO # define WARN_IO 5 #endif #ifndef WARN_CLOSED # define WARN_CLOSED 6 #endif #ifndef WARN_EXEC # define WARN_EXEC 7 #endif #ifndef WARN_LAYER # define WARN_LAYER 8 #endif #ifndef WARN_NEWLINE # define WARN_NEWLINE 9 #endif #ifndef WARN_PIPE # define WARN_PIPE 10 #endif #ifndef WARN_UNOPENED # define WARN_UNOPENED 11 #endif #ifndef WARN_MISC # define WARN_MISC 12 #endif #ifndef WARN_NUMERIC # define WARN_NUMERIC 13 #endif #ifndef WARN_ONCE # define WARN_ONCE 14 #endif #ifndef WARN_OVERFLOW # define WARN_OVERFLOW 15 #endif #ifndef WARN_PACK # define WARN_PACK 16 #endif #ifndef WARN_PORTABLE # define WARN_PORTABLE 17 #endif #ifndef WARN_RECURSION # define WARN_RECURSION 18 #endif #ifndef WARN_REDEFINE # define WARN_REDEFINE 19 #endif #ifndef WARN_REGEXP # define WARN_REGEXP 20 #endif #ifndef WARN_SEVERE # define WARN_SEVERE 21 #endif #ifndef WARN_DEBUGGING # define WARN_DEBUGGING 22 #endif #ifndef WARN_INPLACE # define WARN_INPLACE 23 #endif #ifndef WARN_INTERNAL # define WARN_INTERNAL 24 #endif #ifndef WARN_MALLOC # define WARN_MALLOC 25 #endif #ifndef WARN_SIGNAL # define WARN_SIGNAL 26 #endif #ifndef WARN_SUBSTR # define WARN_SUBSTR 27 #endif #ifndef WARN_SYNTAX # define WARN_SYNTAX 28 #endif #ifndef WARN_AMBIGUOUS # define WARN_AMBIGUOUS 29 #endif #ifndef WARN_BAREWORD # define WARN_BAREWORD 30 #endif #ifndef WARN_DIGIT # define WARN_DIGIT 31 #endif #ifndef WARN_PARENTHESIS # define WARN_PARENTHESIS 32 #endif #ifndef WARN_PRECEDENCE # define WARN_PRECEDENCE 33 #endif #ifndef WARN_PRINTF # define WARN_PRINTF 34 #endif #ifndef WARN_PROTOTYPE # define WARN_PROTOTYPE 35 #endif #ifndef WARN_QW # define WARN_QW 36 #endif #ifndef WARN_RESERVED # define WARN_RESERVED 37 #endif #ifndef WARN_SEMICOLON # define WARN_SEMICOLON 38 #endif #ifndef WARN_TAINT # define WARN_TAINT 39 #endif #ifndef WARN_THREADS # define WARN_THREADS 40 #endif #ifndef WARN_UNINITIALIZED # define WARN_UNINITIALIZED 41 #endif #ifndef WARN_UNPACK # define WARN_UNPACK 42 #endif #ifndef WARN_UNTIE # define WARN_UNTIE 43 #endif #ifndef WARN_UTF8 # define WARN_UTF8 44 #endif #ifndef WARN_VOID # define WARN_VOID 45 #endif #ifndef WARN_ASSERTIONS # define WARN_ASSERTIONS 46 #endif #ifndef packWARN # define packWARN(a) (a) #endif #ifndef ckWARN # ifdef G_WARN_ON # define ckWARN(a) (PL_dowarn & G_WARN_ON) # else # define ckWARN(a) PL_dowarn # endif #endif #if (PERL_BCDVERSION >= 0x5004000) && !defined(warner) #if defined(NEED_warner) static void DPPP_(my_warner)(U32 err, const char *pat, ...); static #else extern void DPPP_(my_warner)(U32 err, const char *pat, ...); #endif #define Perl_warner DPPP_(my_warner) #if defined(NEED_warner) || defined(NEED_warner_GLOBAL) void DPPP_(my_warner)(U32 err, const char *pat, ...) { SV *sv; va_list args; PERL_UNUSED_ARG(err); va_start(args, pat); sv = vnewSVpvf(pat, &args); va_end(args); sv_2mortal(sv); warn("%s", SvPV_nolen(sv)); } #define warner Perl_warner #define Perl_warner_nocontext Perl_warner #endif #endif /* concatenating with "" ensures that only literal strings are accepted as argument * note that STR_WITH_LEN() can't be used as argument to macros or functions that * under some configurations might be macros */ #ifndef STR_WITH_LEN # define STR_WITH_LEN(s) (s ""), (sizeof(s)-1) #endif #ifndef newSVpvs # define newSVpvs(str) newSVpvn(str "", sizeof(str) - 1) #endif #ifndef newSVpvs_flags # define newSVpvs_flags(str, flags) newSVpvn_flags(str "", sizeof(str) - 1, flags) #endif #ifndef newSVpvs_share # define newSVpvs_share(str) newSVpvn_share(str "", sizeof(str) - 1, 0) #endif #ifndef sv_catpvs # define sv_catpvs(sv, str) sv_catpvn(sv, str "", sizeof(str) - 1) #endif #ifndef sv_setpvs # define sv_setpvs(sv, str) sv_setpvn(sv, str "", sizeof(str) - 1) #endif #ifndef hv_fetchs # define hv_fetchs(hv, key, lval) hv_fetch(hv, key "", sizeof(key) - 1, lval) #endif #ifndef hv_stores # define hv_stores(hv, key, val) hv_store(hv, key "", sizeof(key) - 1, val, 0) #endif #ifndef gv_fetchpvs # define gv_fetchpvs(name, flags, svt) gv_fetchpvn_flags(name "", sizeof(name) - 1, flags, svt) #endif #ifndef gv_stashpvs # define gv_stashpvs(name, flags) gv_stashpvn(name "", sizeof(name) - 1, flags) #endif #ifndef get_cvs # define get_cvs(name, flags) get_cvn_flags(name "", sizeof(name)-1, flags) #endif #ifndef SvGETMAGIC # define SvGETMAGIC(x) STMT_START { if (SvGMAGICAL(x)) mg_get(x); } STMT_END #endif /* Some random bits for sv_unmagicext. These should probably be pulled in for real and organized at some point */ #ifndef HEf_SVKEY # define HEf_SVKEY -2 #endif #if defined(__GNUC__) && !defined(PERL_GCC_BRACE_GROUPS_FORBIDDEN) # define MUTABLE_PTR(p) ({ void *_p = (p); _p; }) #else # define MUTABLE_PTR(p) ((void *) (p)) #endif #define MUTABLE_SV(p) ((SV *)MUTABLE_PTR(p)) /* end of random bits */ #ifndef PERL_MAGIC_sv # define PERL_MAGIC_sv '\0' #endif #ifndef PERL_MAGIC_overload # define PERL_MAGIC_overload 'A' #endif #ifndef PERL_MAGIC_overload_elem # define PERL_MAGIC_overload_elem 'a' #endif #ifndef PERL_MAGIC_overload_table # define PERL_MAGIC_overload_table 'c' #endif #ifndef PERL_MAGIC_bm # define PERL_MAGIC_bm 'B' #endif #ifndef PERL_MAGIC_regdata # define PERL_MAGIC_regdata 'D' #endif #ifndef PERL_MAGIC_regdatum # define PERL_MAGIC_regdatum 'd' #endif #ifndef PERL_MAGIC_env # define PERL_MAGIC_env 'E' #endif #ifndef PERL_MAGIC_envelem # define PERL_MAGIC_envelem 'e' #endif #ifndef PERL_MAGIC_fm # define PERL_MAGIC_fm 'f' #endif #ifndef PERL_MAGIC_regex_global # define PERL_MAGIC_regex_global 'g' #endif #ifndef PERL_MAGIC_isa # define PERL_MAGIC_isa 'I' #endif #ifndef PERL_MAGIC_isaelem # define PERL_MAGIC_isaelem 'i' #endif #ifndef PERL_MAGIC_nkeys # define PERL_MAGIC_nkeys 'k' #endif #ifndef PERL_MAGIC_dbfile # define PERL_MAGIC_dbfile 'L' #endif #ifndef PERL_MAGIC_dbline # define PERL_MAGIC_dbline 'l' #endif #ifndef PERL_MAGIC_mutex # define PERL_MAGIC_mutex 'm' #endif #ifndef PERL_MAGIC_shared # define PERL_MAGIC_shared 'N' #endif #ifndef PERL_MAGIC_shared_scalar # define PERL_MAGIC_shared_scalar 'n' #endif #ifndef PERL_MAGIC_collxfrm # define PERL_MAGIC_collxfrm 'o' #endif #ifndef PERL_MAGIC_tied # define PERL_MAGIC_tied 'P' #endif #ifndef PERL_MAGIC_tiedelem # define PERL_MAGIC_tiedelem 'p' #endif #ifndef PERL_MAGIC_tiedscalar # define PERL_MAGIC_tiedscalar 'q' #endif #ifndef PERL_MAGIC_qr # define PERL_MAGIC_qr 'r' #endif #ifndef PERL_MAGIC_sig # define PERL_MAGIC_sig 'S' #endif #ifndef PERL_MAGIC_sigelem # define PERL_MAGIC_sigelem 's' #endif #ifndef PERL_MAGIC_taint # define PERL_MAGIC_taint 't' #endif #ifndef PERL_MAGIC_uvar # define PERL_MAGIC_uvar 'U' #endif #ifndef PERL_MAGIC_uvar_elem # define PERL_MAGIC_uvar_elem 'u' #endif #ifndef PERL_MAGIC_vstring # define PERL_MAGIC_vstring 'V' #endif #ifndef PERL_MAGIC_vec # define PERL_MAGIC_vec 'v' #endif #ifndef PERL_MAGIC_utf8 # define PERL_MAGIC_utf8 'w' #endif #ifndef PERL_MAGIC_substr # define PERL_MAGIC_substr 'x' #endif #ifndef PERL_MAGIC_defelem # define PERL_MAGIC_defelem 'y' #endif #ifndef PERL_MAGIC_glob # define PERL_MAGIC_glob '*' #endif #ifndef PERL_MAGIC_arylen # define PERL_MAGIC_arylen '#' #endif #ifndef PERL_MAGIC_pos # define PERL_MAGIC_pos '.' #endif #ifndef PERL_MAGIC_backref # define PERL_MAGIC_backref '<' #endif #ifndef PERL_MAGIC_ext # define PERL_MAGIC_ext '~' #endif /* That's the best we can do... */ #ifndef sv_catpvn_nomg # define sv_catpvn_nomg sv_catpvn #endif #ifndef sv_catsv_nomg # define sv_catsv_nomg sv_catsv #endif #ifndef sv_setsv_nomg # define sv_setsv_nomg sv_setsv #endif #ifndef sv_pvn_nomg # define sv_pvn_nomg sv_pvn #endif #ifndef SvIV_nomg # define SvIV_nomg SvIV #endif #ifndef SvUV_nomg # define SvUV_nomg SvUV #endif #ifndef sv_catpv_mg # define sv_catpv_mg(sv, ptr) \ STMT_START { \ SV *TeMpSv = sv; \ sv_catpv(TeMpSv,ptr); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_catpvn_mg # define sv_catpvn_mg(sv, ptr, len) \ STMT_START { \ SV *TeMpSv = sv; \ sv_catpvn(TeMpSv,ptr,len); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_catsv_mg # define sv_catsv_mg(dsv, ssv) \ STMT_START { \ SV *TeMpSv = dsv; \ sv_catsv(TeMpSv,ssv); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setiv_mg # define sv_setiv_mg(sv, i) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setiv(TeMpSv,i); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setnv_mg # define sv_setnv_mg(sv, num) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setnv(TeMpSv,num); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setpv_mg # define sv_setpv_mg(sv, ptr) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setpv(TeMpSv,ptr); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setpvn_mg # define sv_setpvn_mg(sv, ptr, len) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setpvn(TeMpSv,ptr,len); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setsv_mg # define sv_setsv_mg(dsv, ssv) \ STMT_START { \ SV *TeMpSv = dsv; \ sv_setsv(TeMpSv,ssv); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_setuv_mg # define sv_setuv_mg(sv, i) \ STMT_START { \ SV *TeMpSv = sv; \ sv_setuv(TeMpSv,i); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef sv_usepvn_mg # define sv_usepvn_mg(sv, ptr, len) \ STMT_START { \ SV *TeMpSv = sv; \ sv_usepvn(TeMpSv,ptr,len); \ SvSETMAGIC(TeMpSv); \ } STMT_END #endif #ifndef SvVSTRING_mg # define SvVSTRING_mg(sv) (SvMAGICAL(sv) ? mg_find(sv, PERL_MAGIC_vstring) : NULL) #endif /* Hint: sv_magic_portable * This is a compatibility function that is only available with * Devel::PPPort. It is NOT in the perl core. * Its purpose is to mimic the 5.8.0 behaviour of sv_magic() when * it is being passed a name pointer with namlen == 0. In that * case, perl 5.8.0 and later store the pointer, not a copy of it. * The compatibility can be provided back to perl 5.004. With * earlier versions, the code will not compile. */ #if (PERL_BCDVERSION < 0x5004000) /* code that uses sv_magic_portable will not compile */ #elif (PERL_BCDVERSION < 0x5008000) # define sv_magic_portable(sv, obj, how, name, namlen) \ STMT_START { \ SV *SvMp_sv = (sv); \ char *SvMp_name = (char *) (name); \ I32 SvMp_namlen = (namlen); \ if (SvMp_name && SvMp_namlen == 0) \ { \ MAGIC *mg; \ sv_magic(SvMp_sv, obj, how, 0, 0); \ mg = SvMAGIC(SvMp_sv); \ mg->mg_len = -42; /* XXX: this is the tricky part */ \ mg->mg_ptr = SvMp_name; \ } \ else \ { \ sv_magic(SvMp_sv, obj, how, SvMp_name, SvMp_namlen); \ } \ } STMT_END #else # define sv_magic_portable(a, b, c, d, e) sv_magic(a, b, c, d, e) #endif #if !defined(mg_findext) #if defined(NEED_mg_findext) static MAGIC * DPPP_(my_mg_findext)(SV * sv, int type, const MGVTBL *vtbl); static #else extern MAGIC * DPPP_(my_mg_findext)(SV * sv, int type, const MGVTBL *vtbl); #endif #define mg_findext DPPP_(my_mg_findext) #define Perl_mg_findext DPPP_(my_mg_findext) #if defined(NEED_mg_findext) || defined(NEED_mg_findext_GLOBAL) MAGIC * DPPP_(my_mg_findext)(SV * sv, int type, const MGVTBL *vtbl) { if (sv) { MAGIC *mg; #ifdef AvPAD_NAMELIST assert(!(SvTYPE(sv) == SVt_PVAV && AvPAD_NAMELIST(sv))); #endif for (mg = SvMAGIC (sv); mg; mg = mg->mg_moremagic) { if (mg->mg_type == type && mg->mg_virtual == vtbl) return mg; } } return NULL; } #endif #endif #if !defined(sv_unmagicext) #if defined(NEED_sv_unmagicext) static int DPPP_(my_sv_unmagicext)(pTHX_ SV * const sv, const int type, MGVTBL * vtbl); static #else extern int DPPP_(my_sv_unmagicext)(pTHX_ SV * const sv, const int type, MGVTBL * vtbl); #endif #ifdef sv_unmagicext # undef sv_unmagicext #endif #define sv_unmagicext(a,b,c) DPPP_(my_sv_unmagicext)(aTHX_ a,b,c) #define Perl_sv_unmagicext DPPP_(my_sv_unmagicext) #if defined(NEED_sv_unmagicext) || defined(NEED_sv_unmagicext_GLOBAL) int DPPP_(my_sv_unmagicext)(pTHX_ SV *const sv, const int type, MGVTBL *vtbl) { MAGIC* mg; MAGIC** mgp; if (SvTYPE(sv) < SVt_PVMG || !SvMAGIC(sv)) return 0; mgp = &(SvMAGIC(sv)); for (mg = *mgp; mg; mg = *mgp) { const MGVTBL* const virt = mg->mg_virtual; if (mg->mg_type == type && virt == vtbl) { *mgp = mg->mg_moremagic; if (virt && virt->svt_free) virt->svt_free(aTHX_ sv, mg); if (mg->mg_ptr && mg->mg_type != PERL_MAGIC_regex_global) { if (mg->mg_len > 0) Safefree(mg->mg_ptr); else if (mg->mg_len == HEf_SVKEY) /* Questionable on older perls... */ SvREFCNT_dec(MUTABLE_SV(mg->mg_ptr)); else if (mg->mg_type == PERL_MAGIC_utf8) Safefree(mg->mg_ptr); } if (mg->mg_flags & MGf_REFCOUNTED) SvREFCNT_dec(mg->mg_obj); Safefree(mg); } else mgp = &mg->mg_moremagic; } if (SvMAGIC(sv)) { if (SvMAGICAL(sv)) /* if we're under save_magic, wait for restore_magic; */ mg_magical(sv); /* else fix the flags now */ } else { SvMAGICAL_off(sv); SvFLAGS(sv) |= (SvFLAGS(sv) & (SVp_IOK|SVp_NOK|SVp_POK)) >> PRIVSHIFT; } return 0; } #endif #endif #ifdef USE_ITHREADS #ifndef CopFILE # define CopFILE(c) ((c)->cop_file) #endif #ifndef CopFILEGV # define CopFILEGV(c) (CopFILE(c) ? gv_fetchfile(CopFILE(c)) : Nullgv) #endif #ifndef CopFILE_set # define CopFILE_set(c,pv) ((c)->cop_file = savepv(pv)) #endif #ifndef CopFILESV # define CopFILESV(c) (CopFILE(c) ? GvSV(gv_fetchfile(CopFILE(c))) : Nullsv) #endif #ifndef CopFILEAV # define CopFILEAV(c) (CopFILE(c) ? GvAV(gv_fetchfile(CopFILE(c))) : Nullav) #endif #ifndef CopSTASHPV # define CopSTASHPV(c) ((c)->cop_stashpv) #endif #ifndef CopSTASHPV_set # define CopSTASHPV_set(c,pv) ((c)->cop_stashpv = ((pv) ? savepv(pv) : Nullch)) #endif #ifndef CopSTASH # define CopSTASH(c) (CopSTASHPV(c) ? gv_stashpv(CopSTASHPV(c),GV_ADD) : Nullhv) #endif #ifndef CopSTASH_set # define CopSTASH_set(c,hv) CopSTASHPV_set(c, (hv) ? HvNAME(hv) : Nullch) #endif #ifndef CopSTASH_eq # define CopSTASH_eq(c,hv) ((hv) && (CopSTASHPV(c) == HvNAME(hv) \ || (CopSTASHPV(c) && HvNAME(hv) \ && strEQ(CopSTASHPV(c), HvNAME(hv))))) #endif #else #ifndef CopFILEGV # define CopFILEGV(c) ((c)->cop_filegv) #endif #ifndef CopFILEGV_set # define CopFILEGV_set(c,gv) ((c)->cop_filegv = (GV*)SvREFCNT_inc(gv)) #endif #ifndef CopFILE_set # define CopFILE_set(c,pv) CopFILEGV_set((c), gv_fetchfile(pv)) #endif #ifndef CopFILESV # define CopFILESV(c) (CopFILEGV(c) ? GvSV(CopFILEGV(c)) : Nullsv) #endif #ifndef CopFILEAV # define CopFILEAV(c) (CopFILEGV(c) ? GvAV(CopFILEGV(c)) : Nullav) #endif #ifndef CopFILE # define CopFILE(c) (CopFILESV(c) ? SvPVX(CopFILESV(c)) : Nullch) #endif #ifndef CopSTASH # define CopSTASH(c) ((c)->cop_stash) #endif #ifndef CopSTASH_set # define CopSTASH_set(c,hv) ((c)->cop_stash = (hv)) #endif #ifndef CopSTASHPV # define CopSTASHPV(c) (CopSTASH(c) ? HvNAME(CopSTASH(c)) : Nullch) #endif #ifndef CopSTASHPV_set # define CopSTASHPV_set(c,pv) CopSTASH_set((c), gv_stashpv(pv,GV_ADD)) #endif #ifndef CopSTASH_eq # define CopSTASH_eq(c,hv) (CopSTASH(c) == (hv)) #endif #endif /* USE_ITHREADS */ #if (PERL_BCDVERSION >= 0x5006000) #ifndef caller_cx # if defined(NEED_caller_cx) || defined(NEED_caller_cx_GLOBAL) static I32 DPPP_dopoptosub_at(const PERL_CONTEXT *cxstk, I32 startingblock) { I32 i; for (i = startingblock; i >= 0; i--) { register const PERL_CONTEXT * const cx = &cxstk[i]; switch (CxTYPE(cx)) { default: continue; case CXt_EVAL: case CXt_SUB: case CXt_FORMAT: return i; } } return i; } # endif # if defined(NEED_caller_cx) static const PERL_CONTEXT * DPPP_(my_caller_cx)(pTHX_ I32 count, const PERL_CONTEXT **dbcxp); static #else extern const PERL_CONTEXT * DPPP_(my_caller_cx)(pTHX_ I32 count, const PERL_CONTEXT **dbcxp); #endif #ifdef caller_cx # undef caller_cx #endif #define caller_cx(a,b) DPPP_(my_caller_cx)(aTHX_ a,b) #define Perl_caller_cx DPPP_(my_caller_cx) #if defined(NEED_caller_cx) || defined(NEED_caller_cx_GLOBAL) const PERL_CONTEXT * DPPP_(my_caller_cx)(pTHX_ I32 count, const PERL_CONTEXT **dbcxp) { register I32 cxix = DPPP_dopoptosub_at(cxstack, cxstack_ix); register const PERL_CONTEXT *cx; register const PERL_CONTEXT *ccstack = cxstack; const PERL_SI *top_si = PL_curstackinfo; for (;;) { /* we may be in a higher stacklevel, so dig down deeper */ while (cxix < 0 && top_si->si_type != PERLSI_MAIN) { top_si = top_si->si_prev; ccstack = top_si->si_cxstack; cxix = DPPP_dopoptosub_at(ccstack, top_si->si_cxix); } if (cxix < 0) return NULL; /* caller() should not report the automatic calls to &DB::sub */ if (PL_DBsub && GvCV(PL_DBsub) && cxix >= 0 && ccstack[cxix].blk_sub.cv == GvCV(PL_DBsub)) count++; if (!count--) break; cxix = DPPP_dopoptosub_at(ccstack, cxix - 1); } cx = &ccstack[cxix]; if (dbcxp) *dbcxp = cx; if (CxTYPE(cx) == CXt_SUB || CxTYPE(cx) == CXt_FORMAT) { const I32 dbcxix = DPPP_dopoptosub_at(ccstack, cxix - 1); /* We expect that ccstack[dbcxix] is CXt_SUB, anyway, the field below is defined for any cx. */ /* caller() should not report the automatic calls to &DB::sub */ if (PL_DBsub && GvCV(PL_DBsub) && dbcxix >= 0 && ccstack[dbcxix].blk_sub.cv == GvCV(PL_DBsub)) cx = &ccstack[dbcxix]; } return cx; } # endif #endif /* caller_cx */ #endif /* 5.6.0 */ #ifndef IN_PERL_COMPILETIME # define IN_PERL_COMPILETIME (PL_curcop == &PL_compiling) #endif #ifndef IN_LOCALE_RUNTIME # define IN_LOCALE_RUNTIME (PL_curcop->op_private & HINT_LOCALE) #endif #ifndef IN_LOCALE_COMPILETIME # define IN_LOCALE_COMPILETIME (PL_hints & HINT_LOCALE) #endif #ifndef IN_LOCALE # define IN_LOCALE (IN_PERL_COMPILETIME ? IN_LOCALE_COMPILETIME : IN_LOCALE_RUNTIME) #endif #ifndef IS_NUMBER_IN_UV # define IS_NUMBER_IN_UV 0x01 #endif #ifndef IS_NUMBER_GREATER_THAN_UV_MAX # define IS_NUMBER_GREATER_THAN_UV_MAX 0x02 #endif #ifndef IS_NUMBER_NOT_INT # define IS_NUMBER_NOT_INT 0x04 #endif #ifndef IS_NUMBER_NEG # define IS_NUMBER_NEG 0x08 #endif #ifndef IS_NUMBER_INFINITY # define IS_NUMBER_INFINITY 0x10 #endif #ifndef IS_NUMBER_NAN # define IS_NUMBER_NAN 0x20 #endif #ifndef GROK_NUMERIC_RADIX # define GROK_NUMERIC_RADIX(sp, send) grok_numeric_radix(sp, send) #endif #ifndef PERL_SCAN_GREATER_THAN_UV_MAX # define PERL_SCAN_GREATER_THAN_UV_MAX 0x02 #endif #ifndef PERL_SCAN_SILENT_ILLDIGIT # define PERL_SCAN_SILENT_ILLDIGIT 0x04 #endif #ifndef PERL_SCAN_ALLOW_UNDERSCORES # define PERL_SCAN_ALLOW_UNDERSCORES 0x01 #endif #ifndef PERL_SCAN_DISALLOW_PREFIX # define PERL_SCAN_DISALLOW_PREFIX 0x02 #endif #ifndef grok_numeric_radix #if defined(NEED_grok_numeric_radix) static bool DPPP_(my_grok_numeric_radix)(pTHX_ const char ** sp, const char * send); static #else extern bool DPPP_(my_grok_numeric_radix)(pTHX_ const char ** sp, const char * send); #endif #ifdef grok_numeric_radix # undef grok_numeric_radix #endif #define grok_numeric_radix(a,b) DPPP_(my_grok_numeric_radix)(aTHX_ a,b) #define Perl_grok_numeric_radix DPPP_(my_grok_numeric_radix) #if defined(NEED_grok_numeric_radix) || defined(NEED_grok_numeric_radix_GLOBAL) bool DPPP_(my_grok_numeric_radix)(pTHX_ const char **sp, const char *send) { #ifdef USE_LOCALE_NUMERIC #ifdef PL_numeric_radix_sv if (PL_numeric_radix_sv && IN_LOCALE) { STRLEN len; char* radix = SvPV(PL_numeric_radix_sv, len); if (*sp + len <= send && memEQ(*sp, radix, len)) { *sp += len; return TRUE; } } #else /* older perls don't have PL_numeric_radix_sv so the radix * must manually be requested from locale.h */ #include dTHR; /* needed for older threaded perls */ struct lconv *lc = localeconv(); char *radix = lc->decimal_point; if (radix && IN_LOCALE) { STRLEN len = strlen(radix); if (*sp + len <= send && memEQ(*sp, radix, len)) { *sp += len; return TRUE; } } #endif #endif /* USE_LOCALE_NUMERIC */ /* always try "." if numeric radix didn't match because * we may have data from different locales mixed */ if (*sp < send && **sp == '.') { ++*sp; return TRUE; } return FALSE; } #endif #endif #ifndef grok_number #if defined(NEED_grok_number) static int DPPP_(my_grok_number)(pTHX_ const char * pv, STRLEN len, UV * valuep); static #else extern int DPPP_(my_grok_number)(pTHX_ const char * pv, STRLEN len, UV * valuep); #endif #ifdef grok_number # undef grok_number #endif #define grok_number(a,b,c) DPPP_(my_grok_number)(aTHX_ a,b,c) #define Perl_grok_number DPPP_(my_grok_number) #if defined(NEED_grok_number) || defined(NEED_grok_number_GLOBAL) int DPPP_(my_grok_number)(pTHX_ const char *pv, STRLEN len, UV *valuep) { const char *s = pv; const char *send = pv + len; const UV max_div_10 = UV_MAX / 10; const char max_mod_10 = UV_MAX % 10; int numtype = 0; int sawinf = 0; int sawnan = 0; while (s < send && isSPACE(*s)) s++; if (s == send) { return 0; } else if (*s == '-') { s++; numtype = IS_NUMBER_NEG; } else if (*s == '+') s++; if (s == send) return 0; /* next must be digit or the radix separator or beginning of infinity */ if (isDIGIT(*s)) { /* UVs are at least 32 bits, so the first 9 decimal digits cannot overflow. */ UV value = *s - '0'; /* This construction seems to be more optimiser friendly. (without it gcc does the isDIGIT test and the *s - '0' separately) With it gcc on arm is managing 6 instructions (6 cycles) per digit. In theory the optimiser could deduce how far to unroll the loop before checking for overflow. */ if (++s < send) { int digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { digit = *s - '0'; if (digit >= 0 && digit <= 9) { value = value * 10 + digit; if (++s < send) { /* Now got 9 digits, so need to check each time for overflow. */ digit = *s - '0'; while (digit >= 0 && digit <= 9 && (value < max_div_10 || (value == max_div_10 && digit <= max_mod_10))) { value = value * 10 + digit; if (++s < send) digit = *s - '0'; else break; } if (digit >= 0 && digit <= 9 && (s < send)) { /* value overflowed. skip the remaining digits, don't worry about setting *valuep. */ do { s++; } while (s < send && isDIGIT(*s)); numtype |= IS_NUMBER_GREATER_THAN_UV_MAX; goto skip_value; } } } } } } } } } } } } } } } } } } numtype |= IS_NUMBER_IN_UV; if (valuep) *valuep = value; skip_value: if (GROK_NUMERIC_RADIX(&s, send)) { numtype |= IS_NUMBER_NOT_INT; while (s < send && isDIGIT(*s)) /* optional digits after the radix */ s++; } } else if (GROK_NUMERIC_RADIX(&s, send)) { numtype |= IS_NUMBER_NOT_INT | IS_NUMBER_IN_UV; /* valuep assigned below */ /* no digits before the radix means we need digits after it */ if (s < send && isDIGIT(*s)) { do { s++; } while (s < send && isDIGIT(*s)); if (valuep) { /* integer approximation is valid - it's 0. */ *valuep = 0; } } else return 0; } else if (*s == 'I' || *s == 'i') { s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; s++; if (s == send || (*s != 'F' && *s != 'f')) return 0; s++; if (s < send && (*s == 'I' || *s == 'i')) { s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; s++; if (s == send || (*s != 'I' && *s != 'i')) return 0; s++; if (s == send || (*s != 'T' && *s != 't')) return 0; s++; if (s == send || (*s != 'Y' && *s != 'y')) return 0; s++; } sawinf = 1; } else if (*s == 'N' || *s == 'n') { /* XXX TODO: There are signaling NaNs and quiet NaNs. */ s++; if (s == send || (*s != 'A' && *s != 'a')) return 0; s++; if (s == send || (*s != 'N' && *s != 'n')) return 0; s++; sawnan = 1; } else return 0; if (sawinf) { numtype &= IS_NUMBER_NEG; /* Keep track of sign */ numtype |= IS_NUMBER_INFINITY | IS_NUMBER_NOT_INT; } else if (sawnan) { numtype &= IS_NUMBER_NEG; /* Keep track of sign */ numtype |= IS_NUMBER_NAN | IS_NUMBER_NOT_INT; } else if (s < send) { /* we can have an optional exponent part */ if (*s == 'e' || *s == 'E') { /* The only flag we keep is sign. Blow away any "it's UV" */ numtype &= IS_NUMBER_NEG; numtype |= IS_NUMBER_NOT_INT; s++; if (s < send && (*s == '-' || *s == '+')) s++; if (s < send && isDIGIT(*s)) { do { s++; } while (s < send && isDIGIT(*s)); } else return 0; } } while (s < send && isSPACE(*s)) s++; if (s >= send) return numtype; if (len == 10 && memEQ(pv, "0 but true", 10)) { if (valuep) *valuep = 0; return IS_NUMBER_IN_UV; } return 0; } #endif #endif /* * The grok_* routines have been modified to use warn() instead of * Perl_warner(). Also, 'hexdigit' was the former name of PL_hexdigit, * which is why the stack variable has been renamed to 'xdigit'. */ #ifndef grok_bin #if defined(NEED_grok_bin) static UV DPPP_(my_grok_bin)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); static #else extern UV DPPP_(my_grok_bin)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); #endif #ifdef grok_bin # undef grok_bin #endif #define grok_bin(a,b,c,d) DPPP_(my_grok_bin)(aTHX_ a,b,c,d) #define Perl_grok_bin DPPP_(my_grok_bin) #if defined(NEED_grok_bin) || defined(NEED_grok_bin_GLOBAL) UV DPPP_(my_grok_bin)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) { const char *s = start; STRLEN len = *len_p; UV value = 0; NV value_nv = 0; const UV max_div_2 = UV_MAX / 2; bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; bool overflowed = FALSE; if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) { /* strip off leading b or 0b. for compatibility silently suffer "b" and "0b" as valid binary numbers. */ if (len >= 1) { if (s[0] == 'b') { s++; len--; } else if (len >= 2 && s[0] == '0' && s[1] == 'b') { s+=2; len-=2; } } } for (; len-- && *s; s++) { char bit = *s; if (bit == '0' || bit == '1') { /* Write it in this wonky order with a goto to attempt to get the compiler to make the common case integer-only loop pretty tight. With gcc seems to be much straighter code than old scan_bin. */ redo: if (!overflowed) { if (value <= max_div_2) { value = (value << 1) | (bit - '0'); continue; } /* Bah. We're just overflowed. */ warn("Integer overflow in binary number"); overflowed = TRUE; value_nv = (NV) value; } value_nv *= 2.0; /* If an NV has not enough bits in its mantissa to * represent a UV this summing of small low-order numbers * is a waste of time (because the NV cannot preserve * the low-order bits anyway): we could just remember when * did we overflow and in the end just multiply value_nv by the * right amount. */ value_nv += (NV)(bit - '0'); continue; } if (bit == '_' && len && allow_underscores && (bit = s[1]) && (bit == '0' || bit == '1')) { --len; ++s; goto redo; } if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) warn("Illegal binary digit '%c' ignored", *s); break; } if ( ( overflowed && value_nv > 4294967295.0) #if UVSIZE > 4 || (!overflowed && value > 0xffffffff ) #endif ) { warn("Binary number > 0b11111111111111111111111111111111 non-portable"); } *len_p = s - start; if (!overflowed) { *flags = 0; return value; } *flags = PERL_SCAN_GREATER_THAN_UV_MAX; if (result) *result = value_nv; return UV_MAX; } #endif #endif #ifndef grok_hex #if defined(NEED_grok_hex) static UV DPPP_(my_grok_hex)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); static #else extern UV DPPP_(my_grok_hex)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); #endif #ifdef grok_hex # undef grok_hex #endif #define grok_hex(a,b,c,d) DPPP_(my_grok_hex)(aTHX_ a,b,c,d) #define Perl_grok_hex DPPP_(my_grok_hex) #if defined(NEED_grok_hex) || defined(NEED_grok_hex_GLOBAL) UV DPPP_(my_grok_hex)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) { const char *s = start; STRLEN len = *len_p; UV value = 0; NV value_nv = 0; const UV max_div_16 = UV_MAX / 16; bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; bool overflowed = FALSE; const char *xdigit; if (!(*flags & PERL_SCAN_DISALLOW_PREFIX)) { /* strip off leading x or 0x. for compatibility silently suffer "x" and "0x" as valid hex numbers. */ if (len >= 1) { if (s[0] == 'x') { s++; len--; } else if (len >= 2 && s[0] == '0' && s[1] == 'x') { s+=2; len-=2; } } } for (; len-- && *s; s++) { xdigit = strchr((char *) PL_hexdigit, *s); if (xdigit) { /* Write it in this wonky order with a goto to attempt to get the compiler to make the common case integer-only loop pretty tight. With gcc seems to be much straighter code than old scan_hex. */ redo: if (!overflowed) { if (value <= max_div_16) { value = (value << 4) | ((xdigit - PL_hexdigit) & 15); continue; } warn("Integer overflow in hexadecimal number"); overflowed = TRUE; value_nv = (NV) value; } value_nv *= 16.0; /* If an NV has not enough bits in its mantissa to * represent a UV this summing of small low-order numbers * is a waste of time (because the NV cannot preserve * the low-order bits anyway): we could just remember when * did we overflow and in the end just multiply value_nv by the * right amount of 16-tuples. */ value_nv += (NV)((xdigit - PL_hexdigit) & 15); continue; } if (*s == '_' && len && allow_underscores && s[1] && (xdigit = strchr((char *) PL_hexdigit, s[1]))) { --len; ++s; goto redo; } if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) warn("Illegal hexadecimal digit '%c' ignored", *s); break; } if ( ( overflowed && value_nv > 4294967295.0) #if UVSIZE > 4 || (!overflowed && value > 0xffffffff ) #endif ) { warn("Hexadecimal number > 0xffffffff non-portable"); } *len_p = s - start; if (!overflowed) { *flags = 0; return value; } *flags = PERL_SCAN_GREATER_THAN_UV_MAX; if (result) *result = value_nv; return UV_MAX; } #endif #endif #ifndef grok_oct #if defined(NEED_grok_oct) static UV DPPP_(my_grok_oct)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); static #else extern UV DPPP_(my_grok_oct)(pTHX_ const char * start, STRLEN * len_p, I32 * flags, NV * result); #endif #ifdef grok_oct # undef grok_oct #endif #define grok_oct(a,b,c,d) DPPP_(my_grok_oct)(aTHX_ a,b,c,d) #define Perl_grok_oct DPPP_(my_grok_oct) #if defined(NEED_grok_oct) || defined(NEED_grok_oct_GLOBAL) UV DPPP_(my_grok_oct)(pTHX_ const char *start, STRLEN *len_p, I32 *flags, NV *result) { const char *s = start; STRLEN len = *len_p; UV value = 0; NV value_nv = 0; const UV max_div_8 = UV_MAX / 8; bool allow_underscores = *flags & PERL_SCAN_ALLOW_UNDERSCORES; bool overflowed = FALSE; for (; len-- && *s; s++) { /* gcc 2.95 optimiser not smart enough to figure that this subtraction out front allows slicker code. */ int digit = *s - '0'; if (digit >= 0 && digit <= 7) { /* Write it in this wonky order with a goto to attempt to get the compiler to make the common case integer-only loop pretty tight. */ redo: if (!overflowed) { if (value <= max_div_8) { value = (value << 3) | digit; continue; } /* Bah. We're just overflowed. */ warn("Integer overflow in octal number"); overflowed = TRUE; value_nv = (NV) value; } value_nv *= 8.0; /* If an NV has not enough bits in its mantissa to * represent a UV this summing of small low-order numbers * is a waste of time (because the NV cannot preserve * the low-order bits anyway): we could just remember when * did we overflow and in the end just multiply value_nv by the * right amount of 8-tuples. */ value_nv += (NV)digit; continue; } if (digit == ('_' - '0') && len && allow_underscores && (digit = s[1] - '0') && (digit >= 0 && digit <= 7)) { --len; ++s; goto redo; } /* Allow \octal to work the DWIM way (that is, stop scanning * as soon as non-octal characters are seen, complain only iff * someone seems to want to use the digits eight and nine). */ if (digit == 8 || digit == 9) { if (!(*flags & PERL_SCAN_SILENT_ILLDIGIT)) warn("Illegal octal digit '%c' ignored", *s); } break; } if ( ( overflowed && value_nv > 4294967295.0) #if UVSIZE > 4 || (!overflowed && value > 0xffffffff ) #endif ) { warn("Octal number > 037777777777 non-portable"); } *len_p = s - start; if (!overflowed) { *flags = 0; return value; } *flags = PERL_SCAN_GREATER_THAN_UV_MAX; if (result) *result = value_nv; return UV_MAX; } #endif #endif #if !defined(my_snprintf) #if defined(NEED_my_snprintf) static int DPPP_(my_my_snprintf)(char * buffer, const Size_t len, const char * format, ...); static #else extern int DPPP_(my_my_snprintf)(char * buffer, const Size_t len, const char * format, ...); #endif #define my_snprintf DPPP_(my_my_snprintf) #define Perl_my_snprintf DPPP_(my_my_snprintf) #if defined(NEED_my_snprintf) || defined(NEED_my_snprintf_GLOBAL) int DPPP_(my_my_snprintf)(char *buffer, const Size_t len, const char *format, ...) { dTHX; int retval; va_list ap; va_start(ap, format); #ifdef HAS_VSNPRINTF retval = vsnprintf(buffer, len, format, ap); #else retval = vsprintf(buffer, format, ap); #endif va_end(ap); if (retval < 0 || (len > 0 && (Size_t)retval >= len)) Perl_croak(aTHX_ "panic: my_snprintf buffer overflow"); return retval; } #endif #endif #if !defined(my_sprintf) #if defined(NEED_my_sprintf) static int DPPP_(my_my_sprintf)(char * buffer, const char * pat, ...); static #else extern int DPPP_(my_my_sprintf)(char * buffer, const char * pat, ...); #endif #define my_sprintf DPPP_(my_my_sprintf) #define Perl_my_sprintf DPPP_(my_my_sprintf) #if defined(NEED_my_sprintf) || defined(NEED_my_sprintf_GLOBAL) int DPPP_(my_my_sprintf)(char *buffer, const char* pat, ...) { va_list args; va_start(args, pat); vsprintf(buffer, pat, args); va_end(args); return strlen(buffer); } #endif #endif #ifdef NO_XSLOCKS # ifdef dJMPENV # define dXCPT dJMPENV; int rEtV = 0 # define XCPT_TRY_START JMPENV_PUSH(rEtV); if (rEtV == 0) # define XCPT_TRY_END JMPENV_POP; # define XCPT_CATCH if (rEtV != 0) # define XCPT_RETHROW JMPENV_JUMP(rEtV) # else # define dXCPT Sigjmp_buf oldTOP; int rEtV = 0 # define XCPT_TRY_START Copy(top_env, oldTOP, 1, Sigjmp_buf); rEtV = Sigsetjmp(top_env, 1); if (rEtV == 0) # define XCPT_TRY_END Copy(oldTOP, top_env, 1, Sigjmp_buf); # define XCPT_CATCH if (rEtV != 0) # define XCPT_RETHROW Siglongjmp(top_env, rEtV) # endif #endif #if !defined(my_strlcat) #if defined(NEED_my_strlcat) static Size_t DPPP_(my_my_strlcat)(char * dst, const char * src, Size_t size); static #else extern Size_t DPPP_(my_my_strlcat)(char * dst, const char * src, Size_t size); #endif #define my_strlcat DPPP_(my_my_strlcat) #define Perl_my_strlcat DPPP_(my_my_strlcat) #if defined(NEED_my_strlcat) || defined(NEED_my_strlcat_GLOBAL) Size_t DPPP_(my_my_strlcat)(char *dst, const char *src, Size_t size) { Size_t used, length, copy; used = strlen(dst); length = strlen(src); if (size > 0 && used < size - 1) { copy = (length >= size - used) ? size - used - 1 : length; memcpy(dst + used, src, copy); dst[used + copy] = '\0'; } return used + length; } #endif #endif #if !defined(my_strlcpy) #if defined(NEED_my_strlcpy) static Size_t DPPP_(my_my_strlcpy)(char * dst, const char * src, Size_t size); static #else extern Size_t DPPP_(my_my_strlcpy)(char * dst, const char * src, Size_t size); #endif #define my_strlcpy DPPP_(my_my_strlcpy) #define Perl_my_strlcpy DPPP_(my_my_strlcpy) #if defined(NEED_my_strlcpy) || defined(NEED_my_strlcpy_GLOBAL) Size_t DPPP_(my_my_strlcpy)(char *dst, const char *src, Size_t size) { Size_t length, copy; length = strlen(src); if (size > 0) { copy = (length >= size) ? size - 1 : length; memcpy(dst, src, copy); dst[copy] = '\0'; } return length; } #endif #endif #ifndef PERL_PV_ESCAPE_QUOTE # define PERL_PV_ESCAPE_QUOTE 0x0001 #endif #ifndef PERL_PV_PRETTY_QUOTE # define PERL_PV_PRETTY_QUOTE PERL_PV_ESCAPE_QUOTE #endif #ifndef PERL_PV_PRETTY_ELLIPSES # define PERL_PV_PRETTY_ELLIPSES 0x0002 #endif #ifndef PERL_PV_PRETTY_LTGT # define PERL_PV_PRETTY_LTGT 0x0004 #endif #ifndef PERL_PV_ESCAPE_FIRSTCHAR # define PERL_PV_ESCAPE_FIRSTCHAR 0x0008 #endif #ifndef PERL_PV_ESCAPE_UNI # define PERL_PV_ESCAPE_UNI 0x0100 #endif #ifndef PERL_PV_ESCAPE_UNI_DETECT # define PERL_PV_ESCAPE_UNI_DETECT 0x0200 #endif #ifndef PERL_PV_ESCAPE_ALL # define PERL_PV_ESCAPE_ALL 0x1000 #endif #ifndef PERL_PV_ESCAPE_NOBACKSLASH # define PERL_PV_ESCAPE_NOBACKSLASH 0x2000 #endif #ifndef PERL_PV_ESCAPE_NOCLEAR # define PERL_PV_ESCAPE_NOCLEAR 0x4000 #endif #ifndef PERL_PV_ESCAPE_RE # define PERL_PV_ESCAPE_RE 0x8000 #endif #ifndef PERL_PV_PRETTY_NOCLEAR # define PERL_PV_PRETTY_NOCLEAR PERL_PV_ESCAPE_NOCLEAR #endif #ifndef PERL_PV_PRETTY_DUMP # define PERL_PV_PRETTY_DUMP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_QUOTE #endif #ifndef PERL_PV_PRETTY_REGPROP # define PERL_PV_PRETTY_REGPROP PERL_PV_PRETTY_ELLIPSES|PERL_PV_PRETTY_LTGT|PERL_PV_ESCAPE_RE #endif /* Hint: pv_escape * Note that unicode functionality is only backported to * those perl versions that support it. For older perl * versions, the implementation will fall back to bytes. */ #ifndef pv_escape #if defined(NEED_pv_escape) static char * DPPP_(my_pv_escape)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags); static #else extern char * DPPP_(my_pv_escape)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags); #endif #ifdef pv_escape # undef pv_escape #endif #define pv_escape(a,b,c,d,e,f) DPPP_(my_pv_escape)(aTHX_ a,b,c,d,e,f) #define Perl_pv_escape DPPP_(my_pv_escape) #if defined(NEED_pv_escape) || defined(NEED_pv_escape_GLOBAL) char * DPPP_(my_pv_escape)(pTHX_ SV *dsv, char const * const str, const STRLEN count, const STRLEN max, STRLEN * const escaped, const U32 flags) { const char esc = flags & PERL_PV_ESCAPE_RE ? '%' : '\\'; const char dq = flags & PERL_PV_ESCAPE_QUOTE ? '"' : esc; char octbuf[32] = "%123456789ABCDF"; STRLEN wrote = 0; STRLEN chsize = 0; STRLEN readsize = 1; #if defined(is_utf8_string) && defined(utf8_to_uvchr) bool isuni = flags & PERL_PV_ESCAPE_UNI ? 1 : 0; #endif const char *pv = str; const char * const end = pv + count; octbuf[0] = esc; if (!(flags & PERL_PV_ESCAPE_NOCLEAR)) sv_setpvs(dsv, ""); #if defined(is_utf8_string) && defined(utf8_to_uvchr) if ((flags & PERL_PV_ESCAPE_UNI_DETECT) && is_utf8_string((U8*)pv, count)) isuni = 1; #endif for (; pv < end && (!max || wrote < max) ; pv += readsize) { const UV u = #if defined(is_utf8_string) && defined(utf8_to_uvchr) isuni ? utf8_to_uvchr((U8*)pv, &readsize) : #endif (U8)*pv; const U8 c = (U8)u & 0xFF; if (u > 255 || (flags & PERL_PV_ESCAPE_ALL)) { if (flags & PERL_PV_ESCAPE_FIRSTCHAR) chsize = my_snprintf(octbuf, sizeof octbuf, "%" UVxf, u); else chsize = my_snprintf(octbuf, sizeof octbuf, "%cx{%" UVxf "}", esc, u); } else if (flags & PERL_PV_ESCAPE_NOBACKSLASH) { chsize = 1; } else { if (c == dq || c == esc || !isPRINT(c)) { chsize = 2; switch (c) { case '\\' : /* fallthrough */ case '%' : if (c == esc) octbuf[1] = esc; else chsize = 1; break; case '\v' : octbuf[1] = 'v'; break; case '\t' : octbuf[1] = 't'; break; case '\r' : octbuf[1] = 'r'; break; case '\n' : octbuf[1] = 'n'; break; case '\f' : octbuf[1] = 'f'; break; case '"' : if (dq == '"') octbuf[1] = '"'; else chsize = 1; break; default: chsize = my_snprintf(octbuf, sizeof octbuf, pv < end && isDIGIT((U8)*(pv+readsize)) ? "%c%03o" : "%c%o", esc, c); } } else { chsize = 1; } } if (max && wrote + chsize > max) { break; } else if (chsize > 1) { sv_catpvn(dsv, octbuf, chsize); wrote += chsize; } else { char tmp[2]; my_snprintf(tmp, sizeof tmp, "%c", c); sv_catpvn(dsv, tmp, 1); wrote++; } if (flags & PERL_PV_ESCAPE_FIRSTCHAR) break; } if (escaped != NULL) *escaped= pv - str; return SvPVX(dsv); } #endif #endif #ifndef pv_pretty #if defined(NEED_pv_pretty) static char * DPPP_(my_pv_pretty)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags); static #else extern char * DPPP_(my_pv_pretty)(pTHX_ SV * dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags); #endif #ifdef pv_pretty # undef pv_pretty #endif #define pv_pretty(a,b,c,d,e,f,g) DPPP_(my_pv_pretty)(aTHX_ a,b,c,d,e,f,g) #define Perl_pv_pretty DPPP_(my_pv_pretty) #if defined(NEED_pv_pretty) || defined(NEED_pv_pretty_GLOBAL) char * DPPP_(my_pv_pretty)(pTHX_ SV *dsv, char const * const str, const STRLEN count, const STRLEN max, char const * const start_color, char const * const end_color, const U32 flags) { const U8 dq = (flags & PERL_PV_PRETTY_QUOTE) ? '"' : '%'; STRLEN escaped; if (!(flags & PERL_PV_PRETTY_NOCLEAR)) sv_setpvs(dsv, ""); if (dq == '"') sv_catpvs(dsv, "\""); else if (flags & PERL_PV_PRETTY_LTGT) sv_catpvs(dsv, "<"); if (start_color != NULL) sv_catpv(dsv, D_PPP_CONSTPV_ARG(start_color)); pv_escape(dsv, str, count, max, &escaped, flags | PERL_PV_ESCAPE_NOCLEAR); if (end_color != NULL) sv_catpv(dsv, D_PPP_CONSTPV_ARG(end_color)); if (dq == '"') sv_catpvs(dsv, "\""); else if (flags & PERL_PV_PRETTY_LTGT) sv_catpvs(dsv, ">"); if ((flags & PERL_PV_PRETTY_ELLIPSES) && escaped < count) sv_catpvs(dsv, "..."); return SvPVX(dsv); } #endif #endif #ifndef pv_display #if defined(NEED_pv_display) static char * DPPP_(my_pv_display)(pTHX_ SV * dsv, const char * pv, STRLEN cur, STRLEN len, STRLEN pvlim); static #else extern char * DPPP_(my_pv_display)(pTHX_ SV * dsv, const char * pv, STRLEN cur, STRLEN len, STRLEN pvlim); #endif #ifdef pv_display # undef pv_display #endif #define pv_display(a,b,c,d,e) DPPP_(my_pv_display)(aTHX_ a,b,c,d,e) #define Perl_pv_display DPPP_(my_pv_display) #if defined(NEED_pv_display) || defined(NEED_pv_display_GLOBAL) char * DPPP_(my_pv_display)(pTHX_ SV *dsv, const char *pv, STRLEN cur, STRLEN len, STRLEN pvlim) { pv_pretty(dsv, pv, cur, pvlim, NULL, NULL, PERL_PV_PRETTY_DUMP); if (len > cur && pv[cur] == '\0') sv_catpvs(dsv, "\\0"); return SvPVX(dsv); } #endif #endif #endif /* _P_P_PORTABILITY_H_ */ /* End of File ppport.h */ Time-Moment-0.44/README000644 000765 000024 00000167450 13274643622 015264 0ustar00chansenstaff000000 000000 NAME Time::Moment - Represents a date and time of day with an offset from UTC SYNOPSIS $tm = Time::Moment->new( year => 2012, month => 12, day => 24, hour => 15, minute => 30, second => 45, nanosecond => 123456789, offset => 0, ); $tm = Time::Moment->now; $tm = Time::Moment->now_utc; $tm = Time::Moment->from_epoch($seconds); $tm = Time::Moment->from_object($object); $tm = Time::Moment->from_string($string); $tm = Time::Moment->from_rd($rd); $tm = Time::Moment->from_jd($jd); $tm = Time::Moment->from_mjd($mjd); $year = $tm->year; # [1, 9999] $quarter = $tm->quarter; # [1, 4] $month = $tm->month; # [1, 12] $week = $tm->week; # [1, 53] $day = $tm->day_of_year; # [1, 366] $day = $tm->day_of_quarter; # [1, 92] $day = $tm->day_of_month; # [1, 31] $day = $tm->day_of_week; # [1=Monday, 7=Sunday] $hour = $tm->hour; # [0, 23] $minute = $tm->minute; # [0, 59] $minute = $tm->minute_of_day; # [0, 1439] $second = $tm->second; # [0, 59] $second = $tm->second_of_day; # [0, 86_399] $millisecond = $tm->millisecond; # [0, 999] $millisecond = $tm->millisecond_of_day; # [0, 86_399_999] $microsecond = $tm->microsecond; # [0, 999_999] $microsecond = $tm->microsecond_of_day; # [0, 86_399_999_999] $nanosecond = $tm->nanosecond; # [0, 999_999_999] $nanosecond = $tm->nanosecond_of_day; # [0, 86_399_999_999_999] $epoch = $tm->epoch; $offset = $tm->offset; # [-1080, 1080] (±18:00) $jd = $tm->jd; # Julian Date $mjd = $tm->mjd; # Modified Julian Date $rd = $tm->rd; # Rata Die $tm2 = $tm1->with($adjuster); $tm2 = $tm1->with_year($year); $tm2 = $tm1->with_quarter($quarter); $tm2 = $tm1->with_month($month); $tm2 = $tm1->with_week($week); $tm2 = $tm1->with_day_of_year($day); $tm2 = $tm1->with_day_of_quarter($day); $tm2 = $tm1->with_day_of_month($day); $tm2 = $tm1->with_day_of_week($day); $tm2 = $tm1->with_hour($hour); $tm2 = $tm1->with_minute($minute); $tm2 = $tm1->with_minute_of_day($minute); $tm2 = $tm1->with_second($second); $tm2 = $tm1->with_second_of_day($second); $tm2 = $tm1->with_millisecond($millisecond); $tm2 = $tm1->with_millisecond_of_day($millisecond); $tm2 = $tm1->with_microsecond($microsecond); $tm2 = $tm1->with_microsecond_of_day($microsecond); $tm2 = $tm1->with_nanosecond($nanosecond); $tm2 = $tm1->with_nanosecond_of_day($nanosecond); $tm2 = $tm1->with_offset_same_instant($offset); $tm2 = $tm1->with_offset_same_local($offset); $tm2 = $tm1->with_precision($precision); $tm2 = $tm1->plus_years($years); $tm2 = $tm1->plus_months($months); $tm2 = $tm1->plus_weeks($weeks); $tm2 = $tm1->plus_days($days); $tm2 = $tm1->plus_hours($hours); $tm2 = $tm1->plus_minutes($minutes); $tm2 = $tm1->plus_seconds($seconds); $tm2 = $tm1->plus_milliseconds($milliseconds); $tm2 = $tm1->plus_microseconds($microseconds); $tm2 = $tm1->plus_nanoseconds($nanoseconds); $tm2 = $tm1->minus_years($years); $tm2 = $tm1->minus_months($months); $tm2 = $tm1->minus_weeks($weeks); $tm2 = $tm1->minus_days($days); $tm2 = $tm1->minus_hours($hours); $tm2 = $tm1->minus_minutes($minutes); $tm2 = $tm1->minus_seconds($seconds); $tm2 = $tm1->minus_milliseconds($milliseconds); $tm2 = $tm1->minus_microseconds($microseconds); $tm2 = $tm1->minus_nanoseconds($nanoseconds); $years = $tm1->delta_years($tm2); $months = $tm1->delta_months($tm2); $weeks = $tm1->delta_weeks($tm2); $days = $tm1->delta_days($tm2); $hours = $tm1->delta_hours($tm2); $minutes = $tm1->delta_minutes($tm2); $seconds = $tm1->delta_seconds($tm2); $milliseconds = $tm1->delta_milliseconds($tm2); $microseconds = $tm1->delta_microseconds($tm2); $nanoseconds = $tm1->delta_nanoseconds($tm2); $tm2 = $tm1->at_utc; $tm2 = $tm1->at_midnight; # T00:00:00.0 $tm2 = $tm1->at_noon; # T12:00:00.0 $tm2 = $tm1->at_last_day_of_year; $tm2 = $tm1->at_last_day_of_quarter; $tm2 = $tm1->at_last_day_of_month; $boolean = $tm1->is_before($tm2); $boolean = $tm1->is_after($tm2); $boolean = $tm1->is_equal($tm2); $integer = $tm1->compare($tm2); $boolean = $tm->is_leap_year; $string = $tm->to_string; $string = $tm->strftime($format); $integer = $tm->length_of_year; # [365, 366] $integer = $tm->length_of_quarter; # [90, 92] $integer = $tm->length_of_month; # [28, 31] $integer = $tm->length_of_week_year; # [52, 53] @values = $tm->utc_rd_values; $seconds = $tm->utc_rd_as_seconds; @values = $tm->local_rd_values; $seconds = $tm->local_rd_as_seconds; $integer = $tm1 <=> $tm2; $boolean = $tm1 == $tm2; $boolean = $tm1 != $tm2; $boolean = $tm1 < $tm2; $boolean = $tm1 > $tm2; $boolean = $tm1 <= $tm2; $boolean = $tm1 >= $tm2; $string = "$tm"; DESCRIPTION "Time::Moment" is an immutable object representing a date and time of day with an offset from UTC in the ISO 8601 calendar system. Time is measured in nanoseconds since "0001-01-01T00Z". In "Time:Moment" leap seconds are ignored. It is assumed that there are exactly "86,400,000,000,000" nanoseconds per day. "Time::Moment" can represent all epoch integers from "-62,135,596,800" to "253,402,300,799"; this range suffices to measure times to nanosecond precision for any instant that is within "0001-01-01T00:00:00Z" to "9999-12-31T23:59:59Z". CONSTRUCTORS new $tm = Time::Moment->new( year => 2012, month => 12, day => 24, hour => 15, minute => 30, second => 45, nanosecond => 123456789, offset => 0, ); Constructs an instance of "Time::Moment" from the given components. Parameters: year The year [1, 9999]. month The month of the year [1, 12]. day The day of the month [1, 31]. The day must be valid for the year and month, otherwise an exception is raised. hour The hour of the day [0, 23]. minute The minute of the hour [0, 59]. second The second of the minute [0, 59]. nanosecond The nanosecond of the second [0, 999_999_999]. offset The offset from UTC in minutes [-1080, 1080] (±18:00). now $tm = Time::Moment->now; Constructs an instance of "Time::Moment" that is set to the current date and time from the system clock in the system time zone, with the offset set to the system's time zone offset from UTC. now_utc $tm = Time::Moment->now_utc; Constructs an instance of "Time::Moment" that is set to the current date and time from the system clock in the UTC time zone. from_epoch $tm = Time::Moment->from_epoch($seconds); $tm = Time::Moment->from_epoch($seconds, $nanosecond); $tm = Time::Moment->from_epoch($seconds [, nanosecond => 0] [, precision => 6]); Constructs an instance of "Time::Moment" from the given *seconds* from the epoch of 1970-01-01T00Z. Fractional seconds is supported if the constructor is invoked with *seconds* only, the default precision is 6 (microseconds). Parameters: nanosecond $tm = Time::Moment->from_epoch($seconds, nanosecond => 0); The optional parameter *nanosecond* [0, 999_999_999] specifies the nanosecond of the second. precision $tm = Time::Moment->from_epoch($seconds, precision => 6); The optional parameter *precision* [0, 9] specifies the precision of the fractional seconds. The default precision is 6 (microseconds). from_object $tm = Time::Moment->from_object($object); Constructs an instance of "Time::Moment" from the given *object*. If the given object is an instance of "Time::Moment" it's returned otherwise an attempt is made to coerce the given object to an instance of "Time::Moment". "Time::Moment" implements coercion handlers for the following object types: DateTime $tm = Time::Moment->from_object( DateTime->now ); The given "DateTime" object must be within the supported range and must have a time zone or an offset from UTC, coercing from the 'floating' time zone is not supported. Time::Piece $tm = Time::Moment->from_object( scalar Time::Piece::localtime() ); The given "Time::Piece" object must be within the supported date range. The coercion scheme is extensible and implemented as documented in Params::Coerce: $tm = Params::Coerce::coerce('Time::Moment', scalar Time::Piece::localtime()); $tm = Params::Coerce::coerce('Time::Moment', DateTime->now); "Time::Moment" also implements a coercion handler from "Time::Moment" to "DateTime" and "Time::Piece": $dt = Params::Coerce::coerce('DateTime', Time::Moment->now); $tp = Params::Coerce::coerce('Time::Piece', Time::Moment->now); from_string $tm = Time::Moment->from_string($string); $tm = Time::Moment->from_string($string [, lenient => false]); Constructs an instance of "Time::Moment" from the given *string*. The string must consist of a complete date representation and time of day followed by a zone designator. The time of day may be reduced to hour of the day, the second of the minute may have a decimal fraction. The decimal sign can be either the comma [,] or the full stop [.]. A decimal fraction must have at least one digit and may have a total of nine digits, if the fractional precision is greater than nine digits, the value will be truncated. The following are examples of complete date and time of day representations: Basic format: Example: YYYYMMDDThhmmssZ 20121224T121530Z YYYYMMDDThhmmss±hhmm 20121224T121530+0100 YYYYMMDDThhmmss±hh 20121224T121530+01 YYYYMMDDThhmmss.ssZ 20121224T121530.500Z YYYYMMDDThhmmss.ss±hhmm 20121224T121530.500+0100 YYYYMMDDThhmmss.ss±hh 20121224T121530.500+01 YYYYMMDDThhZ 20121224T12Z (reduced accuracy) YYYYMMDDThhmmZ 20121224T1215Z (reduced accuracy) YYYYMMDDThhmm±hhmm 20121224T1215+0100 (reduced accuracy) YYYYMMDDThhmm±hh 20121224T1215+01 (reduced accuracy) Extended format: Example: YYYY-MM-DDThh:mm:ssZ 2012-12-24T12:15:30Z YYYY-MM-DDThh:mm:ss±hh:mm 2012-12-24T12:15:30+01:00 YYYY-MM-DDThh:mm:ss±hh 2012-12-24T12:15:30+01 YYYY-MM-DDThh:mm:ss.ssZ 2012-12-24T12:15:30.500Z YYYY-MM-DDThh:mm:ss.ss±hh:mm 2012-12-24T12:15:30.500+01:00 YYYY-MM-DDThh:mm:ss.ss±hh 2012-12-24T12:15:30.500+01 YYYY-MM-DDThhZ 2012-12-24T12Z (reduced accuracy) YYYY-MM-DDThh:mmZ 2012-12-24T12:15Z (reduced accuracy) YYYY-MM-DDThh:mm±hh:mm 2012-12-24T12:15+01:00 (reduced accuracy) YYYY-MM-DDThh:mm±hh 2012-12-24T12:15+01 (reduced accuracy) Where representations using calendar dates are shown, ordinal dates or week dates may be substituted. This ISO 8601 profile correspond to a subset of ISO 8601:2004 4.3 Date and time of day. If the optional boolean parameter *lenient* is true, the following examples are also accepted: YYYY-MM-DD hh:mm:ssZ 2012-12-24 12:15:30Z YYYY-MM-DD hh:mm:ssz 2012-12-24 12:15:30z YYYY-MM-DD hh:mm:ss±hhmm 2012-12-24 12:15:30+0100 YYYY-MM-DD hh:mm:ss±hh:mm 2012-12-24 12:15:30+01:00 YYYY-MM-DD hh:mm:ss±hh 2012-12-24 12:15:30+01 YYYY-MM-DD hh:mm:ss.ssZ 2012-12-24 12:15:30.500Z YYYY-MM-DD hh:mm:ss.ssz 2012-12-24 12:15:30.500z YYYY-MM-DD hh:mm:ss.ss±hhmm 2012-12-24 12:15:30.500+0100 YYYY-MM-DD hh:mm:ss.ss±hh:mm 2012-12-24 12:15:30.500+01:00 YYYY-MM-DD hh:mm:ss.ss±hh 2012-12-24 12:15:30.500+01 YYYY-MM-DD hh:mmZ 2012-12-24 12:15Z YYYY-MM-DD hh:mmz 2012-12-24 12:15z YYYY-MM-DD hh:mm±hhmm 2012-12-24 12:15+0100 YYYY-MM-DD hh:mm±hh:mm 2012-12-24 12:15+01:00 YYYY-MM-DD hh:mm±hh 2012-12-24 12:15+01 YYYY-MM-DD hh:mm:ss ±hh:mm 2012-12-24 12:15:30 +01:00 YYYY-MM-DD hh:mm:ss ±hhmm 2012-12-24 12:15:30 +0100 YYYY-MM-DD hh:mm:ss ±hh 2012-12-24 12:15:30 +01 YYYY-MM-DD hh:mm:ss GMT 2012-12-24 12:15:30 GMT YYYY-MM-DD hh:mm:ss GMT±hh 2012-12-24 12:15:30 GMT+01 YYYY-MM-DD hh:mm:ss UTC 2012-12-24 12:15:30 UTC YYYY-MM-DD hh:mm:ss UTC±hh 2012-12-24 12:15:30 UTC+01 YYYY-MM-DD hh:mm:ss.ss ±hhmm 2012-12-24 12:15:30.500 +0100 YYYY-MM-DD hh:mm:ss.ss ±hh:mm 2012-12-24 12:15:30.500 +01:00 YYYY-MM-DD hh:mm:ss.ss ±hh 2012-12-24 12:15:30.500 +01 YYYY-MM-DD hh:mm ±hh:mm 2012-12-24 12:15 +01:00 YYYY-MM-DD hh:mm ±hhmm 2012-12-24 12:15 +0100 YYYY-MM-DD hh:mm ±hh 2012-12-24 12:15 +01 The string representation may consist of a mixture of the basic format and the extended format. The time designator [T] may be in lower case [t] or replaced with a single space. A single space is also accepted between the time of day and the zone designator. The UTC designator [Z] may also be in lower case [z]. The literal string GMT or UTC may be used as a UTC designator and may have an offset. Usage of these string representations is strongly discouraged as they do not conform to the ISO 8601 standard. from_rd $tm = Time::Moment->from_rd($rd); $tm = Time::Moment->from_rd($rd [, offset => 0] [, precision => 3] [, epoch => 0]); Constructs an instance of "Time::Moment" from the given Rata Die. The Rata Die is a count of days elapsed since 0000-12-31T00. The fractional part corresponds to the fraction of the day after midnight. The minimum acceptable Rata Die is 1 which corresponds to 0001-01-01T00. Parameters: offset $tm = Time::Moment->from_rd($rd, offset => 0); The optional parameter *offset* [-1080, 1080] (±18:00) specifies the offset from UTC in minutes. The default offset is 0. precision $tm = Time::Moment->from_rd($rd, precision => 3); The optional parameter *precision* [0, 9] specifies the precision of the fractional seconds. The default precision is 3 (milliseconds). epoch $tm = Time::Moment->from_rd($rd, epoch => 0); The optional parameter *epoch* specifies the epoch date relative to 0000-12-31T00. The epoch date for the Rata Die is 0. from_jd $tm = Time::Moment->from_jd($jd); $tm = Time::Moment->from_jd($jd [, precision => 3] [, epoch => -1721424.5]); Constructs an instance of "Time::Moment" from the given Julian Date. The Julian Date is a count of days elapsed since -4713-11-24T12Z. The fractional part corresponds to the fraction of the day after noon. The minimum acceptable Julian Date is 1721425.5 which corresponds to 0001-01-01T00Z. Parameters: precision $tm = Time::Moment->from_jd($jd, precision => 3); The optional parameter *precision* [0, 9] specifies the precision of the fractional seconds. The default precision is 3 (milliseconds). epoch $tm = Time::Moment->from_jd($jd, epoch => -1721424.5); The optional parameter *epoch* specifies the epoch date relative to 0000-12-31T00Z. The epoch date for the Julian Date is -1721424.5. from_mjd $tm = Time::Moment->from_mjd($mjd); $tm = Time::Moment->from_mjd($mjd [, precision => 3] [, epoch => 678576]); Constructs an instance of "Time::Moment" from the given Modified Julian Date. The Modified Julian Date is a count of days elapsed since 1858-11-17T00Z. The fractional part corresponds to the fraction of the day after midnight. The minimum acceptable Modified Julian Date is -678575 which corresponds to 0001-01-01T00Z. Parameters: precision $tm = Time::Moment->from_mjd($mjd, precision => 3); The optional parameter *precision* [0, 9] specifies the precision of the fractional seconds. The default precision is 3 (milliseconds). epoch $tm = Time::Moment->from_mjd($mjd, epoch => 678576); The optional parameter *epoch* specifies the epoch date relative to 0000-12-31T00Z. The epoch date for the Modified Julian Date is 678576. INSTANCE METHODS year $year = $tm->year; Returns the year [1, 9999]. quarter $quarter = $tm->quarter; Returns the quarter of the year [1, 4]. month $month = $tm->month; Returns the month of the year [1, 12]. week $week = $tm->week; Returns the week of the year [1, 53]. day_of_year $day = $tm->day_of_year; Returns the day of the year [1, 366]. day_of_quarter $day = $tm->day_of_quarter; Returns the day of the quarter [1, 92]. day_of_month $day = $tm->day_of_month; Returns the day of the month [1, 31]. day_of_week $day = $tm->day_of_week; Returns the day of the week [1=Monday, 7=Sunday]. hour $hour = $tm->hour; Returns the hour of the day [0, 23]. minute $minute = $tm->minute; Returns the minute of the hour [0, 59]. minute_of_day $minute = $tm->minute_of_day; Returns the minute of the day [0, 1439]. second $second = $tm->second; Returns the second of the minute [0, 59]. second_of_day $second = $tm->second_of_day; Returns the second of the day [0, 86_399]. millisecond $millisecond = $tm->millisecond; Returns the millisecond of the second [0, 999]. millisecond_of_day $millisecond = $tm->millisecond_of_day; Returns the millisecond of the day [0, 86_399_999]. microsecond $microsecond = $tm->microsecond; Returns the microsecond of the second [0, 999_999]. microsecond_of_day $microsecond = $tm->microsecond_of_day; Returns the microsecond of the day [0, 86_399_999_999]. nanosecond $nanosecond = $tm->nanosecond; Returns the nanosecond of the second [0, 999_999_999]. nanosecond_of_day $nanosecond = $tm->nanosecond_of_day; Returns the nanosecond of the day [0, 86_399_999_999_999]. epoch $epoch = $tm->epoch; Returns the number of integral seconds from the epoch of 1970-01-01T00Z. offset $offset = $tm->offset; Returns the offset from UTC in minutes [-1080, 1080] (±18:00). precision $precision = $tm->precision; Returns the precision of the time of the day [-3, 9]. Please see with_precision for an explanation of the returned precision value. jd $jd = $tm->jd; $jd = $tm->jd([precision => 3]); Returns the Julian Date. The Julian Date is a count of days elapsed since -4713-11-24T12Z. The fractional part corresponds to the fraction of the day after noon. The optional named parameter *precision* [0, 9] specifies the precision of the fractional seconds. The default precision is 3 (milliseconds). mjd $mjd = $tm->mjd; $mjd = $tm->mjd([precision => 3]); Returns the Modified Julian Date. The Modified Julian Date is a count of days elapsed since 1858-11-17T00Z. The fractional part corresponds to the fraction of the day after midnight. The optional named parameter *precision* [0, 9] specifies the precision of the fractional seconds. The default precision is 3 (milliseconds). rd $rd = $tm->rd; $rd = $tm->rd([precision => 3]); Returns the Rata Die. The Rata Die is a count of days elapsed since 0000-12-31T00. The fractional part corresponds to the fraction of the day after midnight. The optional named parameter *precision* [0, 9] specifies the precision of the fractional seconds. The default precision is 3 (milliseconds). with $tm2 = $tm1->with($adjuster); Returns a copy of this instance adjusted by the given *adjuster*. The adjuster is a CODE reference invoked with an instance of Time::Moment and is expected to return an instance of Time::Moment. Please see Time::Moment::Adjusters for available adjusters. with_year $tm2 = $tm1->with_year($year); Returns a copy of this instance with the given *year* [1, 9999] altered. The day of the month of the date is unchanged unless the day does not exist in the month. In that case, the day is set to the last day of the month. with_quarter $tm2 = $tm1->with_quarter($quarter); Returns a copy of this instance with the given *quarter* of the year [1, 4] altered. The day of the month of the date is unchanged unless the day does not exist in the month of the quarter. In that case, the day is set to the last day of the month. with_month $tm2 = $tm1->with_month($month); Returns a copy of this instance with the given *month* of the year [1, 12] altered. The day of the month of the date is unchanged unless the day does not exist in the given month. In that case, the day is set to the last day of the given month. with_week $tm2 = $tm1->with_week($week); Returns a copy of this instance with the given *week* of the year [1, 53] altered. The week must be valid for the year, otherwise an exception is raised. with_day_of_year $tm2 = $tm1->with_day_of_year($day); Returns a copy of this instance with the given *day* of the year [1, 366] altered. The day must be valid for the year, otherwise an exception is raised. with_day_of_quarter $tm2 = $tm1->with_day_of_quarter($day); Returns a copy of this instance with the given *day* of the quarter [1, 92] altered. The day must be valid for the year and quarter, otherwise an exception is raised. with_day_of_month $tm2 = $tm1->with_day_of_month($day); Returns a copy of this instance with the given *day* of the month [1, 31] altered. The day must be valid for the year and month, otherwise an exception is raised. with_day_of_week $tm2 = $tm1->with_day_of_week($day); Returns a copy of this instance with the given *day* of the week [1=Monday, 7=Sunday] altered. with_hour $tm2 = $tm1->with_hour($hour); Returns a copy of this instance with the given *hour* of the day [0, 23] altered. with_minute $tm2 = $tm1->with_minute($minute); Returns a copy of this instance with the given *minute* of the hour [0, 59] altered. with_minute_of_day $tm2 = $tm1->with_minute_of_day($minute); Returns a copy of this instance with the given *minute* of the day [0, 1439] altered, any lower-order time elements is unaltered. with_second $tm2 = $tm1->with_second($second); Returns a copy of this instance with the given *second* of the minute [0, 59] altered. with_second_of_day $tm2 = $tm1->with_second_of_day($second); Returns a copy of this instance with the given *second* of the day [0, 86_399] altered, any lower-order time elements is unaltered. with_millisecond $tm2 = $tm1->with_millisecond($millisecond); Returns a copy of this instance with the given *millisecond* of the second [0, 999] altered. The nanosecond of the second is replaced with the given *millisecond* multiplied by 1,000,000. with_millisecond_of_day $tm2 = $tm1->with_millisecond_of_day($millisecond); Returns a copy of this instance with the given *millisecond* of the day [0, 86_400_000] altered. A millisecond value of 86_400_000 (T24:00) is normalized to midnight of the following day, any lower-order time elements is truncated. with_microsecond $tm2 = $tm1->with_microsecond($microsecond); Returns a copy of this instance with the given *microsecond* of the second [0, 999_999] altered. The nanosecond of the second is replaced with the given *microsecond* multiplied by 1,000. with_microsecond_of_day $tm2 = $tm1->with_microsecond_of_day($microsecond); Returns a copy of this instance with the given *microsecond* of the day [0, 86_400_000_000] altered. A microsecond value of 86_400_000_000 (T24:00) is normalized to midnight of the following day, any lower-order time elements is truncated. with_nanosecond $tm2 = $tm1->with_nanosecond($nanosecond); Returns a copy of this instance with the given *nanosecond* of the second [0, 999_999_999] altered. with_nanosecond_of_day $tm2 = $tm1->with_nanosecond_of_day($nanosecond); Returns a copy of this instance with the given *nanosecond* of the day [0, 86_400_000_000_000] altered. A nanosecond value of 86_400_000_000_000 (T24:00) is normalized to midnight of the following day. with_offset_same_instant $tm2 = $tm1->with_offset_same_instant($offset); Returns a copy of this instance with the given *offset* from UTC in minutes [-1080, 1080] (±18:00) altered. The resulting time is at the same instant. $tm = Time::Moment->from_string('2012-12-24T15-05') ->with_offset_same_instant(0); say $tm; # 2012-12-24T20Z with_offset_same_local $tm2 = $tm1->with_offset_same_local($offset); Returns a copy of this instance with the given *offset* from UTC in minutes [-1080, 1080] (±18:00) altered. The resulting time has the same local time. $tm = Time::Moment->from_string('2012-12-24T15-05') ->with_offset_same_local(0); say $tm; # 2012-12-24T15Z with_precision $tm2 = $tm1->with_precision($precision); Returns a copy of this instance with the time of the day altered to the given *precision* [-3, 9]. A precision value between [0, 9] alters the precision of the fractional seconds. A precision of -1 truncates to minute of the hour; -2 truncates to hour of the day; -3 truncates to midnight of the day. $tm = Time::Moment->from_string('2012-12-24T12:30:45.123456789Z'); say $tm->with_precision(6); # T12:30:45.123456Z say $tm->with_precision(3); # T12:30:45.123Z say $tm->with_precision(0); # T12:30:45Z say $tm->with_precision(-1); # T12:30:00Z say $tm->with_precision(-2); # T12:00:00Z say $tm->with_precision(-3); # T00:00:00Z plus_years $tm2 = $tm1->plus_years($years); Returns a copy of this instance with the given number of *years* added. The day of the month of the date is unchanged unless the day does not exist in the resulting month. In that case, the day is set to the last day of the resulting month. For example, 2012-02-29 plus one year results in 2013-02-28. plus_months $tm2 = $tm1->plus_months($months); Returns a copy of this instance with the given number of *months* added. The day of the month of the date is unchanged unless the day does not exist in the resulting month. In that case, the day is set to the last day of the resulting month. For example, 2013-01-31 plus one month results in 2013-02-28; 2013-02-28 plus one month results in 2013-03-28. plus_weeks $tm2 = $tm1->plus_weeks($weeks); Returns a copy of this instance with the given number of *weeks* added. plus_days $tm2 = $tm1->plus_days($days); Returns a copy of this instance with the given number of *days* added. plus_hours $tm2 = $tm1->plus_hours($hours); Returns a copy of this instance with the given number of *hours* added. plus_minutes $tm2 = $tm1->plus_minutes($minutes); Returns a copy of this instance with the given number of *minutes* added. plus_seconds $tm2 = $tm1->plus_seconds($seconds); Returns a copy of this instance with the given number of *seconds* added. plus_milliseconds $tm2 = $tm1->plus_milliseconds($milliseconds); Returns a copy of this instance with the given number of *milliseconds* added. plus_microseconds $tm2 = $tm1->plus_microseconds($microseconds); Returns a copy of this instance with the given number of *microseconds* added. plus_nanoseconds $tm2 = $tm1->plus_nanoseconds($nanoeconds); Returns a copy of this instance with the given number of *nanoseconds* added. minus_years $tm2 = $tm1->minus_years($years); Returns a copy of this instance with the given number of *years* subtracted. The day of the month of the date is unchanged unless the day does not exist in the resulting month. In that case, the day is set to the last day of the resulting month. For example, 2012-02-29 minus one year results in 2011-02-28. minus_months $tm2 = $tm1->minus_months($months); Returns a copy of this instance with the given number of *months* subtracted. The day of the month of the date is unchanged unless the day does not exist in the resulting month. In that case, the day is set to the last day of the resulting month. For example, 2013-03-31 minus one month results in 2013-02-28; 2013-02-28 minus one month results in 2013-01-28. minus_weeks $tm2 = $tm1->minus_weeks($weeks); Returns a copy of this instance with the given number of *weeks* subtracted. minus_days $tm2 = $tm1->minus_days($days); Returns a copy of this instance with the given number of *days* subtracted. minus_hours $tm2 = $tm1->minus_hours($hours); Returns a copy of this instance with the given number of *hours* subtracted. minus_minutes $tm2 = $tm1->minus_minutes($minutes); Returns a copy of this instance with the given number of *minutes* subtracted. minus_seconds $tm2 = $tm1->minus_seconds($seconds); Returns a copy of this instance with the given number of *seconds* subtracted. minus_milliseconds $tm2 = $tm1->minus_milliseconds($milliseconds); Returns a copy of this instance with the given number of *milliseconds* subtracted. minus_microseconds $tm2 = $tm1->minus_microseconds($microseconds); Returns a copy of this instance with the given number of *microseconds* subtracted. minus_nanoseconds $tm2 = $tm1->minus_nanoseconds($nanoseconds); Returns a copy of this instance with the given number of *nanoseconds* subtracted. delta_years $years = $tm->delta_years($other); Returns the difference between the local date of this moment and the *other* in terms of complete years. The result will be negative if the local date of the *other* moment is before this. delta_months $months = $tm->delta_months($other); Returns the difference between the local date of this moment and the *other* in terms of complete months. The result will be negative if the local date of the *other* moment is before this. delta_weeks $weeks = $tm->delta_weeks($other); Returns the difference between the local date of this moment and the *other* in terms of complete weeks. The result will be negative if the local date of the *other* moment is before this. delta_days $days = $tm->delta_days($other); Returns the difference between the local date of this moment and the *other* in terms of complete days. The result will be negative if the local date of the *other* moment is before this. delta_hours $hours = $tm->delta_hours($other); Returns the difference between the instant of this moment and the *other* in terms of complete hours. The result will be negative if the instant of the *other* moment is before this. delta_minutes $minutes = $tm->delta_minutes($other); Returns the difference between the instant of this moment and the *other* in terms of complete minutes. The result will be negative if the instant of the *other* moment is before this. delta_seconds $seconds = $tm->delta_seconds($other); Returns the difference between the instant of this moment and the *other* in terms of complete seconds. The result will be negative if the instant of the *other* moment is before this. delta_milliseconds $milliseconds = $tm->delta_milliseconds($other); Returns the difference between the instant of this moment and the *other* in terms of complete milliseconds. The result will be negative if the instant of the *other* moment is before this. delta_microseconds $microseconds = $tm->delta_microseconds($other); Returns the difference between the instant of this moment and the *other* in terms of complete microseconds. The result will be negative if the instant of the *other* moment is before this. delta_nanoseconds $nanoseconds = $tm->delta_nanoseconds($other); Returns the difference between the instant of this moment and the *other* in terms of complete nanoseconds. The result will be negative if the instant of the *other* moment is before this. at_utc $tm2 = $tm1->at_utc; Returns a copy of this instance with the offset from UTC set to zero. This method is equivalent to: $tm2 = $tm1->with_offset_same_instant(0); at_midnight $tm2 = $tm1->at_midnight; Returns a copy of this instance with the time of day set to midnight, T00:00:00.0. This method is equivalent to: $tm2 = $tm1->with_hour(0) ->with_minute(0) ->with_second(0) ->with_nanosecond(0); at_noon $tm2 = $tm1->at_noon; Returns a copy of this instance with the time of day set to noon, T12:00:00.0. This method is equivalent to: $tm2 = $tm1->with_hour(12) ->with_minute(0) ->with_second(0) ->with_nanosecond(0); at_last_day_of_year $tm2 = $tm1->at_last_day_of_year; Returns a copy of this instance with the date adjusted to the last day of the year, the time of the day is unaltered. at_last_day_of_quarter $tm2 = $tm1->at_last_day_of_quarter; Returns a copy of this instance with the date adjusted to the last day of the quarter, the time of the day is unaltered. at_last_day_of_month $tm2 = $tm1->at_last_day_of_month; Returns a copy of this instance with the date adjusted to the last day of the month, the time of the day is unaltered. is_before $boolean = $tm->is_before($other); Returns a boolean indicating whether or not the instant of this time is before the *other* time. is_after $boolean = $tm->is_after($other); Returns a boolean indicating whether or not the instant of this time is after the *other* time. is_equal $boolean = $tm->is_equal($other); Returns a boolean indicating whether or not the instant of this time is equal the *other* time. compare $integer = $tm->compare($other); $integer = $tm->compare($other [, precision => 9]); Returns an integer indicating whether the instant of this time is before, after or equal the *other* time. Returns a value less than zero if this time is before the other; zero if this date is equal the other time; a value greater than zero if this time is after the other time. The optional parameter *precision* [-3, 9] specifies the precision of the comparison. The default precision is 9 (nanoseconds). Please see with_precision for an explanation of the precision value. is_leap_year $boolean = $tm->is_leap_year; Returns a boolean indicating whether or not the year of the local date of this moment is a leap year. to_string $string = $tm->to_string; $string = $tm->to_string([reduced => false]); Returns a string representation of the instance. If the optional named boolean parameter *reduced* is true a shorter representation is attempted. The string will be in one of the following representations: YYYY-MM-DDThh:mm (only if reduced => true) YYYY-MM-DDThh:mm:ss YYYY-MM-DDThh:mm:ss.fff YYYY-MM-DDThh:mm:ss.ffffff YYYY-MM-DDThh:mm:ss.fffffffff Followed by a zone designator in one of the following representations: Z ±hh (only if reduced => true) ±hh:mm The shortest representation will be used where the omitted parts are implied to be zero. strftime $string = $tm->strftime($format); Formats time according to the conversion specifications in the given $format string. The format string consists of zero or more conversion specifications and ordinary characters. All ordinary characters are copied directly into the resulting string. A conversion specification consists of a percent sign "%" and one other character. The following conversion specifications are supported: %a Replaced by the C locale's abbreviated day of the week name. Example: Mon, Tue, ..., Sun. %A Replaced by the C locale's full day of the week name. Example: Monday, Tuesday, ..., Sunday. %b Replaced by the C locale's abbreviated month name. Example: Jan, Feb, ..., Dec. %B Replaced by the C locale's full month name. Example: January, February, ..., December. %c Replaced by the C locale's date and time representation. Equivalent to "%a %b %e %H:%M:%S %Y". %C Replaced by the year divided by 100 and truncated to an integer, as a decimal number [00, 99]. %d Replaced by the day of the month as a decimal number [01, 31]. %D Equivalent to "%m/%d/%y". %e Replaced by the day of the month as a decimal number [1, 31]; a single digit is preceded by a space. %f Replaced by the fractional second including the preceding decimal point or by an empty string if no fractional seconds are present. This conversion specification permits use of an optional maximum field width [0, 9] where the default field width of 0 will use the shortest of the following representations: .fff (millisecond) .ffffff (microsecond) .fffffffff (nanosecond) Example: $tm = Time::Moment->from_string('2012-12-24T15:30:45.123456Z'); $tm->strftime('%f'); # '.123456' $tm->strftime('%3f'); # '.123' $tm->strftime('%9f'); # '.123456000' $tm = Time::Moment->from_string('2012-12-24T15:30:45Z'); $tm->strftime('%f'); # '' $tm->strftime('%3f'); # '' %3f is replaced by decimal point and exactly three fractional digits (zero-padded on the right or truncated if needed) if fractional seconds are present. *This conversion specification is an extension to the "IEEE Std 1003.1" *. %F Equivalent to "%Y-%m-%d". %g Replaced by the last 2 digits of the year of the week as a decimal number [00, 99]. %G Replaced by the week-based year as a decimal number [0001, 9999]. %h Equivalent to %b. %H Replaced by the hour of day (24-hour clock) as a decimal number [00, 23]. %I Replaced by the hour of day (12-hour clock) as a decimal number [01, 12]. %j Replaced by the day of the year as a decimal number [001, 366]. %k Replaced by the hour of day (24-hour clock) as a decimal number [1, 23]; a single digit is preceded by a space. *This conversion specification is an extension to the "IEEE Std 1003.1" *. %l Replaced by the hour of day (12-hour clock) as a decimal number [1, 12]; a single digit is preceded by a space. *This conversion specification is an extension to the "IEEE Std 1003.1" *. %m Replaced by the month of the year as a decimal number [01, 12]. %M Replaced by the minute of hour as a decimal number [00, 59]. %n Replaced by a character. %N Replaced by the fractional second as a decimal number. This conversion specification permits use of an optional maximum field width [0, 9] where the default field width of 0 will use the shortest of the following representations: fff (millisecond) ffffff (microsecond) fffffffff (nanosecond) Example: $tm = Time::Moment->from_string('2012-12-24T15:30:45.123456Z'); $tm->strftime('%N'); # '123456' $tm->strftime('%3N'); # '123' $tm->strftime('%9N'); # '123456000' %3N is replaced by exactly three fractional digits (zero-padded on the right or truncated if needed). *This conversion specification is an extension to the "IEEE Std 1003.1" *. %p Replaced by the C locale's meridian notation. Example: AM, PM. %r Replaced by the C locale's time in a.m. and p.m. notation. Equivalent to "%I:%M:%S %p". %R Replaced by the time in 24-hour notation. Equivalent to "%H:%M". %s Replaced by the number of seconds from the epoch of 1970-01-01T00:00:00Z as a decimal number. *This conversion specification is an extension to the "IEEE Std 1003.1" *. %S Replaced by the second of hour as a decimal number [00, 59]. %t Replaced by a character. %T Replaced by the time of day. Equivalent to "%H:%M:%S". %u Replaced by the day of the week as a decimal number [1, 7], with 1 representing Monday. %U Replaced by the week number of the year as a decimal number [00, 53]. The first Sunday of January is the first day of week 1; days in the new year before this are in week 0. %V Replaced by the week number of the year (Monday as the first day of the week) as a decimal number [01, 53]. If the week containing 1 January has four or more days in the new year, then it is considered week 1. Otherwise, it is the last week of the previous year, and the next week is week 1. Both January 4th and the first Thursday of January are always in week 1. %w Replaced by the day of the week as a decimal number [0, 6], with 0 representing Sunday. %W Replaced by the week number of the year as a decimal number [00, 53]. The first Monday of January is the first day of week 1; days in the new year before this are in week 0. %x Replaced by the C locale's date representation. Equivalent to "%m/%d/%y". %X Replaced by the C locale's time representation. Equivalent to "%H:%M:%S". %y Replaced by the last two digits of the year as a decimal number [00, 99]. %Y Replaced by the year as a decimal number [0001, 9999]. %z Replaced by the offset from UTC in the ISO 8601 basic format (±hhmm). %:z Replaced by the offset from UTC in the ISO 8601 extended format (±hh:mm). %Z Replaced by the offset from UTC in the ISO 8601 extended format or by UTC designator (±hh:mm or Z). "%%" Replaced by %. length_of_year $integer = $tm->length_of_year; Returns the length of the year in days [365, 366]. length_of_quarter $integer = $tm->length_of_quarter; Returns the length of the quarter of the year in days [90, 92]. length_of_month $integer = $tm->length_of_month; Returns the length of the month of the year in days [28, 31]. length_of_week_year $integer = $tm->length_of_week_year; Returns the length of the week of the year in weeks [52, 53]. utc_rd_values ($rdn, $sod, $nanosecond) = $tm->utc_rd_values; Returns a list of three elements: $rdn The number of integral days from the Rata Die epoch of 0000-12-31. $sod The second of the day [0, 86_399]. $nanosecond The nanosecond of the second [0, 999_999_999]. utc_rd_as_seconds $seconds = $tm->utc_rd_as_seconds; Returns the number of integral seconds from the Rata Die epoch of 0000-12-31T00:00:00Z. local_rd_values ($rdn, $sod, $nanosecond) = $tm->local_rd_values; Returns a list of three elements: $rdn The number of integral days from the Rata Die epoch of 0000-12-31. $sod The second of the day [0, 86_399]. $nanosecond The nanosecond of the second [0, 999_999_999]. local_rd_as_seconds $seconds = $tm->local_rd_as_seconds; Returns the number of integral seconds from the Rata Die epoch of 0000-12-31T00:00:00. OVERLOADED OPERATORS stringification $string = "$tm"; The $string will be in one of the following representations: YYYY-MM-DDThh:mm:ss YYYY-MM-DDThh:mm:ss.fff YYYY-MM-DDThh:mm:ss.ffffff YYYY-MM-DDThh:mm:ss.fffffffff Followed by a zone designator in one of the following representations: Z ±hh:mm The shortest representation will be used where the omitted parts are implied to be zero. This representation is conformant with ISO 8601 profiles, such as: * RFC 3339 Date and Time on the Internet: Timestamps * RFC 4287 The Atom Syndication Format * W3C Date and Time Formats * HTML5 * XML Schema The "to_string" method or the "strftime" format string "%Y-%m-%dT%H:%M:%S%f%Z" produces an equivalent string representation: "$tm" eq $tm->to_string; "$tm" eq $tm->strftime("%Y-%m-%dT%H:%M:%S%f%Z"); The total length of the string representation will be between 20 and 35 characters (inclusive). comparison $integer = $tm1 <=> $tm2; $boolean = $tm1 == $tm2; $boolean = $tm1 != $tm2; $boolean = $tm1 < $tm2; $boolean = $tm1 > $tm2; $boolean = $tm1 <= $tm2; $boolean = $tm1 >= $tm2; SERIALIZATION Storable The serialized representation of a "Time::Moment" is a string of 16 bytes that contains MAGIC (2 bytes), time zone offset from UTC (2 bytes), the number of days from Rata Die (4 bytes), second of the day (4 bytes) and nanosecond of the second (4 bytes). The total size of the serialized "Time::Moment" instance using "nfreeze" is 34 bytes. JSON "Time::Moment" implements a "TO_JSON" method that returns the stringified representation of the instance. CBOR "Time::Moment" implements a "TO_CBOR" method that returns the stringified representation of the instance using tag 0 (*standard date/time string*). See CBOR::XS, RFC 7049 Section 2.4.1 and "eg/cbor.pl" for an example how to roundtrip instances of "Time::Moment". Sereal Sereal version 2.030 or later implements support for the generic serialization protocol "FREEZE/THAW". FREEZE/THAW "Time::Moment" implements a "FREEZE" method that returns the stringified representation of the instance and a "THAW" method according to the serialization protocol specified in Types::Serialiser. EXAMPLE FORMAT STRINGS ISO 8601 - Data elements and interchange formats Date Calendar date - 24 December 2012 Basic format: Example: %Y%m%d 20121224 %y%m 201212 (reduced accuracy) Extended format: Example: %Y-%m-%d 2012-12-24 %Y-%m 2012-12 (reduced accuracy) Ordinal date - 24 December 2012 Basic format: Example: %Y%j 2012359 Extended format: Example: %Y-%j 2012-359 Week date - Monday, 24 December 2012 Basic format: Example: %GW%V%u 2012W521 %GW%V 2012W52 (reduced accuracy) Extended format: Example: %G-W%V-%u 2012-W52-1 %G-W%V 2012-W52 (reduced accuracy) Time of day Local time - 30 minutes and 45 seconds past 15 hours Basic format: Example: %H%M%S 153045 %H%M 1530 (reduced accuracy) Extended format: Example: %H:%M:%S 15:30:45 %H:%M 15:30 (reduced accuracy) Local time with decimal fractions - 30 minutes and 45 and a half second past 15 hours Basic format: Example: %H%M%S%f 153045.500 %H%M%S.%1N 153045.5 Extended format: Example: %H:%M:%S%f 15:30:45.500 %H:%M:%S.%1N 15:30:45.5 Local time and the difference from UTC - 30 minutes and 45 seconds past 15 hours, one hour ahead of UTC Basic format: Example: %H%M%S%z 153045+0100 Extended format: Example: %H:%M:%S%Z 15:30:45+01:00 Date and time of day Combinations of calendar date and time of day Basic format: Example: %Y%m%dT%H%M%S%z 20121224T153045+0100 %Y%m%dT%H%M%S%f%z 20121224T153045.500+0100 %Y%m%dT%H%M%z 20121224T1530+0100 (reduced accuracy) Extended format: Example: %Y-%m-%dT%H:%M:%S%Z 2012-12-24T15:30:45+01:00 %Y-%m-%dT%H:%M:%S%f%Z 2012-12-24T15:30:45.500+01:00 %Y-%m-%dT%H:%M%Z 2012-12-24T15:30+01:00 (reduced accuracy) Combinations of ordinal date and time of day Basic format: Example: %Y%jT%H%M%S%z 2012359T153045+0100 %Y%jT%H%M%S%f%z 2012359T153045.500+0100 %Y%jT%H%M%z 2012359T1530+0100 (reduced accuracy) Extended format: Example: %Y-%jT%H:%M:%S%Z 2012-359T15:30:45+01:00 %Y-%jT%H:%M:%S%f%Z 2012-359T15:30:45.500+01:00 %Y-%jT%H:%M%Z 2012-359T15:30+01:00 (reduced accuracy) Combinations of week date and time of day Basic format: Example: %GW%V%uT%H%M%S%z 2012W521T153045+0100 %GW%V%uT%H%M%S%f%z 2012W521T153045.500+0100 %GW%V%uT%H%M%f%z 2012W521T1530+0100 (reduced accuracy) Extended format: Example: %G-W%V-%uT%H:%M:%S%Z 2012-W52-1T15:30:45+01:00 %G-W%V-%uT%H:%M:%S%f%Z 2012-W52-1T15:30:45.500+01:00 %G-W%V-%uT%H:%M%Z 2012-W52-1T15:30+01:00 (reduced accuracy) ISO 9075 - Information technology - Database languages - SQL Literal values from Part 2: Foundation (SQL/Foundation) Date: Example: %Y-%m-%d 2012-12-24 Time: Example: %H:%M:%S 15:30:45 %H:%M:%S%f 15:30:45.500 Timestamp: Example: %Y-%m-%d %H:%M:%S 2012-12-24 15:30:45 %Y-%m-%d %H:%M:%S %:z 2012-12-24 15:30:45 +01:00 %Y-%m-%d %H:%M:%S%f 2012-12-24 15:30:45.500 %Y-%m-%d %H:%M:%S%f %:z 2012-12-24 15:30:45.500 +01:00 RFC 1123 - Requirements for Internet Hosts RFC 822 as updated by RFC 1123 . Format: Example: %a, %d %b %Y %H:%M:%S %z Mon, 24 Dec 2012 15:30:45 +0100 RFC 2616 - HTTP/1.1 RFC 2616 - 3.3.1 Full Date . Format: Example: %a, %d %b %Y %H:%M:%S GMT Mon, 24 Dec 2012 14:30:45 GMT An HTTP date value represents time as an instance of UTC: $string = $tm->at_utc->strftime("%a, %d %b %Y %H:%M:%S GMT"); RFC 5322 - Internet Message Format RFC 5322 - 3.3. Date and Time Specification . Format: Example: %a, %d %b %Y %H:%M:%S %z Mon, 24 Dec 2012 15:30:45 +0100 %a, %d %b %Y %H:%M %z Mon, 24 Dec 2012 15:30 +0100 %d %b %Y %H:%M:%S %z 24 Dec 2012 15:30:45 +0100 %d %b %Y %H:%M %z 24 Dec 2012 15:30 +0100 TIME ZONES An instance of "Time::Moment" represents an unambiguous point in time, but it's not time zone aware. When performing arithmetic on the local date/time or altering the components of the local date/time it may be necessary to use a time zone to convert to the correct representation. "Time::Moment" is API compatible with DateTime::TimeZone and DateTime::TimeZone::Tzfile. Converting from instant time to designated time zone $tm = Time::Moment->new( year => 2012, month => 12, day => 24, hour => 15 ); $zone = DateTime::TimeZone->new(name => 'America/New_York'); $offset = $zone->offset_for_datetime($tm) / 60; say $tm->with_offset_same_instant($offset); # 2012-12-24T10-05 Converting from local time to designated time zone $tm = Time::Moment->new( year => 2012, month => 12, day => 24, hour => 15 ); $zone = DateTime::TimeZone->new(name => 'America/New_York'); $offset = $zone->offset_for_local_datetime($tm) / 60; say $tm->with_offset_same_local($offset); # 2012-12-24T15-05 The Effect of Daylight Saving Time The time zone *Europe/Brussels* has 01:00 UTC as standard time, and 02:00 UTC as daylight savings time, with transition dates according to the European Summer Time . $zone = DateTime::TimeZone->new(name => 'Europe/Brussels'); sub convert_from_instant { my ($tm, $zone) = @_; my $offset = $zone->offset_for_datetime($tm) / 60; return $tm->with_offset_same_instant($offset); } sub convert_from_local { my ($tm, $zone) = @_; my $offset = $zone->offset_for_local_datetime($tm) / 60; return $tm->with_offset_same_local($offset); } European Summer Time begins (clocks go forward) at 01:00 UTC on the last Sunday in March, in 2014 the transition date was March 30. $tm1 = Time::Moment->from_string('2014-03-29T12+01'); $tm2 = $tm1->plus_hours(24); say convert_from_instant($tm2, $zone); # 2014-03-30T13+02 say convert_from_local($tm2, $zone); # 2014-03-30T12+02 During the transition from standard time to daylight savings time, the local time interval between 02:00:00 and 02:59:59 does not exist. Local time values in that interval are invalid. "DateTime::TimeZone" raises an exception when attempting to convert non-existing local time. $tm1 = Time::Moment->from_string('2014-03-29T22+01'); $tm2 = $tm1->plus_hours(4); say convert_from_instant($tm2, $zone); # 2014-03-30T03+02 say convert_from_local($tm2, $zone); # raises an exception European Summer Time ends (clocks go backward) at 01:00 UTC on the last Sunday in October, in 2014 the transition date was October 26. $tm1 = Time::Moment->from_string('2014-10-25T12+02'); $tm2 = $tm1->plus_hours(24); say convert_from_instant($tm2, $zone); # 2014-10-26T11+01 say convert_from_local($tm2, $zone); # 2014-10-26T12+01 During the transition from daylight savings time to standard time, the local time interval between 02:00:00 and 02:59:59 is repeated. Local time values in that interval are ambiguous because they occur twice. When "DateTime::TimeZone" converts an ambiguous local time it returns the numerically lowest offset (usually the standard one). $tm1 = Time::Moment->from_string('2014-10-25T22+02'); $tm2 = $tm1->plus_hours(4); say convert_from_instant($tm2, $zone); # 2014-10-26T02+02 say convert_from_local($tm2, $zone); # 2014-10-26T02+01 DIAGNOSTICS (F) Usage: %s Method called with wrong number of arguments. (F) Parameter '%s' is out of range (F) Parameter '%s' is out of the range [%d, %d] (F) Cannot coerce object of type %s to Time::Moment (F) Could not parse the given string (F) %s is not an instance of Time::Moment (F) A %s object can only be compared to another %s object ('%s', '%s') THREAD SAFETY "Time::Moment" is thread safe. SEE ALSO DateTime Time::Piece SUPPORT Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at . You will be notified automatically of any progress on your issue. SOURCE CODE This is open source software. The code repository is available for public review and contribution under the terms of the license. git clone https://github.com/chansen/p5-time-moment AUTHOR Christian Hansen "chansen@cpan.org" COPYRIGHT Copyright 2013-2017 by Christian Hansen. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Time-Moment-0.44/src/000755 000765 000024 00000000000 13274643625 015161 5ustar00chansenstaff000000 000000 Time-Moment-0.44/t/000755 000765 000024 00000000000 13274643625 014635 5ustar00chansenstaff000000 000000 Time-Moment-0.44/typemap000644 000765 000024 00000000617 12545725221 015771 0ustar00chansenstaff000000 000000 TYPEMAP I64V T_I64V moment_t T_MOMENT const moment_t T_MOMENT moment_t * T_MOMENT_PTR const moment_t * T_MOMENT_PTR INPUT T_I64V $var = SvI64V($arg); T_MOMENT $var = sv_2moment($arg, \"$var\"); T_MOMENT_PTR $var = sv_2moment_ptr($arg, \"$var\"); OUTPUT T_I64V $arg = newSVi64v($var); T_MOMENT $arg = newSVmoment(&$var, stash); Time-Moment-0.44/t/000_load.t000755 000765 000024 00000000456 12262071526 016317 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More tests => 1; use Config; BEGIN { use_ok('Time::Moment'); } my @has = qw(d_gettimeod d_localtime_r); foreach my $var (@has) { $var .= '=' . ($Config{$var} ? 'true' : 'false') } diag("Time::Moment $Time::Moment::VERSION, Perl $], $^X (@has)"); Time-Moment-0.44/t/100_basic.t000755 000765 000024 00000024214 12302250567 016457 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; BEGIN { use_ok('Time::Moment'); } my @tests = ( { day_of_month => 1, day_of_quarter => 1, day_of_week => 4, day_of_year => 1, epoch => 0, hour => 0, local_rd_as_seconds => 62135683200, nanosecond => 0, microsecond => 0, millisecond => 0, minute => 0, month => 1, offset => 0, quarter => 1, second => 0, strftime => { "a" => "Thu", "A" => "Thursday", "B" => "January", "b" => "Jan", "c" => "Thu Jan 1 00:00:00 1970", "C" => "19", "d" => "01", "D" => "01/01/70", "e" => " 1", "_e" => " 1", "-e" => "1", "0e" => "01", "f" => "", "0f" => "", "1f" => "", "2f" => "", "3f" => "", "6f" => "", "9f" => "", "F" => "1970-01-01", "g" => "70", "G" => "1970", "h" => "Jan", "H" => "00", "I" => "12", "j" => "001", "0j" => "001", "_j" => " 1", "-j" => "1", "k" => " 0", "l" => "12", "M" => "00", "m" => "01", "n" => "\n", "N" => "000", "0N" => "000", "3N" => "000", "6N" => "000000", "p" => "AM", "r" => "12:00:00 AM", "R" => "00:00", "s" => "0", "S" => "00", "T" => "00:00:00", "t" => "\t", "u" => "4", "U" => "00", "V" => "01", "w" => "4", "W" => "00", "x" => "01/01/70", "X" => "00:00:00", "Y" => "1970", "y" => "70", "z" => "+0000", ":z" => "+00:00", "Z" => "Z", }, string => "1970-01-01T00:00:00Z", to_string_reduced => "1970-01-01T00:00Z", utc_rd_as_seconds => 62135683200, week => 1, year => 1970, }, { day_of_month => 21, day_of_quarter => 82, day_of_week => 6, day_of_year => 355, epoch => 1387615694, hour => 13, local_rd_as_seconds => 63523314014, nanosecond => 426347000, microsecond => 426347, millisecond => 426, minute => 0, month => 12, offset => 252, quarter => 4, second => 14, strftime => { "a" => "Sat", "A" => "Saturday", "B" => "December", "b" => "Dec", "c" => "Sat Dec 21 13:00:14 2013", "C" => "20", "d" => "21", "D" => "12/21/13", "e" => "21", "f" => ".426347", "0f" => ".426347", "3f" => ".426", "4f" => ".4263", "5f" => ".42634", "6f" => ".426347", "9f" => ".426347000", "F" => "2013-12-21", "g" => "13", "G" => "2013", "h" => "Dec", "H" => "13", "I" => "01", "k" => "13", "l" => " 1", "j" => "355", "M" => "00", "m" => "12", "n" => "\n", "N" => "426347", "0N" => "426347", "3N" => "426", "6N" => "426347", "p" => "PM", "r" => "01:00:14 PM", "R" => "13:00", "s" => "1387615694", "S" => "14", "T" => "13:00:14", "t" => "\t", "u" => "6", "U" => "50", "V" => "51", "w" => "6", "W" => "50", "x" => "12/21/13", "X" => "13:00:14", "Y" => "2013", "y" => "13", "z" => "+0412", ":z" => "+04:12", "Z" => "+04:12", }, string => "2013-12-21T13:00:14.426347+04:12", to_string_reduced => "2013-12-21T13:00:14.426347+04:12", utc_rd_as_seconds => 63523298894, week => 51, year => 2013, }, { day_of_month => 4, day_of_quarter => 66, day_of_week => 5, day_of_year => 247, epoch => 4092260337, hour => 12, local_rd_as_seconds => 66227893137, nanosecond => 91592000, microsecond => 91592, millisecond => 91, minute => 58, month => 9, offset => -840, quarter => 3, second => 57, strftime => { "a" => "Fri", "A" => "Friday", "B" => "September", "b" => "Sep", "c" => "Fri Sep 4 12:58:57 2099", "C" => "20", "d" => "04", "D" => "09/04/99", "e" => " 4", "f" => ".091592", "0f" => ".091592", "3f" => ".091", "F" => "2099-09-04", "g" => "99", "G" => "2099", "h" => "Sep", "H" => "12", "I" => "12", "j" => "247", "k" => "12", "l" => "12", "M" => "58", "m" => "09", "n" => "\n", "N" => "091592", "0N" => "091592", "3N" => "091", "6N" => "091592", "p" => "PM", "r" => "12:58:57 PM", "R" => "12:58", "s" => "4092260337", "S" => "57", "T" => "12:58:57", "t" => "\t", "u" => "5", "U" => "35", "V" => "36", "w" => "5", "W" => "35", "x" => "09/04/99", "X" => "12:58:57", "Y" => "2099", "y" => "99", ":z" => "-14:00", "Z" => "-14:00", }, string => "2099-09-04T12:58:57.091592-14:00", to_string_reduced => "2099-09-04T12:58:57.091592-14", utc_rd_as_seconds => 66227943537, week => 36, year => 2099, }, ); my @Accessors = qw( year quarter month week day_of_year day_of_quarter day_of_month day_of_week hour minute second millisecond microsecond epoch offset utc_rd_as_seconds local_rd_as_seconds ); foreach my $test (@tests) { my $name = $test->{string}; my $tm = Time::Moment->from_epoch(@$test{qw(epoch nanosecond)}) ->with_offset($test->{offset}); foreach my $accessor (@Accessors) { is($tm->$accessor, $test->{$accessor}, "${name} ->${accessor}"); } my $strftime = $test->{strftime}; foreach my $spec (sort keys %{$strftime}) { is($tm->strftime("%${spec}"), $strftime->{$spec}, "${name} strftime('%${spec}')"); } is($tm, $test->{string}, "{$name} expected stringified representation"); is($tm->to_string, $test->{string}, "{$name} ->to_string representation"); is($tm->to_string(reduced => 1), $test->{to_string_reduced}, "{$name} ->to_string(reduced => 1) representation"); } done_testing(); Time-Moment-0.44/t/110_now.t000755 000765 000024 00000001542 13072611661 016202 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use lib 't'; use Test::More; use Util qw[throws_ok lives_ok]; BEGIN { use_ok('Time::Moment'); } { my $tm; lives_ok { $tm = Time::Moment->now }; isa_ok($tm, 'Time::Moment'); cmp_ok($tm->epoch, '>', 0, "epoch"); my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = localtime($tm->epoch); $year += 1900; $yday += 1; $mon += 1; $wday = 1 + ($wday + 6) % 7; is($tm->year, $year, '->year'); is($tm->month, $mon, '->month'); is($tm->day_of_year, $yday, '->day_of_year'); is($tm->day_of_month, $mday, '->day_of_month'); is($tm->day_of_week, $wday, '->day_of_week'); is($tm->hour, $hour, '->hour'); is($tm->minute, $min, '->minute'); is($tm->second, $sec, '->second'); } done_testing(); Time-Moment-0.44/t/120_now_utc.t000755 000765 000024 00000001621 13072611652 017054 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use lib 't'; use Test::More; use Util qw[throws_ok lives_ok]; BEGIN { use_ok('Time::Moment'); } { my $tm; lives_ok { $tm = Time::Moment->now_utc }; isa_ok($tm, 'Time::Moment'); cmp_ok($tm->epoch, '>', 0, "epoch"); cmp_ok($tm->offset, '==', 0, "offset"); my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday) = gmtime($tm->epoch); $year += 1900; $yday += 1; $mon += 1; $wday = 1 + ($wday + 6) % 7; is($tm->year, $year, '->year'); is($tm->month, $mon, '->month'); is($tm->day_of_year, $yday, '->day_of_year'); is($tm->day_of_month, $mday, '->day_of_month'); is($tm->day_of_week, $wday, '->day_of_week'); is($tm->hour, $hour, '->hour'); is($tm->minute, $min, '->minute'); is($tm->second, $sec, '->second'); } done_testing(); Time-Moment-0.44/t/130_from_epoch.t000755 000765 000024 00000043274 13072611652 017532 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use lib 't'; use Test::More; use Util qw[throws_ok lives_ok]; BEGIN { use_ok('Time::Moment'); } { my @tests = ( [ -62135596800, 0, '0001-01-01T00:00:00Z' ], [ -62135596800, 123456789, '0001-01-01T00:00:00.123456789Z' ], [ -62135596800, 123456000, '0001-01-01T00:00:00.123456Z' ], [ -62135596800, 123000000, '0001-01-01T00:00:00.123Z' ], [ 0, 0, '1970-01-01T00:00:00Z' ], [ 253402300799, 0, '9999-12-31T23:59:59Z' ], [ 253402300799, 987654321, '9999-12-31T23:59:59.987654321Z' ], [ 253402300799, 987654000, '9999-12-31T23:59:59.987654Z' ], [ 253402300799, 987000000, '9999-12-31T23:59:59.987Z' ], ); foreach my $test (@tests) { my ($secs, $nos, $string) = @$test; my $tm; { my $prefix = "from_epoch($secs, $nos)"; lives_ok { $tm = Time::Moment->from_epoch($secs, $nos) } $prefix; is($tm->epoch, $secs, "$prefix->epoch"); is($tm->nanosecond, $nos, "$prefix->nanosecond"); is($tm->offset, 0, "$prefix->offset"); is($tm->to_string, $string, "$prefix->to_string"); } { my $prefix = "from_epoch($secs, nanosecond => $nos)"; lives_ok { $tm = Time::Moment->from_epoch($secs, nanosecond => $nos) } $prefix; is($tm->epoch, $secs, "$prefix->epoch"); is($tm->nanosecond, $nos, "$prefix->nanosecond"); is($tm->offset, 0, "$prefix->offset"); is($tm->to_string, $string, "$prefix->to_string"); } } } { my @tests = ( [ '1920-12-31T23:59:59Z', -1546300801.0 ], [ '1920-12-31T23:59:59.000001Z', -1546300800.999999046325684 ], [ '1920-12-31T23:59:59.000002Z', -1546300800.999998092651367 ], [ '1920-12-31T23:59:59.000010Z', -1546300800.999989986419678 ], [ '1920-12-31T23:59:59.000020Z', -1546300800.999979972839355 ], [ '1920-12-31T23:59:59.000100Z', -1546300800.999900102615356 ], [ '1920-12-31T23:59:59.000200Z', -1546300800.999799966812134 ], [ '1920-12-31T23:59:59.001Z', -1546300800.999000072479248 ], [ '1920-12-31T23:59:59.002Z', -1546300800.997999906539917 ], [ '1920-12-31T23:59:59.010Z', -1546300800.990000009536743 ], [ '1920-12-31T23:59:59.020Z', -1546300800.980000019073486 ], [ '1920-12-31T23:59:59.100Z', -1546300800.900000095367432 ], [ '1920-12-31T23:59:59.192Z', -1546300800.808000087738037 ], [ '1920-12-31T23:59:59.192080Z', -1546300800.807919979095459 ], [ '1920-12-31T23:59:59.192090Z', -1546300800.807909965515137 ], [ '1920-12-31T23:59:59.192098Z', -1546300800.807902097702026 ], [ '1920-12-31T23:59:59.192099Z', -1546300800.807900905609131 ], [ '1920-12-31T23:59:59.200Z', -1546300800.799999952316284 ], [ '1920-12-31T23:59:59.300Z', -1546300800.700000047683716 ], [ '1920-12-31T23:59:59.400Z', -1546300800.599999904632568 ], [ '1920-12-31T23:59:59.419200Z', -1546300800.58080005645752 ], [ '1920-12-31T23:59:59.419209Z', -1546300800.580790996551514 ], [ '1920-12-31T23:59:59.490Z', -1546300800.509999990463257 ], [ '1920-12-31T23:59:59.499Z', -1546300800.500999927520752 ], [ '1920-12-31T23:59:59.499900Z', -1546300800.500099897384644 ], [ '1920-12-31T23:59:59.500Z', -1546300800.5 ], [ '1920-12-31T23:59:59.500001Z', -1546300800.499999046325684 ], [ '1920-12-31T23:59:59.500010Z', -1546300800.499989986419678 ], [ '1920-12-31T23:59:59.500100Z', -1546300800.499900102615356 ], [ '1920-12-31T23:59:59.501Z', -1546300800.499000072479248 ], [ '1920-12-31T23:59:59.510Z', -1546300800.490000009536743 ], [ '1920-12-31T23:59:59.600Z', -1546300800.400000095367432 ], [ '1920-12-31T23:59:59.700Z', -1546300800.299999952316284 ], [ '1920-12-31T23:59:59.800Z', -1546300800.200000047683716 ], [ '1920-12-31T23:59:59.900Z', -1546300800.099999904632568 ], [ '1920-12-31T23:59:59.980Z', -1546300800.019999980926514 ], [ '1920-12-31T23:59:59.990Z', -1546300800.009999990463257 ], [ '1920-12-31T23:59:59.998Z', -1546300800.002000093460083 ], [ '1920-12-31T23:59:59.999Z', -1546300800.000999927520752 ], [ '1920-12-31T23:59:59.999800Z', -1546300800.000200033187866 ], [ '1969-12-31T23:59:58Z', -2.0 ], [ '1969-12-31T23:59:58.500Z', -1.5 ], [ '1969-12-31T23:59:58.800Z', -1.2 ], [ '1969-12-31T23:59:58.900Z', -1.1 ], [ '1969-12-31T23:59:58.980Z', -1.02 ], [ '1969-12-31T23:59:58.990Z', -1.01 ], [ '1969-12-31T23:59:58.998Z', -1.002 ], [ '1969-12-31T23:59:58.999Z', -1.001 ], [ '1969-12-31T23:59:58.999800Z', -1.0002 ], [ '1969-12-31T23:59:58.999900Z', -1.0001 ], [ '1969-12-31T23:59:58.999980Z', -1.00002 ], [ '1969-12-31T23:59:58.999990Z', -1.00001 ], [ '1969-12-31T23:59:58.999998Z', -1.000002 ], [ '1969-12-31T23:59:58.999999Z', -1.000001 ], [ '1969-12-31T23:59:59Z', -1.0 ], [ '1969-12-31T23:59:59.000001Z', -0.999999 ], [ '1969-12-31T23:59:59.000002Z', -0.999998 ], [ '1969-12-31T23:59:59.000010Z', -0.99999 ], [ '1969-12-31T23:59:59.000020Z', -0.99998 ], [ '1969-12-31T23:59:59.000100Z', -0.9999 ], [ '1969-12-31T23:59:59.000200Z', -0.9998 ], [ '1969-12-31T23:59:59.001Z', -0.999 ], [ '1969-12-31T23:59:59.002Z', -0.998 ], [ '1969-12-31T23:59:59.010Z', -0.99 ], [ '1969-12-31T23:59:59.020Z', -0.98 ], [ '1969-12-31T23:59:59.100Z', -0.9 ], [ '1969-12-31T23:59:59.200Z', -0.8 ], [ '1969-12-31T23:59:59.300Z', -0.7 ], [ '1969-12-31T23:59:59.400Z', -0.6 ], [ '1969-12-31T23:59:59.490Z', -0.51 ], [ '1969-12-31T23:59:59.499Z', -0.501 ], [ '1969-12-31T23:59:59.499900Z', -0.5001 ], [ '1969-12-31T23:59:59.499990Z', -0.50001 ], [ '1969-12-31T23:59:59.499999Z', -0.500001 ], [ '1969-12-31T23:59:59.500Z', -0.5 ], [ '1969-12-31T23:59:59.500001Z', -0.499999 ], [ '1969-12-31T23:59:59.500010Z', -0.49999 ], [ '1969-12-31T23:59:59.500100Z', -0.4999 ], [ '1969-12-31T23:59:59.501Z', -0.499 ], [ '1969-12-31T23:59:59.510Z', -0.49 ], [ '1969-12-31T23:59:59.600Z', -0.4 ], [ '1969-12-31T23:59:59.700Z', -0.3 ], [ '1969-12-31T23:59:59.800Z', -0.2 ], [ '1969-12-31T23:59:59.900Z', -0.1 ], [ '1969-12-31T23:59:59.980Z', -0.02 ], [ '1969-12-31T23:59:59.990Z', -0.01 ], [ '1969-12-31T23:59:59.998Z', -0.002 ], [ '1969-12-31T23:59:59.999Z', -0.001 ], [ '1969-12-31T23:59:59.999800Z', -0.0002 ], [ '1969-12-31T23:59:59.999900Z', -0.0001 ], [ '1969-12-31T23:59:59.999980Z', -0.00002 ], [ '1969-12-31T23:59:59.999990Z', -0.00001 ], [ '1969-12-31T23:59:59.999998Z', -0.000002 ], [ '1969-12-31T23:59:59.999999Z', -0.000001 ], [ '1970-01-01T00:00:00Z', 0.0 ], [ '1970-01-01T00:00:00.000001Z', 0.000001 ], [ '1970-01-01T00:00:00.000002Z', 0.000002 ], [ '1970-01-01T00:00:00.000010Z', 0.00001 ], [ '1970-01-01T00:00:00.000020Z', 0.00002 ], [ '1970-01-01T00:00:00.000100Z', 0.0001 ], [ '1970-01-01T00:00:00.000200Z', 0.0002 ], [ '1970-01-01T00:00:00.001Z', 0.001 ], [ '1970-01-01T00:00:00.002Z', 0.002 ], [ '1970-01-01T00:00:00.010Z', 0.01 ], [ '1970-01-01T00:00:00.020Z', 0.02 ], [ '1970-01-01T00:00:00.100Z', 0.1 ], [ '1970-01-01T00:00:00.200Z', 0.2 ], [ '1970-01-01T00:00:00.300Z', 0.3 ], [ '1970-01-01T00:00:00.400Z', 0.4 ], [ '1970-01-01T00:00:00.490Z', 0.49 ], [ '1970-01-01T00:00:00.499Z', 0.499 ], [ '1970-01-01T00:00:00.499900Z', 0.4999 ], [ '1970-01-01T00:00:00.499990Z', 0.49999 ], [ '1970-01-01T00:00:00.499999Z', 0.499999 ], [ '1970-01-01T00:00:00.500Z', 0.5 ], [ '1970-01-01T00:00:00.500001Z', 0.500001 ], [ '1970-01-01T00:00:00.500010Z', 0.50001 ], [ '1970-01-01T00:00:00.500100Z', 0.5001 ], [ '1970-01-01T00:00:00.501Z', 0.501 ], [ '1970-01-01T00:00:00.510Z', 0.51 ], [ '1970-01-01T00:00:00.600Z', 0.6 ], [ '1970-01-01T00:00:00.700Z', 0.7 ], [ '1970-01-01T00:00:00.800Z', 0.8 ], [ '1970-01-01T00:00:00.900Z', 0.9 ], [ '1970-01-01T00:00:00.980Z', 0.98 ], [ '1970-01-01T00:00:00.990Z', 0.99 ], [ '1970-01-01T00:00:00.999800Z', 0.9998 ], [ '1970-01-01T00:00:00.999900Z', 0.9999 ], [ '1970-01-01T00:00:00.999980Z', 0.99998 ], [ '1970-01-01T00:00:00.999990Z', 0.99999 ], [ '1970-01-01T00:00:00.999998Z', 0.999998 ], [ '1970-01-01T00:00:00.999999Z', 0.999999 ], [ '1970-01-01T00:00:01Z', 1.0 ], [ '1970-01-01T00:00:01.000001Z', 1.000001 ], [ '1970-01-01T00:00:01.000002Z', 1.000002 ], [ '1970-01-01T00:00:01.000010Z', 1.00001 ], [ '1970-01-01T00:00:01.000020Z', 1.00002 ], [ '1970-01-01T00:00:01.000100Z', 1.0001 ], [ '1970-01-01T00:00:01.000200Z', 1.0002 ], [ '1970-01-01T00:00:01.001Z', 1.001 ], [ '1970-01-01T00:00:01.002Z', 1.002 ], [ '1970-01-01T00:00:01.010Z', 1.01 ], [ '1970-01-01T00:00:01.020Z', 1.02 ], [ '1970-01-01T00:00:01.100Z', 1.1 ], [ '1970-01-01T00:00:01.200Z', 1.2 ], [ '2020-12-31T23:59:59Z', 1609459199.0 ], [ '2020-12-31T23:59:59.000001Z', 1609459199.000000953674316 ], [ '2020-12-31T23:59:59.000002Z', 1609459199.000001907348633 ], [ '2020-12-31T23:59:59.000010Z', 1609459199.000010013580322 ], [ '2020-12-31T23:59:59.000020Z', 1609459199.000020027160645 ], [ '2020-12-31T23:59:59.000100Z', 1609459199.000099897384644 ], [ '2020-12-31T23:59:59.000200Z', 1609459199.000200033187866 ], [ '2020-12-31T23:59:59.001Z', 1609459199.000999927520752 ], [ '2020-12-31T23:59:59.002Z', 1609459199.002000093460083 ], [ '2020-12-31T23:59:59.010Z', 1609459199.009999990463257 ], [ '2020-12-31T23:59:59.020Z', 1609459199.019999980926514 ], [ '2020-12-31T23:59:59.100Z', 1609459199.099999904632568 ], [ '2020-12-31T23:59:59.200Z', 1609459199.200000047683716 ], [ '2020-12-31T23:59:59.202Z', 1609459199.20199990272522 ], [ '2020-12-31T23:59:59.202080Z', 1609459199.202080011367798 ], [ '2020-12-31T23:59:59.202090Z', 1609459199.20209002494812 ], [ '2020-12-31T23:59:59.202098Z', 1609459199.20209789276123 ], [ '2020-12-31T23:59:59.202099Z', 1609459199.202099084854126 ], [ '2020-12-31T23:59:59.300Z', 1609459199.299999952316284 ], [ '2020-12-31T23:59:59.400Z', 1609459199.400000095367432 ], [ '2020-12-31T23:59:59.420200Z', 1609459199.420200109481812 ], [ '2020-12-31T23:59:59.420209Z', 1609459199.420208930969238 ], [ '2020-12-31T23:59:59.490Z', 1609459199.490000009536743 ], [ '2020-12-31T23:59:59.499Z', 1609459199.499000072479248 ], [ '2020-12-31T23:59:59.499900Z', 1609459199.499900102615356 ], [ '2020-12-31T23:59:59.500Z', 1609459199.5 ], [ '2020-12-31T23:59:59.500001Z', 1609459199.500000953674316 ], [ '2020-12-31T23:59:59.500010Z', 1609459199.500010013580322 ], [ '2020-12-31T23:59:59.500100Z', 1609459199.500099897384644 ], [ '2020-12-31T23:59:59.501Z', 1609459199.500999927520752 ], [ '2020-12-31T23:59:59.510Z', 1609459199.509999990463257 ], [ '2020-12-31T23:59:59.600Z', 1609459199.599999904632568 ], [ '2020-12-31T23:59:59.700Z', 1609459199.700000047683716 ], [ '2020-12-31T23:59:59.800Z', 1609459199.799999952316284 ], [ '2020-12-31T23:59:59.900Z', 1609459199.900000095367432 ], [ '2020-12-31T23:59:59.980Z', 1609459199.980000019073486 ], [ '2020-12-31T23:59:59.990Z', 1609459199.990000009536743 ], [ '2020-12-31T23:59:59.998Z', 1609459199.997999906539917 ], [ '2020-12-31T23:59:59.999Z', 1609459199.999000072479248 ], [ '2020-12-31T23:59:59.999800Z', 1609459199.999799966812134 ], ); foreach my $test (@tests) { my ($string, $epoch) = @$test; { my $tm = Time::Moment->from_epoch($epoch); is($tm->to_string, $string, "from_epoch($epoch)"); } { my $tm = Time::Moment->from_epoch($epoch, precision => 6); is($tm->to_string, $string, "from_epoch($epoch, precision => 6)"); } } } { my @tests = ( [ '1920-12-31T23:59:59.499Z', -1546300800.500999927520752 ], [ '1920-12-31T23:59:59.999Z', -1546300800.000999927520752 ], [ '1969-12-31T23:59:58Z', -2.0 ], [ '1969-12-31T23:59:58.500Z', -1.5 ], [ '1969-12-31T23:59:58.800Z', -1.2 ], [ '1969-12-31T23:59:58.900Z', -1.1 ], [ '1969-12-31T23:59:58.980Z', -1.02 ], [ '1969-12-31T23:59:58.990Z', -1.01 ], [ '1969-12-31T23:59:58.998Z', -1.002 ], [ '1969-12-31T23:59:58.999Z', -1.001 ], [ '1969-12-31T23:59:59Z', -1.0 ], [ '1970-01-01T00:00:00Z', 0.0 ], [ '1970-01-01T00:00:00.500Z', 0.5 ], [ '1970-01-01T00:00:00.501Z', 0.501 ], [ '1970-01-01T00:00:00.510Z', 0.51 ], [ '1970-01-01T00:00:00.600Z', 0.6 ], [ '1970-01-01T00:00:00.700Z', 0.7 ], [ '1970-01-01T00:00:00.800Z', 0.8 ], [ '1970-01-01T00:00:00.900Z', 0.9 ], [ '1970-01-01T00:00:00.980Z', 0.98 ], [ '1970-01-01T00:00:00.990Z', 0.99 ], [ '1970-01-01T00:00:00.999Z', 0.999 ], [ '2020-12-31T23:59:59.499Z', 1609459199.499000072479248 ], [ '2020-12-31T23:59:59.999Z', 1609459199.999000072479248 ], ); foreach my $test (@tests) { my ($string, $epoch) = @$test; my $tm = Time::Moment->from_epoch($epoch, precision => 3); is($tm->to_string, $string, "from_epoch($epoch, precision => 3)"); } } done_testing(); Time-Moment-0.44/t/140_from_object.t000755 000765 000024 00000001615 13072611664 017677 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use lib 't'; use Test::More; use Util qw[throws_ok lives_ok]; BEGIN { use_ok('Time::Moment'); } { package MyFoo; sub new { my ($class, %p) = @_; return bless \%p, $class; } sub epoch { return $_[0]->{epoch} } sub __as_Time_Moment { my ($self) = @_; return Time::Moment->from_epoch($self->epoch); } } { package MyBar; sub new { my ($class, %p) = @_; return bless \%p, $class; } } { my $mf = MyFoo->new(epoch => 123456789); my $tm; lives_ok { $tm = Time::Moment->from_object($mf) }; isa_ok($tm, 'Time::Moment'); is($tm->epoch, 123456789, '->epoch'); is($tm->offset, 0, '->offset'); } { my $mb = MyBar->new(epoch => 123456789); throws_ok { Time::Moment->from_object($mb) } q/^Cannot coerce object of type MyBar/; } done_testing(); Time-Moment-0.44/t/145_from_object_tp.t000755 000765 000024 00000001742 13072611665 020411 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use lib 't'; use Test::More; use Test::Requires qw[Time::Piece]; use Util qw[lives_ok]; BEGIN { use_ok('Time::Moment'); } { my $tp = Time::Piece::gmtime(123456789); my $tm; lives_ok { $tm = Time::Moment->from_object($tp) }; isa_ok($tm, 'Time::Moment'); is($tm->epoch, 123456789, '->epoch'); is($tm->offset, 0, '->offset'); } { my $tp = Time::Piece::localtime(123456789); my $tm; lives_ok { $tm = Time::Moment->from_object($tp) }; isa_ok($tm, 'Time::Moment'); is($tm->epoch, 123456789, '->epoch'); is($tm->year, $tp->year, '->year'); is($tm->month, $tp->mon, '->month'); is($tm->day_of_month, $tp->day_of_month, '->day_of_month'); is($tm->hour, $tp->hour, '->hour'); is($tm->minute, $tp->minute, '->minute'); is($tm->second, $tp->second, '->second'); } done_testing(); Time-Moment-0.44/t/150_from_object_dt.t000755 000765 000024 00000002316 13072611666 020370 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use lib 't'; use Test::More; use Test::Requires qw[DateTime]; use Util qw[throws_ok lives_ok]; BEGIN { use_ok('Time::Moment'); } { my $dt = DateTime->from_epoch(epoch => 123456789); my $tm; lives_ok { $tm = Time::Moment->from_object($dt) }; isa_ok($tm, 'Time::Moment'); is($tm->epoch, 123456789, '->epoch'); is($tm->offset, 0, '->offset'); } { my $dt = DateTime->from_epoch(epoch => 123456789, time_zone => '+02:00'); my $tm; lives_ok { $tm = Time::Moment->from_object($dt) }; isa_ok($tm, 'Time::Moment'); is($tm->epoch, 123456789, '->epoch'); is($tm->offset, 2*60, '->offset'); is($tm->year, $dt->year, '->year'); is($tm->month, $dt->month, '->month'); is($tm->day_of_month, $dt->day_of_month, '->day_of_month'); is($tm->hour, $dt->hour, '->hour'); is($tm->minute, $dt->minute, '->minute'); is($tm->second, $dt->second, '->second'); } { my $dt = DateTime->new(year => 2012); throws_ok { Time::Moment->from_object($dt) } qr/^Cannot coerce .* 'floating'/; } done_testing(); Time-Moment-0.44/t/180_from_string.t000755 000765 000024 00000020407 13072611670 017740 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use lib 't'; use Test::More; use Util qw[throws_ok lives_ok]; BEGIN { use_ok('Time::Moment'); } sub TRUE () { !!1 } { my @tests = ( [ '0001-01-01T00:00:00Z', -62135596800, 0, 0 ], [ '00010101T000000Z', -62135596800, 0, 0 ], [ '0001-W01-1T00:00:00Z', -62135596800, 0, 0 ], [ '0001W011T000000Z', -62135596800, 0, 0 ], [ '0001-001T00:00:00Z', -62135596800, 0, 0 ], [ '0001001T000000Z', -62135596800, 0, 0 ], [ '1970-01-01T00:00:00Z', 0, 0, 0 ], [ '1970-01-01T02:00:00+02:00', 0, 0, 120 ], [ '1970-01-01T01:30:00+01:30', 0, 0, 90 ], [ '1970-01-01T01:00:00+01:00', 0, 0, 60 ], [ '1970-01-01T00:01:00+00:01', 0, 0, 1 ], [ '1970-01-01T00:00:00+00:00', 0, 0, 0 ], [ '1969-12-31T23:59:00-00:01', 0, 0, -1 ], [ '1969-12-31T23:00:00-01:00', 0, 0, -60 ], [ '1969-12-31T22:30:00-01:30', 0, 0, -90 ], [ '1969-12-31T22:00:00-02:00', 0, 0, -120 ], [ '1970-01-01T00:00:00.123456789Z', 0, 123456789, 0 ], [ '1970-01-01T00:00:00.12345678Z', 0, 123456780, 0 ], [ '1970-01-01T00:00:00.1234567Z', 0, 123456700, 0 ], [ '1970-01-01T00:00:00.123456Z', 0, 123456000, 0 ], [ '1970-01-01T00:00:00.12345Z', 0, 123450000, 0 ], [ '1970-01-01T00:00:00.1234Z', 0, 123400000, 0 ], [ '1970-01-01T00:00:00.123Z', 0, 123000000, 0 ], [ '1970-01-01T00:00:00.12Z', 0, 120000000, 0 ], [ '1970-01-01T00:00:00.1Z', 0, 100000000, 0 ], [ '1970-01-01T00:00:00.01Z', 0, 10000000, 0 ], [ '1970-01-01T00:00:00.001Z', 0, 1000000, 0 ], [ '1970-01-01T00:00:00.0001Z', 0, 100000, 0 ], [ '1970-01-01T00:00:00.00001Z', 0, 10000, 0 ], [ '1970-01-01T00:00:00.000001Z', 0, 1000, 0 ], [ '1970-01-01T00:00:00.0000001Z', 0, 100, 0 ], [ '1970-01-01T00:00:00.00000001Z', 0, 10, 0 ], [ '1970-01-01T00:00:00.000000001Z', 0, 1, 0 ], [ '1970-01-01T00:00:00.000000009Z', 0, 9, 0 ], [ '1970-01-01T00:00:00.00000009Z', 0, 90, 0 ], [ '1970-01-01T00:00:00.0000009Z', 0, 900, 0 ], [ '1970-01-01T00:00:00.000009Z', 0, 9000, 0 ], [ '1970-01-01T00:00:00.00009Z', 0, 90000, 0 ], [ '1970-01-01T00:00:00.0009Z', 0, 900000, 0 ], [ '1970-01-01T00:00:00.009Z', 0, 9000000, 0 ], [ '1970-01-01T00:00:00.09Z', 0, 90000000, 0 ], [ '1970-01-01T00:00:00.9Z', 0, 900000000, 0 ], [ '1970-01-01T00:00:00.99Z', 0, 990000000, 0 ], [ '1970-01-01T00:00:00.999Z', 0, 999000000, 0 ], [ '1970-01-01T00:00:00.9999Z', 0, 999900000, 0 ], [ '1970-01-01T00:00:00.99999Z', 0, 999990000, 0 ], [ '1970-01-01T00:00:00.999999Z', 0, 999999000, 0 ], [ '1970-01-01T00:00:00.9999999Z', 0, 999999900, 0 ], [ '1970-01-01T00:00:00.99999999Z', 0, 999999990, 0 ], [ '1970-01-01T00:00:00.999999999Z', 0, 999999999, 0 ], [ '1970-01-01T00:00:00.0Z', 0, 0, 0 ], [ '1970-01-01T00:00:00.00Z', 0, 0, 0 ], [ '1970-01-01T00:00:00.000Z', 0, 0, 0 ], [ '1970-01-01T00:00:00.0000Z', 0, 0, 0 ], [ '1970-01-01T00:00:00.00000Z', 0, 0, 0 ], [ '1970-01-01T00:00:00.000000Z', 0, 0, 0 ], [ '1970-01-01T00:00:00.0000000Z', 0, 0, 0 ], [ '1970-01-01T00:00:00.00000000Z', 0, 0, 0 ], [ '1970-01-01T00:00:00.000000000Z', 0, 0, 0 ], [ '1973-11-29T21:33:09Z', 123456789, 0, 0 ], [ '2013-10-28T17:51:56Z', 1382982716, 0, 0 ], [ '9999-12-31T23:59:59Z', 253402300799, 0, 0 ], ); foreach my $test (@tests) { my ($string, $epoch, $nanosecond, $offset) = @$test; my $tm = Time::Moment->from_string($string); is($tm->epoch, $epoch, "${string} epoch"); is($tm->nanosecond, $nanosecond, "${string} nanosecond"); is($tm->offset, $offset, "${string} offset"); } } { my $exp = Time::Moment->from_string('2012-12-24T15:30Z'); my @tests = ( '2012-12-24 15:30Z', '2012-12-24 15:30z', '2012-12-24 16:30+01:00', '2012-12-24 16:30+0100', '2012-12-24 16:30+01', '2012-12-24 14:30-01:00', '2012-12-24 14:30-0100', '2012-12-24 14:30-01', '2012-12-24 15:30:00Z', '2012-12-24 15:30:00z', '2012-12-24 16:30:00+01:00', '2012-12-24 16:30:00+0100', '2012-12-24 14:30:00-01:00', '2012-12-24 14:30:00-0100', '2012-12-24 15:30:00.123456Z', '2012-12-24 15:30:00.123456z', '2012-12-24 16:30:00.123456+01:00', '2012-12-24 16:30:00.123456+01', '2012-12-24 14:30:00.123456-01:00', '2012-12-24 14:30:00.123456-01', '2012-12-24t15:30Z', '2012-12-24t15:30z', '2012-12-24t16:30+01:00', '2012-12-24t16:30+0100', '2012-12-24t14:30-01:00', '2012-12-24t14:30-0100', '2012-12-24t15:30:00Z', '2012-12-24t15:30:00z', '2012-12-24t16:30:00+01:00', '2012-12-24t16:30:00+0100', '2012-12-24t14:30:00-01:00', '2012-12-24t14:30:00-0100', '2012-12-24t15:30:00.123456Z', '2012-12-24t15:30:00.123456z', '2012-12-24t16:30:00.123456+01:00', '2012-12-24t14:30:00.123456-01:00', '2012-12-24 16:30 +01:00', '2012-12-24 14:30 -01:00', '2012-12-24 15:30 UTC', '2012-12-24 16:30 UTC+1', '2012-12-24 16:30 UTC+01', '2012-12-24 16:30 UTC+0100', '2012-12-24 16:30 UTC+01:00', '2012-12-24 14:30 UTC-1', '2012-12-24 14:30 UTC-01', '2012-12-24 14:30 UTC-01:00', '2012-12-24 14:30 UTC-0100', '2012-12-24 15:30 GMT', '2012-12-24 16:30 GMT+1', '2012-12-24 16:30 GMT+01', '2012-12-24 16:30 GMT+0100', '2012-12-24 16:30 GMT+01:00', '2012-12-24 14:30 GMT-1', '2012-12-24 14:30 GMT-01', '2012-12-24 14:30 GMT-01:00', '2012-12-24 14:30 GMT-0100', '2012-12-24 14:30 -01:00', '2012-12-24 16:30:00 +01:00', '2012-12-24 14:30:00 -01:00', '2012-12-24 16:30:00.123456 +01:00', '2012-12-24 14:30:00.123456 -01:00', '2012-12-24 15:30:00.123456 -00:00', '20121224T1630+01:00', '2012-12-24T1630+01:00', '20121224T16:30+01', '20121224T16:30 +01', ); foreach my $string (@tests) { { my $name = "from_string($string)"; throws_ok { Time::Moment->from_string($string) } q/^Could not parse/, $name; } { my $tm; my $name = "->from_string($string, lenient => TRUE)"; lives_ok { $tm = Time::Moment->from_string($string, lenient => TRUE); } $name; is($tm->epoch, $exp->epoch, "$name->epoch"); } } } done_testing(); Time-Moment-0.44/t/190_rd.t000755 000765 000024 00000033655 12606144705 016030 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; use Test::Number::Delta relative => 1E-10; BEGIN { use_ok('Time::Moment'); } { my @tests = ( [ '0001-01-01T00:00:00Z', 1.0 ], [ '0001-01-01T00:00:00.001Z', 1.0000000116 ], [ '0001-01-01T00:00:00.002Z', 1.0000000231 ], [ '0001-01-01T00:00:00.010Z', 1.0000001157 ], [ '0001-01-01T00:00:00.020Z', 1.0000002315 ], [ '0001-01-01T00:00:00.100Z', 1.0000011574 ], [ '0001-01-01T00:00:00.200Z', 1.0000023148 ], [ '0001-01-01T00:00:00.300Z', 1.0000034722 ], [ '0001-01-01T00:00:00.400Z', 1.0000046296 ], [ '0001-01-01T00:00:00.490Z', 1.0000056713 ], [ '0001-01-01T00:00:00.499Z', 1.0000057755 ], [ '0001-01-01T00:00:00.500Z', 1.000005787 ], [ '0001-01-01T00:00:00.501Z', 1.0000057986 ], [ '0001-01-01T00:00:00.510Z', 1.0000059028 ], [ '0001-01-01T00:00:00.600Z', 1.0000069444 ], [ '0001-01-01T00:00:00.700Z', 1.0000081019 ], [ '0001-01-01T00:00:00.800Z', 1.0000092593 ], [ '0001-01-01T00:00:00.900Z', 1.0000104167 ], [ '0001-01-01T00:00:00.980Z', 1.0000113426 ], [ '0001-01-01T00:00:00.990Z', 1.0000114583 ], [ '0001-01-01T00:00:00.998Z', 1.0000115509 ], [ '0001-01-01T00:00:00.999Z', 1.0000115625 ], [ '0001-01-01T00:00:01Z', 1.0000115741 ], [ '0001-01-01T00:00:01.001Z', 1.0000115856 ], [ '0001-01-01T00:00:01.002Z', 1.0000115972 ], [ '0001-01-01T00:00:01.010Z', 1.0000116898 ], [ '0001-01-01T00:00:01.020Z', 1.0000118056 ], [ '0001-01-01T00:00:01.100Z', 1.0000127315 ], [ '0001-01-01T00:00:01.200Z', 1.0000138889 ], [ '1899-12-31T00:00:00Z', 693595.0 ], [ '1900-01-01T00:00:00Z', 693596.0 ], [ '1900-02-27T00:00:00Z', 693653.0 ], [ '1900-02-28T00:00:00Z', 693654.0 ], [ '1900-03-01T00:00:00Z', 693655.0 ], [ '1900-03-02T00:00:00Z', 693656.0 ], [ '1969-12-31T23:59:58Z', 719162.9999768519 ], [ '1969-12-31T23:59:58.500Z', 719162.9999826389 ], [ '1969-12-31T23:59:58.800Z', 719162.9999861111 ], [ '1969-12-31T23:59:58.900Z', 719162.9999872685 ], [ '1969-12-31T23:59:58.980Z', 719162.9999881944 ], [ '1969-12-31T23:59:58.990Z', 719162.9999883102 ], [ '1969-12-31T23:59:58.998Z', 719162.9999884028 ], [ '1969-12-31T23:59:58.999Z', 719162.9999884143 ], [ '1969-12-31T23:59:59Z', 719162.9999884259 ], [ '1969-12-31T23:59:59.001Z', 719162.9999884375 ], [ '1969-12-31T23:59:59.002Z', 719162.999988449 ], [ '1969-12-31T23:59:59.010Z', 719162.9999885417 ], [ '1969-12-31T23:59:59.020Z', 719162.9999886574 ], [ '1969-12-31T23:59:59.100Z', 719162.9999895834 ], [ '1969-12-31T23:59:59.200Z', 719162.9999907408 ], [ '1969-12-31T23:59:59.300Z', 719162.9999918982 ], [ '1969-12-31T23:59:59.400Z', 719162.9999930556 ], [ '1969-12-31T23:59:59.490Z', 719162.9999940973 ], [ '1969-12-31T23:59:59.499Z', 719162.9999942014 ], [ '1969-12-31T23:59:59.500Z', 719162.999994213 ], [ '1969-12-31T23:59:59.501Z', 719162.9999942245 ], [ '1969-12-31T23:59:59.510Z', 719162.9999943287 ], [ '1969-12-31T23:59:59.600Z', 719162.9999953704 ], [ '1969-12-31T23:59:59.700Z', 719162.9999965278 ], [ '1969-12-31T23:59:59.800Z', 719162.9999976852 ], [ '1969-12-31T23:59:59.900Z', 719162.9999988426 ], [ '1969-12-31T23:59:59.980Z', 719162.9999997686 ], [ '1969-12-31T23:59:59.990Z', 719162.9999998843 ], [ '1969-12-31T23:59:59.998Z', 719162.9999999768 ], [ '1969-12-31T23:59:59.999Z', 719162.9999999885 ], [ '1970-01-01T00:00:00Z', 719163.0 ], [ '1970-01-01T00:00:00.001Z', 719163.0000000115 ], [ '1970-01-01T00:00:00.002Z', 719163.0000000232 ], [ '1970-01-01T00:00:00.010Z', 719163.0000001157 ], [ '1970-01-01T00:00:00.020Z', 719163.0000002314 ], [ '1970-01-01T00:00:00.100Z', 719163.0000011574 ], [ '1970-01-01T00:00:00.200Z', 719163.0000023148 ], [ '1970-01-01T00:00:00.300Z', 719163.0000034722 ], [ '1970-01-01T00:00:00.400Z', 719163.0000046296 ], [ '1970-01-01T00:00:00.490Z', 719163.0000056713 ], [ '1970-01-01T00:00:00.499Z', 719163.0000057755 ], [ '1970-01-01T00:00:00.500Z', 719163.000005787 ], [ '1970-01-01T00:00:00.501Z', 719163.0000057986 ], [ '1970-01-01T00:00:00.510Z', 719163.0000059027 ], [ '1970-01-01T00:00:00.600Z', 719163.0000069444 ], [ '1970-01-01T00:00:00.700Z', 719163.0000081018 ], [ '1970-01-01T00:00:00.800Z', 719163.0000092592 ], [ '1970-01-01T00:00:00.900Z', 719163.0000104166 ], [ '1970-01-01T00:00:00.980Z', 719163.0000113426 ], [ '1970-01-01T00:00:00.990Z', 719163.0000114583 ], [ '1970-01-01T00:00:00.998Z', 719163.000011551 ], [ '1970-01-01T00:00:00.999Z', 719163.0000115625 ], [ '1970-01-01T00:00:01Z', 719163.0000115741 ], [ '1970-01-01T00:00:01.001Z', 719163.0000115857 ], [ '1970-01-01T00:00:01.002Z', 719163.0000115972 ], [ '1970-01-01T00:00:01.010Z', 719163.0000116898 ], [ '1970-01-01T00:00:01.020Z', 719163.0000118056 ], [ '1970-01-01T00:00:01.100Z', 719163.0000127315 ], [ '1970-01-01T00:00:01.200Z', 719163.0000138889 ], [ '1982-08-25T00:15:20.213Z', 723782.0106506135 ], [ '2065-04-19T00:16:48.290Z', 753970.0116700232 ], [ '2147-12-15T00:55:25.446Z', 784159.0384889584 ], [ '2230-08-10T01:02:46.891Z', 814347.0435982755 ], [ '2313-04-06T01:04:15.597Z', 844536.0446249653 ], [ '2395-11-30T01:09:40.889Z', 874724.048389919 ], [ '2478-07-25T01:11:32.560Z', 904912.0496824074 ], [ '2561-03-21T01:30:19.169Z', 935101.0627218634 ], [ '2643-11-15T01:48:25.580Z', 965289.0752960648 ], [ '2726-07-12T02:03:31.919Z', 995478.0857860995 ], [ '2809-03-06T02:11:11.986Z', 1025666.0911109491 ], [ '2891-10-31T02:24:37.095Z', 1055855.1004293403 ], [ '2974-06-26T02:35:07.220Z', 1086043.1077224538 ], [ '3057-02-19T02:45:12.109Z', 1116231.1147234838 ], [ '3139-10-17T03:06:39.990Z', 1146420.1296295139 ], [ '3222-06-11T03:08:08.251Z', 1176608.1306510533 ], [ '3305-02-05T03:19:12.576Z', 1206797.1383400001 ], [ '3387-10-01T03:29:42.574Z', 1236985.1456316435 ], [ '3470-05-27T03:37:30.813Z', 1267173.1510510764 ], [ '3553-01-21T04:14:38.231Z', 1297362.1768313772 ], [ '3635-09-16T04:16:28.559Z', 1327550.1781083217 ], [ '3718-05-13T04:17:58.222Z', 1357739.179146088 ], [ '3801-01-06T04:21:41.794Z', 1387927.1817337268 ], [ '3883-09-02T04:56:35.792Z', 1418116.2059698149 ], [ '3966-04-28T05:25:14.885Z', 1448304.2258667245 ], [ '4048-12-21T05:26:05.724Z', 1478492.226455139 ], [ '4131-08-18T05:46:44.068Z', 1508681.2407878242 ], [ '4214-04-13T05:48:01.141Z', 1538869.2416798726 ], [ '4296-12-07T05:53:52.315Z', 1569058.2457443867 ], [ '4379-08-03T06:14:48.580Z', 1599246.2602844907 ], [ '4462-03-28T06:46:15.738Z', 1629434.2821265971 ], [ '4544-11-22T07:31:20.407Z', 1659623.3134306367 ], [ '4627-07-19T07:58:33.754Z', 1689811.3323351156 ], [ '4710-03-15T08:07:43.130Z', 1720000.3386936344 ], [ '4792-11-07T08:29:11.091Z', 1750188.3536005903 ], [ '4875-07-04T09:08:15.328Z', 1780377.3807329629 ], [ '4958-02-27T09:30:41.781Z', 1810565.3963169097 ], [ '5040-10-23T09:34:04.462Z', 1840753.3986627546 ], [ '5123-06-20T09:37:23.945Z', 1870942.4009715857 ], [ '5206-02-12T09:37:56.655Z', 1901130.4013501736 ], [ '5288-10-08T09:45:12.230Z', 1931319.406391551 ], [ '5371-06-04T09:54:14.782Z', 1961507.412671088 ], [ '5454-01-28T09:54:22.108Z', 1991695.4127558796 ], [ '5536-09-24T10:01:36.151Z', 2021884.4177795255 ], [ '5619-05-20T12:09:48.602Z', 2052072.5068125231 ], [ '5702-01-14T12:34:08.549Z', 2082261.5237100578 ], [ '5784-09-08T12:56:06.495Z', 2112449.5389640625 ], [ '5867-05-06T12:58:58.217Z', 2142638.5409515859 ], [ '5949-12-30T12:59:54.263Z', 2172826.541600266 ], [ '6032-08-24T13:34:41.331Z', 2203014.5657561459 ], [ '6115-04-21T13:58:28.601Z', 2233203.5822754744 ], [ '6197-12-14T14:02:16.899Z', 2263391.5849178126 ], [ '6280-08-10T14:36:17.444Z', 2293580.6085352316 ], [ '6363-04-06T14:37:57.451Z', 2323768.6096927198 ], [ '6445-11-30T14:57:42.757Z', 2353957.6234115395 ], [ '6528-07-26T15:10:48.307Z', 2384145.6325035533 ], [ '6611-03-22T15:14:39.890Z', 2414333.6351839122 ], [ '6693-11-15T15:19:47.988Z', 2444522.6387498612 ], [ '6776-07-11T16:04:24.344Z', 2474710.6697262037 ], [ '6859-03-07T16:22:23.952Z', 2504899.6822216664 ], [ '6941-10-31T16:29:55.999Z', 2535087.6874536923 ], [ '7024-06-26T16:58:20.259Z', 2565275.7071789238 ], [ '7107-02-21T17:04:02.415Z', 2595464.7111390624 ], [ '7189-10-16T17:18:29.630Z', 2625652.7211762732 ], [ '7272-06-11T17:47:21.323Z', 2655841.7412190163 ], [ '7355-02-05T17:53:29.866Z', 2686029.7454845603 ], [ '7437-10-02T17:53:41.076Z', 2716218.7456143056 ], [ '7520-05-28T17:55:06.044Z', 2746406.7465977315 ], [ '7603-01-21T18:14:49.151Z', 2776594.7602910995 ], [ '7685-09-16T18:17:45.738Z', 2806783.7623349307 ], [ '7768-05-12T18:29:59.700Z', 2836971.7708298611 ], [ '7851-01-07T18:33:21.233Z', 2867160.773162419 ], [ '7933-09-02T19:14:24.673Z', 2897348.8016744559 ], [ '8016-04-27T19:17:12.816Z', 2927536.8036205554 ], [ '8098-12-22T19:23:36.418Z', 2957725.8080603937 ], [ '8181-08-17T19:46:25.908Z', 2987913.8239109721 ], [ '8264-04-13T20:07:47.314Z', 3018102.8387420601 ], [ '8346-12-08T20:31:37.603Z', 3048290.855296331 ], [ '8429-08-03T20:39:57.770Z', 3078479.8610853008 ], [ '8512-03-29T20:50:17.067Z', 3108667.8682530904 ], [ '8594-11-22T21:02:57.827Z', 3138855.8770581828 ], [ '8677-07-19T21:23:05.519Z', 3169044.8910360998 ], [ '8760-03-14T21:34:49.572Z', 3199232.8991848612 ], [ '8842-11-08T21:39:05.944Z', 3229421.9021521294 ], [ '8925-07-04T21:39:18.426Z', 3259609.9022965971 ], [ '9008-02-28T21:46:07.769Z', 3289797.9070343636 ], [ '9090-10-24T21:57:55.662Z', 3319986.9152275696 ], [ '9173-06-19T22:19:11.732Z', 3350174.9299968979 ], [ '9256-02-13T22:23:51.376Z', 3380363.9332335186 ], [ '9338-10-09T22:27:58.771Z', 3410551.9360968866 ], [ '9421-06-05T22:43:30.392Z', 3440740.9468795368 ], [ '9504-01-30T22:48:25.834Z', 3470928.9502990046 ], [ '9586-09-24T22:53:51.727Z', 3501116.9540709145 ], [ '9669-05-20T23:12:56.536Z', 3531305.9673210187 ], [ '9752-01-14T23:15:54.109Z', 3561493.9693762613 ], [ '9834-09-10T23:17:12.632Z', 3591682.9702850925 ], [ '9999-12-31T23:59:58Z', 3652059.999976852 ], [ '9999-12-31T23:59:58.500Z', 3652059.9999826388 ], [ '9999-12-31T23:59:58.800Z', 3652059.9999861112 ], [ '9999-12-31T23:59:58.900Z', 3652059.9999872684 ], [ '9999-12-31T23:59:58.980Z', 3652059.9999881946 ], [ '9999-12-31T23:59:58.990Z', 3652059.99998831 ], [ '9999-12-31T23:59:58.998Z', 3652059.9999884027 ], [ '9999-12-31T23:59:58.999Z', 3652059.9999884143 ], [ '9999-12-31T23:59:59Z', 3652059.999988426 ], [ '9999-12-31T23:59:59.001Z', 3652059.9999884376 ], [ '9999-12-31T23:59:59.002Z', 3652059.9999884493 ], [ '9999-12-31T23:59:59.010Z', 3652059.9999885415 ], [ '9999-12-31T23:59:59.020Z', 3652059.9999886574 ], [ '9999-12-31T23:59:59.100Z', 3652059.9999895832 ], [ '9999-12-31T23:59:59.200Z', 3652059.9999907408 ], [ '9999-12-31T23:59:59.300Z', 3652059.999991898 ], [ '9999-12-31T23:59:59.400Z', 3652059.9999930556 ], [ '9999-12-31T23:59:59.490Z', 3652059.9999940973 ], [ '9999-12-31T23:59:59.499Z', 3652059.9999942016 ], [ '9999-12-31T23:59:59.500Z', 3652059.9999942128 ], [ '9999-12-31T23:59:59.501Z', 3652059.9999942244 ], [ '9999-12-31T23:59:59.510Z', 3652059.9999943287 ], [ '9999-12-31T23:59:59.600Z', 3652059.9999953704 ], [ '9999-12-31T23:59:59.700Z', 3652059.9999965276 ], [ '9999-12-31T23:59:59.800Z', 3652059.9999976852 ], [ '9999-12-31T23:59:59.900Z', 3652059.9999988424 ], [ '9999-12-31T23:59:59.980Z', 3652059.9999997686 ], [ '9999-12-31T23:59:59.990Z', 3652059.9999998841 ], [ '9999-12-31T23:59:59.998Z', 3652059.9999999767 ], [ '9999-12-31T23:59:59.999Z', 3652059.9999999884 ], ); foreach my $test (@tests) { my ($string, $rd) = @$test; my $tm = Time::Moment->from_rd($rd); is($tm->to_string, $string, "Time::Moment->from_rd($rd)"); delta_ok($tm->rd, $rd, "$tm->rd"); } } { my $tm = Time::Moment->from_rd(719163, offset => 60); is($tm->to_string, '1970-01-01T00:00:00+01:00'); } { my $tm = Time::Moment->from_rd(719163, offset => -60); is($tm->to_string, '1970-01-01T00:00:00-01:00'); } { my $tm = Time::Moment->from_rd(0, epoch => 719163, offset => 60); is($tm->to_string, '1970-01-01T00:00:00+01:00'); } { my $tm = Time::Moment->from_rd(0, epoch => 719163, offset => -60); is($tm->to_string, '1970-01-01T00:00:00-01:00'); } { my $tm = Time::Moment->from_rd(0.000001428888889, epoch => 719163, precision => 6); is($tm->to_string, '1970-01-01T00:00:00.123456Z'); } done_testing(); Time-Moment-0.44/t/191_jd.t000755 000765 000024 00000033235 12606144722 016012 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; use Test::Number::Delta relative => 1E-10; BEGIN { use_ok('Time::Moment'); } { my @tests = ( [ '0001-01-01T00:00:00Z', 1721425.5 ], [ '0001-01-01T00:00:00.001Z', 1721425.5000000116 ], [ '0001-01-01T00:00:00.002Z', 1721425.5000000233 ], [ '0001-01-01T00:00:00.010Z', 1721425.5000001157 ], [ '0001-01-01T00:00:00.020Z', 1721425.5000002314 ], [ '0001-01-01T00:00:00.100Z', 1721425.5000011574 ], [ '0001-01-01T00:00:00.200Z', 1721425.5000023148 ], [ '0001-01-01T00:00:00.300Z', 1721425.5000034722 ], [ '0001-01-01T00:00:00.400Z', 1721425.5000046296 ], [ '0001-01-01T00:00:00.490Z', 1721425.5000056713 ], [ '0001-01-01T00:00:00.499Z', 1721425.5000057756 ], [ '0001-01-01T00:00:00.500Z', 1721425.500005787 ], [ '0001-01-01T00:00:00.501Z', 1721425.5000057986 ], [ '0001-01-01T00:00:00.510Z', 1721425.5000059027 ], [ '0001-01-01T00:00:00.600Z', 1721425.5000069444 ], [ '0001-01-01T00:00:00.700Z', 1721425.5000081018 ], [ '0001-01-01T00:00:00.800Z', 1721425.5000092592 ], [ '0001-01-01T00:00:00.900Z', 1721425.5000104166 ], [ '0001-01-01T00:00:00.980Z', 1721425.5000113426 ], [ '0001-01-01T00:00:00.990Z', 1721425.5000114583 ], [ '0001-01-01T00:00:00.998Z', 1721425.500011551 ], [ '0001-01-01T00:00:00.999Z', 1721425.5000115624 ], [ '0001-01-01T00:00:01Z', 1721425.500011574 ], [ '0001-01-01T00:00:01.001Z', 1721425.5000115857 ], [ '0001-01-01T00:00:01.002Z', 1721425.5000115973 ], [ '0001-01-01T00:00:01.010Z', 1721425.50001169 ], [ '0001-01-01T00:00:01.020Z', 1721425.5000118054 ], [ '0001-01-01T00:00:01.100Z', 1721425.5000127316 ], [ '0001-01-01T00:00:01.200Z', 1721425.5000138888 ], [ '1899-12-31T00:00:00Z', 2415019.5 ], [ '1900-01-01T00:00:00Z', 2415020.5 ], [ '1900-02-27T00:00:00Z', 2415077.5 ], [ '1900-02-28T00:00:00Z', 2415078.5 ], [ '1900-03-01T00:00:00Z', 2415079.5 ], [ '1900-03-02T00:00:00Z', 2415080.5 ], [ '1969-12-31T23:59:58Z', 2440587.499976852 ], [ '1969-12-31T23:59:58.500Z', 2440587.4999826388 ], [ '1969-12-31T23:59:58.800Z', 2440587.4999861112 ], [ '1969-12-31T23:59:58.900Z', 2440587.4999872684 ], [ '1969-12-31T23:59:58.980Z', 2440587.4999881946 ], [ '1969-12-31T23:59:58.990Z', 2440587.49998831 ], [ '1969-12-31T23:59:58.998Z', 2440587.4999884027 ], [ '1969-12-31T23:59:58.999Z', 2440587.4999884143 ], [ '1969-12-31T23:59:59Z', 2440587.499988426 ], [ '1969-12-31T23:59:59.001Z', 2440587.4999884376 ], [ '1969-12-31T23:59:59.002Z', 2440587.4999884493 ], [ '1969-12-31T23:59:59.010Z', 2440587.4999885415 ], [ '1969-12-31T23:59:59.020Z', 2440587.4999886574 ], [ '1969-12-31T23:59:59.100Z', 2440587.4999895832 ], [ '1969-12-31T23:59:59.200Z', 2440587.4999907408 ], [ '1969-12-31T23:59:59.300Z', 2440587.499991898 ], [ '1969-12-31T23:59:59.400Z', 2440587.4999930556 ], [ '1969-12-31T23:59:59.490Z', 2440587.4999940973 ], [ '1969-12-31T23:59:59.499Z', 2440587.4999942016 ], [ '1969-12-31T23:59:59.500Z', 2440587.4999942128 ], [ '1969-12-31T23:59:59.501Z', 2440587.4999942244 ], [ '1969-12-31T23:59:59.510Z', 2440587.4999943287 ], [ '1969-12-31T23:59:59.600Z', 2440587.4999953704 ], [ '1969-12-31T23:59:59.700Z', 2440587.4999965276 ], [ '1969-12-31T23:59:59.800Z', 2440587.4999976852 ], [ '1969-12-31T23:59:59.900Z', 2440587.4999988424 ], [ '1969-12-31T23:59:59.980Z', 2440587.4999997686 ], [ '1969-12-31T23:59:59.990Z', 2440587.4999998841 ], [ '1969-12-31T23:59:59.998Z', 2440587.4999999767 ], [ '1969-12-31T23:59:59.999Z', 2440587.4999999884 ], [ '1970-01-01T00:00:00Z', 2440587.5 ], [ '1970-01-01T00:00:00.001Z', 2440587.5000000116 ], [ '1970-01-01T00:00:00.002Z', 2440587.5000000233 ], [ '1970-01-01T00:00:00.010Z', 2440587.5000001159 ], [ '1970-01-01T00:00:00.020Z', 2440587.5000002314 ], [ '1970-01-01T00:00:00.100Z', 2440587.5000011576 ], [ '1970-01-01T00:00:00.200Z', 2440587.5000023148 ], [ '1970-01-01T00:00:00.300Z', 2440587.5000034724 ], [ '1970-01-01T00:00:00.400Z', 2440587.5000046296 ], [ '1970-01-01T00:00:00.490Z', 2440587.5000056713 ], [ '1970-01-01T00:00:00.499Z', 2440587.5000057756 ], [ '1970-01-01T00:00:00.500Z', 2440587.5000057872 ], [ '1970-01-01T00:00:00.501Z', 2440587.5000057984 ], [ '1970-01-01T00:00:00.510Z', 2440587.5000059027 ], [ '1970-01-01T00:00:00.600Z', 2440587.5000069444 ], [ '1970-01-01T00:00:00.700Z', 2440587.500008102 ], [ '1970-01-01T00:00:00.800Z', 2440587.5000092592 ], [ '1970-01-01T00:00:00.900Z', 2440587.5000104168 ], [ '1970-01-01T00:00:00.980Z', 2440587.5000113426 ], [ '1970-01-01T00:00:00.990Z', 2440587.5000114585 ], [ '1970-01-01T00:00:00.998Z', 2440587.5000115507 ], [ '1970-01-01T00:00:00.999Z', 2440587.5000115624 ], [ '1970-01-01T00:00:01Z', 2440587.500011574 ], [ '1970-01-01T00:00:01.001Z', 2440587.5000115857 ], [ '1970-01-01T00:00:01.002Z', 2440587.5000115973 ], [ '1970-01-01T00:00:01.010Z', 2440587.50001169 ], [ '1970-01-01T00:00:01.020Z', 2440587.5000118054 ], [ '1970-01-01T00:00:01.100Z', 2440587.5000127316 ], [ '1970-01-01T00:00:01.200Z', 2440587.5000138888 ], [ '1982-08-25T00:15:20.213Z', 2445206.5106506133 ], [ '2065-04-19T00:16:48.290Z', 2475394.5116700232 ], [ '2147-12-15T00:55:25.446Z', 2505583.5384889585 ], [ '2230-08-10T01:02:46.891Z', 2535771.5435982756 ], [ '2313-04-06T01:04:15.597Z', 2565960.5446249652 ], [ '2395-11-30T01:09:40.889Z', 2596148.5483899191 ], [ '2478-07-25T01:11:32.560Z', 2626336.5496824076 ], [ '2561-03-21T01:30:19.169Z', 2656525.5627218634 ], [ '2643-11-15T01:48:25.580Z', 2686713.5752960648 ], [ '2726-07-12T02:03:31.919Z', 2716902.5857860995 ], [ '2809-03-06T02:11:11.986Z', 2747090.5911109489 ], [ '2891-10-31T02:24:37.095Z', 2777279.6004293403 ], [ '2974-06-26T02:35:07.220Z', 2807467.6077224538 ], [ '3057-02-19T02:45:12.109Z', 2837655.614723484 ], [ '3139-10-17T03:06:39.990Z', 2867844.6296295137 ], [ '3222-06-11T03:08:08.251Z', 2898032.630651053 ], [ '3305-02-05T03:19:12.576Z', 2928221.6383400001 ], [ '3387-10-01T03:29:42.574Z', 2958409.6456316435 ], [ '3470-05-27T03:37:30.813Z', 2988597.6510510761 ], [ '3553-01-21T04:14:38.231Z', 3018786.6768313772 ], [ '3635-09-16T04:16:28.559Z', 3048974.6781083215 ], [ '3718-05-13T04:17:58.222Z', 3079163.6791460877 ], [ '3801-01-06T04:21:41.794Z', 3109351.681733727 ], [ '3883-09-02T04:56:35.792Z', 3139540.7059698147 ], [ '3966-04-28T05:25:14.885Z', 3169728.7258667247 ], [ '4048-12-21T05:26:05.724Z', 3199916.726455139 ], [ '4131-08-18T05:46:44.068Z', 3230105.7407878242 ], [ '4214-04-13T05:48:01.141Z', 3260293.7416798729 ], [ '4296-12-07T05:53:52.315Z', 3290482.7457443867 ], [ '4379-08-03T06:14:48.580Z', 3320670.7602844909 ], [ '4462-03-28T06:46:15.738Z', 3350858.7821265971 ], [ '4544-11-22T07:31:20.407Z', 3381047.8134306367 ], [ '4627-07-19T07:58:33.754Z', 3411235.8323351159 ], [ '4710-03-15T08:07:43.130Z', 3441424.8386936341 ], [ '4792-11-07T08:29:11.091Z', 3471612.8536005905 ], [ '4875-07-04T09:08:15.328Z', 3501801.8807329629 ], [ '4958-02-27T09:30:41.781Z', 3531989.8963169097 ], [ '5040-10-23T09:34:04.462Z', 3562177.8986627543 ], [ '5123-06-20T09:37:23.945Z', 3592366.9009715859 ], [ '5206-02-12T09:37:56.655Z', 3622554.9013501736 ], [ '5288-10-08T09:45:12.230Z', 3652743.9063915508 ], [ '5371-06-04T09:54:14.782Z', 3682931.9126710882 ], [ '5454-01-28T09:54:22.108Z', 3713119.9127558796 ], [ '5536-09-24T10:01:36.151Z', 3743308.9177795257 ], [ '5619-05-20T12:09:48.602Z', 3773497.0068125231 ], [ '5702-01-14T12:34:08.549Z', 3803686.0237100581 ], [ '5784-09-08T12:56:06.495Z', 3833874.0389640625 ], [ '5867-05-06T12:58:58.217Z', 3864063.0409515854 ], [ '5949-12-30T12:59:54.263Z', 3894251.0416002665 ], [ '6032-08-24T13:34:41.331Z', 3924439.0657561459 ], [ '6115-04-21T13:58:28.601Z', 3954628.0822754744 ], [ '6197-12-14T14:02:16.899Z', 3984816.0849178126 ], [ '6280-08-10T14:36:17.444Z', 4015005.1085352316 ], [ '6363-04-06T14:37:57.451Z', 4045193.1096927198 ], [ '6445-11-30T14:57:42.757Z', 4075382.123411539 ], [ '6528-07-26T15:10:48.307Z', 4105570.1325035533 ], [ '6611-03-22T15:14:39.890Z', 4135758.1351839118 ], [ '6693-11-15T15:19:47.988Z', 4165947.1387498612 ], [ '6776-07-11T16:04:24.344Z', 4196135.1697262041 ], [ '6859-03-07T16:22:23.952Z', 4226324.1822216669 ], [ '6941-10-31T16:29:55.999Z', 4256512.1874536918 ], [ '7024-06-26T16:58:20.259Z', 4286700.2071789233 ], [ '7107-02-21T17:04:02.415Z', 4316889.2111390624 ], [ '7189-10-16T17:18:29.630Z', 4347077.2211762732 ], [ '7272-06-11T17:47:21.323Z', 4377266.2412190158 ], [ '7355-02-05T17:53:29.866Z', 4407454.2454845607 ], [ '7437-10-02T17:53:41.076Z', 4437643.2456143051 ], [ '7520-05-28T17:55:06.044Z', 4467831.2465977315 ], [ '7603-01-21T18:14:49.151Z', 4498019.2602910995 ], [ '7685-09-16T18:17:45.738Z', 4528208.2623349307 ], [ '7768-05-12T18:29:59.700Z', 4558396.2708298611 ], [ '7851-01-07T18:33:21.233Z', 4588585.273162419 ], [ '7933-09-02T19:14:24.673Z', 4618773.3016744554 ], [ '8016-04-27T19:17:12.816Z', 4648961.3036205554 ], [ '8098-12-22T19:23:36.418Z', 4679150.3080603937 ], [ '8181-08-17T19:46:25.908Z', 4709338.3239109721 ], [ '8264-04-13T20:07:47.314Z', 4739527.3387420606 ], [ '8346-12-08T20:31:37.603Z', 4769715.3552963305 ], [ '8429-08-03T20:39:57.770Z', 4799904.3610853013 ], [ '8512-03-29T20:50:17.067Z', 4830092.3682530904 ], [ '8594-11-22T21:02:57.827Z', 4860280.3770581828 ], [ '8677-07-19T21:23:05.519Z', 4890469.3910360998 ], [ '8760-03-14T21:34:49.572Z', 4920657.3991848612 ], [ '8842-11-08T21:39:05.944Z', 4950846.4021521294 ], [ '8925-07-04T21:39:18.426Z', 4981034.4022965971 ], [ '9008-02-28T21:46:07.769Z', 5011222.4070343636 ], [ '9090-10-24T21:57:55.662Z', 5041411.4152275696 ], [ '9173-06-19T22:19:11.732Z', 5071599.4299968984 ], [ '9256-02-13T22:23:51.376Z', 5101788.4332335182 ], [ '9338-10-09T22:27:58.771Z', 5131976.4360968862 ], [ '9421-06-05T22:43:30.392Z', 5162165.4468795368 ], [ '9504-01-30T22:48:25.834Z', 5192353.4502990041 ], [ '9586-09-24T22:53:51.727Z', 5222541.4540709145 ], [ '9669-05-20T23:12:56.536Z', 5252730.4673210187 ], [ '9752-01-14T23:15:54.109Z', 5282918.4693762613 ], [ '9834-09-10T23:17:12.632Z', 5313107.4702850925 ], [ '9999-12-31T23:59:58Z', 5373484.499976852 ], [ '9999-12-31T23:59:58.500Z', 5373484.4999826383 ], [ '9999-12-31T23:59:58.800Z', 5373484.4999861112 ], [ '9999-12-31T23:59:58.900Z', 5373484.4999872688 ], [ '9999-12-31T23:59:58.980Z', 5373484.4999881946 ], [ '9999-12-31T23:59:58.990Z', 5373484.49998831 ], [ '9999-12-31T23:59:58.998Z', 5373484.4999884032 ], [ '9999-12-31T23:59:58.999Z', 5373484.4999884143 ], [ '9999-12-31T23:59:59Z', 5373484.4999884255 ], [ '9999-12-31T23:59:59.001Z', 5373484.4999884376 ], [ '9999-12-31T23:59:59.002Z', 5373484.4999884497 ], [ '9999-12-31T23:59:59.010Z', 5373484.499988541 ], [ '9999-12-31T23:59:59.020Z', 5373484.4999886574 ], [ '9999-12-31T23:59:59.100Z', 5373484.4999895832 ], [ '9999-12-31T23:59:59.200Z', 5373484.4999907408 ], [ '9999-12-31T23:59:59.300Z', 5373484.4999918975 ], [ '9999-12-31T23:59:59.400Z', 5373484.4999930561 ], [ '9999-12-31T23:59:59.490Z', 5373484.4999940973 ], [ '9999-12-31T23:59:59.499Z', 5373484.4999942016 ], [ '9999-12-31T23:59:59.500Z', 5373484.4999942128 ], [ '9999-12-31T23:59:59.501Z', 5373484.4999942239 ], [ '9999-12-31T23:59:59.510Z', 5373484.4999943282 ], [ '9999-12-31T23:59:59.600Z', 5373484.4999953704 ], [ '9999-12-31T23:59:59.700Z', 5373484.499996528 ], [ '9999-12-31T23:59:59.800Z', 5373484.4999976847 ], [ '9999-12-31T23:59:59.900Z', 5373484.4999988424 ], [ '9999-12-31T23:59:59.980Z', 5373484.499999769 ], [ '9999-12-31T23:59:59.990Z', 5373484.4999998845 ], [ '9999-12-31T23:59:59.998Z', 5373484.4999999767 ], [ '9999-12-31T23:59:59.999Z', 5373484.4999999888 ], ); foreach my $test (@tests) { my ($string, $jd) = @$test; my $tm = Time::Moment->from_jd($jd); is($tm->to_string, $string, "Time::Moment->from_jd($jd)"); delta_ok($tm->jd, $jd, "$tm->jd"); } } { my $tm = Time::Moment->from_jd(0, epoch => 719163); is($tm->to_string, '1970-01-01T00:00:00Z'); } { my $tm = Time::Moment->from_jd(0, epoch => 719163); is($tm->to_string, '1970-01-01T00:00:00Z'); } { my $tm = Time::Moment->from_jd(0.000001428888889, epoch => 719163, precision => 6); is($tm->to_string, '1970-01-01T00:00:00.123456Z'); } done_testing(); Time-Moment-0.44/t/192_mjd.t000755 000765 000024 00000033344 12606144734 016174 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; use Test::Number::Delta relative => 1E-10; BEGIN { use_ok('Time::Moment'); } { my @tests = ( [ '0001-01-01T00:00:00Z', -678575.0 ], [ '0001-01-01T00:00:00.001Z', -678574.9999999885 ], [ '0001-01-01T00:00:00.002Z', -678574.9999999768 ], [ '0001-01-01T00:00:00.010Z', -678574.9999998843 ], [ '0001-01-01T00:00:00.020Z', -678574.9999997686 ], [ '0001-01-01T00:00:00.100Z', -678574.9999988426 ], [ '0001-01-01T00:00:00.200Z', -678574.9999976852 ], [ '0001-01-01T00:00:00.300Z', -678574.9999965278 ], [ '0001-01-01T00:00:00.400Z', -678574.9999953704 ], [ '0001-01-01T00:00:00.490Z', -678574.9999943287 ], [ '0001-01-01T00:00:00.499Z', -678574.9999942245 ], [ '0001-01-01T00:00:00.500Z', -678574.999994213 ], [ '0001-01-01T00:00:00.501Z', -678574.9999942014 ], [ '0001-01-01T00:00:00.510Z', -678574.9999940973 ], [ '0001-01-01T00:00:00.600Z', -678574.9999930556 ], [ '0001-01-01T00:00:00.700Z', -678574.9999918982 ], [ '0001-01-01T00:00:00.800Z', -678574.9999907408 ], [ '0001-01-01T00:00:00.900Z', -678574.9999895834 ], [ '0001-01-01T00:00:00.980Z', -678574.9999886574 ], [ '0001-01-01T00:00:00.990Z', -678574.9999885417 ], [ '0001-01-01T00:00:00.998Z', -678574.999988449 ], [ '0001-01-01T00:00:00.999Z', -678574.9999884375 ], [ '0001-01-01T00:00:01Z', -678574.9999884259 ], [ '0001-01-01T00:00:01.001Z', -678574.9999884143 ], [ '0001-01-01T00:00:01.002Z', -678574.9999884028 ], [ '0001-01-01T00:00:01.010Z', -678574.9999883102 ], [ '0001-01-01T00:00:01.020Z', -678574.9999881944 ], [ '0001-01-01T00:00:01.100Z', -678574.9999872685 ], [ '0001-01-01T00:00:01.200Z', -678574.9999861111 ], [ '1899-12-31T00:00:00Z', 15019.0 ], [ '1900-01-01T00:00:00Z', 15020.0 ], [ '1900-02-27T00:00:00Z', 15077.0 ], [ '1900-02-28T00:00:00Z', 15078.0 ], [ '1900-03-01T00:00:00Z', 15079.0 ], [ '1900-03-02T00:00:00Z', 15080.0 ], [ '1969-12-31T23:59:58Z', 40586.9999768519 ], [ '1969-12-31T23:59:58.500Z', 40586.9999826389 ], [ '1969-12-31T23:59:58.800Z', 40586.9999861111 ], [ '1969-12-31T23:59:58.900Z', 40586.9999872685 ], [ '1969-12-31T23:59:58.980Z', 40586.9999881944 ], [ '1969-12-31T23:59:58.990Z', 40586.9999883102 ], [ '1969-12-31T23:59:58.998Z', 40586.9999884028 ], [ '1969-12-31T23:59:58.999Z', 40586.9999884144 ], [ '1969-12-31T23:59:59Z', 40586.9999884259 ], [ '1969-12-31T23:59:59.001Z', 40586.9999884375 ], [ '1969-12-31T23:59:59.002Z', 40586.9999884491 ], [ '1969-12-31T23:59:59.010Z', 40586.9999885417 ], [ '1969-12-31T23:59:59.020Z', 40586.9999886574 ], [ '1969-12-31T23:59:59.100Z', 40586.9999895833 ], [ '1969-12-31T23:59:59.200Z', 40586.9999907407 ], [ '1969-12-31T23:59:59.300Z', 40586.9999918981 ], [ '1969-12-31T23:59:59.400Z', 40586.9999930556 ], [ '1969-12-31T23:59:59.490Z', 40586.9999940972 ], [ '1969-12-31T23:59:59.499Z', 40586.9999942014 ], [ '1969-12-31T23:59:59.500Z', 40586.999994213 ], [ '1969-12-31T23:59:59.501Z', 40586.9999942245 ], [ '1969-12-31T23:59:59.510Z', 40586.9999943287 ], [ '1969-12-31T23:59:59.600Z', 40586.9999953704 ], [ '1969-12-31T23:59:59.700Z', 40586.9999965278 ], [ '1969-12-31T23:59:59.800Z', 40586.9999976852 ], [ '1969-12-31T23:59:59.900Z', 40586.9999988426 ], [ '1969-12-31T23:59:59.980Z', 40586.9999997685 ], [ '1969-12-31T23:59:59.990Z', 40586.9999998843 ], [ '1969-12-31T23:59:59.998Z', 40586.9999999769 ], [ '1969-12-31T23:59:59.999Z', 40586.9999999884 ], [ '1970-01-01T00:00:00Z', 40587.0 ], [ '1970-01-01T00:00:00.001Z', 40587.0000000116 ], [ '1970-01-01T00:00:00.002Z', 40587.0000000231 ], [ '1970-01-01T00:00:00.010Z', 40587.0000001157 ], [ '1970-01-01T00:00:00.020Z', 40587.0000002315 ], [ '1970-01-01T00:00:00.100Z', 40587.0000011574 ], [ '1970-01-01T00:00:00.200Z', 40587.0000023148 ], [ '1970-01-01T00:00:00.300Z', 40587.0000034722 ], [ '1970-01-01T00:00:00.400Z', 40587.0000046296 ], [ '1970-01-01T00:00:00.490Z', 40587.0000056713 ], [ '1970-01-01T00:00:00.499Z', 40587.0000057755 ], [ '1970-01-01T00:00:00.500Z', 40587.000005787 ], [ '1970-01-01T00:00:00.501Z', 40587.0000057986 ], [ '1970-01-01T00:00:00.510Z', 40587.0000059028 ], [ '1970-01-01T00:00:00.600Z', 40587.0000069444 ], [ '1970-01-01T00:00:00.700Z', 40587.0000081019 ], [ '1970-01-01T00:00:00.800Z', 40587.0000092593 ], [ '1970-01-01T00:00:00.900Z', 40587.0000104167 ], [ '1970-01-01T00:00:00.980Z', 40587.0000113426 ], [ '1970-01-01T00:00:00.990Z', 40587.0000114583 ], [ '1970-01-01T00:00:00.998Z', 40587.0000115509 ], [ '1970-01-01T00:00:00.999Z', 40587.0000115625 ], [ '1970-01-01T00:00:01Z', 40587.0000115741 ], [ '1970-01-01T00:00:01.001Z', 40587.0000115856 ], [ '1970-01-01T00:00:01.002Z', 40587.0000115972 ], [ '1970-01-01T00:00:01.010Z', 40587.0000116898 ], [ '1970-01-01T00:00:01.020Z', 40587.0000118056 ], [ '1970-01-01T00:00:01.100Z', 40587.0000127315 ], [ '1970-01-01T00:00:01.200Z', 40587.0000138889 ], [ '1982-08-25T00:15:20.213Z', 45206.0106506134 ], [ '2065-04-19T00:16:48.290Z', 75394.0116700231 ], [ '2147-12-15T00:55:25.446Z', 105583.0384889583 ], [ '2230-08-10T01:02:46.891Z', 135771.0435982755 ], [ '2313-04-06T01:04:15.597Z', 165960.0446249653 ], [ '2395-11-30T01:09:40.889Z', 196148.048389919 ], [ '2478-07-25T01:11:32.560Z', 226336.0496824074 ], [ '2561-03-21T01:30:19.169Z', 256525.0627218634 ], [ '2643-11-15T01:48:25.580Z', 286713.0752960648 ], [ '2726-07-12T02:03:31.919Z', 316902.0857860995 ], [ '2809-03-06T02:11:11.986Z', 347090.0911109491 ], [ '2891-10-31T02:24:37.095Z', 377279.1004293403 ], [ '2974-06-26T02:35:07.220Z', 407467.1077224537 ], [ '3057-02-19T02:45:12.109Z', 437655.1147234838 ], [ '3139-10-17T03:06:39.990Z', 467844.1296295139 ], [ '3222-06-11T03:08:08.251Z', 498032.1306510532 ], [ '3305-02-05T03:19:12.576Z', 528221.1383399999 ], [ '3387-10-01T03:29:42.574Z', 558409.1456316435 ], [ '3470-05-27T03:37:30.813Z', 588597.1510510764 ], [ '3553-01-21T04:14:38.231Z', 618786.1768313773 ], [ '3635-09-16T04:16:28.559Z', 648974.1781083217 ], [ '3718-05-13T04:17:58.222Z', 679163.179146088 ], [ '3801-01-06T04:21:41.794Z', 709351.1817337269 ], [ '3883-09-02T04:56:35.792Z', 739540.2059698148 ], [ '3966-04-28T05:25:14.885Z', 769728.2258667245 ], [ '4048-12-21T05:26:05.724Z', 799916.2264551389 ], [ '4131-08-18T05:46:44.068Z', 830105.240787824 ], [ '4214-04-13T05:48:01.141Z', 860293.2416798727 ], [ '4296-12-07T05:53:52.315Z', 890482.2457443866 ], [ '4379-08-03T06:14:48.580Z', 920670.2602844908 ], [ '4462-03-28T06:46:15.738Z', 950858.2821265972 ], [ '4544-11-22T07:31:20.407Z', 981047.3134306365 ], [ '4627-07-19T07:58:33.754Z', 1011235.3323351158 ], [ '4710-03-15T08:07:43.130Z', 1041424.3386936343 ], [ '4792-11-07T08:29:11.091Z', 1071612.3536005903 ], [ '4875-07-04T09:08:15.328Z', 1101801.3807329629 ], [ '4958-02-27T09:30:41.781Z', 1131989.3963169097 ], [ '5040-10-23T09:34:04.462Z', 1162177.3986627546 ], [ '5123-06-20T09:37:23.945Z', 1192366.4009715857 ], [ '5206-02-12T09:37:56.655Z', 1222554.4013501736 ], [ '5288-10-08T09:45:12.230Z', 1252743.406391551 ], [ '5371-06-04T09:54:14.782Z', 1282931.412671088 ], [ '5454-01-28T09:54:22.108Z', 1313119.4127558796 ], [ '5536-09-24T10:01:36.151Z', 1343308.4177795255 ], [ '5619-05-20T12:09:48.602Z', 1373496.5068125231 ], [ '5702-01-14T12:34:08.549Z', 1403685.5237100578 ], [ '5784-09-08T12:56:06.495Z', 1433873.5389640625 ], [ '5867-05-06T12:58:58.217Z', 1464062.5409515856 ], [ '5949-12-30T12:59:54.263Z', 1494250.5416002662 ], [ '6032-08-24T13:34:41.331Z', 1524438.5657561459 ], [ '6115-04-21T13:58:28.601Z', 1554627.5822754744 ], [ '6197-12-14T14:02:16.899Z', 1584815.5849178126 ], [ '6280-08-10T14:36:17.444Z', 1615004.6085352316 ], [ '6363-04-06T14:37:57.451Z', 1645192.60969272 ], [ '6445-11-30T14:57:42.757Z', 1675381.6234115392 ], [ '6528-07-26T15:10:48.307Z', 1705569.6325035533 ], [ '6611-03-22T15:14:39.890Z', 1735757.635183912 ], [ '6693-11-15T15:19:47.988Z', 1765946.6387498612 ], [ '6776-07-11T16:04:24.344Z', 1796134.6697262037 ], [ '6859-03-07T16:22:23.952Z', 1826323.6822216667 ], [ '6941-10-31T16:29:55.999Z', 1856511.6874536921 ], [ '7024-06-26T16:58:20.259Z', 1886699.7071789235 ], [ '7107-02-21T17:04:02.415Z', 1916888.7111390624 ], [ '7189-10-16T17:18:29.630Z', 1947076.7211762732 ], [ '7272-06-11T17:47:21.323Z', 1977265.7412190163 ], [ '7355-02-05T17:53:29.866Z', 2007453.7454845603 ], [ '7437-10-02T17:53:41.076Z', 2037642.7456143056 ], [ '7520-05-28T17:55:06.044Z', 2067830.7465977315 ], [ '7603-01-21T18:14:49.151Z', 2098018.7602910995 ], [ '7685-09-16T18:17:45.738Z', 2128207.7623349307 ], [ '7768-05-12T18:29:59.700Z', 2158395.7708298611 ], [ '7851-01-07T18:33:21.233Z', 2188584.773162419 ], [ '7933-09-02T19:14:24.673Z', 2218772.8016744559 ], [ '8016-04-27T19:17:12.816Z', 2248960.8036205554 ], [ '8098-12-22T19:23:36.418Z', 2279149.8080603937 ], [ '8181-08-17T19:46:25.908Z', 2309337.8239109721 ], [ '8264-04-13T20:07:47.314Z', 2339526.8387420601 ], [ '8346-12-08T20:31:37.603Z', 2369714.855296331 ], [ '8429-08-03T20:39:57.770Z', 2399903.8610853008 ], [ '8512-03-29T20:50:17.067Z', 2430091.8682530904 ], [ '8594-11-22T21:02:57.827Z', 2460279.8770581828 ], [ '8677-07-19T21:23:05.519Z', 2490468.8910360998 ], [ '8760-03-14T21:34:49.572Z', 2520656.8991848612 ], [ '8842-11-08T21:39:05.944Z', 2550845.9021521294 ], [ '8925-07-04T21:39:18.426Z', 2581033.9022965971 ], [ '9008-02-28T21:46:07.769Z', 2611221.9070343636 ], [ '9090-10-24T21:57:55.662Z', 2641410.9152275696 ], [ '9173-06-19T22:19:11.732Z', 2671598.9299968979 ], [ '9256-02-13T22:23:51.376Z', 2701787.9332335186 ], [ '9338-10-09T22:27:58.771Z', 2731975.9360968866 ], [ '9421-06-05T22:43:30.392Z', 2762164.9468795368 ], [ '9504-01-30T22:48:25.834Z', 2792352.9502990046 ], [ '9586-09-24T22:53:51.727Z', 2822540.9540709145 ], [ '9669-05-20T23:12:56.536Z', 2852729.9673210187 ], [ '9752-01-14T23:15:54.109Z', 2882917.9693762613 ], [ '9834-09-10T23:17:12.632Z', 2913106.9702850925 ], [ '9999-12-31T23:59:58Z', 2973483.999976852 ], [ '9999-12-31T23:59:58.500Z', 2973483.9999826388 ], [ '9999-12-31T23:59:58.800Z', 2973483.9999861112 ], [ '9999-12-31T23:59:58.900Z', 2973483.9999872684 ], [ '9999-12-31T23:59:58.980Z', 2973483.9999881946 ], [ '9999-12-31T23:59:58.990Z', 2973483.99998831 ], [ '9999-12-31T23:59:58.998Z', 2973483.9999884027 ], [ '9999-12-31T23:59:58.999Z', 2973483.9999884143 ], [ '9999-12-31T23:59:59Z', 2973483.999988426 ], [ '9999-12-31T23:59:59Z', 2973483.999988426 ], [ '9999-12-31T23:59:59.001Z', 2973483.9999884376 ], [ '9999-12-31T23:59:59.002Z', 2973483.9999884493 ], [ '9999-12-31T23:59:59.010Z', 2973483.9999885415 ], [ '9999-12-31T23:59:59.020Z', 2973483.9999886574 ], [ '9999-12-31T23:59:59.100Z', 2973483.9999895832 ], [ '9999-12-31T23:59:59.200Z', 2973483.9999907408 ], [ '9999-12-31T23:59:59.300Z', 2973483.999991898 ], [ '9999-12-31T23:59:59.400Z', 2973483.9999930556 ], [ '9999-12-31T23:59:59.490Z', 2973483.9999940973 ], [ '9999-12-31T23:59:59.499Z', 2973483.9999942016 ], [ '9999-12-31T23:59:59.500Z', 2973483.9999942128 ], [ '9999-12-31T23:59:59.501Z', 2973483.9999942244 ], [ '9999-12-31T23:59:59.510Z', 2973483.9999943287 ], [ '9999-12-31T23:59:59.600Z', 2973483.9999953704 ], [ '9999-12-31T23:59:59.700Z', 2973483.9999965276 ], [ '9999-12-31T23:59:59.800Z', 2973483.9999976852 ], [ '9999-12-31T23:59:59.900Z', 2973483.9999988424 ], [ '9999-12-31T23:59:59.980Z', 2973483.9999997686 ], [ '9999-12-31T23:59:59.990Z', 2973483.9999998841 ], [ '9999-12-31T23:59:59.998Z', 2973483.9999999767 ], [ '9999-12-31T23:59:59.999Z', 2973483.9999999884 ], ); foreach my $test (@tests) { my ($string, $mjd) = @$test; my $tm = Time::Moment->from_mjd($mjd); is($tm->to_string, $string, "Time::Moment->from_mjd($mjd)"); delta_ok($tm->mjd, $mjd, "$tm->mjd"); } } { my $tm = Time::Moment->from_mjd(0, epoch => 719163); is($tm->to_string, '1970-01-01T00:00:00Z'); } { my $tm = Time::Moment->from_mjd(0, epoch => 719163); is($tm->to_string, '1970-01-01T00:00:00Z'); } { my $tm = Time::Moment->from_mjd(0.000001428888889, epoch => 719163, precision => 6); is($tm->to_string, '1970-01-01T00:00:00.123456Z'); } done_testing(); Time-Moment-0.44/t/200_compare.t000755 000765 000024 00000003075 12246751402 017030 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; BEGIN { use_ok('Time::Moment'); } { my $tm1 = Time::Moment->from_epoch(0); my $tm2 = Time::Moment->from_epoch(86400); is($tm1->is_before($tm2), !!1, "$tm1 is before $tm2"); is($tm1->is_after($tm2), !!0, "$tm1 is not after $tm2"); is($tm1->is_equal($tm2), !!0, "$tm1 is not equal $tm2"); is($tm2->is_before($tm1), !!0, "$tm2 is not before $tm1"); is($tm2->is_after($tm1), !!1, "$tm2 is after $tm1"); is($tm2->is_equal($tm1), !!0, "$tm2 is not equal $tm1"); is($tm1->is_equal($tm1), !!1, "$tm1 is equal $tm1"); is($tm2->is_equal($tm2), !!1, "$tm2 is equal $tm2"); cmp_ok($tm1->compare($tm2), '<', 0, "$tm1 ->compare $tm2"); cmp_ok($tm2->compare($tm1), '>', 0, "$tm2 ->compare $tm1"); cmp_ok($tm1->compare($tm1), '==', 0, "$tm1 ->compare $tm1"); cmp_ok($tm2->compare($tm2), '==', 0, "$tm2 ->compare $tm2"); cmp_ok($tm1, '!=', $tm2, "$tm1 != $tm2"); cmp_ok($tm1, '<', $tm2, "$tm1 < $tm2"); cmp_ok($tm1, '<=', $tm2, "$tm1 <= $tm2"); cmp_ok($tm1, '==', $tm1, "$tm1 == $tm1"); cmp_ok($tm2, '!=', $tm1, "$tm2 != $tm1"); cmp_ok($tm2, '>', $tm1, "$tm2 > $tm1"); cmp_ok($tm2, '>=', $tm1, "$tm2 >= $tm1"); cmp_ok($tm2, '==', $tm2, "$tm2 == $tm2"); my $s1 = '1970-01-01T00:00:00Z'; my $s2 = '1970-01-02T00:00:00Z'; cmp_ok($tm2, 'ne', $s1, "$tm2 ne $s1"); cmp_ok($tm2, 'gt', $s1, "$tm2 gt $s1"); cmp_ok($tm2, 'ge', $s1, "$tm2 ge $s1"); cmp_ok($tm2, 'eq', $s2, "$tm2 eq $s2"); } done_testing(); Time-Moment-0.44/t/300_strftime.t000755 000765 000024 00000021151 12256043054 017231 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; BEGIN { use_ok('Time::Moment'); } { my @tests = ( # Combinations of calendar date and time of day [ '%Y%m%dT%H%M%S%z', '20121224T153045+0100' ], [ '%Y%m%dT%H%M%S%f%z', '20121224T153045.500+0100' ], [ '%Y%m%dT%H%M%z', '20121224T1530+0100' ], [ '%Y-%m-%dT%H:%M:%S%Z', '2012-12-24T15:30:45+01:00' ], [ '%Y-%m-%dT%H:%M:%S%f%Z', '2012-12-24T15:30:45.500+01:00' ], [ '%Y-%m-%dT%H:%M%Z', '2012-12-24T15:30+01:00' ], # Combinations of ordinal date and time of day [ '%Y%jT%H%M%S%z', '2012359T153045+0100' ], [ '%Y%jT%H%M%S%f%z', '2012359T153045.500+0100' ], [ '%Y%jT%H%M%z', '2012359T1530+0100' ], [ '%Y-%jT%H:%M:%S%Z', '2012-359T15:30:45+01:00', ], [ '%Y-%jT%H:%M:%S%f%Z', '2012-359T15:30:45.500+01:00' ], [ '%Y-%jT%H:%M%Z', '2012-359T15:30+01:00' ], # Combinations of week date and time of day [ '%GW%V%uT%H%M%S%z', '2012W521T153045+0100' ], [ '%GW%V%uT%H%M%S%f%z', '2012W521T153045.500+0100' ], [ '%GW%V%uT%H%M%f%z', '2012W521T1530+0100' ], [ '%G-W%V-%uT%H:%M:%S%Z', '2012-W52-1T15:30:45+01:00' ], [ '%G-W%V-%uT%H:%M:%S%f%Z', '2012-W52-1T15:30:45.500+01:00' ], [ '%G-W%V-%uT%H:%M%Z', '2012-W52-1T15:30+01:00' ], ); foreach my $test (@tests) { my ($format, $string) = @$test; my $tm = Time::Moment->from_string($string); is($tm->strftime($format), $string, "$string '$format'"); } } { my $string = '0001-01-01T01:01:01Z'; my $tm = Time::Moment->from_string($string); my @single = ( # Years [ '0001', [ qw( Y 0Y G 0G ) ] ], [ ' 1', [ qw( _Y _G ) ] ], [ '1', [ qw( -Y -G ) ] ], [ '01', [ qw( y 0y g 0g ) ] ], [ ' 1', [ qw( _y _g ) ] ], [ '1', [ qw( -y -g ) ] ], [ '00', [ qw( C 0C ) ] ], [ ' 0', [ qw( _C ) ] ], [ '0', [ qw( -C ) ] ], # Month of year [ '01', [ qw( m 0m ) ] ], [ ' 1', [ qw( _m ) ] ], [ '1', [ qw( -m ) ] ], # Week numbers [ '01', [ qw( V 0V W 0W ) ] ], [ ' 1', [ qw( _V _W ) ] ], [ '1', [ qw( -V -W ) ] ], [ '00', [ qw( U 0U ) ] ], [ ' 0', [ qw( _U ) ] ], [ '0', [ qw( -U ) ] ], # Day of month [ '01', [ qw( d 0d 0e ) ] ], [ ' 1', [ qw( _d e _e ) ] ], [ '1', [ qw( -d -e ) ] ], # Day of year [ '001', [ qw( j 0j ) ] ], [ ' 1', [ qw( _j ) ] ], [ '1', [ qw( -j ) ] ], # Day of week [ '1', [ qw( u w ) ] ], # Time components [ '01', [ qw( H 0H M 0M S 0S 0k ) ] ], [ ' 1', [ qw( _H _M _S _k ) ] ], [ '1', [ qw( -H -M -S -k ) ] ], [ '01', [ qw( I 0I 0l ) ] ], [ ' 1', [ qw( l _l _I ) ] ], [ '1', [ qw( -l -I ) ] ], ); foreach my $test (@single) { my ($exp, @specifiers) = ($test->[0], @{$test->[1]}); foreach my $specifier (@specifiers) { is($tm->strftime("%${specifier}"), $exp, "$string '%${specifier}'"); } } my @combined = ( [ 'c', 'Mon Jan 1 01:01:01 0001' ], [ 'D', '01/01/01' ], [ 'F', '0001-01-01' ], [ 'r', '01:01:01 AM' ], [ 'R', '01:01' ], [ 'T', '01:01:01' ], [ 'X', '01:01:01' ], [ 'x', '01/01/01' ], ); foreach my $test (@combined) { my ($specifier, $exp) = @$test; is($tm->strftime("%${specifier}"), $exp, "$string '%${specifier}'"); } } { my $string = '9999-12-31T23:59:59Z'; my $tm = Time::Moment->from_string($string); my @single = ( # Years [ '9999', [ qw( Y 0Y G 0G ) ] ], [ '9999', [ qw( _Y _G ) ] ], [ '9999', [ qw( -Y -G ) ] ], [ '99', [ qw( y 0y g 0g ) ] ], [ '99', [ qw( _y _g ) ] ], [ '99', [ qw( -y -g ) ] ], [ '99', [ qw( C 0C _C -C ) ] ], # Month of year [ '12', [ qw( m 0m _m -m ) ] ], # Week numbers [ '52', [ qw( V 0V W 0W U 0U ) ] ], [ '52', [ qw( _V _W _U ) ] ], [ '52', [ qw( -V -W -U ) ] ], # Day of month [ '31', [ qw( d 0d _d -d e 0e _e -e ) ] ], # Day of year [ '365', [ qw( j 0j _j -j ) ] ], # Day of week [ '5', [ qw( u w ) ] ], # Time components [ '23', [ qw( H 0H _H -H k 0k _k -k ) ] ], [ '59', [ qw( M 0M S 0S ) ] ], [ '59', [ qw( _M _S ) ] ], [ '59', [ qw( -M -S ) ] ], [ '11', [ qw( I 0I 0l ) ] ], [ '11', [ qw( l _l _I ) ] ], [ '11', [ qw( -l -I ) ] ], ); foreach my $test (@single) { my ($exp, @specifiers) = ($test->[0], @{$test->[1]}); foreach my $specifier (@specifiers) { is($tm->strftime("%${specifier}"), $exp, "$string '%${specifier}'"); } } my @combined = ( [ 'c', 'Fri Dec 31 23:59:59 9999' ], [ 'D', '12/31/99' ], [ 'F', '9999-12-31' ], [ 'r', '11:59:59 PM' ], [ 'R', '23:59' ], [ 'T', '23:59:59' ], [ 'X', '23:59:59' ], [ 'x', '12/31/99' ], ); foreach my $test (@combined) { my ($specifier, $exp) = @$test; is($tm->strftime("%${specifier}"), $exp, "$string '%${specifier}'"); } } { my @times = map { Time::Moment->new(year => 1, month => 1, day => $_) } (1..7); my @DayShort = qw( Mon Tue Wed Thu Fri Sat Sun ); my @DayFull = qw( Monday Tuesday Wednesday Thursday Friday Saturday Sunday ); for (my $i = 0; $i < @times; $i++) { my $tm = $times[$i]; is($tm->strftime('%a'), $DayShort[$i], "$tm '%a'"); is($tm->strftime('%A'), $DayFull[$i], "$tm '%A'"); } } { my @times = map { Time::Moment->new(year => 1, month => $_, day => 1) } (1..12); my @MonthShort = qw( Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec ); my @MonthFull = qw( January February March April May June July August September October November December ); for (my $i = 0; $i < @times; $i++) { my $tm = $times[$i]; is($tm->strftime('%h'), $MonthShort[$i], "$tm '%h'"); is($tm->strftime('%b'), $MonthShort[$i], "$tm '%b'"); is($tm->strftime('%B'), $MonthFull[$i], "$tm '%B'"); } } { my @hours = (0, 3, 6, 9, 12, 15, 17); my @minutes = (0, 1, 15, 30, 45, 59); my @sign = qw(- +); foreach my $h (@hours) { foreach my $m (@minutes) { my $n = $h * 60 + $m; foreach my $off ($n == 0 ? ($n) : ($n, -$n)) { my $tm = Time::Moment->new(year => 2000, offset => $off); my $exp; $exp = sprintf '%s%02d%02d', $sign[$off >= 0], $h, $m; is($tm->strftime('%z'), $exp, "$tm '%z'"); $exp = sprintf '%s%02d:%02d', $sign[$off >= 0], $h, $m; is($tm->strftime('%:z'), $exp, "$tm '%:z'"); $exp = $off == 0 ? 'Z' : $exp; is($tm->strftime('%Z'), $exp, "$tm '%Z'"); } } } } done_testing(); Time-Moment-0.44/t/400_with.t000755 000765 000024 00000046074 12612761054 016366 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; BEGIN { use_ok('Time::Moment'); } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789Z"); for my $year (1, 100, 1000, 2000, 9999) { my $got = $tm->with_year($year); my $prefix = "$tm->with_year($year)"; is($got->year, $year, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, 12, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789Z"); for my $quarter (1..4) { my $got = $tm->with_quarter($quarter); my $prefix = "$tm->with_quarter($quarter)"; is($got->year, 2012, "$prefix->year"); is($got->quarter, $quarter, "$prefix->quarter"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, 12, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789Z"); for my $month (1..12) { my $got = $tm->with_month($month); my $prefix = "$tm->with_month($month)"; is($got->year, 2012, "$prefix->year"); is($got->month, $month, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, 12, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789Z"); for my $day (1..31) { my $got = $tm->with_day_of_month($day); my $prefix = "$tm->with_day_of_month($day)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, $day, "$prefix->day_of_month"); is($got->hour, 12, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); } } { my $tm = Time::Moment->from_string("2012-359T12:30:45.123456789Z"); for my $day (1..366) { my $got = $tm->with_day_of_year($day); my $prefix = "$tm->with_day_of_year($day)"; is($got->year, 2012, "$prefix->year"); is($got->day_of_year, $day, "$prefix->day_of_year"); is($got->hour, 12, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789Z"); for my $day (1..92) { my $got = $tm->with_day_of_quarter($day); my $prefix = "$tm->with_day_of_quarter($day)"; is($got->year, 2012, "$prefix->year"); is($got->day_of_quarter, $day, "$prefix->day_of_quarter"); is($got->hour, 12, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789Z"); for my $hour (0..23) { my $got = $tm->with_hour($hour); my $prefix = "$tm->with_hour($hour)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, $hour, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); is($got->offset, 0, "$prefix->offset"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789+12:34"); for my $hour (0..23) { my $got = $tm->with_hour($hour); my $prefix = "$tm->with_hour($hour)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, $hour, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); is($got->offset, 12*60+34, "$prefix->offset"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789Z"); for my $minute (0..59) { my $got = $tm->with_minute($minute); my $prefix = "$tm->with_minute($minute)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, 12, "$prefix->hour"); is($got->minute, $minute, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); is($got->offset, 0, "$prefix->offset"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789+12:34"); for my $minute (0..59) { my $got = $tm->with_minute($minute); my $prefix = "$tm->with_minute($minute)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, 12, "$prefix->hour"); is($got->minute, $minute, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); is($got->offset, 12*60+34, "$prefix->offset"); } } { my @tests; foreach my $h (0, 12, 23) { foreach my $m (0, 30, 59) { push @tests, [$h, $m]; } } my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789+12:34"); foreach my $test (@tests) { my ($h, $m) = @$test; my $mod = $h * 60 + $m; my $got = $tm->with_minute_of_day($mod); my $prefix = "$tm->with_minute_of_day($mod)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, $h, "$prefix->hour"); is($got->minute, $m, "$prefix->minute"); is($got->minute_of_day, $mod, "$prefix->minute_of_day"); is($got->second, 45, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); is($got->offset, 12*60+34, "$prefix->offset"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789Z"); for my $second (0..59) { my $got = $tm->with_second($second); my $prefix = "$tm->with_second($second)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, 12, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, $second, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); is($got->offset, 0, "$prefix->offset"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789+12:34"); for my $second (0..59) { my $got = $tm->with_second($second); my $prefix = "$tm->with_second($second)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, 12, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, $second, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); is($got->offset, 12*60+34, "$prefix->offset"); } } { my @tests; foreach my $h (0, 12, 23) { foreach my $m (0, 30, 59) { foreach my $s (0, 30, 45, 59) { push @tests, [$h, $m, $s]; } } } my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789+12:34"); foreach my $test (@tests) { my ($h, $m, $s) = @$test; my $sod = ($h * 60 + $m) * 60 + $s; my $got = $tm->with_second_of_day($sod); my $prefix = "$tm->with_second_of_day($sod)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, $h, "$prefix->hour"); is($got->minute, $m, "$prefix->minute"); is($got->second, $s, "$prefix->second"); is($got->second_of_day, $sod, "$prefix->second_of_day"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); is($got->offset, 12*60+34, "$prefix->offset"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789+12:34"); for my $millisecond (0, 123, 456, 999) { my $microsecond = $millisecond * 1000; my $nanosecond = $microsecond * 1000; my $got = $tm->with_millisecond($millisecond); my $prefix = "$tm->with_millisecond($millisecond)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, 12, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, $millisecond, "$prefix->millisecond"); is($got->microsecond, $microsecond, "$prefix->microsecond"); is($got->nanosecond, $nanosecond, "$prefix->nanosecond"); is($got->offset, 12*60+34, "$prefix->offset"); } } { my @tests; foreach my $h (0, 12, 23) { foreach my $m (0, 30, 59) { foreach my $s (0, 30, 45, 59) { foreach my $ms (0, 100, 500, 999) { push @tests, [$h, $m, $s, $ms]; } } } } my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789+12:34"); foreach my $test (@tests) { my ($h, $m, $s, $ms) = @$test; my $msod = (($h * 60 + $m) * 60 + $s) * 1000 + $ms; my $us = $ms * 1000; my $ns = $us * 1000; my $got = $tm->with_millisecond_of_day($msod); my $prefix = "$tm->with_millisecond_of_day($msod)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, $h, "$prefix->hour"); is($got->minute, $m, "$prefix->minute"); is($got->second, $s, "$prefix->second"); is($got->millisecond, $ms, "$prefix->millisecond"); is($got->millisecond_of_day, $msod, "$prefix->millisecond_of_day"); is($got->microsecond, $us, "$prefix->microsecond"); is($got->nanosecond, $ns, "$prefix->nanosecond"); is($got->offset, 12*60+34, "$prefix->offset"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789+12:34"); for my $microsecond (0, 123, 456, 123_456, 999_999) { my $millisecond = int($microsecond / 1000); my $nanosecond = $microsecond * 1000; my $got = $tm->with_microsecond($microsecond); my $prefix = "$tm->with_microsecond($microsecond)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, 12, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, $millisecond, "$prefix->millisecond"); is($got->microsecond, $microsecond, "$prefix->microsecond"); is($got->nanosecond, $nanosecond, "$prefix->nanosecond"); is($got->offset, 12*60+34, "$prefix->offset"); } } { my @tests; foreach my $h (0, 12, 23) { foreach my $m (0, 30, 59) { foreach my $s (0, 30, 45, 59) { foreach my $us (0, 123456, 500500, 999999) { push @tests, [$h, $m, $s, $us]; } } } } my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789+12:34"); foreach my $test (@tests) { my ($h, $m, $s, $us) = @$test; my $usod = (($h * 60 + $m) * 60 + $s) * 1000_000 + $us; my $ms = int($us / 1000); my $ns = $us * 1000; my $got = $tm->with_microsecond_of_day($usod); my $prefix = "$tm->with_microsecond_of_day($usod)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, $h, "$prefix->hour"); is($got->minute, $m, "$prefix->minute"); is($got->second, $s, "$prefix->second"); is($got->millisecond, $ms, "$prefix->millisecond"); is($got->microsecond, $us, "$prefix->microsecond"); is($got->microsecond_of_day, $usod, "$prefix->microsecond_of_day"); is($got->nanosecond, $ns, "$prefix->nanosecond"); is($got->offset, 12*60+34, "$prefix->offset"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789+12:34"); for my $nanosecond (0, 123, 456, 123_456, 123_456_789, 999_999_999) { my $microsecond = int($nanosecond / 1000); my $millisecond = int($microsecond / 1000); my $got = $tm->with_nanosecond($nanosecond); my $prefix = "$tm->with_nanosecond($nanosecond)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, 12, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, $millisecond, "$prefix->millisecond"); is($got->microsecond, $microsecond, "$prefix->microsecond"); is($got->nanosecond, $nanosecond, "$prefix->nanosecond"); is($got->offset, 12*60+34, "$prefix->offset"); } } { my @tests; foreach my $h (0, 12, 23) { foreach my $m (0, 30, 59) { foreach my $s (0, 30, 45, 59) { foreach my $ns (0, 123456789, 500500500, 999999999) { push @tests, [$h, $m, $s, $ns]; } } } } my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789+12:34"); foreach my $test (@tests) { my ($h, $m, $s, $ns) = @$test; my $nsod = (($h * 60 + $m) * 60 + $s) * 1000_000_000 + $ns; my $us = int($ns / 1000); my $ms = int($us / 1000); my $got = $tm->with_nanosecond_of_day($nsod); my $prefix = "$tm->with_nanosecond_of_day($nsod)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, $h, "$prefix->hour"); is($got->minute, $m, "$prefix->minute"); is($got->second, $s, "$prefix->second"); is($got->millisecond, $ms, "$prefix->millisecond"); is($got->microsecond, $us, "$prefix->microsecond"); is($got->nanosecond, $ns, "$prefix->nanosecond"); is($got->nanosecond_of_day, $nsod, "$prefix->nanosecond_of_day"); is($got->offset, 12*60+34, "$prefix->offset"); } } done_testing(); Time-Moment-0.44/t/410_with_offset.t000755 000765 000024 00000003373 12260367037 017732 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; BEGIN { use_ok('Time::Moment'); } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789Z"); for my $offset (-1080, -600, -120, -60, -30, -1, 0, 1, 30, 60, 120, 600, 1080) { my $got = $tm->with_offset_same_instant($offset); my $prefix = "$tm->with_offset_same_instant($offset)"; is($got->epoch, $tm->epoch, "$prefix->epoch"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); is($got->utc_rd_as_seconds, $tm->utc_rd_as_seconds, "$prefix->utc_rd_as_seconds"); } } { my $tm = Time::Moment->from_string("2012-12-24T12:30:45.123456789Z"); for my $offset (-1080, -600, -120, -60, -30, -1, 0, 1, 30, 60, 120, 600, 1080) { my $got = $tm->with_offset_same_local($offset); my $prefix = "$tm->with_offset_same_local($offset)"; is($got->year, 2012, "$prefix->year"); is($got->month, 12, "$prefix->month"); is($got->day_of_month, 24, "$prefix->day_of_month"); is($got->hour, 12, "$prefix->hour"); is($got->minute, 30, "$prefix->minute"); is($got->second, 45, "$prefix->second"); is($got->millisecond, 123, "$prefix->millisecond"); is($got->microsecond, 123456, "$prefix->microsecond"); is($got->nanosecond, 123456789, "$prefix->nanosecond"); is($got->local_rd_as_seconds, $tm->local_rd_as_seconds, "$prefix->local_rd_as_seconds"); } } done_testing(); Time-Moment-0.44/t/411_with_adjusters.t000755 000765 000024 00000004022 13274642012 020434 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; BEGIN { use_ok('Time::Moment'); use_ok('Time::Moment::Adjusters', qw[ NextDayOfWeek PreviousDayOfWeek NextOrSameDayOfWeek PreviousOrSameDayOfWeek ]); } my $Sunday = Time::Moment->from_string('2018-W02-7T00Z'); { my @M = ( # M T W T F S S 7,1,2,3,4,5,6, # M 6,7,1,2,3,4,5, # T 5,6,7,1,2,3,4, # W 4,5,6,7,1,2,3, # T 3,4,5,6,7,1,2, # F 2,3,4,5,6,7,1, # S 1,2,3,4,5,6,7, # S ); foreach my $d1 (1..7) { my $tm = $Sunday->plus_days($d1); foreach my $d2 (1..7) { my $got = $tm->with(NextDayOfWeek($d2)); my $exp = $tm->plus_days($M[7 * $d1 + $d2 - 8]); is($got, $exp, "$tm->with(NextDayOfWeek($d2))"); } } foreach my $d1 (1..7) { my $tm = $Sunday->plus_days($d1); foreach my $d2 (1..7) { my $got = $tm->with(PreviousDayOfWeek($d2)); my $exp = $tm->minus_days($M[7 * $d2 + $d1 - 8]); is($got, $exp, "$tm->with(PreviousDayOfWeek($d2))"); } } } { my @M = ( # M T W T F S S 0,1,2,3,4,5,6, # M 6,0,1,2,3,4,5, # T 5,6,0,1,2,3,4, # W 4,5,6,0,1,2,3, # T 3,4,5,6,0,1,2, # F 2,3,4,5,6,0,1, # S 1,2,3,4,5,6,0, # S ); foreach my $d1 (1..7) { my $tm = $Sunday->plus_days($d1); foreach my $d2 (1..7) { my $got = $tm->with(NextOrSameDayOfWeek($d2)); my $exp = $tm->plus_days($M[7 * $d1 + $d2 - 8]); is($got, $exp, "$tm->with(NextOrSameDayOfWeek($d2))"); } } foreach my $d1 (1..7) { my $tm = $Sunday->plus_days($d1); foreach my $d2 (1..7) { my $got = $tm->with(PreviousOrSameDayOfWeek($d2)); my $exp = $tm->minus_days($M[7 * $d2 + $d1 - 8]); is($got, $exp, "$tm->with(PreviousOrSameDayOfWeek($d2))"); } } } done_testing(); Time-Moment-0.44/t/415_precision.t000755 000765 000024 00000006326 12721125227 017405 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; BEGIN { use_ok('Time::Moment'); } { my $tm = Time::Moment->from_string('2012-12-24T12:30:45.123456789Z'); my @tests = ( [ 9, '2012-12-24T12:30:45.123456789Z' ], [ 8, '2012-12-24T12:30:45.123456780Z' ], [ 7, '2012-12-24T12:30:45.123456700Z' ], [ 6, '2012-12-24T12:30:45.123456Z' ], [ 5, '2012-12-24T12:30:45.123450Z' ], [ 4, '2012-12-24T12:30:45.123400Z' ], [ 3, '2012-12-24T12:30:45.123Z' ], [ 2, '2012-12-24T12:30:45.120Z' ], [ 1, '2012-12-24T12:30:45.100Z' ], [ 0, '2012-12-24T12:30:45Z' ], [ -1, '2012-12-24T12:30:00Z' ], [ -2, '2012-12-24T12:00:00Z' ], [ -3, '2012-12-24T00:00:00Z' ], ); for my $test (@tests) { my ($precision, $string) = @$test; my $got = $tm->with_precision($precision); is($got->to_string, $string, "->with_precision($precision)"); is($got->precision, $precision, "$got->precision"); } } { my $tm = Time::Moment->from_string('2012-12-24T12:30:45.123456789+14:30'); my @tests = ( [ 9, '2012-12-24T12:30:45.123456789+14:30' ], [ 8, '2012-12-24T12:30:45.123456780+14:30' ], [ 7, '2012-12-24T12:30:45.123456700+14:30' ], [ 6, '2012-12-24T12:30:45.123456+14:30' ], [ 5, '2012-12-24T12:30:45.123450+14:30' ], [ 4, '2012-12-24T12:30:45.123400+14:30' ], [ 3, '2012-12-24T12:30:45.123+14:30' ], [ 2, '2012-12-24T12:30:45.120+14:30' ], [ 1, '2012-12-24T12:30:45.100+14:30' ], [ 0, '2012-12-24T12:30:45+14:30' ], [ -1, '2012-12-24T12:30:00+14:30' ], [ -2, '2012-12-24T12:00:00+14:30' ], [ -3, '2012-12-24T00:00:00+14:30' ], ); for my $test (@tests) { my ($precision, $string) = @$test; my $got = $tm->with_precision($precision); is($got->to_string, $string, "->with_precision($precision)"); is($got->precision, $precision, "$got->precision"); } } { my $tm = Time::Moment->from_string('2012-12-24T12:30:45.123456789-14:30'); my @tests = ( [ 9, '2012-12-24T12:30:45.123456789-14:30' ], [ 8, '2012-12-24T12:30:45.123456780-14:30' ], [ 7, '2012-12-24T12:30:45.123456700-14:30' ], [ 6, '2012-12-24T12:30:45.123456-14:30' ], [ 5, '2012-12-24T12:30:45.123450-14:30' ], [ 4, '2012-12-24T12:30:45.123400-14:30' ], [ 3, '2012-12-24T12:30:45.123-14:30' ], [ 2, '2012-12-24T12:30:45.120-14:30' ], [ 1, '2012-12-24T12:30:45.100-14:30' ], [ 0, '2012-12-24T12:30:45-14:30' ], [ -1, '2012-12-24T12:30:00-14:30' ], [ -2, '2012-12-24T12:00:00-14:30' ], [ -3, '2012-12-24T00:00:00-14:30' ], ); for my $test (@tests) { my ($precision, $string) = @$test; my $got = $tm->with_precision($precision); is($got->to_string, $string, "->with_precision($precision)"); is($got->precision, $precision, "$got->precision"); } } done_testing(); Time-Moment-0.44/t/420_at.t000755 000765 000024 00000010556 12565035221 016012 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; BEGIN { use_ok('Time::Moment'); } { my $tm = Time::Moment->from_string('2012-12-24T12:30:45.123456789Z'); is($tm->at_noon, '2012-12-24T12:00:00Z', '->at_noon'); is($tm->at_midnight, '2012-12-24T00:00:00Z', '->at_midnight'); is($tm->at_utc, '2012-12-24T12:30:45.123456789Z', '->at_utc'); } { my $tm = Time::Moment->from_string('2012-12-24T12:30:45.123456789+02:00'); is($tm->at_noon, '2012-12-24T12:00:00+02:00', '->at_noon'); is($tm->at_midnight, '2012-12-24T00:00:00+02:00', '->at_midnight'); is($tm->at_utc, '2012-12-24T10:30:45.123456789Z', '->at_utc'); } { my $tm = Time::Moment->from_string('2012-12-24T12:30:45.123456789-02:00'); is($tm->at_noon, '2012-12-24T12:00:00-02:00', '->at_noon'); is($tm->at_midnight, '2012-12-24T00:00:00-02:00', '->at_midnight'); is($tm->at_utc, '2012-12-24T14:30:45.123456789Z', '->at_utc'); } { my $tm = Time::Moment->new(year => 2012); my $exp = $tm->with_day_of_year(366); my $got = $tm->at_last_day_of_year; is($got, $exp, "->at_last_day_of_year (leap year)"); } { my $tm = Time::Moment->new(year => 2013); my $exp = $tm->with_day_of_year(365); my $got = $tm->at_last_day_of_year; is($got, $exp, "->at_last_day_of_year (common year)"); } { # Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec my @months = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); my $year = Time::Moment->new(year => 2012); my $month = 0; foreach my $day (@months) { ++$month; my $exp = $year->with_month($month) ->with_day_of_month($day); my $got = $year->with_month($month) ->at_last_day_of_month; is($got, $exp, "->at_last_day_of_month (leap year)"); } } { # Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec my @months = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); my $year = Time::Moment->new(year => 2013); my $month = 0; foreach my $day (@months) { ++$month; my $exp = $year->with_month($month) ->with_day_of_month($day); my $got = $year->with_month($month) ->at_last_day_of_month; is($got, $exp, "->at_last_day_of_month (common year)"); } } { # Q1 Q2 Q3 Q4 my @quarters = (91, 91, 92, 92); my $year = Time::Moment->new(year => 2012); my $quarter = 0; foreach my $day (@quarters) { ++$quarter; my $exp = $year->with_month(3 * $quarter) ->with_day_of_quarter($day); my $got = $year->with_month(3 * $quarter) ->at_last_day_of_quarter; is($got, $exp, "->at_last_day_of_quarter (leap year)"); } } { # Q1 Q2 Q3 Q4 my @quarters = (90, 91, 92, 92); my $year = Time::Moment->new(year => 2013); my $quarter = 0; foreach my $day (@quarters) { ++$quarter; my $exp = $year->with_month(3 * $quarter) ->with_day_of_quarter($day); my $got = $year->with_month(3 * $quarter) ->at_last_day_of_quarter; is($got, $exp, "->at_last_day_of_quarter (common year)"); } } { my $tm = Time::Moment->from_string('2012-12-24T12:30:45.123+02:00'); is($tm->at_last_day_of_year, '2012-12-31T12:30:45.123+02:00', '->at_last_day_of_year'); is($tm->at_last_day_of_quarter, '2012-12-31T12:30:45.123+02:00', '->at_last_day_of_quarter'); is($tm->at_last_day_of_month, '2012-12-31T12:30:45.123+02:00', '->at_last_day_of_month'); } { my $tm = Time::Moment->from_string('2012-01-24T12:30:45.123-02:00'); is($tm->at_last_day_of_year, '2012-12-31T12:30:45.123-02:00', '->at_last_day_of_year'); is($tm->at_last_day_of_quarter, '2012-03-31T12:30:45.123-02:00', '->at_last_day_of_quarter'); is($tm->at_last_day_of_month, '2012-01-31T12:30:45.123-02:00', '->at_last_day_of_month'); } { my $tm = Time::Moment->from_string('2012-07-24T12:30:45.123Z'); is($tm->at_last_day_of_year, '2012-12-31T12:30:45.123Z', '->at_last_day_of_year'); is($tm->at_last_day_of_quarter, '2012-09-30T12:30:45.123Z', '->at_last_day_of_quarter'); is($tm->at_last_day_of_month, '2012-07-31T12:30:45.123Z', '->at_last_day_of_month'); } done_testing(); Time-Moment-0.44/t/430_length.t000755 000765 000024 00000003452 12565311115 016664 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; BEGIN { use_ok('Time::Moment'); } { my $tm = Time::Moment->new(year => 2012); is($tm->length_of_year, 366, "length of year in a leap year is 366"); } { my $tm = Time::Moment->new(year => 2013); is($tm->length_of_year, 365, "length of year in a common year is 365"); } { # Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec my @lengths = (31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); my $year = Time::Moment->new(year => 2012); my $month = 1; foreach my $length (@lengths) { my $tm = $year->with_month($month++); is($tm->length_of_month, $length, "length of month $month is $length in a leap year"); } } { # Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec my @lengths = (31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); my $year = Time::Moment->new(year => 2013); my $month = 1; foreach my $length (@lengths) { my $tm = $year->with_month($month++); is($tm->length_of_month, $length, "length of month $month is $length in a common year"); } } { # Q1 Q2 Q3 Q4 my @lengths = (91, 91, 92, 92); my $year = Time::Moment->new(year => 2012); my $quarter = 1; foreach my $length (@lengths) { my $tm = $year->with_month(3 * $quarter++); is($tm->length_of_quarter, $length, "length of quarter $quarter is $length in a leap year"); } } { # Q1 Q2 Q3 Q4 my @lengths = (90, 91, 92, 92); my $year = Time::Moment->new(year => 2013); my $quarter = 1; foreach my $length (@lengths) { my $tm = $year->with_month(3 * $quarter++); is($tm->length_of_quarter, $length, "length of quarter $quarter is $length in a common year"); } } done_testing(); Time-Moment-0.44/t/450_delta_time.t000755 000765 000024 00000011255 12600616573 017522 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; BEGIN { use_ok('Time::Moment'); } { my $tm = Time::Moment->from_string('2012-12-24T15:30:45.123456789Z'); for my $n (-20..20) { my $x = $n * ($n ** 4); { my $exp = $x; { my $got = $tm->delta_hours($tm->plus_hours($x)); is($got, $exp, "delta_hours(plus_hours($x))"); } { my $got = $tm->delta_minutes($tm->plus_minutes($x)); is($got, $exp, "delta_minutes(plus_minutes($x))"); } { my $got = $tm->delta_seconds($tm->plus_seconds($x)); is($got, $exp, "delta_seconds(plus_seconds($x))"); } { my $got = $tm->delta_milliseconds($tm->plus_milliseconds($x)); is($got, $exp, "delta_milliseconds(plus_milliseconds($x))"); } { my $got = $tm->delta_microseconds($tm->plus_microseconds($x)); is($got, $exp, "delta_microseconds(plus_microseconds($x))"); } { my $got = $tm->delta_nanoseconds($tm->plus_nanoseconds($x)); is($got, $exp, "delta_nanoseconds(plus_nanoseconds($x))"); } } { my $exp = -$x; { my $got = $tm->delta_hours($tm->minus_hours($x)); is($got, $exp, "delta_hours(minus_hours($x))"); } { my $got = $tm->delta_minutes($tm->minus_minutes($x)); is($got, $exp, "delta_minutes(minus_minutes($x))"); } { my $got = $tm->delta_seconds($tm->minus_seconds($x)); is($got, $exp, "delta_seconds(minus_seconds($x))"); } { my $got = $tm->delta_milliseconds($tm->minus_milliseconds($x)); is($got, $exp, "delta_milliseconds(minus_milliseconds($x))"); } { my $got = $tm->delta_microseconds($tm->minus_microseconds($x)); is($got, $exp, "delta_microseconds(minus_microseconds($x))"); } { my $got = $tm->delta_nanoseconds($tm->minus_nanoseconds($x)); is($got, $exp, "delta_nanoseconds(minus_nanoseconds($x))"); } } } } { my $tm1 = Time::Moment->from_string('2012-12-24T15:30:45Z'); for my $h (-10, -1, 0, 1, 10) { my $tm2 = $tm1->with_offset_same_instant($h*60); is($tm1->delta_hours($tm2), 0, "$tm1->delta_hours($tm2)"); is($tm1->delta_minutes($tm2), 0, "$tm1->delta_minutes($tm2)"); is($tm1->delta_seconds($tm2), 0, "$tm1->delta_seconds($tm2)"); is($tm1->delta_milliseconds($tm2), 0, "$tm1->delta_milliseconds($tm2)"); is($tm1->delta_microseconds($tm2), 0, "$tm1->delta_microseconds($tm2)"); is($tm1->delta_nanoseconds($tm2), 0, "$tm1->delta_nanoseconds($tm2)"); is($tm2->delta_hours($tm1), 0, "$tm2->delta_hours($tm1)"); is($tm2->delta_minutes($tm1), 0, "$tm2->delta_minutes($tm1)"); is($tm2->delta_seconds($tm1), 0, "$tm2->delta_seconds($tm1)"); is($tm2->delta_milliseconds($tm1), 0, "$tm2->delta_milliseconds($tm1)"); is($tm2->delta_microseconds($tm1), 0, "$tm2->delta_microseconds($tm1)"); is($tm2->delta_nanoseconds($tm1), 0, "$tm2->delta_nanoseconds($tm1)"); } } { my $tm1 = Time::Moment->from_string('2012-12-24T15:30:45Z'); for my $h (-10, -1, 0, 1, 10) { my $tm2 = $tm1->with_offset_same_local($h*60); is($tm1->delta_hours($tm2), -$h, "$tm1->delta_hours($tm2)"); is($tm1->delta_minutes($tm2), -$h*60, "$tm1->delta_minutes($tm2)"); is($tm1->delta_seconds($tm2), -$h*60*60, "$tm1->delta_seconds($tm2)"); is($tm1->delta_milliseconds($tm2), -$h*60*60*1E3, "$tm1->delta_milliseconds($tm2)"); is($tm1->delta_microseconds($tm2), -$h*60*60*1E6, "$tm1->delta_microseconds($tm2)"); is($tm1->delta_nanoseconds($tm2), -$h*60*60*1E9, "$tm1->delta_nanoseconds($tm2)"); is($tm2->delta_hours($tm1), $h, "$tm2->delta_hours($tm1)"); is($tm2->delta_minutes($tm1), $h*60, "$tm2->delta_minutes($tm1)"); is($tm2->delta_seconds($tm1), $h*60*60, "$tm2->delta_seconds($tm1)"); is($tm2->delta_milliseconds($tm1), $h*60*60*1E3, "$tm2->delta_milliseconds($tm1)"); is($tm2->delta_microseconds($tm1), $h*60*60*1E6, "$tm2->delta_microseconds($tm1)"); is($tm2->delta_nanoseconds($tm1), $h*60*60*1E9, "$tm2->delta_nanoseconds($tm1)"); } } done_testing(); Time-Moment-0.44/t/455_delta_date.t000755 000765 000024 00000004237 12600735237 017507 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; BEGIN { use_ok('Time::Moment'); } { my $tm = Time::Moment->from_string('2012-12-24T15:30:45.123456789Z'); for my $n (-10..10) { my $x = $n * ($n ** 2); { my $exp = $x; { my $got = $tm->delta_years($tm->plus_years($x)); is($got, $exp, "delta_years(plus_years($x))"); } { my $got = $tm->delta_months($tm->plus_months($x)); is($got, $exp, "delta_months(plus_months($x))"); } { my $got = $tm->delta_weeks($tm->plus_weeks($x)); is($got, $exp, "delta_weeks(plus_weeks($x))"); } { my $got = $tm->delta_days($tm->plus_days($x)); is($got, $exp, "delta_days(plus_days($x))"); } } { my $exp = -$x; { my $got = $tm->delta_years($tm->minus_years($x)); is($got, $exp, "delta_years(minus_years($x))"); } { my $got = $tm->delta_months($tm->minus_months($x)); is($got, $exp, "delta_months(minus_months($x))"); } { my $got = $tm->delta_weeks($tm->minus_weeks($x)); is($got, $exp, "delta_weeks(minus_weeks($x))"); } { my $got = $tm->delta_days($tm->minus_days($x)); is($got, $exp, "delta_days(minus_days($x))"); } } } } { my $tm1 = Time::Moment->from_string('2012-12-23T15:30:45+12'); my $tm2 = Time::Moment->from_string('2012-12-24T15:30:45-12'); is($tm1->delta_days($tm2), 1, "$tm1->delta_days($tm2)"); } { my $tm1 = Time::Moment->from_string('2012-10-23T15:30:45+12'); my $tm2 = Time::Moment->from_string('2012-12-22T15:30:45-12'); is($tm1->delta_months($tm2), 1, "$tm1->delta_months($tm2)"); } { my $tm1 = Time::Moment->from_string('2012-10-23T15:30:45+12'); my $tm2 = Time::Moment->from_string('2012-12-23T15:30:45-12'); is($tm1->delta_months($tm2), 2, "$tm1->delta_months($tm2)"); } done_testing(); Time-Moment-0.44/t/500_storable.t000755 000765 000024 00000002233 13072611672 017215 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use lib 't'; use Test::More; use Test::Requires qw[Storable]; use Util qw[throws_ok lives_ok]; BEGIN { use_ok('Time::Moment'); } { my ($tm, $freezed, $thawed); $tm = Time::Moment->from_string("2012-12-24T15:30:45.123456789+01:00"); lives_ok { $freezed = Storable::nfreeze($tm) } 'Storable::nfreeze()'; lives_ok { $thawed = Storable::thaw($freezed) } 'Storable::thaw()'; isa_ok($thawed, 'Time::Moment'); is($thawed, '2012-12-24T15:30:45.123456789+01:00'); } { my ($tm, $freezed, $thawed); $tm = Time::Moment->from_string("2012-12-24T15:30:45.123456789-01:00"); lives_ok { $freezed = Storable::nfreeze($tm) } 'Storable::nfreeze()'; lives_ok { $thawed = Storable::thaw($freezed) } 'Storable::thaw()'; isa_ok($thawed, 'Time::Moment'); is($thawed, '2012-12-24T15:30:45.123456789-01:00'); } { my ($tm, $cloned); $tm = Time::Moment->from_string("2012-12-24T15:30:45.123456789+01:00"); lives_ok { $cloned = Storable::dclone($tm) } 'Storable::dclone()'; isa_ok($cloned, 'Time::Moment'); is($cloned, '2012-12-24T15:30:45.123456789+01:00'); } done_testing(); Time-Moment-0.44/t/510_json.t000755 000765 000024 00000001027 13072611673 016355 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use lib 't'; use Test::More; use Test::Requires qw[JSON::XS]; use Util qw[throws_ok lives_ok]; BEGIN { use_ok('Time::Moment'); } { my ($tm, $json, $serialized); $json = JSON::XS->new->convert_blessed; $tm = Time::Moment->from_string("2012-12-24T15:30:45.123456789+01:00"); lives_ok { $serialized = $json->encode([$tm]) } '$json->encode()'; ok(index($serialized, '2012-12-24T15:30:45.123456789+01:00') != -1, "serialized contains timestamp"); } done_testing(); Time-Moment-0.44/t/520_cbor.t000755 000765 000024 00000001154 13072611674 016334 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use lib 't'; use Test::More; use Test::Requires { 'CBOR::XS' => '1.25' }; use Util qw[throws_ok lives_ok]; BEGIN { use_ok('Time::Moment'); } { my ($tm, $encoded, $decoded); $tm = Time::Moment->from_string("2012-12-24T15:30:45.123456789+01:00"); lives_ok { $encoded = CBOR::XS::encode_cbor([$tm]) } 'encode_cbor()'; lives_ok { $decoded = CBOR::XS->new->filter(sub { return $_[1] })->decode($encoded); } '$cbor->decode()'; is_deeply($decoded, ['2012-12-24T15:30:45.123456789+01:00'], 'decoded values'); } done_testing(); Time-Moment-0.44/t/530_sereal.t000755 000765 000024 00000002012 13072611675 016656 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use lib 't'; use Test::More; use Test::Requires { Sereal => '2.060' }; use Util qw[throws_ok lives_ok]; BEGIN { use_ok('Time::Moment'); } { my ($tm, $encoded, $decoded); my @moments = map { Time::Moment->from_string($_) } qw[2012-12-24T15:30:45.123456789+01:00 2012-12-24T15:30:45.987654321+01:00]; lives_ok { $encoded = Sereal::encode_sereal([@moments], { freeze_callbacks => 1 }) } 'Sereal::encode_sereal()'; lives_ok { $decoded = Sereal::decode_sereal($encoded); } 'Sereal::decode_sereal()'; isa_ok($decoded, 'ARRAY'); is(scalar @$decoded, 2, 'ARRAY has two elements'); isa_ok($decoded->[0], 'Time::Moment', 'first element'); isa_ok($decoded->[1], 'Time::Moment', 'second element'); is($decoded->[0]->to_string, $moments[0]->to_string, 'first element has right time'); is($decoded->[1]->to_string, $moments[1]->to_string, 'second element has right time'); } done_testing(); Time-Moment-0.44/t/600_coerce_dt.t000755 000765 000024 00000001423 13072611676 017336 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use lib 't'; use Test::More; use Test::Requires qw[Params::Coerce DateTime]; use Util qw[throws_ok lives_ok]; BEGIN { use_ok('Time::Moment'); } { my $dt = DateTime->from_epoch(epoch => 123456789); my $tm; lives_ok { $tm = Params::Coerce::coerce('Time::Moment', $dt) }; isa_ok($tm, 'Time::Moment'); is($tm->epoch, 123456789, '->epoch'); } { my $dt = DateTime->new(year => 2012); throws_ok { Params::Coerce::coerce('Time::Moment', $dt) } qr/^Cannot coerce .* 'floating'/; } { my $tm = Time::Moment->from_epoch(123456789); my $dt; lives_ok { $dt = Params::Coerce::coerce('DateTime', $tm) }; isa_ok($dt, 'DateTime'); is($dt->epoch, 123456789, '->epoch'); } done_testing(); Time-Moment-0.44/t/610_coerce_tp.t000755 000765 000024 00000001153 13072611700 017337 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use lib 't'; use Test::More; use Test::Requires qw[Params::Coerce Time::Piece]; use Util qw[lives_ok]; BEGIN { use_ok('Time::Moment'); } { my $tp = Time::Piece::gmtime(123456789); my $tm; lives_ok { $tm = Params::Coerce::coerce('Time::Moment', $tp) }; isa_ok($tm, 'Time::Moment'); is($tm->epoch, 123456789, '->epoch'); } { my $tm = Time::Moment->from_epoch(123456789); my $tp; lives_ok { $tp = Params::Coerce::coerce('Time::Piece', $tm) }; isa_ok($tp, 'Time::Piece'); is($tp->epoch, 123456789, '->epoch'); } done_testing(); Time-Moment-0.44/t/900_bug_reuse.t000755 000765 000024 00000002014 12403505552 017357 0ustar00chansenstaff000000 000000 #!perl use strict; use warnings; use Test::More; BEGIN { use_ok('Time::Moment'); } # Test cases for issue #7 # https://github.com/chansen/p5-time-moment/issues/7 { package MyObject; sub new { @_ == 2 || die; my ($class, $moment) = @_; return bless { moment => $moment }, $class; } sub moment { return $_[0]->{moment}; } } { my $tm1 = Time::Moment->from_string('0001-01-01T00:00:00Z'); my $obj = MyObject->new($tm1); my $tm2 = $obj->moment->plus_seconds(1); is($tm1, '0001-01-01T00:00:00Z', '$tm1'); is($tm2, '0001-01-01T00:00:01Z', '$tm2'); } { my $tm = Time::Moment->from_string('0001-01-01T00:00:00Z'); my @moments = map { sub { $tm }->()->plus_seconds($_) } (0..3); is($moments[0], '0001-01-01T00:00:00Z', '$moments[0]'); is($moments[1], '0001-01-01T00:00:01Z', '$moments[1]'); is($moments[2], '0001-01-01T00:00:02Z', '$moments[2]'); is($moments[3], '0001-01-01T00:00:03Z', '$moments[4]'); } done_testing(); Time-Moment-0.44/t/Util.pm000644 000765 000024 00000003271 13072611473 016103 0ustar00chansenstaff000000 000000 package Util; use strict; use warnings; use Carp qw[]; use Test::Fatal qw[exception lives_ok]; BEGIN { our @EXPORT_OK = qw[ throws_ok warns_ok lives_ok ]; our %EXPORT_TAGS = ( all => [ @EXPORT_OK ], ); require Exporter; *import = \&Exporter::import; } my $Tester; sub throws_ok (&$;$) { my ($code, $regexp, $name) = @_; require Test::Builder; $Tester ||= Test::Builder->new; my $e = exception(\&$code); my $ok = ($e && $e =~ m/$regexp/); $Tester->ok($ok, $name); unless ($ok) { if ($e) { $Tester->diag("expecting: " . $regexp); $Tester->diag("found: " . $e); } else { $Tester->diag("expected an exception but none was raised"); } } } sub warns_ok (&$;$) { my ($code, $regexp, $name) = @_; require Test::Builder; $Tester ||= Test::Builder->new; my @warnings = (); local $SIG{__WARN__} = sub { push @warnings, @_ }; my $e = exception(\&$code); my $ok = (!$e && @warnings == 1 && $warnings[0] =~ m/$regexp/); $Tester->ok($ok, $name); unless ($ok) { if ($e) { $Tester->diag("expected a warning but an exception was raised"); $Tester->diag("exception: " . $e); } elsif (@warnings == 0) { $Tester->diag("expected a warning but none were issued"); } elsif (@warnings >= 2) { $Tester->diag("expected a warning but several were issued"); $Tester->diag("warnings: " . join '', @warnings); } else { $Tester->diag("expecting: " . $regexp); $Tester->diag("found: " . $warnings[0]); } } } 1; Time-Moment-0.44/src/dt_accessor.c000644 000765 000024 00000004347 12271265726 017624 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "dt_core.h" dt_t dt_from_cjdn(int n) { return dt_from_rdn(n - 1721425); } int dt_cjdn(dt_t dt) { return dt_rdn(dt) + 1721425; } int dt_year(dt_t dt) { int y; dt_to_yd(dt, &y, NULL); return y; } int dt_quarter(dt_t dt) { int q; dt_to_yqd(dt, NULL, &q, NULL); return q; } int dt_month(dt_t dt) { int m; dt_to_ymd(dt, NULL, &m, NULL); return m; } int dt_doy(dt_t dt) { int d; dt_to_yd(dt, NULL, &d); return d; } int dt_doq(dt_t dt) { int d; dt_to_yqd(dt, NULL, NULL, &d); return d; } int dt_dom(dt_t dt) { int d; dt_to_ymd(dt, NULL, NULL, &d); return d; } int dt_woy(dt_t dt) { int w; dt_to_ywd(dt, NULL, &w, NULL); return w; } int dt_yow(dt_t dt) { int y; dt_to_ywd(dt, &y, NULL, NULL); return y; } Time-Moment-0.44/src/dt_accessor.h000644 000765 000024 00000003625 12271265726 017627 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __DT_ACCESSOR_H__ #define __DT_ACCESSOR_H__ #include "dt_core.h" #ifdef __cplusplus extern "C" { #endif dt_t dt_from_cjdn (int n); int dt_cjdn (dt_t dt); int dt_year (dt_t dt); int dt_quarter (dt_t dt); int dt_month (dt_t dt); int dt_doy (dt_t dt); int dt_doq (dt_t dt); int dt_dom (dt_t dt); int dt_woy (dt_t dt); int dt_yow (dt_t dt); #ifdef __cplusplus } #endif #endif Time-Moment-0.44/src/dt_arithmetic.c000644 000765 000024 00000013101 12271265726 020137 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "dt_core.h" #include "dt_util.h" #include "dt_arithmetic.h" dt_t dt_add_years(dt_t dt, int delta, dt_adjust_t adjust) { int y, d; dt_to_yd(dt, &y, &d); if (adjust == DT_EXCESS || d < 365) return dt_from_yd(y + delta, d); else { int ry = y + delta; int diy; diy = dt_days_in_year(ry); if (d > diy || (adjust == DT_SNAP && d == dt_days_in_year(y))) d = diy; return dt_from_yd(ry, d); } } dt_t dt_add_quarters(dt_t dt, int delta, dt_adjust_t adjust) { int y, q, d; dt_to_yqd(dt, &y, &q, &d); if (adjust == DT_EXCESS || d < 90) return dt_from_yqd(y, q + delta, d); else { int ry = y; int rq = q + delta; int diq; if (rq < 1 || rq > 4) { ry += rq / 4; rq %= 4; if (rq < 1) ry--, rq += 4; } diq = dt_days_in_quarter(ry, rq); if (d > diq || (adjust == DT_SNAP && d == dt_days_in_quarter(y, q))) d = diq; return dt_from_yqd(ry, rq, d); } } dt_t dt_add_months(dt_t dt, int delta, dt_adjust_t adjust) { int y, m, d; dt_to_ymd(dt, &y, &m, &d); if (adjust == DT_EXCESS || d < 28) return dt_from_ymd(y, m + delta, d); else { int ry = y; int rm = m + delta; int dim; if (rm < 1 || rm > 12) { ry += rm / 12; rm %= 12; if (rm < 1) ry--, rm += 12; } dim = dt_days_in_month(ry, rm); if (d > dim || (adjust == DT_SNAP && d == dt_days_in_month(y, m))) d = dim; return dt_from_ymd(ry, rm, d); } } void dt_delta_yd(dt_t dt1, dt_t dt2, int *yp, int *dp) { int y1, y2, d1, d2, ny, nd; dt_to_yd(dt1, &y1, &d1); dt_to_yd(dt2, &y2, &d2); ny = y2 - y1; nd = d2 - d1; if (ny > 0 && nd < 0) { ny--; nd = dt2 - dt_add_years(dt1, ny, DT_LIMIT); } else if (ny < 0 && nd > 0) { ny++; nd -= dt_days_in_year(y2); } if (yp) *yp = ny; if (dp) *dp = nd; } void dt_delta_yqd(dt_t dt1, dt_t dt2, int *yp, int *qp, int *dp) { int y1, y2, q1, q2, d1, d2, ny, nq, nd; dt_to_yqd(dt1, &y1, &q1, &d1); dt_to_yqd(dt2, &y2, &q2, &d2); nq = 4 * (y2 - y1) + q2 - q1; nd = d2 - d1; if (nq > 0 && nd < 0) { nq--; nd = dt2 - dt_add_quarters(dt1, nq, DT_LIMIT); } else if (nq < 0 && nd > 0) { nq++; nd -= dt_days_in_quarter(y2, q2); } ny = nq / 4; nq = nq - ny * 4; if (qp) *yp = ny; if (qp) *qp = nq; if (dp) *dp = nd; } void dt_delta_ymd(dt_t dt1, dt_t dt2, int *yp, int *mp, int *dp) { int y1, y2, m1, m2, d1, d2, ny, nm, nd; dt_to_ymd(dt1, &y1, &m1, &d1); dt_to_ymd(dt2, &y2, &m2, &d2); nm = 12 * (y2 - y1) + m2 - m1; nd = d2 - d1; if (nm > 0 && nd < 0) { nm--; nd = dt2 - dt_add_months(dt1, nm, DT_LIMIT); } else if (nm < 0 && nd > 0) { nm++; nd -= dt_days_in_month(y2, m2); } ny = nm / 12; nm = nm - ny * 12; if (yp) *yp = ny; if (mp) *mp = nm; if (dp) *dp = nd; } int dt_delta_years(dt_t dt1, dt_t dt2, bool complete) { int y1, y2, d1, d2, ny; dt_to_yd(dt1, &y1, &d1); dt_to_yd(dt2, &y2, &d2); ny = y2 - y1; if (complete) { if (dt1 > dt2) ny += (d2 > d1); else ny -= (d1 > d2); } return ny; } int dt_delta_quarters(dt_t dt1, dt_t dt2, bool complete) { int y1, y2, q1, q2, d1, d2, nq; dt_to_yqd(dt1, &y1, &q1, &d1); dt_to_yqd(dt2, &y2, &q2, &d2); nq = 4 * (y2 - y1) + q2 - q1; if (complete) { if (dt1 > dt2) nq += (d2 > d1); else nq -= (d1 > d2); } return nq; } int dt_delta_months(dt_t dt1, dt_t dt2, bool complete) { int y1, y2, m1, m2, d1, d2, nm; dt_to_ymd(dt1, &y1, &m1, &d1); dt_to_ymd(dt2, &y2, &m2, &d2); nm = 12 * (y2 - y1) + m2 - m1; if (complete) { if (dt1 > dt2) nm += (d2 > d1); else nm -= (d1 > d2); } return nm; } int dt_delta_weeks(dt_t dt1, dt_t dt2) { return (dt2 - dt1) / 7; } Time-Moment-0.44/src/dt_arithmetic.h000644 000765 000024 00000004526 12271265726 020157 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __DT_ARITHMETIC_H__ #define __DT_ARITHMETIC_H__ #include "dt_core.h" #ifdef __cplusplus extern "C" { #endif typedef enum { DT_EXCESS, DT_LIMIT, DT_SNAP } dt_adjust_t; dt_t dt_add_years (dt_t dt, int delta, dt_adjust_t adjust); dt_t dt_add_quarters (dt_t dt, int delta, dt_adjust_t adjust); dt_t dt_add_months (dt_t dt, int delta, dt_adjust_t adjust); void dt_delta_yd (dt_t start, dt_t end, int *y, int *d); void dt_delta_ymd (dt_t start, dt_t end, int *y, int *m, int *d); void dt_delta_yqd (dt_t start, dt_t end, int *y, int *q, int *d); int dt_delta_years (dt_t start, dt_t end, bool complete); int dt_delta_quarters (dt_t start, dt_t end, bool complete); int dt_delta_months (dt_t start, dt_t end, bool complete); int dt_delta_weeks (dt_t start, dt_t end); #ifdef __cplusplus } #endif #endif Time-Moment-0.44/src/dt_config.h000644 000765 000024 00000004405 13250235447 017262 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __DT_CONFIG_H__ #define __DT_CONFIG_H__ #if (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 199901L) || \ (defined(__GNUC__) && __GNUC__ >= 3) || \ (defined(_MSC_VER) && _MSC_VER >= 1800) # include #endif #if !defined(__cplusplus) && !defined(__bool_true_false_are_defined) typedef char _Bool; # define bool _Bool # define true 1 # define false 0 # define __bool_true_false_are_defined 1 #endif /* Chronological Julian Date, January 1, 4713 BC, Monday #define DT_EPOCH_OFFSET 1721425 */ /* Network Time Protocol (NTP), January 1, 1900, Monday #define DT_EPOCH_OFFSET -693596 */ /* Unix, January 1, 1970, Thursday #define DT_EPOCH_OFFSET -719163 */ /* Rata Die, January 1, 0001, Monday (as Day 1) */ #define DT_EPOCH_OFFSET 0 #ifdef __cplusplus extern "C" { #endif typedef int dt_t; #ifdef __cplusplus } #endif #endif Time-Moment-0.44/src/dt_core.c000644 000765 000024 00000012231 12271265726 016741 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "dt_core.h" #define LEAP_YEAR(y) \ (((y) & 3) == 0 && ((y) % 100 != 0 || (y) % 400 == 0)) #define DAYS_IN_YEAR(y) \ (LEAP_YEAR(y) ? 366 : 365) static const int days_preceding_month[2][13] = { { 0, 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334 }, { 0, 0, 31, 60, 91, 121, 152, 182, 213, 244, 274, 305, 335 } }; static const int days_preceding_quarter[2][5] = { { 0, 0, 90, 181, 273 }, { 0, 0, 91, 182, 274 } }; dt_t dt_from_rdn(int n) { return n + DT_EPOCH_OFFSET; } dt_t dt_from_yd(int y, int d) { y--; if (y < 0) { const int n400 = 1 - y/400; y += n400 * 400; d -= n400 * 146097; } return 365 * y + y/4 - y/100 + y/400 + d + DT_EPOCH_OFFSET; } dt_t dt_from_ymd(int y, int m, int d) { if (m < 1 || m > 12) { y += m / 12; m %= 12; if (m < 1) y--, m += 12; } assert(m >= 1); assert(m <= 12); return dt_from_yd(y, days_preceding_month[LEAP_YEAR(y)][m] + d); } dt_t dt_from_yqd(int y, int q, int d) { if (q < 1 || q > 4) { y += q / 4; q %= 4; if (q < 1) y--, q += 4; } assert(q >= 1); assert(q <= 4); return dt_from_yd(y, days_preceding_quarter[LEAP_YEAR(y)][q] + d); } dt_t dt_from_ywd(int y, int w, int d) { dt_t dt; dt = dt_from_yd(y, 4); dt -= dt_dow(dt); dt += w * 7 + d - 7; return dt; } #ifndef DT_NO_SHORTCUTS static const dt_t DT1901 = 693961 + DT_EPOCH_OFFSET; /* 1901-01-01 */ static const dt_t DT2099 = 766644 + DT_EPOCH_OFFSET; /* 2099-12-31 */ #endif void dt_to_yd(dt_t d, int *yp, int *dp) { int y, n100, n1; y = 0; #ifndef DT_NO_SHORTCUTS /* Shortcut dates between the years 1901-2099 inclusive */ if (d >= DT1901 && d <= DT2099) { d -= DT1901 - 1; y += (4 * d - 1) / 1461; d -= (1461 * y) / 4; y += 1901; } else #endif { d -= DT_EPOCH_OFFSET; if (d < 1) { const int n400 = 1 - d/146097; y -= n400 * 400; d += n400 * 146097; } d--; y += 400 * (d / 146097); d %= 146097; n100 = d / 36524; y += 100 * n100; d %= 36524; y += 4 * (d / 1461); d %= 1461; n1 = d / 365; y += n1; d %= 365; if (n100 == 4 || n1 == 4) d = 366; else y++, d++; } if (yp) *yp = y; if (dp) *dp = (int)d; } void dt_to_ymd(dt_t dt, int *yp, int *mp, int *dp) { int y, doy, m, l; dt_to_yd(dt, &y, &doy); l = LEAP_YEAR(y); m = doy < 32 ? 1 : 1 + (5 * (doy - 59 - l) + 303) / 153; assert(m >= 1); assert(m <= 12); if (yp) *yp = y; if (mp) *mp = m; if (dp) *dp = doy - days_preceding_month[l][m]; } void dt_to_yqd(dt_t dt, int *yp, int *qp, int *dp) { int y, doy, q, l; dt_to_yd(dt, &y, &doy); l = LEAP_YEAR(y); q = doy < 91 ? 1 : 1 + (5 * (doy - 59 - l) + 303) / 459; assert(q >= 1); assert(q <= 4); if (yp) *yp = y; if (qp) *qp = q; if (dp) *dp = doy - days_preceding_quarter[l][q]; } void dt_to_ywd(dt_t dt, int *yp, int *wp, int *dp) { int y, doy, dow; dt_to_yd(dt, &y, &doy); dow = dt_dow(dt); doy = doy + 4 - dow; if (doy < 1) { y--; doy += DAYS_IN_YEAR(y); } else if (doy > 365) { const int diy = DAYS_IN_YEAR(y); if (doy > diy) { doy -= diy; y++; } } if (yp) *yp = y; if (wp) *wp = (doy + 6) / 7; if (dp) *dp = dow; } int dt_rdn(dt_t dt) { return dt - DT_EPOCH_OFFSET; } dt_dow_t dt_dow(dt_t dt) { int dow = (dt - DT_EPOCH_OFFSET) % 7; if (dow < 1) dow += 7; assert(dow >= 1); assert(dow <= 7); return dow; } Time-Moment-0.44/src/dt_core.h000644 000765 000024 00000004614 12271265726 016754 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __DT_CORE_H__ #define __DT_CORE_H__ #include "dt_config.h" #ifdef __cplusplus extern "C" { #endif typedef enum { DT_MON = 1, DT_MONDAY = 1, DT_TUE = 2, DT_TUESDAY = 2, DT_WED = 3, DT_WEDNESDAY = 3, DT_THU = 4, DT_THURSDAY = 4, DT_FRI = 5, DT_FRIDAY = 5, DT_SAT = 6, DT_SATURDAY = 6, DT_SUN = 7, DT_SUNDAY = 7, } dt_dow_t; dt_t dt_from_rdn (int n); dt_t dt_from_yd (int y, int d); dt_t dt_from_ymd (int y, int m, int d); dt_t dt_from_yqd (int y, int q, int d); dt_t dt_from_ywd (int y, int w, int d); void dt_to_yd (dt_t dt, int *y, int *d); void dt_to_ymd (dt_t dt, int *y, int *m, int *d); void dt_to_yqd (dt_t dt, int *y, int *q, int *d); void dt_to_ywd (dt_t dt, int *y, int *w, int *d); int dt_rdn (dt_t dt); dt_dow_t dt_dow (dt_t dt); #ifdef __cplusplus } #endif #endif Time-Moment-0.44/src/dt_easter.c000644 000765 000024 00000004233 13015655011 017262 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2015 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "dt_core.h" #include "dt_easter.h" /* * Easter algorithms by Al Petrofsky, San Mateo County, California, U.S.A. * */ static int easter_gregorian(unsigned int y) { unsigned int a, b; a = y/100 * 1483 - y/400 * 2225 + 2613; b = ((y % 19 * 3510 + a/25 * 319) / 330) % 29; return 56 - b - ((y * 5/4) + a - b) % 7; } static int easter_julian(unsigned int y) { unsigned int a; a = (y % 19 * 19 + 15) % 30; return 28 + a - ((y * 5/4) + a) % 7; } dt_t dt_from_easter(int y, dt_computus_t computus) { if (y < 1) return 0; if (computus == DT_WESTERN) return dt_from_ymd(y, 3, easter_gregorian(y)); else return dt_from_ymd(y, 3, easter_julian(y) + y/100 - y/400 - 2); } Time-Moment-0.44/src/dt_easter.h000644 000765 000024 00000003256 13015655011 017273 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2015 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __DT_EASTER_H__ #define __DT_EASTER_H__ #include "dt_core.h" #ifdef __cplusplus extern "C" { #endif typedef enum { DT_ORTHODOX, DT_WESTERN } dt_computus_t; dt_t dt_from_easter (int y, dt_computus_t computus); #ifdef __cplusplus } #endif #endif Time-Moment-0.44/src/dt_length.c000644 000765 000024 00000003650 12434225316 017267 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "dt_core.h" #include "dt_util.h" int dt_length_of_year(dt_t dt) { int y; dt_to_yd(dt, &y, NULL); return dt_days_in_year(y); } int dt_length_of_quarter(dt_t dt) { int y, q; dt_to_yqd(dt, &y, &q, NULL); return dt_days_in_quarter(y, q); } int dt_length_of_month(dt_t dt) { int y, m; dt_to_ymd(dt, &y, &m, NULL); return dt_days_in_month(y, m); } int dt_length_of_week_year(dt_t dt) { int y; dt_to_yd(dt, &y, NULL); return dt_weeks_in_year(y); } Time-Moment-0.44/src/dt_length.h000644 000765 000024 00000003335 12434225346 017277 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __DT_LENGTH_H__ #define __DT_LENGTH_H__ #include "dt_core.h" #ifdef __cplusplus extern "C" { #endif int dt_length_of_year (dt_t dt); int dt_length_of_quarter (dt_t dt); int dt_length_of_month (dt_t dt); int dt_length_of_week_year (dt_t dt); #ifdef __cplusplus } #endif #endif Time-Moment-0.44/src/dt_parse_iso.c000644 000765 000024 00000032576 12426232354 020004 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include #include "dt_core.h" #include "dt_valid.h" static size_t count_digits(const unsigned char * const p, size_t i, const size_t len) { const size_t n = i; for(; i < len; i++) { const unsigned char c = p[i] - '0'; if (c > 9) break; } return i - n; } static int parse_number(const unsigned char * const p, size_t i, const size_t len) { int v = 0; switch (len) { case 9: v += (p[i++] - '0') * 100000000; case 8: v += (p[i++] - '0') * 10000000; case 7: v += (p[i++] - '0') * 1000000; case 6: v += (p[i++] - '0') * 100000; case 5: v += (p[i++] - '0') * 10000; case 4: v += (p[i++] - '0') * 1000; case 3: v += (p[i++] - '0') * 100; case 2: v += (p[i++] - '0') * 10; case 1: v += (p[i++] - '0'); } return v; } static const int pow_10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, }; /* * fffffffff */ static size_t parse_fraction_digits(const unsigned char *p, size_t i, size_t len, int *fp) { size_t n, ndigits; ndigits = n = count_digits(p, i, len); if (ndigits < 1) return 0; if (ndigits > 9) ndigits = 9; if (fp) *fp = parse_number(p, i, ndigits) * pow_10[9 - ndigits]; return n; } /* * hh * hhmm * hhmmss * hhmmss.fffffffff * hhmmss,fffffffff */ size_t dt_parse_iso_time_basic(const char *str, size_t len, int *sp, int *fp) { const unsigned char *p; int h, m, s, f; size_t n; p = (const unsigned char *)str; n = count_digits(p, 0, len); m = s = f = 0; switch (n) { case 2: /* hh */ h = parse_number(p, 0, 2); goto hms; case 4: /* hhmm */ h = parse_number(p, 0, 2); m = parse_number(p, 2, 2); goto hms; case 6: /* hhmmss */ h = parse_number(p, 0, 2); m = parse_number(p, 2, 2); s = parse_number(p, 4, 2); break; default: return 0; } /* hhmmss.fffffffff */ if (n < len && (p[n] == '.' || p[n] == ',')) { size_t r = parse_fraction_digits(p, ++n, len, &f); if (!r) return 0; n += r; } hms: if (h > 23 || m > 59 || s > 59) { if (!(h == 24 && m == 0 && s == 0 && f == 0)) return 0; } if (sp) *sp = h * 3600 + m * 60 + s; if (fp) *fp = f; return n; } /* * Z * ±hh * ±hhmm */ size_t dt_parse_iso_zone_basic(const char *str, size_t len, int *op) { const unsigned char *p; int o, h, m, sign; size_t n; if (len < 1) return 0; p = (const unsigned char *)str; switch (*p) { case 'Z': o = 0; n = 1; goto zulu; case '+': sign = 1; break; case '-': sign = -1; break; default: return 0; } if (len < 3) return 0; n = count_digits(p, 1, len); m = 0; switch (n) { case 2: /* ±hh */ h = parse_number(p, 1, 2); n = 3; break; case 4: /* ±hhmm */ h = parse_number(p, 1, 2); m = parse_number(p, 3, 2); n = 5; break; default: return 0; } if (h > 23 || m > 59) return 0; o = sign * (h * 60 + m); #ifdef DT_PARSE_ISO_STRICT if (o == 0 && sign < 0) return 0; #endif zulu: if (op) *op = o; return n; } /* * hh * hh:mm * hh:mm:ss * hh:mm:ss.fffffffff * hh:mm:ss,fffffffff */ size_t dt_parse_iso_time_extended(const char *str, size_t len, int *sp, int *fp) { const unsigned char *p; int h, m, s, f; size_t n; p = (const unsigned char *)str; if (count_digits(p, 0, len) != 2) return 0; h = parse_number(p, 0, 2); m = s = f = 0; n = 2; if (len < 3 || p[2] != ':') goto hms; if (count_digits(p, 3, len) != 2) return 0; m = parse_number(p, 3, 2); n = 5; if (len < 6 || p[5] != ':') goto hms; if (count_digits(p, 6, len) != 2) return 0; s = parse_number(p, 6, 2); n = 8; /* hh:mm:ss.fffffffff */ if (n < len && (p[n] == '.' || p[n] == ',')) { size_t r = parse_fraction_digits(p, ++n, len, &f); if (!r) return 0; n += r; } hms: if (h > 23 || m > 59 || s > 59) { if (!(h == 24 && m == 0 && s == 0 && f == 0)) return 0; } if (sp) *sp = h * 3600 + m * 60 + s; if (fp) *fp = f; return n; } /* * Z * ±hh * ±hh:mm */ size_t dt_parse_iso_zone_extended(const char *str, size_t len, int *op) { const unsigned char *p; int o, h, m, sign; size_t n; if (len < 1) return 0; p = (const unsigned char *)str; switch (*p) { case 'Z': o = 0; n = 1; goto zulu; case '+': sign = 1; break; case '-': sign = -1; break; default: return 0; } if (len < 3 || count_digits(p, 1, len) != 2) return 0; h = parse_number(p, 1, 2); m = 0; n = 3; if (len < 4 || p[3] != ':') goto hm; if (count_digits(p, 4, len) != 2) return 0; m = parse_number(p, 4, 2); n = 6; hm: if (h > 23 || m > 59) return 0; o = sign * (h * 60 + m); #ifdef DT_PARSE_ISO_STRICT if (o == 0 && sign < 0) return 0; #endif zulu: if (op) *op = o; return n; } /* * z * Z * GMT * GMT±h * GMT±hhmm * GMT±h:mm * GMT±hh:mm * UTC * UTC±h * UTC±hhmm * UTC±h:mm * UTC±hh:mm * ±h * ±hh * ±hhmm * ±h:mm * ±hh:mm */ size_t dt_parse_iso_zone_lenient(const char *str, size_t len, int *op) { const unsigned char *p; int o, h, m, sign; size_t n; if (len < 1) return 0; p = (const unsigned char *)str; switch (*p) { case 'z': case 'Z': o = 0; n = 1; goto zulu; case 'G': if (len < 3 || p[1] != 'M' || p[2] != 'T') return 0; if (len > 3 && (p[3] == '+' || p[3] == '-')) { if (!(n = dt_parse_iso_zone_lenient(str + 3, len - 3, op))) return 0; return n + 3; } o = 0; n = 3; goto zulu; case 'U': if (len < 3 || p[1] != 'T' || p[2] != 'C') return 0; if (len > 3 && (p[3] == '+' || p[3] == '-')) { if (!(n = dt_parse_iso_zone_lenient(str + 3, len - 3, op))) return 0; return n + 3; } o = 0; n = 3; goto zulu; case '+': sign = 1; break; case '-': sign = -1; break; default: return 0; } if (len < 2) return 0; n = count_digits(p, 1, len); m = 0; switch (n) { case 1: /* ±h */ h = parse_number(p, 1, 1); n = 2; break; case 2: /* ±hh */ h = parse_number(p, 1, 2); n = 3; break; case 4: /* ±hhmm */ h = parse_number(p, 1, 2); m = parse_number(p, 3, 2); n = 5; goto hm; default: return 0; } if (len < n + 1 || p[n] != ':') goto hm; if (count_digits(p, ++n, len) != 2) return 0; m = parse_number(p, n, 2); n += 2; hm: if (h > 23 || m > 59) return 0; o = sign * (h * 60 + m); zulu: if (op) *op = o; return n; } /* * Basic Extended * 20121224 2012-12-24 Calendar date (ISO 8601) * 2012359 2012-359 Ordinal date (ISO 8601) * 2012W521 2012-W52-1 Week date (ISO 8601) * 2012Q485 2012-Q4-85 Quarter date */ size_t dt_parse_iso_date(const char *str, size_t len, dt_t *dtp) { const unsigned char *p; int y, x, d; size_t n; dt_t dt; p = (const unsigned char *)str; n = count_digits(p, 0, len); switch (n) { case 4: /* 2012 (year) */ y = parse_number(p, 0, 4); break; case 7: /* 2012359 (basic ordinal date) */ y = parse_number(p, 0, 4); d = parse_number(p, 4, 3); goto yd; case 8: /* 20121224 (basic calendar date) */ y = parse_number(p, 0, 4); x = parse_number(p, 4, 2); d = parse_number(p, 6, 2); goto ymd; default: return 0; } if (len < 8) return 0; n = count_digits(p, 5, len); switch (p[4]) { case '-': /* 2012-359 | 2012-12-24 | 2012-W52-1 | 2012-Q4-85 */ break; #ifndef DT_PARSE_ISO_STRICT case 'Q': /* 2012Q485 */ if (n != 3) return 0; x = parse_number(p, 5, 1); d = parse_number(p, 6, 2); n = 8; goto yqd; #endif case 'W': /* 2012W521 */ if (n != 3) return 0; x = parse_number(p, 5, 2); d = parse_number(p, 7, 1); n = 8; goto ywd; default: return 0; } switch (n) { case 0: /* 2012-Q4-85 | 2012-W52-1 */ break; case 2: /* 2012-12-24 */ if (p[7] != '-' || count_digits(p, 8, len) != 2) return 0; x = parse_number(p, 5, 2); d = parse_number(p, 8, 2); n = 10; goto ymd; case 3: /* 2012-359 */ d = parse_number(p, 5, 3); n = 8; goto yd; default: return 0; } if (len < 10) return 0; n = count_digits(p, 6, len); switch (p[5]) { #ifndef DT_PARSE_ISO_STRICT case 'Q': /* 2012-Q4-85 */ if (n != 1 || p[7] != '-' || count_digits(p, 8, len) != 2) return 0; x = parse_number(p, 6, 1); d = parse_number(p, 8, 2); n = 10; goto yqd; #endif case 'W': /* 2012-W52-1 */ if (n != 2 || p[8] != '-' || count_digits(p, 9, len) != 1) return 0; x = parse_number(p, 6, 2); d = parse_number(p, 9, 1); n = 10; goto ywd; default: return 0; } yd: if (!dt_valid_yd(y, d)) return 0; dt = dt_from_yd(y, d); goto finish; ymd: if (!dt_valid_ymd(y, x, d)) return 0; dt = dt_from_ymd(y, x, d); goto finish; #ifndef DT_PARSE_ISO_STRICT yqd: if (!dt_valid_yqd(y, x, d)) return 0; dt = dt_from_yqd(y, x, d); goto finish; #endif ywd: if (!dt_valid_ywd(y, x, d)) return 0; dt = dt_from_ywd(y, x, d); finish: #ifndef DT_PARSE_ISO_YEAR0 if (y < 1) return 0; #endif if (dtp) *dtp = dt; return n; } /* * Basic Extended * T12 N/A * T1230 T12:30 * T123045 T12:30:45 * T123045.123456789 T12:30:45.123456789 * T123045,123456789 T12:30:45,123456789 * * The time designator [T] may be omitted. */ size_t dt_parse_iso_time(const char *str, size_t len, int *sod, int *nsec) { size_t n, r; if (len < 2) return 0; if (str[0] == 'T') r = 1, ++str, --len; else r = 0; if (len < 2 || str[2] == ':') n = dt_parse_iso_time_extended(str, len, sod, nsec); else n = dt_parse_iso_time_basic(str, len, sod, nsec); if (!n) return 0; return r + n; } /* * Basic Extended * Z N/A * ±hh N/A * ±hhmm ±hh:mm */ size_t dt_parse_iso_zone(const char *str, size_t len, int *offset) { if (len < 3 || str[3] == ':') return dt_parse_iso_zone_extended(str, len, offset); else return dt_parse_iso_zone_basic(str, len, offset); } Time-Moment-0.44/src/dt_parse_iso.h000644 000765 000024 00000004312 12271265726 020003 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __DT_PARSE_H__ #define __DT_PARSE_H__ #include #include "dt_core.h" #ifdef __cplusplus extern "C" { #endif size_t dt_parse_iso_date (const char *str, size_t len, dt_t *dt); size_t dt_parse_iso_time (const char *str, size_t len, int *sod, int *nsec); size_t dt_parse_iso_time_basic (const char *str, size_t len, int *sod, int *nsec); size_t dt_parse_iso_time_extended (const char *str, size_t len, int *sod, int *nsec); size_t dt_parse_iso_zone (const char *str, size_t len, int *offset); size_t dt_parse_iso_zone_basic (const char *str, size_t len, int *offset); size_t dt_parse_iso_zone_extended (const char *str, size_t len, int *offset); size_t dt_parse_iso_zone_lenient (const char *str, size_t len, int *offset); #ifdef __cplusplus } #endif #endif Time-Moment-0.44/src/dt_util.c000644 000765 000024 00000004611 12271265726 016771 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "dt_core.h" bool dt_leap_year(int y) { return ((y & 3) == 0 && (y % 100 != 0 || y % 400 == 0)); } int dt_days_in_year(int y) { return dt_leap_year(y) ? 366 : 365; } int dt_days_in_quarter(int y, int q) { static const int days_in_quarter[2][5] = { { 0, 90, 91, 92, 92 }, { 0, 91, 91, 92, 92 } }; if (q < 1 || q > 4) return 0; return days_in_quarter[dt_leap_year(y)][q]; } int dt_days_in_month(int y, int m) { static const int days_in_month[2][13] = { { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }, { 0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 } }; if (m < 1 || m > 12) return 0; return days_in_month[dt_leap_year(y)][m]; } int dt_weeks_in_year(int year) { unsigned int y, d; if (year < 1) year += 400 * (1 - year/400); y = year - 1; d = (y + y/4 - y/100 + y/400) % 7; /* Mon = 0, ... Sun = 6 */ return (d == 3 || (d == 2 && dt_leap_year(year))) ? 53 : 52; } Time-Moment-0.44/src/dt_util.h000644 000765 000024 00000003410 12271265726 016772 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __DT_UTIL_H__ #define __DT_UTIL_H__ #include "dt_core.h" #ifdef __cplusplus extern "C" { #endif bool dt_leap_year (int y); int dt_days_in_year (int y); int dt_days_in_quarter (int y, int q); int dt_days_in_month (int y, int m); int dt_weeks_in_year (int y); #ifdef __cplusplus } #endif #endif Time-Moment-0.44/src/dt_valid.c000644 000765 000024 00000003740 12271265726 017115 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "dt_core.h" #include "dt_util.h" bool dt_valid_yd(int y, int d) { return (d >= 1 && (d <= 365 || d == dt_days_in_year(y))); } bool dt_valid_ymd(int y, int m, int d) { return ((m >= 1 && m <= 12) && (d >= 1 && (d <= 28 || d <= dt_days_in_month(y, m)))); } bool dt_valid_yqd(int y, int q, int d) { return ((q >= 1 && q <= 4) && (d >= 1 && (d <= 90 || d <= dt_days_in_quarter(y, q)))); } bool dt_valid_ywd(int y, int w, int d) { return ((d >= 1 && d <= 7) && (w >= 1 && (w <= 52 || w == dt_weeks_in_year(y)))); } Time-Moment-0.44/src/dt_valid.h000644 000765 000024 00000003404 12271265726 017117 0ustar00chansenstaff000000 000000 /* * Copyright (c) 2012-2014 Christian Hansen * * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * 1. Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #ifndef __DT_VALID_H__ #define __DT_VALID_H__ #include "dt_core.h" #ifdef __cplusplus extern "C" { #endif bool dt_valid_yd (int y, int d); bool dt_valid_ymd (int y, int m, int d); bool dt_valid_yqd (int y, int q, int d); bool dt_valid_ywd (int y, int w, int d); #ifdef __cplusplus } #endif #endif Time-Moment-0.44/src/moment.c000644 000765 000024 00000104317 13015663441 016621 0ustar00chansenstaff000000 000000 #include "moment.h" #include "dt_core.h" #include "dt_accessor.h" #include "dt_arithmetic.h" #include "dt_util.h" #include "dt_length.h" #include "dt_easter.h" static const int32_t kPow10[10] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000, }; static void THX_moment_check_self(pTHX_ const moment_t *mt) { if (mt->sec < MIN_RANGE || mt->sec > MAX_RANGE) croak("Time::Moment is out of range"); } static moment_t THX_moment_from_local(pTHX_ int64_t sec, IV nsec, IV offset) { moment_t r; r.sec = sec; r.nsec = (int32_t)nsec; r.offset = (int32_t)offset; THX_moment_check_self(aTHX_ &r); return r; } static moment_t THX_moment_from_instant(pTHX_ int64_t sec, IV nsec, IV offset) { moment_t r; r.sec = sec + offset * 60; r.nsec = (int32_t)nsec; r.offset = (int32_t)offset; THX_moment_check_self(aTHX_ &r); return r; } int64_t moment_instant_rd_seconds(const moment_t *mt) { return mt->sec - mt->offset * 60; } int moment_instant_rd(const moment_t *mt) { return (int)(moment_instant_rd_seconds(mt) / SECS_PER_DAY); } void moment_to_instant_rd_values(const moment_t *mt, IV *rdn, IV *sod, IV *nos) { const int64_t sec = moment_instant_rd_seconds(mt); *rdn = (IV)(sec / SECS_PER_DAY); *sod = (IV)(sec % SECS_PER_DAY); *nos = (IV)mt->nsec; } int64_t moment_local_rd_seconds(const moment_t *mt) { return mt->sec; } int moment_local_rd(const moment_t *mt) { return (int)(moment_local_rd_seconds(mt) / SECS_PER_DAY); } dt_t moment_local_dt(const moment_t *mt) { return dt_from_rdn(moment_local_rd(mt)); } void moment_to_local_rd_values(const moment_t *mt, IV *rdn, IV *sod, IV *nos) { const int64_t sec = moment_local_rd_seconds(mt); *rdn = (IV)(sec / SECS_PER_DAY); *sod = (IV)(sec % SECS_PER_DAY); *nos = (IV)mt->nsec; } static void THX_check_year(pTHX_ int64_t v) { if (v < 1 || v > 9999) croak("Parameter 'year' is out of the range [1, 9999]"); } static void THX_check_quarter(pTHX_ int64_t v) { if (v < 1 || v > 4) croak("Parameter 'quarter' is out of the range [1, 4]"); } static void THX_check_month(pTHX_ int64_t v) { if (v < 1 || v > 12) croak("Parameter 'month' is out of the range [1, 12]"); } static void THX_check_week(pTHX_ int64_t v) { if (v < 1 || v > 53) croak("Parameter 'week' is out of the range [1, 53]"); } static void THX_check_day_of_year(pTHX_ int64_t v) { if (v < 1 || v > 366) croak("Parameter 'day' is out of the range [1, 366]"); } static void THX_check_day_of_quarter(pTHX_ int64_t v) { if (v < 1 || v > 92) croak("Parameter 'day' is out of the range [1, 92]"); } static void THX_check_day_of_month(pTHX_ int64_t v) { if (v < 1 || v > 31) croak("Parameter 'day' is out of the range [1, 31]"); } static void THX_check_day_of_week(pTHX_ int64_t v) { if (v < 1 || v > 7) croak("Parameter 'day' is out of the range [1, 7]"); } static void THX_check_hour(pTHX_ int64_t v) { if (v < 0 || v > 23) croak("Parameter 'hour' is out of the range [1, 23]"); } static void THX_check_minute(pTHX_ int64_t v) { if (v < 0 || v > 59) croak("Parameter 'minute' is out of the range [1, 59]"); } static void THX_check_minute_of_day(pTHX_ int64_t v) { if (v < 0 || v > 1439) croak("Parameter 'minute' is out of the range [1, 1439]"); } static void THX_check_second(pTHX_ int64_t v) { if (v < 0 || v > 59) croak("Parameter 'second' is out of the range [1, 59]"); } static void THX_check_second_of_day(pTHX_ int64_t v) { if (v < 0 || v > 86399) croak("Parameter 'second' is out of the range [0, 86_399]"); } static void THX_check_millisecond(pTHX_ int64_t v) { if (v < 0 || v > 999) croak("Parameter 'millisecond' is out of the range [0, 999]"); } static void THX_check_microsecond(pTHX_ int64_t v) { if (v < 0 || v > 999999) croak("Parameter 'microsecond' is out of the range [0, 999_999]"); } static void THX_check_nanosecond(pTHX_ int64_t v) { if (v < 0 || v > 999999999) croak("Parameter 'nanosecond' is out of the range [0, 999_999_999]"); } static void THX_check_offset(pTHX_ int64_t v) { if (v < -1080 || v > 1080) croak("Parameter 'offset' is out of the range [-1080, 1080]"); } static void THX_check_epoch_seconds(pTHX_ int64_t v) { if (!VALID_EPOCH_SEC(v)) croak("Parameter 'seconds' is out of range"); } static void THX_check_rata_die_day(pTHX_ int64_t v) { if (v < MIN_RATA_DIE_DAY || v > MAX_RATA_DIE_DAY) croak("Parameter 'rdn' is out of range"); } static void THX_check_unit_years(pTHX_ int64_t v) { if (v < MIN_UNIT_YEARS || v > MAX_UNIT_YEARS) croak("Parameter 'years' is out of range"); } static void THX_check_unit_months(pTHX_ int64_t v) { if (v < MIN_UNIT_MONTHS || v > MAX_UNIT_MONTHS) croak("Parameter 'months' is out of range"); } static void THX_check_unit_weeks(pTHX_ int64_t v) { if (v < MIN_UNIT_WEEKS || v > MAX_UNIT_WEEKS) croak("Parameter 'weeks' is out of range"); } static void THX_check_unit_days(pTHX_ int64_t v) { if (v < MIN_UNIT_DAYS || v > MAX_UNIT_DAYS) croak("Parameter 'days' is out of range"); } static void THX_check_unit_hours(pTHX_ int64_t v) { if (v < MIN_UNIT_HOURS || v > MAX_UNIT_HOURS) croak("Parameter 'hours' is out of range"); } static void THX_check_unit_minutes(pTHX_ int64_t v) { if (v < MIN_UNIT_MINUTES || v > MAX_UNIT_MINUTES) croak("Parameter 'minutes' is out of range"); } static void THX_check_unit_seconds(pTHX_ int64_t v) { if (v < MIN_UNIT_SECONDS || v > MAX_UNIT_SECONDS) croak("Parameter 'seconds' is out of range"); } static void THX_check_unit_milliseconds(pTHX_ int64_t v) { if (v < MIN_UNIT_MILLIS || v > MAX_UNIT_MILLIS) croak("Parameter 'milliseconds' is out of range"); } static void THX_check_unit_microseconds(pTHX_ int64_t v) { if (v < MIN_UNIT_MICROS || v > MAX_UNIT_MICROS) croak("Parameter 'microseconds' is out of range"); } moment_t THX_moment_from_epoch(pTHX_ int64_t sec, IV nsec, IV offset) { THX_check_epoch_seconds(aTHX_ sec); THX_check_nanosecond(aTHX_ nsec); THX_check_offset(aTHX_ offset); sec += UNIX_EPOCH; return THX_moment_from_instant(aTHX_ sec, nsec, offset); } moment_t THX_moment_from_epoch_nv(pTHX_ NV sec, IV precision) { static const NV SEC_MIN = -62135596801.0; /* 0000-12-31T23:59:59Z */ static const NV SEC_MAX = 253402300800.0; /* 10000-01-01T00:00:00Z */ NV s, f, n, denom; if (precision < 0 || precision > 9) croak("Parameter 'precision' is out of the range [0, 9]"); if (!(sec > SEC_MIN && sec < SEC_MAX)) croak("Parameter 'seconds' is out of range"); f = n = Perl_fmod(sec, 1.0); s = Perl_floor(sec - f); if (n < 0) n += 1.0; s = s + Perl_floor(f - n); denom = Perl_pow(10.0, (NV)precision); n = (Perl_floor(n * denom + 0.5) / denom) * 1E9; return THX_moment_from_epoch(aTHX_ (int64_t)s, (IV)(n + 0.5), 0); } static int THX_moment_from_sd(pTHX_ NV sd, NV epoch, IV precision, int64_t *sec, int32_t *nsec) { static const NV SD_MIN = -146097 * 50; static const NV SD_MAX = 146097 * 50; NV d1, d2, f1, f2, f, d, s, denom; if (precision < 0 || precision > 9) croak("Parameter 'precision' is out of the range [0, 9]"); if (!(sd > SD_MIN && sd < SD_MAX)) return -1; if (!(epoch > SD_MIN && epoch < SD_MAX)) croak("Parameter 'epoch' is out of range"); if (sd >= epoch) { d1 = sd; d2 = epoch; } else { d1 = epoch; d2 = sd; } f1 = Perl_fmod(d1, 1.0); f2 = Perl_fmod(d2, 1.0); d1 = Perl_floor(d1 - f1); d2 = Perl_floor(d2 - f2); f = Perl_fmod(f1 + f2, 1.0); if (f < 0.0) f += 1.0; d = d1 + d2 + Perl_floor(f1 + f2 - f); f *= 86400; s = Perl_floor(f); if (d < 1 || d > 3652059) return -2; denom = Perl_pow(10.0, (NV)precision); f = (Perl_floor((f - s) * denom + 0.5) / denom) * 1E9; *sec = (int64_t)d * 86400 + (int32_t)s; *nsec = (int32_t)(f + 0.5); if (*nsec >= NANOS_PER_SEC) { *nsec -= NANOS_PER_SEC; *sec += 1; } return 0; } moment_t THX_moment_from_rd(pTHX_ NV jd, NV epoch, IV precision, IV offset) { int64_t sec; int32_t nsec; int r; THX_check_offset(aTHX_ offset); r = THX_moment_from_sd(aTHX_ jd, epoch, precision, &sec, &nsec); if (r < 0) { if (r == -1) croak("Parameter 'rd' is out of range"); else croak("Rata Die is out of range"); } return THX_moment_from_local(aTHX_ sec, nsec, offset); } moment_t THX_moment_from_jd(pTHX_ NV jd, NV epoch, IV precision) { int64_t sec; int32_t nsec; int r; r = THX_moment_from_sd(aTHX_ jd, epoch, precision, &sec, &nsec); if (r < 0) { if (r == -1) croak("Parameter 'jd' is out of range"); else croak("Julian date is out of range"); } return THX_moment_from_instant(aTHX_ sec, nsec, 0); } moment_t THX_moment_from_mjd(pTHX_ NV jd, NV epoch, IV precision) { int64_t sec; int32_t nsec; int r; r = THX_moment_from_sd(aTHX_ jd, epoch, precision, &sec, &nsec); if (r < 0) { if (r == -1) croak("Parameter 'mjd' is out of range"); else croak("Modified Julian date is out of range"); } return THX_moment_from_instant(aTHX_ sec, nsec, 0); } moment_t THX_moment_new(pTHX_ IV Y, IV M, IV D, IV h, IV m, IV s, IV nsec, IV offset) { int64_t rdn, sec; THX_check_year(aTHX_ Y); THX_check_month(aTHX_ M); THX_check_day_of_month(aTHX_ D); if (D > 28) { int dim = dt_days_in_month((int)Y, (int)M); if (D > dim) croak("Parameter 'day' is out of the range [1, %d]", dim); } THX_check_hour(aTHX_ h); THX_check_minute(aTHX_ m); THX_check_second(aTHX_ s); THX_check_nanosecond(aTHX_ nsec); THX_check_offset(aTHX_ offset); rdn = dt_rdn(dt_from_ymd((int)Y, (int)M, (int)D)); sec = ((rdn * 24 + h) * 60 + m) * 60 + s; return THX_moment_from_local(aTHX_ sec, nsec, offset); } static moment_t THX_moment_with_local_dt(pTHX_ const moment_t *mt, const dt_t dt) { int64_t sec; sec = (int64_t)dt_rdn(dt) * 86400 + moment_second_of_day(mt); return THX_moment_from_local(aTHX_ sec, mt->nsec, mt->offset); } static moment_t THX_moment_with_ymd(pTHX_ const moment_t *mt, int y, int m, int d) { if (d > 28) { int dim = dt_days_in_month(y, m); if (d > dim) d = dim; } return THX_moment_with_local_dt(aTHX_ mt, dt_from_ymd(y, m, d)); } static moment_t THX_moment_with_year(pTHX_ const moment_t *mt, int64_t v) { int m, d; THX_check_year(aTHX_ v); dt_to_ymd(moment_local_dt(mt), NULL, &m, &d); return THX_moment_with_ymd(aTHX_ mt, (int)v, m, d); } static moment_t THX_moment_with_quarter(pTHX_ const moment_t *mt, int64_t v) { int y, m, d; THX_check_quarter(aTHX_ v); dt_to_ymd(moment_local_dt(mt), &y, &m, &d); m = 1 + 3 * ((int)v - 1) + (m - 1) % 3; return THX_moment_with_ymd(aTHX_ mt, y, m, d); } static moment_t THX_moment_with_month(pTHX_ const moment_t *mt, int64_t v) { int y, d; THX_check_month(aTHX_ v); dt_to_ymd(moment_local_dt(mt), &y, NULL, &d); return THX_moment_with_local_dt(aTHX_ mt, dt_from_ymd(y, (int)v, d)); } static moment_t THX_moment_with_week(pTHX_ const moment_t *mt, int64_t v) { int y, w, d; THX_check_week(aTHX_ v); dt_to_ywd(moment_local_dt(mt), &y, NULL, &d); w = (int)v; if (w > 52) { int wiy = dt_weeks_in_year(y); if (w > wiy) croak("Parameter 'week' is out of the range [1, %d]", wiy); } return THX_moment_with_local_dt(aTHX_ mt, dt_from_ywd(y, w, d)); } static moment_t THX_moment_with_day_of_month(pTHX_ const moment_t *mt, int64_t v) { int y, m, d; THX_check_day_of_month(aTHX_ v); dt_to_ymd(moment_local_dt(mt), &y, &m, NULL); d = (int)v; if (d > 28) { int dim = dt_days_in_month(y, m); if (d > dim) croak("Parameter 'day' is out of the range [1, %d]", dim); } return THX_moment_with_local_dt(aTHX_ mt, dt_from_ymd(y, m, d)); } static moment_t THX_moment_with_day_of_quarter(pTHX_ const moment_t *mt, int64_t v) { int y, q, d; THX_check_day_of_quarter(aTHX_ v); dt_to_yqd(moment_local_dt(mt), &y, &q, NULL); d = (int)v; if (d > 90) { int diq = dt_days_in_quarter(y, q); if (d > diq) croak("Parameter 'day' is out of the range [1, %d]", diq); } return THX_moment_with_local_dt(aTHX_ mt, dt_from_yqd(y, q, d)); } static moment_t THX_moment_with_day_of_year(pTHX_ const moment_t *mt, int64_t v) { int y, d; THX_check_day_of_year(aTHX_ v); dt_to_yd(moment_local_dt(mt), &y, NULL); d = (int)v; if (d > 365) { int diy = dt_days_in_year(y); if (v > diy) croak("Parameter 'day' is out of the range [1, %d]", diy); } return THX_moment_with_local_dt(aTHX_ mt, dt_from_yd(y, d)); } static moment_t THX_moment_with_day_of_week(pTHX_ const moment_t *mt, int64_t v) { dt_t dt; THX_check_day_of_week(aTHX_ v); dt = moment_local_dt(mt); return THX_moment_with_local_dt(aTHX_ mt, dt - (dt_dow(dt) - v)); } static moment_t THX_moment_with_rata_die_day(pTHX_ const moment_t *mt, int64_t v) { dt_t dt; THX_check_rata_die_day(aTHX_ v); dt = dt_from_rdn((int)v); return THX_moment_with_local_dt(aTHX_ mt, dt); } static moment_t THX_moment_with_hour(pTHX_ const moment_t *mt, int64_t v) { int64_t sec; THX_check_hour(aTHX_ v); sec = moment_local_rd_seconds(mt) + (v - moment_hour(mt)) * 3600; return THX_moment_from_local(aTHX_ sec, mt->nsec, mt->offset); } static moment_t THX_moment_with_minute(pTHX_ const moment_t *mt, int64_t v) { int64_t sec; THX_check_minute(aTHX_ v); sec = moment_local_rd_seconds(mt) + (v - moment_minute(mt)) * 60; return THX_moment_from_local(aTHX_ sec, mt->nsec, mt->offset); } static moment_t THX_moment_with_minute_of_day(pTHX_ const moment_t *mt, int64_t v) { int64_t sec; THX_check_minute_of_day(aTHX_ v); sec = moment_local_rd_seconds(mt) + (v - moment_minute_of_day(mt)) * 60; return THX_moment_from_local(aTHX_ sec, mt->nsec, mt->offset); } static moment_t THX_moment_with_second(pTHX_ const moment_t *mt, int64_t v) { int64_t sec; THX_check_second(aTHX_ v); sec = moment_local_rd_seconds(mt) + (v - moment_second(mt)); return THX_moment_from_local(aTHX_ sec, mt->nsec, mt->offset); } static moment_t THX_moment_with_second_of_day(pTHX_ const moment_t *mt, int64_t v) { int64_t sec; THX_check_second_of_day(aTHX_ v); sec = moment_local_rd_seconds(mt) + (v - moment_second_of_day(mt)); return THX_moment_from_local(aTHX_ sec, mt->nsec, mt->offset); } static moment_t THX_moment_with_millisecond(pTHX_ const moment_t *mt, int64_t v) { int64_t sec; THX_check_millisecond(aTHX_ v); sec = moment_local_rd_seconds(mt); return THX_moment_from_local(aTHX_ sec, v * 1000000, mt->offset); } static moment_t THX_moment_with_microsecond(pTHX_ const moment_t *mt, int64_t v) { int64_t sec; THX_check_microsecond(aTHX_ v); sec = moment_local_rd_seconds(mt); return THX_moment_from_local(aTHX_ sec, v * 1000, mt->offset); } static moment_t THX_moment_with_nanosecond(pTHX_ const moment_t *mt, int64_t v) { int64_t sec; THX_check_nanosecond(aTHX_ v); sec = moment_local_rd_seconds(mt); return THX_moment_from_local(aTHX_ sec, v, mt->offset); } static moment_t THX_moment_with_nanosecond_of_day(pTHX_ const moment_t *mt, int64_t v) { int64_t sec; int32_t nsec; if (v < 0 || v > INT64_C(86400000000000)) croak("Paramteter 'nanosecond' is out of the range [0, 86_400_000_000_000]"); sec = moment_local_rd_seconds(mt) + v / NANOS_PER_SEC - moment_second_of_day(mt); nsec = v % NANOS_PER_SEC; return THX_moment_from_local(aTHX_ sec, nsec, mt->offset); } static moment_t THX_moment_with_microsecond_of_day(pTHX_ const moment_t *mt, int64_t v) { if (v < 0 || v > INT64_C(86400000000)) croak("Paramteter 'microsecond' is out of the range [0, 86_400_000_000]"); return THX_moment_with_nanosecond_of_day(aTHX_ mt, v * 1000); } static moment_t THX_moment_with_millisecond_of_day(pTHX_ const moment_t *mt, int64_t v) { if (v < 0 || v > INT64_C(86400000)) croak("Paramteter 'millisecond' is out of the range [0, 86_400_000]"); return THX_moment_with_nanosecond_of_day(aTHX_ mt, v * 1000000); } moment_t THX_moment_with_field(pTHX_ const moment_t *mt, moment_component_t c, int64_t v) { switch (c) { case MOMENT_FIELD_YEAR: return THX_moment_with_year(aTHX_ mt, v); case MOMENT_FIELD_QUARTER_OF_YEAR: return THX_moment_with_quarter(aTHX_ mt, v); case MOMENT_FIELD_MONTH_OF_YEAR: return THX_moment_with_month(aTHX_ mt, v); case MOMENT_FIELD_WEEK_OF_YEAR: return THX_moment_with_week(aTHX_ mt, v); case MOMENT_FIELD_DAY_OF_MONTH: return THX_moment_with_day_of_month(aTHX_ mt, v); case MOMENT_FIELD_DAY_OF_QUARTER: return THX_moment_with_day_of_quarter(aTHX_ mt, v); case MOMENT_FIELD_DAY_OF_YEAR: return THX_moment_with_day_of_year(aTHX_ mt, v); case MOMENT_FIELD_DAY_OF_WEEK: return THX_moment_with_day_of_week(aTHX_ mt, v); case MOMENT_FIELD_HOUR_OF_DAY: return THX_moment_with_hour(aTHX_ mt, v); case MOMENT_FIELD_MINUTE_OF_HOUR: return THX_moment_with_minute(aTHX_ mt, v); case MOMENT_FIELD_MINUTE_OF_DAY: return THX_moment_with_minute_of_day(aTHX_ mt, v); case MOMENT_FIELD_SECOND_OF_MINUTE: return THX_moment_with_second(aTHX_ mt, v); case MOMENT_FIELD_SECOND_OF_DAY: return THX_moment_with_second_of_day(aTHX_ mt, v); case MOMENT_FIELD_MILLI_OF_SECOND: return THX_moment_with_millisecond(aTHX_ mt, v); case MOMENT_FIELD_MILLI_OF_DAY: return THX_moment_with_millisecond_of_day(aTHX_ mt, v); case MOMENT_FIELD_MICRO_OF_SECOND: return THX_moment_with_microsecond(aTHX_ mt, v); case MOMENT_FIELD_MICRO_OF_DAY: return THX_moment_with_microsecond_of_day(aTHX_ mt, v); case MOMENT_FIELD_NANO_OF_SECOND: return THX_moment_with_nanosecond(aTHX_ mt, v); case MOMENT_FIELD_NANO_OF_DAY: return THX_moment_with_nanosecond_of_day(aTHX_ mt, v); case MOMENT_FIELD_PRECISION: return THX_moment_with_precision(aTHX_ mt, v); case MOMENT_FIELD_RATA_DIE_DAY: return THX_moment_with_rata_die_day(aTHX_ mt, v); } croak("panic: THX_moment_with_component() called with unknown component (%d)", (int)c); } static moment_t THX_moment_plus_months(pTHX_ const moment_t *mt, int64_t v) { dt_t dt; THX_check_unit_months(aTHX_ v); dt = dt_add_months(moment_local_dt(mt), (int)v, DT_LIMIT); return THX_moment_with_local_dt(aTHX_ mt, dt); } static moment_t THX_moment_plus_days(pTHX_ const moment_t *mt, int64_t v) { int64_t sec; THX_check_unit_days(aTHX_ v); sec = moment_local_rd_seconds(mt) + v * 86400; return THX_moment_from_local(aTHX_ sec, mt->nsec, mt->offset); } static moment_t THX_moment_plus_seconds(pTHX_ const moment_t *mt, int64_t v) { int64_t sec; THX_check_unit_seconds(aTHX_ v); sec = moment_instant_rd_seconds(mt) + v; return THX_moment_from_instant(aTHX_ sec, mt->nsec, mt->offset); } static moment_t THX_moment_plus_time(pTHX_ const moment_t *mt, int64_t sec, int64_t nsec, int sign) { sec = sec + (nsec / NANOS_PER_SEC); nsec = nsec % NANOS_PER_SEC; sec = moment_instant_rd_seconds(mt) + sec * sign; nsec = mt->nsec + nsec * sign; if (nsec < 0) { nsec += NANOS_PER_SEC; sec--; } else if (nsec >= NANOS_PER_SEC) { nsec -= NANOS_PER_SEC; sec++; } return THX_moment_from_instant(aTHX_ sec, (IV)nsec, mt->offset); } moment_t THX_moment_plus_unit(pTHX_ const moment_t *mt, moment_unit_t u, int64_t v) { switch (u) { case MOMENT_UNIT_YEARS: THX_check_unit_years(aTHX_ v); return THX_moment_plus_months(aTHX_ mt, v * 12); case MOMENT_UNIT_MONTHS: THX_check_unit_months(aTHX_ v); return THX_moment_plus_months(aTHX_ mt, v); case MOMENT_UNIT_WEEKS: THX_check_unit_weeks(aTHX_ v); return THX_moment_plus_days(aTHX_ mt, v * 7); case MOMENT_UNIT_DAYS: THX_check_unit_days(aTHX_ v); return THX_moment_plus_days(aTHX_ mt, v); case MOMENT_UNIT_HOURS: THX_check_unit_hours(aTHX_ v); return THX_moment_plus_seconds(aTHX_ mt, v * 3600); case MOMENT_UNIT_MINUTES: THX_check_unit_minutes(aTHX_ v); return THX_moment_plus_seconds(aTHX_ mt, v * 60); case MOMENT_UNIT_SECONDS: THX_check_unit_seconds(aTHX_ v); return THX_moment_plus_seconds(aTHX_ mt, v); case MOMENT_UNIT_MILLIS: THX_check_unit_milliseconds(aTHX_ v); return THX_moment_plus_time(aTHX_ mt, v / 1000, (v % 1000) * 1000000, 1); case MOMENT_UNIT_MICROS: THX_check_unit_microseconds(aTHX_ v); return THX_moment_plus_time(aTHX_ mt, v / 1000000, (v % 1000000) * 1000, 1); case MOMENT_UNIT_NANOS: return THX_moment_plus_time(aTHX_ mt, 0, v, 1); } croak("panic: THX_moment_plus_unit() called with unknown unit (%d)", (int)u); } moment_t THX_moment_minus_unit(pTHX_ const moment_t *mt, moment_unit_t u, int64_t v) { switch (u) { case MOMENT_UNIT_YEARS: THX_check_unit_years(aTHX_ v); return THX_moment_plus_months(aTHX_ mt, -v * 12); case MOMENT_UNIT_MONTHS: THX_check_unit_months(aTHX_ v); return THX_moment_plus_months(aTHX_ mt, -v); case MOMENT_UNIT_WEEKS: THX_check_unit_weeks(aTHX_ v); return THX_moment_plus_days(aTHX_ mt, -v * 7); case MOMENT_UNIT_DAYS: THX_check_unit_days(aTHX_ v); return THX_moment_plus_days(aTHX_ mt, -v); case MOMENT_UNIT_HOURS: THX_check_unit_hours(aTHX_ v); return THX_moment_plus_seconds(aTHX_ mt, -v * 3600); case MOMENT_UNIT_MINUTES: THX_check_unit_minutes(aTHX_ v); return THX_moment_plus_seconds(aTHX_ mt, -v * 60); case MOMENT_UNIT_SECONDS: THX_check_unit_seconds(aTHX_ v); return THX_moment_plus_seconds(aTHX_ mt, -v); case MOMENT_UNIT_MILLIS: THX_check_unit_milliseconds(aTHX_ v); return THX_moment_plus_time(aTHX_ mt, v / 1000, (v % 1000) * 1000000, -1); case MOMENT_UNIT_MICROS: THX_check_unit_microseconds(aTHX_ v); return THX_moment_plus_time(aTHX_ mt, v / 1000000, (v % 1000000) * 1000, -1); case MOMENT_UNIT_NANOS: return THX_moment_plus_time(aTHX_ mt, 0, v, -1); } croak("panic: THX_moment_minus_unit() called with unknown unit (%d)", (int)u); } moment_t THX_moment_with_offset_same_instant(pTHX_ const moment_t *mt, IV offset) { int64_t sec; THX_check_offset(aTHX_ offset); sec = moment_instant_rd_seconds(mt); return THX_moment_from_instant(aTHX_ sec, mt->nsec, offset); } moment_t THX_moment_with_offset_same_local(pTHX_ const moment_t *mt, IV offset) { int64_t sec; THX_check_offset(aTHX_ offset); sec = moment_local_rd_seconds(mt); return THX_moment_from_local(aTHX_ sec, mt->nsec, offset); } moment_t THX_moment_with_precision(pTHX_ const moment_t *mt, int64_t precision) { int64_t sec; int32_t nsec; if (precision < -3 || precision > 9) croak("Parameter 'precision' is out of the range [-3, 9]"); sec = moment_local_rd_seconds(mt); nsec = mt->nsec; if (precision <= 0) { nsec = 0; switch (precision) { case -1: sec -= sec % 60; break; case -2: sec -= sec % 3600; break; case -3: sec -= sec % 86400; break; } } else { nsec -= nsec % kPow10[9 - precision]; } return THX_moment_from_local(aTHX_ sec, nsec, mt->offset); } moment_duration_t moment_subtract_moment(const moment_t *mt1, const moment_t *mt2) { const int64_t s1 = moment_instant_rd_seconds(mt1); const int64_t s2 = moment_instant_rd_seconds(mt2); moment_duration_t d; d.sec = s2 - s1; d.nsec = mt2->nsec - mt1->nsec; if (d.nsec < 0) { d.sec -= 1; d.nsec += NANOS_PER_SEC; } return d; } static int moment_delta_days(const moment_t *mt1, const moment_t *mt2) { const dt_t dt1 = moment_local_dt(mt1); const dt_t dt2 = moment_local_dt(mt2); return dt2 - dt1; } static int moment_delta_weeks(const moment_t *mt1, const moment_t *mt2) { return moment_delta_days(mt1, mt2) / 7; } static int moment_delta_months(const moment_t *mt1, const moment_t *mt2) { const dt_t dt1 = moment_local_dt(mt1); const dt_t dt2 = moment_local_dt(mt2); return dt_delta_months(dt1, dt2, true); } static int moment_delta_years(const moment_t *mt1, const moment_t *mt2) { return moment_delta_months(mt1, mt2) / 12; } static int64_t THX_moment_delta_hours(pTHX_ const moment_t *mt1, const moment_t *mt2) { moment_duration_t d; d = moment_subtract_moment(mt1, mt2); return (d.sec / 3600); } static int64_t THX_moment_delta_minutes(pTHX_ const moment_t *mt1, const moment_t *mt2) { moment_duration_t d; d = moment_subtract_moment(mt1, mt2); return (d.sec / 60); } static int64_t THX_moment_delta_seconds(pTHX_ const moment_t *mt1, const moment_t *mt2) { moment_duration_t d; d = moment_subtract_moment(mt1, mt2); return d.sec; } static int64_t THX_moment_delta_milliseconds(pTHX_ const moment_t *mt1, const moment_t *mt2) { moment_duration_t d; d = moment_subtract_moment(mt1, mt2); return d.sec * 1000 + (d.nsec / 1000000); } static int64_t THX_moment_delta_microseconds(pTHX_ const moment_t *mt1, const moment_t *mt2) { moment_duration_t d; d = moment_subtract_moment(mt1, mt2); return d.sec * 1000000 + (d.nsec / 1000); } static int64_t THX_moment_delta_nanoseconds(pTHX_ const moment_t *mt1, const moment_t *mt2) { static const int64_t kMaxSec = INT64_C(9223372035); moment_duration_t d; d = moment_subtract_moment(mt1, mt2); if (d.sec > kMaxSec || d.sec < -kMaxSec) croak("Nanosecond duration is too large to be represented in a 64-bit integer"); return d.sec * 1000000000 + d.nsec; } int64_t THX_moment_delta_unit(pTHX_ const moment_t *mt1, const moment_t *mt2, moment_unit_t u) { switch (u) { case MOMENT_UNIT_YEARS: return moment_delta_years(mt1, mt2); case MOMENT_UNIT_MONTHS: return moment_delta_months(mt1, mt2); case MOMENT_UNIT_WEEKS: return moment_delta_weeks(mt1, mt2); case MOMENT_UNIT_DAYS: return moment_delta_days(mt1, mt2); case MOMENT_UNIT_HOURS: return THX_moment_delta_hours(aTHX_ mt1, mt2); case MOMENT_UNIT_MINUTES: return THX_moment_delta_minutes(aTHX_ mt1, mt2); case MOMENT_UNIT_SECONDS: return THX_moment_delta_seconds(aTHX_ mt1, mt2); case MOMENT_UNIT_MILLIS: return THX_moment_delta_milliseconds(aTHX_ mt1, mt2); case MOMENT_UNIT_MICROS: return THX_moment_delta_microseconds(aTHX_ mt1, mt2); case MOMENT_UNIT_NANOS: return THX_moment_delta_nanoseconds(aTHX_ mt1, mt2); default: croak("panic: THX_moment_delta_unit() called with unknown unit (%d)", (int)u); } } moment_t THX_moment_at_utc(pTHX_ const moment_t *mt) { return THX_moment_with_offset_same_instant(aTHX_ mt, 0); } moment_t THX_moment_at_midnight(pTHX_ const moment_t *mt) { return THX_moment_with_millisecond_of_day(aTHX_ mt, 0); } moment_t THX_moment_at_noon(pTHX_ const moment_t *mt) { return THX_moment_with_millisecond_of_day(aTHX_ mt, 12*60*60*1000); } moment_t THX_moment_at_last_day_of_year(pTHX_ const moment_t *mt) { int y; dt_to_yd(moment_local_dt(mt), &y, NULL); return THX_moment_with_local_dt(aTHX_ mt, dt_from_yd(y + 1, 0)); } moment_t THX_moment_at_last_day_of_quarter(pTHX_ const moment_t *mt) { int y, q; dt_to_yqd(moment_local_dt(mt), &y, &q, NULL); return THX_moment_with_local_dt(aTHX_ mt, dt_from_yqd(y, q + 1, 0)); } moment_t THX_moment_at_last_day_of_month(pTHX_ const moment_t *mt) { int y, m; dt_to_ymd(moment_local_dt(mt), &y, &m, NULL); return THX_moment_with_local_dt(aTHX_ mt, dt_from_ymd(y, m + 1, 0)); } int moment_compare_instant(const moment_t *m1, const moment_t *m2) { const int64_t s1 = moment_instant_rd_seconds(m1); const int64_t s2 = moment_instant_rd_seconds(m2); int r; r = (s1 > s2) - (s1 < s2); if (r == 0) r = (m1->nsec > m2->nsec) - (m1->nsec < m2->nsec); return r; } int moment_compare_local(const moment_t *m1, const moment_t *m2) { const int64_t s1 = moment_local_rd_seconds(m1); const int64_t s2 = moment_local_rd_seconds(m2); int r; r = (s1 > s2) - (s1 < s2); if (r == 0) r = (m1->nsec > m2->nsec) - (m1->nsec < m2->nsec); return r; } int THX_moment_compare_precision(pTHX_ const moment_t *m1, const moment_t *m2, IV precision) { int64_t n1, n2; int r; if (precision < -3 || precision > 9) croak("Parameter 'precision' is out of the range [-3, 9]"); if (precision < 0) { int32_t n; n = 0; switch (precision) { case -1: n = 60; break; case -2: n = 3600; break; case -3: n = 86400; break; } n1 = moment_local_rd_seconds(m1); n2 = moment_local_rd_seconds(m2); n1 -= n1 % n; n2 -= n2 % n; n1 -= m1->offset * 60; n2 -= m2->offset * 60; r = (n1 > n2) - (n1 < n2); } else { n1 = moment_instant_rd_seconds(m1); n2 = moment_instant_rd_seconds(m2); r = (n1 > n2) - (n1 < n2); if (r == 0 && precision != 0) { n1 = m1->nsec - m1->nsec % kPow10[9 - precision]; n2 = m2->nsec - m2->nsec % kPow10[9 - precision]; r = (n1 > n2) - (n1 < n2); } } return r; } bool moment_equals(const moment_t *m1, const moment_t *m2) { return memcmp(m1, m2, sizeof(moment_t)) == 0; } int64_t moment_epoch(const moment_t *mt) { return (moment_instant_rd_seconds(mt) - UNIX_EPOCH); } int moment_year(const moment_t *mt) { return dt_year(moment_local_dt(mt)); } int moment_month(const moment_t *mt) { return dt_month(moment_local_dt(mt)); } int moment_quarter(const moment_t *mt) { return dt_quarter(moment_local_dt(mt)); } int moment_week(const moment_t *mt) { return dt_woy(moment_local_dt(mt)); } int moment_day_of_year(const moment_t *mt) { return dt_doy(moment_local_dt(mt)); } int moment_day_of_quarter(const moment_t *mt) { return dt_doq(moment_local_dt(mt)); } int moment_day_of_month(const moment_t *mt) { return dt_dom(moment_local_dt(mt)); } int moment_day_of_week(const moment_t *mt) { return dt_dow(moment_local_dt(mt)); } int moment_hour(const moment_t *mt) { return (int)((moment_local_rd_seconds(mt) / 3600) % 24); } int moment_minute(const moment_t *mt) { return (int)((moment_local_rd_seconds(mt) / 60) % 60); } int moment_minute_of_day(const moment_t *mt) { return (int)((moment_local_rd_seconds(mt) / 60) % 1440); } int moment_second(const moment_t *mt) { return (int)(moment_local_rd_seconds(mt) % 60); } int moment_second_of_day(const moment_t *mt) { return (int)(moment_local_rd_seconds(mt) % 86400); } int moment_millisecond(const moment_t *mt) { return (mt->nsec / 1000000); } int moment_millisecond_of_day(const moment_t *mt) { return moment_second_of_day(mt) * 1000 + moment_millisecond(mt); } int moment_microsecond(const moment_t *mt) { return (mt->nsec / 1000); } int64_t moment_microsecond_of_day(const moment_t *mt) { const int64_t sod = moment_local_rd_seconds(mt) % 86400; return sod * 1000000 + (mt->nsec / 1000); } int moment_nanosecond(const moment_t *mt) { return mt->nsec; } int64_t moment_nanosecond_of_day(const moment_t *mt) { const int64_t sod = moment_local_rd_seconds(mt) % 86400; return sod * 1000000000 + mt->nsec; } NV moment_jd(const moment_t *mt) { return moment_mjd(mt) + 2400000.5; } NV moment_mjd(const moment_t *mt) { const int64_t s = moment_instant_rd_seconds(mt); const int64_t d = (s / SECS_PER_DAY) - 678576; const int64_t n = (s % SECS_PER_DAY) * NANOS_PER_SEC + mt->nsec; return (NV)d + (NV)n * (1E-9/60/60/24); } NV moment_rd(const moment_t *mt) { const int64_t s = moment_local_rd_seconds(mt); const int64_t d = (s / SECS_PER_DAY); const int64_t n = (s % SECS_PER_DAY) * NANOS_PER_SEC + mt->nsec; return (NV)d + (NV)n * (1E-9/60/60/24); } int moment_rata_die_day(const moment_t *mt) { return dt_rdn(moment_local_dt(mt)); } int moment_offset(const moment_t *mt) { return mt->offset; } int moment_precision(const moment_t *mt) { int v, i; v = mt->nsec; if (v != 0) { for (i = 8; i > 0; i--) { if ((v % kPow10[i]) == 0) break; } return 9 - i; } v = moment_second_of_day(mt); if (v != 0) { if ((v % 3600) == 0) return -2; else if ((v % 60) == 0) return -1; else return 0; } return -3; } int moment_length_of_year(const moment_t *mt) { return dt_length_of_year(moment_local_dt(mt)); } int moment_length_of_quarter(const moment_t *mt) { return dt_length_of_quarter(moment_local_dt(mt)); } int moment_length_of_month(const moment_t *mt) { return dt_length_of_month(moment_local_dt(mt)); } int moment_length_of_week_year(const moment_t *mt) { return dt_length_of_week_year(moment_local_dt(mt)); } bool moment_is_leap_year(const moment_t *mt) { return dt_leap_year(moment_year(mt)); } int THX_moment_internal_western_easter(pTHX_ int64_t y) { THX_check_year(aTHX_ y); return dt_rdn(dt_from_easter((int)y, DT_WESTERN)); } int THX_moment_internal_orthodox_easter(pTHX_ int64_t y) { THX_check_year(aTHX_ y); return dt_rdn(dt_from_easter((int)y, DT_ORTHODOX)); } Time-Moment-0.44/src/moment.h000644 000765 000024 00000022107 13016301701 016607 0ustar00chansenstaff000000 000000 #ifndef __MOMENT_H__ #define __MOMENT_H__ #define PERL_NO_GET_CONTEXT #include "EXTERN.h" #include "perl.h" #include "dt_core.h" #ifndef _MSC_VER # include #else # if _MSC_VER >= 1600 # include # else typedef __int32 int32_t; typedef __int64 int64_t; typedef unsigned __int32 uint32_t; typedef unsigned __int64 uint64_t; # endif # ifndef INT64_C # define INT64_C(x) x##i64 # endif #endif #define SECS_PER_DAY 86400 #define NANOS_PER_SEC 1000000000 #define MIN_UNIT_YEARS INT64_C(-10000) #define MAX_UNIT_YEARS INT64_C(10000) #define MIN_UNIT_MONTHS INT64_C(-120000) #define MAX_UNIT_MONTHS INT64_C(120000) #define MIN_UNIT_WEEKS INT64_C(-521775) #define MAX_UNIT_WEEKS INT64_C(521775) #define MIN_UNIT_DAYS INT64_C(-3652425) #define MAX_UNIT_DAYS INT64_C(3652425) #define MIN_UNIT_HOURS INT64_C(-87658200) #define MAX_UNIT_HOURS INT64_C(87658200) #define MIN_UNIT_MINUTES INT64_C(-5259492000) #define MAX_UNIT_MINUTES INT64_C(5259492000) #define MIN_UNIT_SECONDS INT64_C(-315569520000) #define MAX_UNIT_SECONDS INT64_C(315569520000) #define MIN_UNIT_MILLIS INT64_C(-315569520000000) #define MAX_UNIT_MILLIS INT64_C(315569520000000) #define MIN_UNIT_MICROS INT64_C(-315569520000000000) #define MAX_UNIT_MICROS INT64_C(315569520000000000) #define MIN_RATA_DIE_DAY INT64_C(1) /* 0001-01-01 */ #define MAX_RATA_DIE_DAY INT64_C(3652059) /* 9999-12-31 */ #define MIN_RANGE INT64_C(86400) /* 0001-01-01T00:00:00Z */ #define MAX_RANGE INT64_C(315537983999) /* 9999-12-31T23:59:59Z */ #define UNIX_EPOCH INT64_C(62135683200) /* 1970-01-01T00:00:00Z */ #define MIN_EPOCH_SEC INT64_C(-62135596800) /* 0001-01-01T00:00:00Z */ #define MAX_EPOCH_SEC INT64_C(253402300799) /* 9999-12-31T23:59:59Z */ #define VALID_EPOCH_SEC(s) \ (s >= MIN_EPOCH_SEC && s <= MAX_EPOCH_SEC) typedef struct { int64_t sec; int32_t nsec; int32_t offset; } moment_t; typedef struct { int64_t sec; int32_t nsec; } moment_duration_t; typedef enum { MOMENT_UNIT_YEARS=0, MOMENT_UNIT_MONTHS, MOMENT_UNIT_WEEKS, MOMENT_UNIT_DAYS, MOMENT_UNIT_HOURS, MOMENT_UNIT_MINUTES, MOMENT_UNIT_SECONDS, MOMENT_UNIT_MILLIS, MOMENT_UNIT_MICROS, MOMENT_UNIT_NANOS, } moment_unit_t; typedef enum { MOMENT_FIELD_YEAR=0, MOMENT_FIELD_QUARTER_OF_YEAR, MOMENT_FIELD_MONTH_OF_YEAR, MOMENT_FIELD_WEEK_OF_YEAR, MOMENT_FIELD_DAY_OF_YEAR, MOMENT_FIELD_DAY_OF_QUARTER, MOMENT_FIELD_DAY_OF_MONTH, MOMENT_FIELD_DAY_OF_WEEK, MOMENT_FIELD_HOUR_OF_DAY, MOMENT_FIELD_MINUTE_OF_HOUR, MOMENT_FIELD_MINUTE_OF_DAY, MOMENT_FIELD_SECOND_OF_MINUTE, MOMENT_FIELD_SECOND_OF_DAY, MOMENT_FIELD_MILLI_OF_SECOND, MOMENT_FIELD_MILLI_OF_DAY, MOMENT_FIELD_MICRO_OF_SECOND, MOMENT_FIELD_MICRO_OF_DAY, MOMENT_FIELD_NANO_OF_SECOND, MOMENT_FIELD_NANO_OF_DAY, MOMENT_FIELD_PRECISION, MOMENT_FIELD_RATA_DIE_DAY, } moment_component_t; moment_t THX_moment_new(pTHX_ IV Y, IV M, IV D, IV h, IV m, IV s, IV ns, IV offset); moment_t THX_moment_from_epoch(pTHX_ int64_t sec, IV usec, IV offset); moment_t THX_moment_from_epoch_nv(pTHX_ NV sec, IV precision); moment_t THX_moment_from_rd(pTHX_ NV jd, NV epoch, IV precision, IV offset); moment_t THX_moment_from_jd(pTHX_ NV jd, NV epoch, IV precision); moment_t THX_moment_from_mjd(pTHX_ NV jd, NV epoch, IV precision); moment_t THX_moment_with_field(pTHX_ const moment_t *mt, moment_component_t u, int64_t v); moment_t THX_moment_with_offset_same_instant(pTHX_ const moment_t *mt, IV offset); moment_t THX_moment_with_offset_same_local(pTHX_ const moment_t *mt, IV offset); moment_t THX_moment_with_precision(pTHX_ const moment_t *mt, int64_t precision); moment_t THX_moment_plus_unit(pTHX_ const moment_t *mt, moment_unit_t u, int64_t v); moment_t THX_moment_minus_unit(pTHX_ const moment_t *mt, moment_unit_t u, int64_t v); int64_t THX_moment_delta_unit(pTHX_ const moment_t *mt1, const moment_t *mt2, moment_unit_t u); int64_t moment_instant_rd_seconds(const moment_t *mt); int64_t moment_local_rd_seconds(const moment_t *mt); dt_t moment_local_dt(const moment_t *mt); void moment_to_instant_rd_values(const moment_t *mt, IV *rdn, IV *sod, IV *nos); void moment_to_local_rd_values(const moment_t *mt, IV *rdn, IV *sod, IV *nos); int THX_moment_compare_precision(pTHX_ const moment_t *mt1, const moment_t *mt2, IV precision); int moment_compare_instant(const moment_t *m1, const moment_t *m2); int moment_compare_local(const moment_t *m1, const moment_t *m2); bool moment_equals(const moment_t *m1, const moment_t *m2); int moment_year(const moment_t *mt); int moment_quarter(const moment_t *mt); int moment_month(const moment_t *mt); int moment_week(const moment_t *mt); int moment_day_of_year(const moment_t *mt); int moment_day_of_quarter(const moment_t *mt); int moment_day_of_month(const moment_t *mt); int moment_day_of_week(const moment_t *mt); int moment_hour(const moment_t *mt); int moment_minute(const moment_t *mt); int moment_minute_of_day(const moment_t *mt); int moment_second(const moment_t *mt); int moment_second_of_day(const moment_t *mt); int moment_millisecond(const moment_t *mt); int moment_millisecond_of_day(const moment_t *mt); int moment_microsecond(const moment_t *mt); int64_t moment_microsecond_of_day(const moment_t *mt); int moment_nanosecond(const moment_t *mt); int64_t moment_nanosecond_of_day(const moment_t *mt); int moment_offset(const moment_t *mt); int64_t moment_epoch(const moment_t *mt); int moment_precision(const moment_t *mt); int moment_rata_die_day(const moment_t *mt); bool moment_is_leap_year(const moment_t *mt); NV moment_jd(const moment_t *mt); NV moment_mjd(const moment_t *mt); NV moment_rd(const moment_t *mt); int moment_length_of_year(const moment_t *mt); int moment_length_of_quarter(const moment_t *mt); int moment_length_of_month(const moment_t *mt); int moment_length_of_week_year(const moment_t *mt); moment_t THX_moment_at_utc(pTHX_ const moment_t *mt); moment_t THX_moment_at_midnight(pTHX_ const moment_t *mt); moment_t THX_moment_at_noon(pTHX_ const moment_t *mt); moment_t THX_moment_at_last_day_of_year(pTHX_ const moment_t *mt); moment_t THX_moment_at_last_day_of_quarter(pTHX_ const moment_t *mt); moment_t THX_moment_at_last_day_of_month(pTHX_ const moment_t *mt); int THX_moment_internal_western_easter(pTHX_ int64_t y); int THX_moment_internal_orthodox_easter(pTHX_ int64_t y); #define moment_new(Y, M, D, h, m, s, ns, offset) \ THX_moment_new(aTHX_ Y, M, D, h, m, s, ns, offset) #define moment_from_epoch(sec, nsec, offset) \ THX_moment_from_epoch(aTHX_ sec, nsec, offset) #define moment_from_epoch_nv(sec, precision) \ THX_moment_from_epoch_nv(aTHX_ sec, precision) #define moment_from_rd(rd, epoch, precision, offset) \ THX_moment_from_rd(aTHX_ rd, epoch, precision, offset) #define moment_from_jd(jd, epoch, precision) \ THX_moment_from_jd(aTHX_ jd, epoch, precision) #define moment_from_mjd(mjd, epoch, precision) \ THX_moment_from_mjd(aTHX_ mjd, epoch, precision) #define moment_with_offset_same_instant(self, offset) \ THX_moment_with_offset_same_instant(aTHX_ self, offset) #define moment_with_offset_same_local(self, offset) \ THX_moment_with_offset_same_local(aTHX_ self, offset) #define moment_with_precision(self, precision) \ THX_moment_with_precision(aTHX_ self, precision) #define moment_with_nanosecond(self, nsec) \ THX_moment_with_nanosecond(aTHX_ self, nsec) #define moment_plus_unit(self, unit, v) \ THX_moment_plus_unit(aTHX_ self, unit, v) #define moment_minus_unit(self, unit, v) \ THX_moment_minus_unit(aTHX_ self, unit, v) #define moment_delta_unit(self, other, unit) \ THX_moment_delta_unit(aTHX_ self, other, unit) #define moment_with_field(self, component, v) \ THX_moment_with_field(aTHX_ self, component, v) #define moment_at_utc(self) \ THX_moment_at_utc(aTHX_ self) #define moment_at_midnight(self) \ THX_moment_at_midnight(aTHX_ self) #define moment_at_noon(self) \ THX_moment_at_noon(aTHX_ self) #define moment_at_last_day_of_year(self) \ THX_moment_at_last_day_of_year(aTHX_ self) #define moment_at_last_day_of_quarter(self) \ THX_moment_at_last_day_of_quarter(aTHX_ self) #define moment_at_last_day_of_month(self) \ THX_moment_at_last_day_of_month(aTHX_ self) #define moment_compare_precision(mt1, mt2, precision) \ THX_moment_compare_precision(aTHX_ mt1, mt2, precision) /* Internal API but exposed in Perl */ #define moment_internal_western_easter(year) \ THX_moment_internal_western_easter(aTHX_ year) #define moment_internal_orthodox_easter(year) \ THX_moment_internal_orthodox_easter(aTHX_ year) #endif Time-Moment-0.44/src/moment_fmt.c000644 000765 000024 00000032653 12573233231 017470 0ustar00chansenstaff000000 000000 #include "moment.h" #include "dt_core.h" #include "dt_accessor.h" typedef enum { PAD_DEFAULT, PAD_NONE, PAD_ZERO, PAD_SPACE, } pad_t; static const char *aDoW[] = { "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", }; static const char *fDoW[] = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday", }; static const char *aMonth[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec", }; static const char *fMonth[] = { "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December", }; static const char *Meridiem[] = { "AM", "PM", }; /* * The first Sunday of January is the first day of week 1; days in the new * year before this are in week 0. */ static int dt_week_number_sun(dt_t dt) { int sunday = dt_doy(dt) - dt_dow(dt) % 7; return (sunday + 6) / 7; } /* * The first Monday of January is the first day of week 1; days in the new * year before this are in week 0. */ static int dt_week_number_mon(dt_t dt) { int monday = dt_doy(dt) - (dt_dow(dt) + 6) % 7; return (monday + 6) / 7; } static int moment_hour_12(const moment_t *mt) { int h = moment_hour(mt) % 12; if (h == 0) h = 12; return h; } static const char * moment_hour_meridiem(const moment_t *mt) { return Meridiem[moment_hour(mt) / 12]; } static bool supports_padding_flag(const char c) { switch (c) { case 'C': case 'd': case 'e': case 'g': case 'G': case 'H': case 'I': case 'j': case 'k': case 'l': case 'm': case 'M': case 'S': case 'U': case 'V': case 'W': case 'y': case 'Y': return TRUE; } return FALSE; } static void THX_format_num(pTHX_ SV *dsv, size_t width, pad_t want, pad_t def, unsigned int v) { char buf[20], *p, *e, *d, c; size_t nlen, plen, dlen; p = e = buf + sizeof(buf); do { *--p = '0' + (v % 10); } while (v /= 10); if (want == PAD_DEFAULT) want = def; if (want == PAD_ZERO) c = '0'; else if (want == PAD_SPACE) c = ' '; else width = 0; nlen = e - p; plen = (width > nlen) ? width - nlen : 0; dlen = nlen + plen; (void)SvGROW(dsv, SvCUR(dsv) + dlen + 1); d = SvPVX(dsv) + SvCUR(dsv); if (plen) { memset(d, c, plen); d += plen; } memcpy(d, p, nlen); SvCUR_set(dsv, SvCUR(dsv) + dlen); *SvEND(dsv) = '\0'; } #define CHR(n, d) (char)('0' + ((n) / (d)) % 10) static void THX_format_f(pTHX_ SV *dsv, const moment_t *mt, int len) { char buf[9]; int ns; if (len > 9) len = 9; else if (len < 0) len = 0; ns = moment_nanosecond(mt); if (len == 0) { if ((ns % 1000000) == 0) len = 3; else if ((ns % 1000) == 0) len = 6; else len = 9; } switch (len) { case 9: buf[8] = CHR(ns, 1); case 8: buf[7] = CHR(ns, 10); case 7: buf[6] = CHR(ns, 100); case 6: buf[5] = CHR(ns, 1000); case 5: buf[4] = CHR(ns, 10000); case 4: buf[3] = CHR(ns, 100000); case 3: buf[2] = CHR(ns, 1000000); case 2: buf[1] = CHR(ns, 10000000); case 1: buf[0] = CHR(ns, 100000000); } sv_catpvn(dsv, buf, len); } #undef CHR static void THX_format_s(pTHX_ SV *dsv, const moment_t *mt) { char buf[30], *p, *e; int64_t v; v = moment_epoch(mt); p = e = buf + sizeof(buf); if (v < 0) { do { *--p = '0' - (v % 10); } while (v /= 10); *--p = '-'; } else { do { *--p = '0' + (v % 10); } while (v /= 10); } sv_catpvn(dsv, p, e - p); } static void THX_format_z(pTHX_ SV *dsv, const moment_t *mt, int extended) { int offset, sign; offset = moment_offset(mt); if (offset < 0) sign = '-', offset = -offset; else sign = '+'; if (extended) sv_catpvf(dsv, "%c%02d:%02d", sign, offset / 60, offset % 60); else sv_catpvf(dsv, "%c%04d", sign, (offset / 60) * 100 + (offset % 60)); } static void THX_format_Z(pTHX_ SV *dsv, const moment_t *mt) { int offset, sign; offset = moment_offset(mt); if (offset == 0) sv_catpvn(dsv, "Z", 1); else { if (offset < 0) sign = '-', offset = -offset; else sign = '+'; sv_catpvf(dsv, "%c%02d:%02d", sign, offset / 60, offset % 60); } } #define format_num(dsv, width, wanted, def, num) \ THX_format_num(aTHX_ dsv, width, wanted, def, num) #define format_f(dsv, mt, len) \ THX_format_f(aTHX_ dsv, mt, len) #define format_s(dsv, mt) \ THX_format_s(aTHX_ dsv, mt) #define format_z(dsv, mt, extended) \ THX_format_z(aTHX_ dsv, mt, extended) #define format_Z(dsv, mt) \ THX_format_Z(aTHX_ dsv, mt) SV * THX_moment_strftime(pTHX_ const moment_t *mt, const char *s, STRLEN len) { const char *e, *p; char c; SV *dsv; dt_t dt; pad_t pad; int year, month, day, width, zextd; dsv = sv_2mortal(newSV(16)); SvCUR_set(dsv, 0); SvPOK_only(dsv); dt = moment_local_dt(mt); dt_to_ymd(dt, &year, &month, &day); e = s + len; while (s < e) { p = (const char *)memchr(s, '%', e - s); if (p == NULL || p + 1 == e) p = e; sv_catpvn(dsv, s, p - s); if (p == e) break; pad = PAD_DEFAULT; width = -1; zextd = 0; s = p + 1; label: switch (c = *s++) { case 'a': /* locale's abbreviated day of the week name */ sv_catpv(dsv, aDoW[dt_dow(dt) - 1]); break; case 'A': /* locale's full day of the week name */ sv_catpv(dsv, fDoW[dt_dow(dt) - 1]); break; case 'b': /* locale's abbreviated month name */ case 'h': sv_catpv(dsv, aMonth[month - 1]); break; case 'B': /* locale's full month name */ sv_catpv(dsv, fMonth[month - 1]); break; case 'c': /* locale's date and time (C locale: %a %b %e %H:%M:%S %Y) */ sv_catpvf(dsv, "%s %s %2d %02d:%02d:%02d %04d", aDoW[dt_dow(dt) - 1], aMonth[month - 1], day, moment_hour(mt), moment_minute(mt), moment_second(mt), year); break; case 'C': format_num(dsv, 2, pad, PAD_ZERO, year / 100); break; case 'd': format_num(dsv, 2, pad, PAD_ZERO, day); break; case 'x': /* locale's time representation (C locale: %m/%d/%y) */ case 'D': sv_catpvf(dsv, "%02d/%02d/%02d", month, day, year % 100); break; case 'e': format_num(dsv, 2, pad, PAD_SPACE, day); break; case 'f': /* extended conversion specification */ if (moment_nanosecond(mt)) { sv_catpvn(dsv, ".", 1); format_f(dsv, mt, width); } break; case 'F': sv_catpvf(dsv, "%04d-%02d-%02d", year, month, day); break; case 'g': format_num(dsv, 2, pad, PAD_ZERO, dt_yow(dt) % 100); break; case 'G': format_num(dsv, 4, pad, PAD_ZERO, dt_yow(dt)); break; case 'H': format_num(dsv, 2, pad, PAD_ZERO, moment_hour(mt)); break; case 'I': format_num(dsv, 2, pad, PAD_ZERO, moment_hour_12(mt)); break; case 'j': format_num(dsv, 3, pad, PAD_ZERO, dt_doy(dt)); break; case 'k': /* extended conversion specification */ format_num(dsv, 2, pad, PAD_SPACE, moment_hour(mt)); break; case 'l': /* extended conversion specification */ format_num(dsv, 2, pad, PAD_SPACE, moment_hour_12(mt)); break; case 'm': format_num(dsv, 2, pad, PAD_ZERO, month); break; case 'M': format_num(dsv, 2, pad, PAD_ZERO, moment_minute(mt)); break; case 'n': sv_catpvn(dsv, "\n", 1); break; case 'N': /* extended conversion specification */ format_f(dsv, mt, width); break; case 'p': /* locale's equivalent of either a.m. or p.m (C locale: AM or PM) */ sv_catpv(dsv, moment_hour_meridiem(mt)); break; case 'r': /* locale's time in a.m. and p.m. notation (C locale: %I:%M:%S %p) */ sv_catpvf(dsv, "%02d:%02d:%02d %s", moment_hour_12(mt), moment_minute(mt), moment_second(mt), moment_hour_meridiem(mt)); break; case 'R': sv_catpvf(dsv, "%02d:%02d", moment_hour(mt), moment_minute(mt)); break; case 's': /* extended conversion specification */ format_s(dsv, mt); break; case 'S': format_num(dsv, 2, pad, PAD_ZERO, moment_second(mt)); break; case 't': sv_catpvn(dsv, "\t", 1); break; case 'X': /* locale's date representation (C locale: %H:%M:%S) */ case 'T': sv_catpvf(dsv, "%02d:%02d:%02d", moment_hour(mt), moment_minute(mt), moment_second(mt)); break; case 'u': sv_catpvf(dsv, "%d", dt_dow(dt)); break; case 'U': format_num(dsv, 2, pad, PAD_ZERO, dt_week_number_sun(dt)); break; case 'V': format_num(dsv, 2, pad, PAD_ZERO, dt_woy(dt)); break; case 'w': sv_catpvf(dsv, "%d", dt_dow(dt) % 7); break; case 'W': format_num(dsv, 2, pad, PAD_ZERO, dt_week_number_mon(dt)); break; case 'y': format_num(dsv, 2, pad, PAD_ZERO, year % 100); break; case 'Y': format_num(dsv, 4, pad, PAD_ZERO, year); break; case 'z': format_z(dsv, mt, zextd); break; case 'Z': format_Z(dsv, mt); break; case '%': sv_catpvn(dsv, "%", 1); break; case ':': if (s < e && *s == 'z') { zextd = 1; goto label; } goto unknown; case '_': if (s < e && supports_padding_flag(*s)) { pad = PAD_SPACE; goto label; } goto unknown; case '-': if (s < e && supports_padding_flag(*s)) { pad = PAD_NONE; goto label; } goto unknown; case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': case '8': case '9': if (s < e && (*s == 'f' || *s == 'N')) { width = c - '0'; goto label; } if (s < e && c == '0' && supports_padding_flag(*s)) { pad = PAD_ZERO; goto label; } /* FALLTROUGH */ default: unknown: sv_catpvn(dsv, p, s - p); break; } } return dsv; } SV * THX_moment_to_string(pTHX_ const moment_t *mt, bool reduced) { SV *dsv; dt_t dt; int year, month, day, sec, ns, offset, sign; dsv = sv_2mortal(newSV(16)); SvCUR_set(dsv, 0); SvPOK_only(dsv); dt = moment_local_dt(mt); dt_to_ymd(dt, &year, &month, &day); sv_catpvf(dsv, "%04d-%02d-%02dT%02d:%02d", year, month, day, moment_hour(mt), moment_minute(mt)); sec = moment_second(mt); ns = moment_nanosecond(mt); if (!reduced || sec || ns) { sv_catpvf(dsv, ":%02d", sec); if (ns) { if ((ns % 1000000) == 0) sv_catpvf(dsv, ".%03d", ns / 1000000); else if ((ns % 1000) == 0) sv_catpvf(dsv, ".%06d", ns / 1000); else sv_catpvf(dsv, ".%09d", ns); } } offset = moment_offset(mt); if (offset == 0) sv_catpvn(dsv, "Z", 1); else { if (offset < 0) sign = '-', offset = -offset; else sign = '+'; if (reduced && (offset % 60) == 0) sv_catpvf(dsv, "%c%02d", sign, offset / 60); else sv_catpvf(dsv, "%c%02d:%02d", sign, offset / 60, offset % 60); } return dsv; } Time-Moment-0.44/src/moment_fmt.h000644 000765 000024 00000000616 12573233240 017467 0ustar00chansenstaff000000 000000 #ifndef __MOMENT_FMT_H__ #define __MOMENT_FMT_H__ #include "moment.h" SV * THX_moment_strftime(pTHX_ const moment_t *mt, const char *str, STRLEN len); SV * THX_moment_to_string(pTHX_ const moment_t *mt, bool reduced); #define moment_strftime(mt, str, len) \ THX_moment_strftime(aTHX_ mt, str, len) #define moment_to_string(mt, reduced) \ THX_moment_to_string(aTHX_ mt, reduced) #endif Time-Moment-0.44/src/moment_parse.c000644 000765 000024 00000004267 12575037501 020020 0ustar00chansenstaff000000 000000 #include "moment.h" #include "dt_core.h" #include "dt_parse_iso.h" static int parse_string_lenient(const char *str, size_t len, int64_t *sp, IV *np, IV *op) { size_t n; dt_t dt; char c; int sod, nanosecond, offset; n = dt_parse_iso_date(str, len, &dt); if (!n || n == len) return 1; c = str[n++]; if (!(c == 'T' || c == 't' || c == ' ')) return 1; str += n; len -= n; n = dt_parse_iso_time(str, len, &sod, &nanosecond); if (!n || n == len) return 1; if (str[n] == ' ') n++; str += n; len -= n; n = dt_parse_iso_zone_lenient(str, len, &offset); if (!n || n != len) return 1; *sp = ((int64_t)dt_rdn(dt) - 719163) * 86400 + sod - offset * 60; *np = nanosecond; *op = offset; return 0; } static int parse_string_strict(const char *str, size_t len, int64_t *sp, IV *np, IV *op) { size_t n; dt_t dt; int sod, nanosecond, offset; bool extended; n = dt_parse_iso_date(str, len, &dt); if (!n || n == len) return 1; /* * 0123456789 * 2012-12-14 */ extended = str[4] == '-'; if (str[n++] != 'T') return 1; str += n; len -= n; if (extended) n = dt_parse_iso_time_extended(str, len, &sod, &nanosecond); else n = dt_parse_iso_time_basic(str, len, &sod, &nanosecond); if (!n || n == len) return 1; str += n; len -= n; if (extended) n = dt_parse_iso_zone_extended(str, len, &offset); else n = dt_parse_iso_zone_basic(str, len, &offset); if (!n || n != len) return 1; *sp = ((int64_t)dt_rdn(dt) - 719163) * 86400 + sod - offset * 60; *np = nanosecond; *op = offset; return 0; } moment_t THX_moment_from_string(pTHX_ const char *str, STRLEN len, bool lenient) { int ret; int64_t seconds; IV nanosecond, offset; if (lenient) ret = parse_string_lenient(str, len, &seconds, &nanosecond, &offset); else ret = parse_string_strict(str, len, &seconds, &nanosecond, &offset); if (ret != 0) croak("Could not parse the given string"); return moment_from_epoch(seconds, nanosecond, offset); } Time-Moment-0.44/src/moment_parse.h000644 000765 000024 00000000413 12256131711 020004 0ustar00chansenstaff000000 000000 #ifndef __MOMENT_PARSE_H__ #define __MOMENT_PARSE_H__ #include "moment.h" moment_t THX_moment_from_string(pTHX_ const char *str, STRLEN len, bool lenient); #define moment_from_string(str, len, lenient) \ THX_moment_from_string(aTHX_ str, len, lenient) #endif Time-Moment-0.44/lib/Time/000755 000765 000024 00000000000 13274643625 016036 5ustar00chansenstaff000000 000000 Time-Moment-0.44/lib/Time/Moment/000755 000765 000024 00000000000 13274643625 017275 5ustar00chansenstaff000000 000000 Time-Moment-0.44/lib/Time/Moment.pm000644 000765 000024 00000006072 13274643443 017636 0ustar00chansenstaff000000 000000 package Time::Moment; use strict; use warnings; use Carp qw[]; BEGIN { our $VERSION = '0.44'; require XSLoader; XSLoader::load(__PACKAGE__, $VERSION); } BEGIN { unless (exists &Time::Moment::now) { require Time::HiRes; eval sprintf <<'EOC', __FILE__; # line 17 %s # expects normalized tm values; algorithm is only valid for tm year's [1, 199] sub timegm { my ($y, $d, $h, $m, $s) = @_[5,7,2,1,0]; return ((1461 * --$y >> 2) + $d - 25202) * 86400 + $h * 3600 + $m * 60 + $s; } sub now { @_ == 1 || Carp::croak(q/Usage: Time::Moment->now()/); my ($class) = @_; my ($sec, $usec) = Time::HiRes::gettimeofday(); my $offset = int((timegm(localtime($sec)) - $sec) / 60); return $class->from_epoch($sec, $usec * 1000) ->with_offset_same_instant($offset); } sub now_utc { @_ == 1 || Carp::croak(q/Usage: Time::Moment->now_utc()/); my ($class) = @_; my ($sec, $usec) = Time::HiRes::gettimeofday(); return $class->from_epoch($sec, $usec * 1000); } EOC die $@ if $@; } } BEGIN { delete @Time::Moment::{qw(timegm)}; } sub __as_DateTime { my ($tm) = @_; return DateTime->from_epoch( epoch => $tm->epoch, time_zone => $tm->strftime('%Z'), )->set_nanosecond($tm->nanosecond); } sub __as_Time_Piece { my ($tm) = @_; return scalar Time::Piece::gmtime($tm->epoch); } sub DateTime::__as_Time_Moment { my ($dt) = @_; (!$dt->time_zone->is_floating) or Carp::croak(q/Cannot coerce an instance of DateTime in the 'floating' / .q/time zone to an instance of Time::Moment/); return Time::Moment->from_epoch($dt->epoch, $dt->nanosecond) ->with_offset_same_instant(int($dt->offset / 60)); } sub Time::Piece::__as_Time_Moment { my ($tp) = @_; return Time::Moment->from_epoch($tp->epoch) ->with_offset_same_instant(int($tp->tzoffset / 60)); } sub STORABLE_freeze { my ($self, $cloning) = @_; return if $cloning; return pack 'nnNNN', 0x544D, $self->offset, $self->utc_rd_values; } sub STORABLE_thaw { my ($self, $cloning, $packed) = @_; return if $cloning; (length($packed) == 16 && vec($packed, 0, 16) == 0x544D) # TM or die(q/Cannot deserialize corrupted data/); # Don't replace die with Carp! my ($offset, $rdn, $sod, $nos) = unpack 'xxnNNN', $packed; $offset = ($offset & 0x7FFF) - 0x8000 if ($offset & 0x8000); my $seconds = ($rdn - 719163) * 86400 + $sod; $$self = ${ ref($self)->from_epoch($seconds, $nos) ->with_offset_same_instant($offset) }; } sub TO_JSON { return $_[0]->to_string; } sub TO_CBOR { # Use the standard tag for date/time string; see RFC 7049 Section 2.4.1 return CBOR::XS::tag(0, $_[0]->to_string); } sub FREEZE { return $_[0]->to_string; } sub THAW { my ($class, undef, $string) = @_; return $class->from_string($string); } # Alias *with_offset = \&with_offset_same_instant; # used by DateTime::TimeZone sub utc_year { return $_[0]->with_offset_same_instant(0)->year; } 1; Time-Moment-0.44/lib/Time/Moment.pod000644 000765 000024 00000162501 13250235447 017777 0ustar00chansenstaff000000 000000 =encoding utf-8 =head1 NAME Time::Moment - Represents a date and time of day with an offset from UTC =head1 SYNOPSIS $tm = Time::Moment->new( year => 2012, month => 12, day => 24, hour => 15, minute => 30, second => 45, nanosecond => 123456789, offset => 0, ); $tm = Time::Moment->now; $tm = Time::Moment->now_utc; $tm = Time::Moment->from_epoch($seconds); $tm = Time::Moment->from_object($object); $tm = Time::Moment->from_string($string); $tm = Time::Moment->from_rd($rd); $tm = Time::Moment->from_jd($jd); $tm = Time::Moment->from_mjd($mjd); $year = $tm->year; # [1, 9999] $quarter = $tm->quarter; # [1, 4] $month = $tm->month; # [1, 12] $week = $tm->week; # [1, 53] $day = $tm->day_of_year; # [1, 366] $day = $tm->day_of_quarter; # [1, 92] $day = $tm->day_of_month; # [1, 31] $day = $tm->day_of_week; # [1=Monday, 7=Sunday] $hour = $tm->hour; # [0, 23] $minute = $tm->minute; # [0, 59] $minute = $tm->minute_of_day; # [0, 1439] $second = $tm->second; # [0, 59] $second = $tm->second_of_day; # [0, 86_399] $millisecond = $tm->millisecond; # [0, 999] $millisecond = $tm->millisecond_of_day; # [0, 86_399_999] $microsecond = $tm->microsecond; # [0, 999_999] $microsecond = $tm->microsecond_of_day; # [0, 86_399_999_999] $nanosecond = $tm->nanosecond; # [0, 999_999_999] $nanosecond = $tm->nanosecond_of_day; # [0, 86_399_999_999_999] $epoch = $tm->epoch; $offset = $tm->offset; # [-1080, 1080] (±18:00) $jd = $tm->jd; # Julian Date $mjd = $tm->mjd; # Modified Julian Date $rd = $tm->rd; # Rata Die $tm2 = $tm1->with($adjuster); $tm2 = $tm1->with_year($year); $tm2 = $tm1->with_quarter($quarter); $tm2 = $tm1->with_month($month); $tm2 = $tm1->with_week($week); $tm2 = $tm1->with_day_of_year($day); $tm2 = $tm1->with_day_of_quarter($day); $tm2 = $tm1->with_day_of_month($day); $tm2 = $tm1->with_day_of_week($day); $tm2 = $tm1->with_hour($hour); $tm2 = $tm1->with_minute($minute); $tm2 = $tm1->with_minute_of_day($minute); $tm2 = $tm1->with_second($second); $tm2 = $tm1->with_second_of_day($second); $tm2 = $tm1->with_millisecond($millisecond); $tm2 = $tm1->with_millisecond_of_day($millisecond); $tm2 = $tm1->with_microsecond($microsecond); $tm2 = $tm1->with_microsecond_of_day($microsecond); $tm2 = $tm1->with_nanosecond($nanosecond); $tm2 = $tm1->with_nanosecond_of_day($nanosecond); $tm2 = $tm1->with_offset_same_instant($offset); $tm2 = $tm1->with_offset_same_local($offset); $tm2 = $tm1->with_precision($precision); $tm2 = $tm1->plus_years($years); $tm2 = $tm1->plus_months($months); $tm2 = $tm1->plus_weeks($weeks); $tm2 = $tm1->plus_days($days); $tm2 = $tm1->plus_hours($hours); $tm2 = $tm1->plus_minutes($minutes); $tm2 = $tm1->plus_seconds($seconds); $tm2 = $tm1->plus_milliseconds($milliseconds); $tm2 = $tm1->plus_microseconds($microseconds); $tm2 = $tm1->plus_nanoseconds($nanoseconds); $tm2 = $tm1->minus_years($years); $tm2 = $tm1->minus_months($months); $tm2 = $tm1->minus_weeks($weeks); $tm2 = $tm1->minus_days($days); $tm2 = $tm1->minus_hours($hours); $tm2 = $tm1->minus_minutes($minutes); $tm2 = $tm1->minus_seconds($seconds); $tm2 = $tm1->minus_milliseconds($milliseconds); $tm2 = $tm1->minus_microseconds($microseconds); $tm2 = $tm1->minus_nanoseconds($nanoseconds); $years = $tm1->delta_years($tm2); $months = $tm1->delta_months($tm2); $weeks = $tm1->delta_weeks($tm2); $days = $tm1->delta_days($tm2); $hours = $tm1->delta_hours($tm2); $minutes = $tm1->delta_minutes($tm2); $seconds = $tm1->delta_seconds($tm2); $milliseconds = $tm1->delta_milliseconds($tm2); $microseconds = $tm1->delta_microseconds($tm2); $nanoseconds = $tm1->delta_nanoseconds($tm2); $tm2 = $tm1->at_utc; $tm2 = $tm1->at_midnight; # T00:00:00.0 $tm2 = $tm1->at_noon; # T12:00:00.0 $tm2 = $tm1->at_last_day_of_year; $tm2 = $tm1->at_last_day_of_quarter; $tm2 = $tm1->at_last_day_of_month; $boolean = $tm1->is_before($tm2); $boolean = $tm1->is_after($tm2); $boolean = $tm1->is_equal($tm2); $integer = $tm1->compare($tm2); $boolean = $tm->is_leap_year; $string = $tm->to_string; $string = $tm->strftime($format); $integer = $tm->length_of_year; # [365, 366] $integer = $tm->length_of_quarter; # [90, 92] $integer = $tm->length_of_month; # [28, 31] $integer = $tm->length_of_week_year; # [52, 53] @values = $tm->utc_rd_values; $seconds = $tm->utc_rd_as_seconds; @values = $tm->local_rd_values; $seconds = $tm->local_rd_as_seconds; $integer = $tm1 <=> $tm2; $boolean = $tm1 == $tm2; $boolean = $tm1 != $tm2; $boolean = $tm1 < $tm2; $boolean = $tm1 > $tm2; $boolean = $tm1 <= $tm2; $boolean = $tm1 >= $tm2; $string = "$tm"; =head1 DESCRIPTION C is an immutable object representing a date and time of day with an offset from UTC in the ISO 8601 calendar system. Time is measured in nanoseconds since C<0001-01-01T00Z>. In C leap seconds are ignored. It is assumed that there are exactly C<86,400,000,000,000> nanoseconds per day. C can represent all epoch integers from C<-62,135,596,800> to C<253,402,300,799>; this range suffices to measure times to nanosecond precision for any instant that is within C<0001-01-01T00:00:00Z> to C<9999-12-31T23:59:59Z>. =head1 CONSTRUCTORS =head2 new $tm = Time::Moment->new( year => 2012, month => 12, day => 24, hour => 15, minute => 30, second => 45, nanosecond => 123456789, offset => 0, ); Constructs an instance of C from the given components. B =over 4 =item year The year [1, 9999]. =item month The month of the year [1, 12]. =item day The day of the month [1, 31]. The day must be valid for the year and month, otherwise an exception is raised. =item hour The hour of the day [0, 23]. =item minute The minute of the hour [0, 59]. =item second The second of the minute [0, 59]. =item nanosecond The nanosecond of the second [0, 999_999_999]. =item offset The offset from UTC in minutes [-1080, 1080] (±18:00). =back =head2 now $tm = Time::Moment->now; Constructs an instance of C that is set to the current date and time from the system clock in the system time zone, with the offset set to the system's time zone offset from UTC. =head2 now_utc $tm = Time::Moment->now_utc; Constructs an instance of C that is set to the current date and time from the system clock in the UTC time zone. =head2 from_epoch $tm = Time::Moment->from_epoch($seconds); $tm = Time::Moment->from_epoch($seconds, $nanosecond); $tm = Time::Moment->from_epoch($seconds [, nanosecond => 0] [, precision => 6]); Constructs an instance of C from the given I from the epoch of 1970-01-01T00Z. Fractional seconds is supported if the constructor is invoked with I only, the default precision is 6 (microseconds). B =over 4 =item nanosecond $tm = Time::Moment->from_epoch($seconds, nanosecond => 0); The optional parameter I [0, 999_999_999] specifies the nanosecond of the second. =item precision $tm = Time::Moment->from_epoch($seconds, precision => 6); The optional parameter I [0, 9] specifies the precision of the fractional seconds. The default precision is 6 (microseconds). =back =head2 from_object $tm = Time::Moment->from_object($object); Constructs an instance of C from the given I. If the given object is an instance of C it's returned otherwise an attempt is made to coerce the given object to an instance of C. C implements coercion handlers for the following object types: =over 4 =item L $tm = Time::Moment->from_object( DateTime->now ); The given C object must be within the supported range and must have a time zone or an offset from UTC, coercing from the 'floating' time zone is not supported. =item L $tm = Time::Moment->from_object( scalar Time::Piece::localtime() ); The given C object must be within the supported date range. =back The coercion scheme is extensible and implemented as documented in L: $tm = Params::Coerce::coerce('Time::Moment', scalar Time::Piece::localtime()); $tm = Params::Coerce::coerce('Time::Moment', DateTime->now); C also implements a coercion handler from C to C and C: $dt = Params::Coerce::coerce('DateTime', Time::Moment->now); $tp = Params::Coerce::coerce('Time::Piece', Time::Moment->now); =head2 from_string $tm = Time::Moment->from_string($string); $tm = Time::Moment->from_string($string [, lenient => false]); Constructs an instance of C from the given I. The string must consist of a complete date representation and time of day followed by a zone designator. The time of day may be reduced to hour of the day, the second of the minute may have a decimal fraction. The decimal sign can be either the comma [,] or the full stop [.]. A decimal fraction must have at least one digit and may have a total of nine digits, if the fractional precision is greater than nine digits, the value will be truncated. The following are examples of complete date and time of day representations: Basic format: Example: YYYYMMDDThhmmssZ 20121224T121530Z YYYYMMDDThhmmss±hhmm 20121224T121530+0100 YYYYMMDDThhmmss±hh 20121224T121530+01 YYYYMMDDThhmmss.ssZ 20121224T121530.500Z YYYYMMDDThhmmss.ss±hhmm 20121224T121530.500+0100 YYYYMMDDThhmmss.ss±hh 20121224T121530.500+01 YYYYMMDDThhZ 20121224T12Z (reduced accuracy) YYYYMMDDThhmmZ 20121224T1215Z (reduced accuracy) YYYYMMDDThhmm±hhmm 20121224T1215+0100 (reduced accuracy) YYYYMMDDThhmm±hh 20121224T1215+01 (reduced accuracy) Extended format: Example: YYYY-MM-DDThh:mm:ssZ 2012-12-24T12:15:30Z YYYY-MM-DDThh:mm:ss±hh:mm 2012-12-24T12:15:30+01:00 YYYY-MM-DDThh:mm:ss±hh 2012-12-24T12:15:30+01 YYYY-MM-DDThh:mm:ss.ssZ 2012-12-24T12:15:30.500Z YYYY-MM-DDThh:mm:ss.ss±hh:mm 2012-12-24T12:15:30.500+01:00 YYYY-MM-DDThh:mm:ss.ss±hh 2012-12-24T12:15:30.500+01 YYYY-MM-DDThhZ 2012-12-24T12Z (reduced accuracy) YYYY-MM-DDThh:mmZ 2012-12-24T12:15Z (reduced accuracy) YYYY-MM-DDThh:mm±hh:mm 2012-12-24T12:15+01:00 (reduced accuracy) YYYY-MM-DDThh:mm±hh 2012-12-24T12:15+01 (reduced accuracy) Where representations using calendar dates are shown, ordinal dates or week dates may be substituted. This ISO 8601 profile correspond to a subset of ISO 8601:2004 4.3 Date and time of day. If the optional boolean parameter I is true, the following examples are also accepted: YYYY-MM-DD hh:mm:ssZ 2012-12-24 12:15:30Z YYYY-MM-DD hh:mm:ssz 2012-12-24 12:15:30z YYYY-MM-DD hh:mm:ss±hhmm 2012-12-24 12:15:30+0100 YYYY-MM-DD hh:mm:ss±hh:mm 2012-12-24 12:15:30+01:00 YYYY-MM-DD hh:mm:ss±hh 2012-12-24 12:15:30+01 YYYY-MM-DD hh:mm:ss.ssZ 2012-12-24 12:15:30.500Z YYYY-MM-DD hh:mm:ss.ssz 2012-12-24 12:15:30.500z YYYY-MM-DD hh:mm:ss.ss±hhmm 2012-12-24 12:15:30.500+0100 YYYY-MM-DD hh:mm:ss.ss±hh:mm 2012-12-24 12:15:30.500+01:00 YYYY-MM-DD hh:mm:ss.ss±hh 2012-12-24 12:15:30.500+01 YYYY-MM-DD hh:mmZ 2012-12-24 12:15Z YYYY-MM-DD hh:mmz 2012-12-24 12:15z YYYY-MM-DD hh:mm±hhmm 2012-12-24 12:15+0100 YYYY-MM-DD hh:mm±hh:mm 2012-12-24 12:15+01:00 YYYY-MM-DD hh:mm±hh 2012-12-24 12:15+01 YYYY-MM-DD hh:mm:ss ±hh:mm 2012-12-24 12:15:30 +01:00 YYYY-MM-DD hh:mm:ss ±hhmm 2012-12-24 12:15:30 +0100 YYYY-MM-DD hh:mm:ss ±hh 2012-12-24 12:15:30 +01 YYYY-MM-DD hh:mm:ss GMT 2012-12-24 12:15:30 GMT YYYY-MM-DD hh:mm:ss GMT±hh 2012-12-24 12:15:30 GMT+01 YYYY-MM-DD hh:mm:ss UTC 2012-12-24 12:15:30 UTC YYYY-MM-DD hh:mm:ss UTC±hh 2012-12-24 12:15:30 UTC+01 YYYY-MM-DD hh:mm:ss.ss ±hhmm 2012-12-24 12:15:30.500 +0100 YYYY-MM-DD hh:mm:ss.ss ±hh:mm 2012-12-24 12:15:30.500 +01:00 YYYY-MM-DD hh:mm:ss.ss ±hh 2012-12-24 12:15:30.500 +01 YYYY-MM-DD hh:mm ±hh:mm 2012-12-24 12:15 +01:00 YYYY-MM-DD hh:mm ±hhmm 2012-12-24 12:15 +0100 YYYY-MM-DD hh:mm ±hh 2012-12-24 12:15 +01 The string representation may consist of a mixture of the basic format and the extended format. The time designator [T] may be in lower case [t] or replaced with a single space. A single space is also accepted between the time of day and the zone designator. The UTC designator [Z] may also be in lower case [z]. The literal string GMT or UTC may be used as a UTC designator and may have an offset. Usage of these string representations is strongly discouraged as they do not conform to the ISO 8601 standard. =head2 from_rd $tm = Time::Moment->from_rd($rd); $tm = Time::Moment->from_rd($rd [, offset => 0] [, precision => 3] [, epoch => 0]); Constructs an instance of C from the given Rata Die. The Rata Die is a count of days elapsed since 0000-12-31T00. The fractional part corresponds to the fraction of the day after midnight. The minimum acceptable Rata Die is C<1> which corresponds to 0001-01-01T00. B =over 4 =item offset $tm = Time::Moment->from_rd($rd, offset => 0); The optional parameter I [-1080, 1080] (±18:00) specifies the offset from UTC in minutes. The default offset is 0. =item precision $tm = Time::Moment->from_rd($rd, precision => 3); The optional parameter I [0, 9] specifies the precision of the fractional seconds. The default precision is 3 (milliseconds). =item epoch $tm = Time::Moment->from_rd($rd, epoch => 0); The optional parameter I specifies the epoch date relative to 0000-12-31T00. The epoch date for the Rata Die is C<0>. =back =head2 from_jd $tm = Time::Moment->from_jd($jd); $tm = Time::Moment->from_jd($jd [, precision => 3] [, epoch => -1721424.5]); Constructs an instance of C from the given Julian Date. The Julian Date is a count of days elapsed since -4713-11-24T12Z. The fractional part corresponds to the fraction of the day after noon. The minimum acceptable Julian Date is C<1721425.5> which corresponds to 0001-01-01T00Z. B =over 4 =item precision $tm = Time::Moment->from_jd($jd, precision => 3); The optional parameter I [0, 9] specifies the precision of the fractional seconds. The default precision is 3 (milliseconds). =item epoch $tm = Time::Moment->from_jd($jd, epoch => -1721424.5); The optional parameter I specifies the epoch date relative to 0000-12-31T00Z. The epoch date for the Julian Date is C<-1721424.5>. =back =head2 from_mjd $tm = Time::Moment->from_mjd($mjd); $tm = Time::Moment->from_mjd($mjd [, precision => 3] [, epoch => 678576]); Constructs an instance of C from the given Modified Julian Date. The Modified Julian Date is a count of days elapsed since 1858-11-17T00Z. The fractional part corresponds to the fraction of the day after midnight. The minimum acceptable Modified Julian Date is C<-678575> which corresponds to 0001-01-01T00Z. B =over 4 =item precision $tm = Time::Moment->from_mjd($mjd, precision => 3); The optional parameter I [0, 9] specifies the precision of the fractional seconds. The default precision is 3 (milliseconds). =item epoch $tm = Time::Moment->from_mjd($mjd, epoch => 678576); The optional parameter I specifies the epoch date relative to 0000-12-31T00Z. The epoch date for the Modified Julian Date is C<678576>. =back =head1 INSTANCE METHODS =head2 year $year = $tm->year; Returns the year [1, 9999]. =head2 quarter $quarter = $tm->quarter; Returns the quarter of the year [1, 4]. =head2 month $month = $tm->month; Returns the month of the year [1, 12]. =head2 week $week = $tm->week; Returns the week of the year [1, 53]. =head2 day_of_year $day = $tm->day_of_year; Returns the day of the year [1, 366]. =head2 day_of_quarter $day = $tm->day_of_quarter; Returns the day of the quarter [1, 92]. =head2 day_of_month $day = $tm->day_of_month; Returns the day of the month [1, 31]. =head2 day_of_week $day = $tm->day_of_week; Returns the day of the week [1=Monday, 7=Sunday]. =head2 hour $hour = $tm->hour; Returns the hour of the day [0, 23]. =head2 minute $minute = $tm->minute; Returns the minute of the hour [0, 59]. =head2 minute_of_day $minute = $tm->minute_of_day; Returns the minute of the day [0, 1439]. =head2 second $second = $tm->second; Returns the second of the minute [0, 59]. =head2 second_of_day $second = $tm->second_of_day; Returns the second of the day [0, 86_399]. =head2 millisecond $millisecond = $tm->millisecond; Returns the millisecond of the second [0, 999]. =head2 millisecond_of_day $millisecond = $tm->millisecond_of_day; Returns the millisecond of the day [0, 86_399_999]. =head2 microsecond $microsecond = $tm->microsecond; Returns the microsecond of the second [0, 999_999]. =head2 microsecond_of_day $microsecond = $tm->microsecond_of_day; Returns the microsecond of the day [0, 86_399_999_999]. =head2 nanosecond $nanosecond = $tm->nanosecond; Returns the nanosecond of the second [0, 999_999_999]. =head2 nanosecond_of_day $nanosecond = $tm->nanosecond_of_day; Returns the nanosecond of the day [0, 86_399_999_999_999]. =head2 epoch $epoch = $tm->epoch; Returns the number of integral seconds from the epoch of 1970-01-01T00Z. =head2 offset $offset = $tm->offset; Returns the offset from UTC in minutes [-1080, 1080] (±18:00). =head2 precision $precision = $tm->precision; Returns the precision of the time of the day [-3, 9]. Please see L for an explanation of the returned precision value. =head2 jd $jd = $tm->jd; $jd = $tm->jd([precision => 3]); Returns the Julian Date. The Julian Date is a count of days elapsed since -4713-11-24T12Z. The fractional part corresponds to the fraction of the day after noon. The optional named parameter I [0, 9] specifies the precision of the fractional seconds. The default precision is 3 (milliseconds). =head2 mjd $mjd = $tm->mjd; $mjd = $tm->mjd([precision => 3]); Returns the Modified Julian Date. The Modified Julian Date is a count of days elapsed since 1858-11-17T00Z. The fractional part corresponds to the fraction of the day after midnight. The optional named parameter I [0, 9] specifies the precision of the fractional seconds. The default precision is 3 (milliseconds). =head2 rd $rd = $tm->rd; $rd = $tm->rd([precision => 3]); Returns the Rata Die. The Rata Die is a count of days elapsed since 0000-12-31T00. The fractional part corresponds to the fraction of the day after midnight. The optional named parameter I [0, 9] specifies the precision of the fractional seconds. The default precision is 3 (milliseconds). =head2 with $tm2 = $tm1->with($adjuster); Returns a copy of this instance adjusted by the given I. The adjuster is a CODE reference invoked with an instance of Time::Moment and is expected to return an instance of Time::Moment. Please see L for available adjusters. =head2 with_year $tm2 = $tm1->with_year($year); Returns a copy of this instance with the given I [1, 9999] altered. The day of the month of the date is unchanged unless the day does not exist in the month. In that case, the day is set to the last day of the month. =head2 with_quarter $tm2 = $tm1->with_quarter($quarter); Returns a copy of this instance with the given I of the year [1, 4] altered. The day of the month of the date is unchanged unless the day does not exist in the month of the quarter. In that case, the day is set to the last day of the month. =head2 with_month $tm2 = $tm1->with_month($month); Returns a copy of this instance with the given I of the year [1, 12] altered. The day of the month of the date is unchanged unless the day does not exist in the given month. In that case, the day is set to the last day of the given month. =head2 with_week $tm2 = $tm1->with_week($week); Returns a copy of this instance with the given I of the year [1, 53] altered. The week must be valid for the year, otherwise an exception is raised. =head2 with_day_of_year $tm2 = $tm1->with_day_of_year($day); Returns a copy of this instance with the given I of the year [1, 366] altered. The day must be valid for the year, otherwise an exception is raised. =head2 with_day_of_quarter $tm2 = $tm1->with_day_of_quarter($day); Returns a copy of this instance with the given I of the quarter [1, 92] altered. The day must be valid for the year and quarter, otherwise an exception is raised. =head2 with_day_of_month $tm2 = $tm1->with_day_of_month($day); Returns a copy of this instance with the given I of the month [1, 31] altered. The day must be valid for the year and month, otherwise an exception is raised. =head2 with_day_of_week $tm2 = $tm1->with_day_of_week($day); Returns a copy of this instance with the given I of the week [1=Monday, 7=Sunday] altered. =head2 with_hour $tm2 = $tm1->with_hour($hour); Returns a copy of this instance with the given I of the day [0, 23] altered. =head2 with_minute $tm2 = $tm1->with_minute($minute); Returns a copy of this instance with the given I of the hour [0, 59] altered. =head2 with_minute_of_day $tm2 = $tm1->with_minute_of_day($minute); Returns a copy of this instance with the given I of the day [0, 1439] altered, any lower-order time elements is unaltered. =head2 with_second $tm2 = $tm1->with_second($second); Returns a copy of this instance with the given I of the minute [0, 59] altered. =head2 with_second_of_day $tm2 = $tm1->with_second_of_day($second); Returns a copy of this instance with the given I of the day [0, 86_399] altered, any lower-order time elements is unaltered. =head2 with_millisecond $tm2 = $tm1->with_millisecond($millisecond); Returns a copy of this instance with the given I of the second [0, 999] altered. The nanosecond of the second is replaced with the given I multiplied by 1,000,000. =head2 with_millisecond_of_day $tm2 = $tm1->with_millisecond_of_day($millisecond); Returns a copy of this instance with the given I of the day [0, 86_400_000] altered. A millisecond value of 86_400_000 (T24:00) is normalized to midnight of the following day, any lower-order time elements is truncated. =head2 with_microsecond $tm2 = $tm1->with_microsecond($microsecond); Returns a copy of this instance with the given I of the second [0, 999_999] altered. The nanosecond of the second is replaced with the given I multiplied by 1,000. =head2 with_microsecond_of_day $tm2 = $tm1->with_microsecond_of_day($microsecond); Returns a copy of this instance with the given I of the day [0, 86_400_000_000] altered. A microsecond value of 86_400_000_000 (T24:00) is normalized to midnight of the following day, any lower-order time elements is truncated. =head2 with_nanosecond $tm2 = $tm1->with_nanosecond($nanosecond); Returns a copy of this instance with the given I of the second [0, 999_999_999] altered. =head2 with_nanosecond_of_day $tm2 = $tm1->with_nanosecond_of_day($nanosecond); Returns a copy of this instance with the given I of the day [0, 86_400_000_000_000] altered. A nanosecond value of 86_400_000_000_000 (T24:00) is normalized to midnight of the following day. =head2 with_offset_same_instant $tm2 = $tm1->with_offset_same_instant($offset); Returns a copy of this instance with the given I from UTC in minutes [-1080, 1080] (±18:00) altered. The resulting time is at the same instant. $tm = Time::Moment->from_string('2012-12-24T15-05') ->with_offset_same_instant(0); say $tm; # 2012-12-24T20Z =head2 with_offset_same_local $tm2 = $tm1->with_offset_same_local($offset); Returns a copy of this instance with the given I from UTC in minutes [-1080, 1080] (±18:00) altered. The resulting time has the same local time. $tm = Time::Moment->from_string('2012-12-24T15-05') ->with_offset_same_local(0); say $tm; # 2012-12-24T15Z =head2 with_precision $tm2 = $tm1->with_precision($precision); Returns a copy of this instance with the time of the day altered to the given I [-3, 9]. A precision value between [0, 9] alters the precision of the fractional seconds. A precision of C<-1> truncates to minute of the hour; C<-2> truncates to hour of the day; C<-3> truncates to midnight of the day. $tm = Time::Moment->from_string('2012-12-24T12:30:45.123456789Z'); say $tm->with_precision(6); # T12:30:45.123456Z say $tm->with_precision(3); # T12:30:45.123Z say $tm->with_precision(0); # T12:30:45Z say $tm->with_precision(-1); # T12:30:00Z say $tm->with_precision(-2); # T12:00:00Z say $tm->with_precision(-3); # T00:00:00Z =head2 plus_years $tm2 = $tm1->plus_years($years); Returns a copy of this instance with the given number of I added. The day of the month of the date is unchanged unless the day does not exist in the resulting month. In that case, the day is set to the last day of the resulting month. For example, 2012-02-29 plus one year results in 2013-02-28. =head2 plus_months $tm2 = $tm1->plus_months($months); Returns a copy of this instance with the given number of I added. The day of the month of the date is unchanged unless the day does not exist in the resulting month. In that case, the day is set to the last day of the resulting month. For example, 2013-01-31 plus one month results in 2013-02-28; 2013-02-28 plus one month results in 2013-03-28. =head2 plus_weeks $tm2 = $tm1->plus_weeks($weeks); Returns a copy of this instance with the given number of I added. =head2 plus_days $tm2 = $tm1->plus_days($days); Returns a copy of this instance with the given number of I added. =head2 plus_hours $tm2 = $tm1->plus_hours($hours); Returns a copy of this instance with the given number of I added. =head2 plus_minutes $tm2 = $tm1->plus_minutes($minutes); Returns a copy of this instance with the given number of I added. =head2 plus_seconds $tm2 = $tm1->plus_seconds($seconds); Returns a copy of this instance with the given number of I added. =head2 plus_milliseconds $tm2 = $tm1->plus_milliseconds($milliseconds); Returns a copy of this instance with the given number of I added. =head2 plus_microseconds $tm2 = $tm1->plus_microseconds($microseconds); Returns a copy of this instance with the given number of I added. =head2 plus_nanoseconds $tm2 = $tm1->plus_nanoseconds($nanoeconds); Returns a copy of this instance with the given number of I added. =head2 minus_years $tm2 = $tm1->minus_years($years); Returns a copy of this instance with the given number of I subtracted. The day of the month of the date is unchanged unless the day does not exist in the resulting month. In that case, the day is set to the last day of the resulting month. For example, 2012-02-29 minus one year results in 2011-02-28. =head2 minus_months $tm2 = $tm1->minus_months($months); Returns a copy of this instance with the given number of I subtracted. The day of the month of the date is unchanged unless the day does not exist in the resulting month. In that case, the day is set to the last day of the resulting month. For example, 2013-03-31 minus one month results in 2013-02-28; 2013-02-28 minus one month results in 2013-01-28. =head2 minus_weeks $tm2 = $tm1->minus_weeks($weeks); Returns a copy of this instance with the given number of I subtracted. =head2 minus_days $tm2 = $tm1->minus_days($days); Returns a copy of this instance with the given number of I subtracted. =head2 minus_hours $tm2 = $tm1->minus_hours($hours); Returns a copy of this instance with the given number of I subtracted. =head2 minus_minutes $tm2 = $tm1->minus_minutes($minutes); Returns a copy of this instance with the given number of I subtracted. =head2 minus_seconds $tm2 = $tm1->minus_seconds($seconds); Returns a copy of this instance with the given number of I subtracted. =head2 minus_milliseconds $tm2 = $tm1->minus_milliseconds($milliseconds); Returns a copy of this instance with the given number of I subtracted. =head2 minus_microseconds $tm2 = $tm1->minus_microseconds($microseconds); Returns a copy of this instance with the given number of I subtracted. =head2 minus_nanoseconds $tm2 = $tm1->minus_nanoseconds($nanoseconds); Returns a copy of this instance with the given number of I subtracted. =head2 delta_years $years = $tm->delta_years($other); Returns the difference between the local date of this moment and the I in terms of complete years. The result will be negative if the local date of the I moment is before this. =head2 delta_months $months = $tm->delta_months($other); Returns the difference between the local date of this moment and the I in terms of complete months. The result will be negative if the local date of the I moment is before this. =head2 delta_weeks $weeks = $tm->delta_weeks($other); Returns the difference between the local date of this moment and the I in terms of complete weeks. The result will be negative if the local date of the I moment is before this. =head2 delta_days $days = $tm->delta_days($other); Returns the difference between the local date of this moment and the I in terms of complete days. The result will be negative if the local date of the I moment is before this. =head2 delta_hours $hours = $tm->delta_hours($other); Returns the difference between the instant of this moment and the I in terms of complete hours. The result will be negative if the instant of the I moment is before this. =head2 delta_minutes $minutes = $tm->delta_minutes($other); Returns the difference between the instant of this moment and the I in terms of complete minutes. The result will be negative if the instant of the I moment is before this. =head2 delta_seconds $seconds = $tm->delta_seconds($other); Returns the difference between the instant of this moment and the I in terms of complete seconds. The result will be negative if the instant of the I moment is before this. =head2 delta_milliseconds $milliseconds = $tm->delta_milliseconds($other); Returns the difference between the instant of this moment and the I in terms of complete milliseconds. The result will be negative if the instant of the I moment is before this. =head2 delta_microseconds $microseconds = $tm->delta_microseconds($other); Returns the difference between the instant of this moment and the I in terms of complete microseconds. The result will be negative if the instant of the I moment is before this. =head2 delta_nanoseconds $nanoseconds = $tm->delta_nanoseconds($other); Returns the difference between the instant of this moment and the I in terms of complete nanoseconds. The result will be negative if the instant of the I moment is before this. =head2 at_utc $tm2 = $tm1->at_utc; Returns a copy of this instance with the offset from UTC set to zero. This method is equivalent to: $tm2 = $tm1->with_offset_same_instant(0); =head2 at_midnight $tm2 = $tm1->at_midnight; Returns a copy of this instance with the time of day set to midnight, T00:00:00.0. This method is equivalent to: $tm2 = $tm1->with_hour(0) ->with_minute(0) ->with_second(0) ->with_nanosecond(0); =head2 at_noon $tm2 = $tm1->at_noon; Returns a copy of this instance with the time of day set to noon, T12:00:00.0. This method is equivalent to: $tm2 = $tm1->with_hour(12) ->with_minute(0) ->with_second(0) ->with_nanosecond(0); =head2 at_last_day_of_year $tm2 = $tm1->at_last_day_of_year; Returns a copy of this instance with the date adjusted to the last day of the year, the time of the day is unaltered. =head2 at_last_day_of_quarter $tm2 = $tm1->at_last_day_of_quarter; Returns a copy of this instance with the date adjusted to the last day of the quarter, the time of the day is unaltered. =head2 at_last_day_of_month $tm2 = $tm1->at_last_day_of_month; Returns a copy of this instance with the date adjusted to the last day of the month, the time of the day is unaltered. =head2 is_before $boolean = $tm->is_before($other); Returns a boolean indicating whether or not the instant of this time is before the I time. =head2 is_after $boolean = $tm->is_after($other); Returns a boolean indicating whether or not the instant of this time is after the I time. =head2 is_equal $boolean = $tm->is_equal($other); Returns a boolean indicating whether or not the instant of this time is equal the I time. =head2 compare $integer = $tm->compare($other); $integer = $tm->compare($other [, precision => 9]); Returns an integer indicating whether the instant of this time is before, after or equal the I time. Returns a value less than zero if this time is before the other; zero if this date is equal the other time; a value greater than zero if this time is after the other time. The optional parameter I [-3, 9] specifies the precision of the comparison. The default precision is 9 (nanoseconds). Please see L for an explanation of the precision value. =head2 is_leap_year $boolean = $tm->is_leap_year; Returns a boolean indicating whether or not the year of the local date of this moment is a leap year. =head2 to_string $string = $tm->to_string; $string = $tm->to_string([reduced => false]); Returns a string representation of the instance. If the optional named boolean parameter I is true a shorter representation is attempted. The string will be in one of the following representations: YYYY-MM-DDThh:mm (only if reduced => true) YYYY-MM-DDThh:mm:ss YYYY-MM-DDThh:mm:ss.fff YYYY-MM-DDThh:mm:ss.ffffff YYYY-MM-DDThh:mm:ss.fffffffff Followed by a zone designator in one of the following representations: Z ±hh (only if reduced => true) ±hh:mm The shortest representation will be used where the omitted parts are implied to be zero. =head2 strftime $string = $tm->strftime($format); Formats time according to the conversion specifications in the given C<$format> string. The format string consists of zero or more conversion specifications and ordinary characters. All ordinary characters are copied directly into the resulting string. A conversion specification consists of a percent sign C<%> and one other character. The following conversion specifications are supported: =over 4 =item C<%a> Replaced by the C locale's abbreviated day of the week name. Example: Mon, Tue, ..., Sun. =item C<%A> Replaced by the C locale's full day of the week name. Example: Monday, Tuesday, ..., Sunday. =item C<%b> Replaced by the C locale's abbreviated month name. Example: Jan, Feb, ..., Dec. =item C<%B> Replaced by the C locale's full month name. Example: January, February, ..., December. =item C<%c> Replaced by the C locale's date and time representation. Equivalent to C<"%a %b %e %H:%M:%S %Y">. =item C<%C> Replaced by the year divided by 100 and truncated to an integer, as a decimal number [00, 99]. =item C<%d> Replaced by the day of the month as a decimal number [01, 31]. =item C<%D> Equivalent to C<"%m/%d/%y">. =item C<%e> Replaced by the day of the month as a decimal number [1, 31]; a single digit is preceded by a space. =item C<%f> Replaced by the fractional second including the preceding decimal point or by an empty string if no fractional seconds are present. This conversion specification permits use of an optional maximum field width [0, 9] where the default field width of 0 will use the shortest of the following representations: .fff (millisecond) .ffffff (microsecond) .fffffffff (nanosecond) Example: $tm = Time::Moment->from_string('2012-12-24T15:30:45.123456Z'); $tm->strftime('%f'); # '.123456' $tm->strftime('%3f'); # '.123' $tm->strftime('%9f'); # '.123456000' $tm = Time::Moment->from_string('2012-12-24T15:30:45Z'); $tm->strftime('%f'); # '' $tm->strftime('%3f'); # '' C<%3f> is replaced by decimal point and exactly three fractional digits (zero-padded on the right or truncated if needed) if fractional seconds are present. I>. =item C<%F> Equivalent to C<"%Y-%m-%d">. =item C<%g> Replaced by the last 2 digits of the year of the week as a decimal number [00, 99]. =item C<%G> Replaced by the week-based year as a decimal number [0001, 9999]. =item C<%h> Equivalent to C<%b>. =item C<%H> Replaced by the hour of day (24-hour clock) as a decimal number [00, 23]. =item C<%I> Replaced by the hour of day (12-hour clock) as a decimal number [01, 12]. =item C<%j> Replaced by the day of the year as a decimal number [001, 366]. =item C<%k> Replaced by the hour of day (24-hour clock) as a decimal number [1, 23]; a single digit is preceded by a space. I>. =item C<%l> Replaced by the hour of day (12-hour clock) as a decimal number [1, 12]; a single digit is preceded by a space. I>. =item C<%m> Replaced by the month of the year as a decimal number [01, 12]. =item C<%M> Replaced by the minute of hour as a decimal number [00, 59]. =item C<%n> Replaced by a character. =item C<%N> Replaced by the fractional second as a decimal number. This conversion specification permits use of an optional maximum field width [0, 9] where the default field width of 0 will use the shortest of the following representations: fff (millisecond) ffffff (microsecond) fffffffff (nanosecond) Example: $tm = Time::Moment->from_string('2012-12-24T15:30:45.123456Z'); $tm->strftime('%N'); # '123456' $tm->strftime('%3N'); # '123' $tm->strftime('%9N'); # '123456000' C<%3N> is replaced by exactly three fractional digits (zero-padded on the right or truncated if needed). I>. =item C<%p> Replaced by the C locale's meridian notation. Example: AM, PM. =item C<%r> Replaced by the C locale's time in a.m. and p.m. notation. Equivalent to C<"%I:%M:%S %p">. =item C<%R> Replaced by the time in 24-hour notation. Equivalent to C<"%H:%M">. =item C<%s> Replaced by the number of seconds from the epoch of 1970-01-01T00:00:00Z as a decimal number. I>. =item C<%S> Replaced by the second of hour as a decimal number [00, 59]. =item C<%t> Replaced by a character. =item C<%T> Replaced by the time of day. Equivalent to C<"%H:%M:%S">. =item C<%u> Replaced by the day of the week as a decimal number [1, 7], with 1 representing Monday. =item C<%U> Replaced by the week number of the year as a decimal number [00, 53]. The first Sunday of January is the first day of week 1; days in the new year before this are in week 0. =item C<%V> Replaced by the week number of the year (Monday as the first day of the week) as a decimal number [01, 53]. If the week containing 1 January has four or more days in the new year, then it is considered week 1. Otherwise, it is the last week of the previous year, and the next week is week 1. Both January 4th and the first Thursday of January are always in week 1. =item C<%w> Replaced by the day of the week as a decimal number [0, 6], with 0 representing Sunday. =item C<%W> Replaced by the week number of the year as a decimal number [00, 53]. The first Monday of January is the first day of week 1; days in the new year before this are in week 0. =item C<%x> Replaced by the C locale's date representation. Equivalent to C<"%m/%d/%y">. =item C<%X> Replaced by the C locale's time representation. Equivalent to C<"%H:%M:%S">. =item C<%y> Replaced by the last two digits of the year as a decimal number [00, 99]. =item C<%Y> Replaced by the year as a decimal number [0001, 9999]. =item C<%z> Replaced by the offset from UTC in the ISO 8601 basic format (±hhmm). =item C<%:z> Replaced by the offset from UTC in the ISO 8601 extended format (±hh:mm). =item C<%Z> Replaced by the offset from UTC in the ISO 8601 extended format or by UTC designator (±hh:mm or Z). =item C<%%> Replaced by %. =back =head2 length_of_year $integer = $tm->length_of_year; Returns the length of the year in days [365, 366]. =head2 length_of_quarter $integer = $tm->length_of_quarter; Returns the length of the quarter of the year in days [90, 92]. =head2 length_of_month $integer = $tm->length_of_month; Returns the length of the month of the year in days [28, 31]. =head2 length_of_week_year $integer = $tm->length_of_week_year; Returns the length of the week of the year in weeks [52, 53]. =head2 utc_rd_values ($rdn, $sod, $nanosecond) = $tm->utc_rd_values; Returns a list of three elements: =over 4 =item C<$rdn> The number of integral days from the Rata Die epoch of 0000-12-31. =item C<$sod> The second of the day [0, 86_399]. =item C<$nanosecond> The nanosecond of the second [0, 999_999_999]. =back =head2 utc_rd_as_seconds $seconds = $tm->utc_rd_as_seconds; Returns the number of integral seconds from the Rata Die epoch of 0000-12-31T00:00:00Z. =head2 local_rd_values ($rdn, $sod, $nanosecond) = $tm->local_rd_values; Returns a list of three elements: =over 4 =item C<$rdn> The number of integral days from the Rata Die epoch of 0000-12-31. =item C<$sod> The second of the day [0, 86_399]. =item C<$nanosecond> The nanosecond of the second [0, 999_999_999]. =back =head2 local_rd_as_seconds $seconds = $tm->local_rd_as_seconds; Returns the number of integral seconds from the Rata Die epoch of 0000-12-31T00:00:00. =head1 OVERLOADED OPERATORS =head2 stringification $string = "$tm"; The C<$string> will be in one of the following representations: YYYY-MM-DDThh:mm:ss YYYY-MM-DDThh:mm:ss.fff YYYY-MM-DDThh:mm:ss.ffffff YYYY-MM-DDThh:mm:ss.fffffffff Followed by a zone designator in one of the following representations: Z ±hh:mm The shortest representation will be used where the omitted parts are implied to be zero. This representation is conformant with ISO 8601 profiles, such as: =over 4 =item * L =item * L =item * L =item * L =item * L =back The C method or the C format string C<"%Y-%m-%dT%H:%M:%S%f%Z"> produces an equivalent string representation: "$tm" eq $tm->to_string; "$tm" eq $tm->strftime("%Y-%m-%dT%H:%M:%S%f%Z"); The total length of the string representation will be between 20 and 35 characters (inclusive). =head2 comparison $integer = $tm1 <=> $tm2; $boolean = $tm1 == $tm2; $boolean = $tm1 != $tm2; $boolean = $tm1 < $tm2; $boolean = $tm1 > $tm2; $boolean = $tm1 <= $tm2; $boolean = $tm1 >= $tm2; =head1 SERIALIZATION =head2 Storable The serialized representation of a C is a string of 16 bytes that contains MAGIC (2 bytes), time zone offset from UTC (2 bytes), the number of days from Rata Die (4 bytes), second of the day (4 bytes) and nanosecond of the second (4 bytes). The total size of the serialized C instance using C is 34 bytes. =head2 JSON C implements a C method that returns the L representation of the instance. =head2 CBOR C implements a C method that returns the L representation of the instance using tag C<0> (I). See L, L and C for an example how to roundtrip instances of C. =head2 Sereal L version 2.030 or later implements support for the generic serialization protocol C. =head2 FREEZE/THAW C implements a C method that returns the L representation of the instance and a C method according to the serialization protocol specified in L. =head1 EXAMPLE FORMAT STRINGS =head2 ISO 8601 - Data elements and interchange formats =head3 Date Calendar date - 24 December 2012 Basic format: Example: %Y%m%d 20121224 %y%m 201212 (reduced accuracy) Extended format: Example: %Y-%m-%d 2012-12-24 %Y-%m 2012-12 (reduced accuracy) Ordinal date - 24 December 2012 Basic format: Example: %Y%j 2012359 Extended format: Example: %Y-%j 2012-359 Week date - Monday, 24 December 2012 Basic format: Example: %GW%V%u 2012W521 %GW%V 2012W52 (reduced accuracy) Extended format: Example: %G-W%V-%u 2012-W52-1 %G-W%V 2012-W52 (reduced accuracy) =head3 Time of day Local time - 30 minutes and 45 seconds past 15 hours Basic format: Example: %H%M%S 153045 %H%M 1530 (reduced accuracy) Extended format: Example: %H:%M:%S 15:30:45 %H:%M 15:30 (reduced accuracy) Local time with decimal fractions - 30 minutes and 45 and a half second past 15 hours Basic format: Example: %H%M%S%f 153045.500 %H%M%S.%1N 153045.5 Extended format: Example: %H:%M:%S%f 15:30:45.500 %H:%M:%S.%1N 15:30:45.5 Local time and the difference from UTC - 30 minutes and 45 seconds past 15 hours, one hour ahead of UTC Basic format: Example: %H%M%S%z 153045+0100 Extended format: Example: %H:%M:%S%Z 15:30:45+01:00 =head3 Date and time of day Combinations of calendar date and time of day Basic format: Example: %Y%m%dT%H%M%S%z 20121224T153045+0100 %Y%m%dT%H%M%S%f%z 20121224T153045.500+0100 %Y%m%dT%H%M%z 20121224T1530+0100 (reduced accuracy) Extended format: Example: %Y-%m-%dT%H:%M:%S%Z 2012-12-24T15:30:45+01:00 %Y-%m-%dT%H:%M:%S%f%Z 2012-12-24T15:30:45.500+01:00 %Y-%m-%dT%H:%M%Z 2012-12-24T15:30+01:00 (reduced accuracy) Combinations of ordinal date and time of day Basic format: Example: %Y%jT%H%M%S%z 2012359T153045+0100 %Y%jT%H%M%S%f%z 2012359T153045.500+0100 %Y%jT%H%M%z 2012359T1530+0100 (reduced accuracy) Extended format: Example: %Y-%jT%H:%M:%S%Z 2012-359T15:30:45+01:00 %Y-%jT%H:%M:%S%f%Z 2012-359T15:30:45.500+01:00 %Y-%jT%H:%M%Z 2012-359T15:30+01:00 (reduced accuracy) Combinations of week date and time of day Basic format: Example: %GW%V%uT%H%M%S%z 2012W521T153045+0100 %GW%V%uT%H%M%S%f%z 2012W521T153045.500+0100 %GW%V%uT%H%M%f%z 2012W521T1530+0100 (reduced accuracy) Extended format: Example: %G-W%V-%uT%H:%M:%S%Z 2012-W52-1T15:30:45+01:00 %G-W%V-%uT%H:%M:%S%f%Z 2012-W52-1T15:30:45.500+01:00 %G-W%V-%uT%H:%M%Z 2012-W52-1T15:30+01:00 (reduced accuracy) =head2 ISO 9075 - Information technology - Database languages - SQL Literal values from Part 2: Foundation (SQL/Foundation) Date: Example: %Y-%m-%d 2012-12-24 Time: Example: %H:%M:%S 15:30:45 %H:%M:%S%f 15:30:45.500 Timestamp: Example: %Y-%m-%d %H:%M:%S 2012-12-24 15:30:45 %Y-%m-%d %H:%M:%S %:z 2012-12-24 15:30:45 +01:00 %Y-%m-%d %H:%M:%S%f 2012-12-24 15:30:45.500 %Y-%m-%d %H:%M:%S%f %:z 2012-12-24 15:30:45.500 +01:00 =head2 RFC 1123 - Requirements for Internet Hosts L as updated by L. Format: Example: %a, %d %b %Y %H:%M:%S %z Mon, 24 Dec 2012 15:30:45 +0100 =head2 RFC 2616 - HTTP/1.1 L. Format: Example: %a, %d %b %Y %H:%M:%S GMT Mon, 24 Dec 2012 14:30:45 GMT An HTTP date value represents time as an instance of UTC: $string = $tm->at_utc->strftime("%a, %d %b %Y %H:%M:%S GMT"); =head2 RFC 5322 - Internet Message Format L. Format: Example: %a, %d %b %Y %H:%M:%S %z Mon, 24 Dec 2012 15:30:45 +0100 %a, %d %b %Y %H:%M %z Mon, 24 Dec 2012 15:30 +0100 %d %b %Y %H:%M:%S %z 24 Dec 2012 15:30:45 +0100 %d %b %Y %H:%M %z 24 Dec 2012 15:30 +0100 =head1 TIME ZONES An instance of C represents an unambiguous point in time, but it's not time zone aware. When performing arithmetic on the local date/time or altering the components of the local date/time it may be necessary to use a time zone to convert to the correct representation. C is API compatible with L and L. =head2 Converting from instant time to designated time zone $tm = Time::Moment->new( year => 2012, month => 12, day => 24, hour => 15 ); $zone = DateTime::TimeZone->new(name => 'America/New_York'); $offset = $zone->offset_for_datetime($tm) / 60; say $tm->with_offset_same_instant($offset); # 2012-12-24T10-05 =head2 Converting from local time to designated time zone $tm = Time::Moment->new( year => 2012, month => 12, day => 24, hour => 15 ); $zone = DateTime::TimeZone->new(name => 'America/New_York'); $offset = $zone->offset_for_local_datetime($tm) / 60; say $tm->with_offset_same_local($offset); # 2012-12-24T15-05 =head2 The Effect of Daylight Saving Time The time zone I has 01:00 UTC as standard time, and 02:00 UTC as daylight savings time, with transition dates according to the L. $zone = DateTime::TimeZone->new(name => 'Europe/Brussels'); sub convert_from_instant { my ($tm, $zone) = @_; my $offset = $zone->offset_for_datetime($tm) / 60; return $tm->with_offset_same_instant($offset); } sub convert_from_local { my ($tm, $zone) = @_; my $offset = $zone->offset_for_local_datetime($tm) / 60; return $tm->with_offset_same_local($offset); } European Summer Time begins (clocks go forward) at 01:00 UTC on the last Sunday in March, in 2014 the transition date was March 30. $tm1 = Time::Moment->from_string('2014-03-29T12+01'); $tm2 = $tm1->plus_hours(24); say convert_from_instant($tm2, $zone); # 2014-03-30T13+02 say convert_from_local($tm2, $zone); # 2014-03-30T12+02 During the transition from standard time to daylight savings time, the local time interval between 02:00:00 and 02:59:59 does not exist. Local time values in that interval are invalid. C raises an exception when attempting to convert non-existing local time. $tm1 = Time::Moment->from_string('2014-03-29T22+01'); $tm2 = $tm1->plus_hours(4); say convert_from_instant($tm2, $zone); # 2014-03-30T03+02 say convert_from_local($tm2, $zone); # raises an exception European Summer Time ends (clocks go backward) at 01:00 UTC on the last Sunday in October, in 2014 the transition date was October 26. $tm1 = Time::Moment->from_string('2014-10-25T12+02'); $tm2 = $tm1->plus_hours(24); say convert_from_instant($tm2, $zone); # 2014-10-26T11+01 say convert_from_local($tm2, $zone); # 2014-10-26T12+01 During the transition from daylight savings time to standard time, the local time interval between 02:00:00 and 02:59:59 is repeated. Local time values in that interval are ambiguous because they occur twice. When C converts an ambiguous local time it returns the numerically lowest offset (usually the standard one). $tm1 = Time::Moment->from_string('2014-10-25T22+02'); $tm2 = $tm1->plus_hours(4); say convert_from_instant($tm2, $zone); # 2014-10-26T02+02 say convert_from_local($tm2, $zone); # 2014-10-26T02+01 =head1 DIAGNOSTICS =over 4 =item B<(F)> Usage: %s Method called with wrong number of arguments. =item B<(F)> Parameter '%s' is out of range =item B<(F)> Parameter '%s' is out of the range [%d, %d] =item B<(F)> Cannot coerce object of type %s to Time::Moment =item B<(F)> Could not parse the given string =item B<(F)> %s is not an instance of Time::Moment =item B<(F)> A %s object can only be compared to another %s object ('%s', '%s') =back =head1 THREAD SAFETY C is thread safe. =head1 SEE ALSO L L =head1 SUPPORT =head2 Bugs / Feature Requests Please report any bugs or feature requests through the issue tracker at L. You will be notified automatically of any progress on your issue. =head2 SOURCE CODE This is open source software. The code repository is available for public review and contribution under the terms of the license. L git clone https://github.com/chansen/p5-time-moment =head1 AUTHOR Christian Hansen C =head1 COPYRIGHT Copyright 2013-2017 by Christian Hansen. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Time-Moment-0.44/lib/Time/Moment/Adjusters.pm000644 000765 000024 00000010676 13274643453 021610 0ustar00chansenstaff000000 000000 package Time::Moment::Adjusters; use strict; use warnings; use Carp qw[]; BEGIN { our $VERSION = '0.44'; our @EXPORT_OK = qw[ NextDayOfWeek NextOrSameDayOfWeek PreviousDayOfWeek PreviousOrSameDayOfWeek FirstDayOfWeekInMonth LastDayOfWeekInMonth NthDayOfWeekInMonth WesternEasterSunday OrthodoxEasterSunday NearestMinuteInterval ]; our %EXPORT_TAGS = ( all => [ @EXPORT_OK ], ); require Exporter; *import = \&Exporter::import; } sub NextDayOfWeek { @_ == 1 or Carp::croak(q); my ($day) = @_; ($day >= 1 && $day <= 7) or Carp::croak(q); return sub { my ($tm) = @_; return $tm->plus_days(($day - $tm->day_of_week + 6) % 7 + 1); }; } sub NextOrSameDayOfWeek { @_ == 1 or Carp::croak(q); my ($day) = @_; ($day >= 1 && $day <= 7) or Carp::croak(q); return sub { my ($tm) = @_; return $tm->plus_days(($day - $tm->day_of_week) % 7); }; } sub PreviousDayOfWeek { @_ == 1 or Carp::croak(q); my ($day) = @_; ($day >= 1 && $day <= 7) or Carp::croak(q); return sub { my ($tm) = @_; return $tm->minus_days(($tm->day_of_week - $day + 6) % 7 + 1); }; } sub PreviousOrSameDayOfWeek { @_ == 1 or Carp::croak(q); my ($day) = @_; ($day >= 1 && $day <= 7) or Carp::croak(q); return sub { my ($tm) = @_; return $tm->minus_days(($tm->day_of_week - $day) % 7); }; } sub FirstDayOfWeekInMonth { @_ == 1 or Carp::croak(q); my ($day) = @_; ($day >= 1 && $day <= 7) or Carp::croak(q); return sub { my ($tm) = @_; $tm = $tm->with_day_of_month(1); return $tm->plus_days(($day - $tm->day_of_week) % 7); }; } sub LastDayOfWeekInMonth { @_ == 1 or Carp::croak(q); my ($day) = @_; ($day >= 1 && $day <= 7) or Carp::croak(q); return sub { my ($tm) = @_; $tm = $tm->at_last_day_of_month; return $tm->minus_days(($tm->day_of_week - $day) % 7); }; } sub NthDayOfWeekInMonth { @_ == 2 or Carp::croak(q); my ($ordinal, $day) = @_; ($ordinal >= -4 && $ordinal <= 4 && $ordinal != 0) or Carp::croak(q); ($day >= 1 && $day <= 7) or Carp::croak(q); if ($ordinal > 0) { my $days = 7 * --$ordinal; return sub { my ($tm) = @_; $tm = $tm->with_day_of_month(1); return $tm->plus_days($days + ($day - $tm->day_of_week) % 7); }; } else { my $days = 7 * ++$ordinal; return sub { my ($tm) = @_; $tm = $tm->at_last_day_of_month; return $tm->plus_days($days - ($tm->day_of_week - $day) % 7); }; } } sub WesternEasterSunday { @_ == 0 or Carp::croak(q); return sub { my ($tm) = @_; return $tm->with_rdn(Time::Moment::Internal::western_easter_sunday($tm->year)); }; } sub OrthodoxEasterSunday { @_ == 0 or Carp::croak(q); return sub { my ($tm) = @_; return $tm->with_rdn(Time::Moment::Internal::orthodox_easter_sunday($tm->year)); }; } sub NearestMinuteInterval { @_ == 1 or Carp::croak(q); my ($interval) = @_; ($interval >= 1 && $interval <= 1440) or Carp::croak(q); my $msec = $interval * 60 * 1000; my $mid = int(($msec + 1) / 2); return sub { my ($tm) = @_; my $msod = $msec * int(($tm->millisecond_of_day + $mid) / $msec); return $tm->with_millisecond_of_day($msod); }; } 1; Time-Moment-0.44/lib/Time/Moment/Adjusters.pod000644 000765 000024 00000007111 13072612120 021723 0ustar00chansenstaff000000 000000 =encoding utf-8 =head1 NAME Time::Moment::Adjusters - Adjusters for Time::Moment =head1 SYNOPSIS $adjuster = NextDayOfWeek($day); $adjuster = NextOrSameDayOfWeek($day); $adjuster = PreviousDayOfWeek($day); $adjuster = PreviousOrSameDayOfWeek($day); $adjuster = FirstDayOfWeekInMonth($day); $adjuster = LastDayOfWeekInMonth($day); $adjuster = NthDayOfWeekInMonth($ordinal, $day); $adjuster = WesternEasterSunday(); $adjuster = OrthodoxEasterSunday(); $adjuster = NearestMinuteInterval($interval); =head1 DESCRIPTION C provides adjusters. An adjuster is a CODE reference invoked with an instance of Time::Moment and is expected to return an instance of Time::Moment. =head1 FUNCTIONS =head2 NextDayOfWeek $adjuster = NextDayOfWeek($day); The C<$adjuster> adjusts the date to the next occurrence of the given I of the week [1=Monday, 7=Sunday] that is after the date. =head2 NextOrSameDayOfWeek $adjuster = NextOrSameDayOfWeek($day); The C<$adjuster> adjusts the date to the next occurrence of the given I of the week [1=Monday, 7=Sunday]. If the date already falls on the given I of the week it's unaltered. =head2 PreviousDayOfWeek $adjuster = PreviousDayOfWeek($day); The C<$adjuster> adjusts the date to the previous occurrence of the given I of the week [1=Monday, 7=Sunday] that is before the date. =head2 PreviousOrSameDayOfWeek $adjuster = PreviousOrSameDayOfWeek($day); The C<$adjuster> adjusts the date to the previous occurrence of the given I of the week [1=Monday, 7=Sunday]. If the date already falls on the given I of the week it's unaltered. =head2 FirstDayOfWeekInMonth $adjuster = FirstDayOfWeekInMonth($day); The C<$adjuster> adjusts the date to the first occurrence of the given I of the week [1=Monday, 7=Sunday] within the month. =head2 LastDayOfWeekInMonth $adjuster = LastDayOfWeekInMonth($day); The C<$adjuster> adjusts the date to the last occurrence of the given I of the week [1=Monday, 7=Sunday] within the month. =head2 NthDayOfWeekInMonth $adjuster = NthDayOfWeekInMonth($ordinal, $day); The C<$adjuster> adjusts the date to the given I I of the week within the month. B =over 4 =item ordinal The I of the week within the month [-4, -1] ∪ [1, 4]. =item day The I of the week [1=Monday, 7=Sunday]. =back =head2 WesternEasterSunday $adjuster = WesternEasterSunday(); The C<$adjuster> adjusts the date to the Western Easter Sunday. The Western computus is based on the Gregorian calendar. =head2 OrthodoxEasterSunday $adjuster = OrthodoxEasterSunday(); The C<$adjuster> adjusts the date to the Orthodox Easter Sunday. The Orthodox computus is based on the Julian calendar with the Julian date converted to the equivalent Gregorian date. =head2 NearestMinuteInterval $adjuster = NearestMinuteInterval($interval); The C<$adjuster> adjusts the time of day to the nearest minute of the given minute I [1, 1440]. Given an minute interval of C<30>: T10:14:59 => T10:00:00 T10:15:00 => T10:30:00 T10:29:59 => T10:30:00 T23:55:00 => T00:00:00 (midnight of the following day) =head1 EXPORTS None by default. All functions can be exported using the C<:all> tag or individually. =head1 AUTHOR Christian Hansen C =head1 COPYRIGHT Copyright 2015-2017 by Christian Hansen. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. Time-Moment-0.44/inc/Module/000755 000765 000024 00000000000 13274643625 016370 5ustar00chansenstaff000000 000000 Time-Moment-0.44/inc/Module/Install/000755 000765 000024 00000000000 13274643625 017776 5ustar00chansenstaff000000 000000 Time-Moment-0.44/inc/Module/Install.pm000644 000765 000024 00000030217 13274643621 020333 0ustar00chansenstaff000000 000000 #line 1 package Module::Install; # For any maintainers: # The load order for Module::Install is a bit magic. # It goes something like this... # # IF ( host has Module::Install installed, creating author mode ) { # 1. Makefile.PL calls "use inc::Module::Install" # 2. $INC{inc/Module/Install.pm} set to installed version of inc::Module::Install # 3. The installed version of inc::Module::Install loads # 4. inc::Module::Install calls "require Module::Install" # 5. The ./inc/ version of Module::Install loads # } ELSE { # 1. Makefile.PL calls "use inc::Module::Install" # 2. $INC{inc/Module/Install.pm} set to ./inc/ version of Module::Install # 3. The ./inc/ version of Module::Install loads # } use 5.006; use strict 'vars'; use Cwd (); use File::Find (); use File::Path (); use vars qw{$VERSION $MAIN}; BEGIN { # All Module::Install core packages now require synchronised versions. # This will be used to ensure we don't accidentally load old or # different versions of modules. # This is not enforced yet, but will be some time in the next few # releases once we can make sure it won't clash with custom # Module::Install extensions. $VERSION = '1.16'; # Storage for the pseudo-singleton $MAIN = undef; *inc::Module::Install::VERSION = *VERSION; @inc::Module::Install::ISA = __PACKAGE__; } sub import { my $class = shift; my $self = $class->new(@_); my $who = $self->_caller; #------------------------------------------------------------- # all of the following checks should be included in import(), # to allow "eval 'require Module::Install; 1' to test # installation of Module::Install. (RT #51267) #------------------------------------------------------------- # Whether or not inc::Module::Install is actually loaded, the # $INC{inc/Module/Install.pm} is what will still get set as long as # the caller loaded module this in the documented manner. # If not set, the caller may NOT have loaded the bundled version, and thus # they may not have a MI version that works with the Makefile.PL. This would # result in false errors or unexpected behaviour. And we don't want that. my $file = join( '/', 'inc', split /::/, __PACKAGE__ ) . '.pm'; unless ( $INC{$file} ) { die <<"END_DIE" } Please invoke ${\__PACKAGE__} with: use inc::${\__PACKAGE__}; not: use ${\__PACKAGE__}; END_DIE # This reportedly fixes a rare Win32 UTC file time issue, but # as this is a non-cross-platform XS module not in the core, # we shouldn't really depend on it. See RT #24194 for detail. # (Also, this module only supports Perl 5.6 and above). eval "use Win32::UTCFileTime" if $^O eq 'MSWin32' && $] >= 5.006; # If the script that is loading Module::Install is from the future, # then make will detect this and cause it to re-run over and over # again. This is bad. Rather than taking action to touch it (which # is unreliable on some platforms and requires write permissions) # for now we should catch this and refuse to run. if ( -f $0 ) { my $s = (stat($0))[9]; # If the modification time is only slightly in the future, # sleep briefly to remove the problem. my $a = $s - time; if ( $a > 0 and $a < 5 ) { sleep 5 } # Too far in the future, throw an error. my $t = time; if ( $s > $t ) { die <<"END_DIE" } Your installer $0 has a modification time in the future ($s > $t). This is known to create infinite loops in make. Please correct this, then run $0 again. END_DIE } # Build.PL was formerly supported, but no longer is due to excessive # difficulty in implementing every single feature twice. if ( $0 =~ /Build.PL$/i ) { die <<"END_DIE" } Module::Install no longer supports Build.PL. It was impossible to maintain duel backends, and has been deprecated. Please remove all Build.PL files and only use the Makefile.PL installer. END_DIE #------------------------------------------------------------- # To save some more typing in Module::Install installers, every... # use inc::Module::Install # ...also acts as an implicit use strict. $^H |= strict::bits(qw(refs subs vars)); #------------------------------------------------------------- unless ( -f $self->{file} ) { foreach my $key (keys %INC) { delete $INC{$key} if $key =~ /Module\/Install/; } local $^W; require "$self->{path}/$self->{dispatch}.pm"; File::Path::mkpath("$self->{prefix}/$self->{author}"); $self->{admin} = "$self->{name}::$self->{dispatch}"->new( _top => $self ); $self->{admin}->init; @_ = ($class, _self => $self); goto &{"$self->{name}::import"}; } local $^W; *{"${who}::AUTOLOAD"} = $self->autoload; $self->preload; # Unregister loader and worker packages so subdirs can use them again delete $INC{'inc/Module/Install.pm'}; delete $INC{'Module/Install.pm'}; # Save to the singleton $MAIN = $self; return 1; } sub autoload { my $self = shift; my $who = $self->_caller; my $cwd = Cwd::getcwd(); my $sym = "${who}::AUTOLOAD"; $sym->{$cwd} = sub { my $pwd = Cwd::getcwd(); if ( my $code = $sym->{$pwd} ) { # Delegate back to parent dirs goto &$code unless $cwd eq $pwd; } unless ($$sym =~ s/([^:]+)$//) { # XXX: it looks like we can't retrieve the missing function # via $$sym (usually $main::AUTOLOAD) in this case. # I'm still wondering if we should slurp Makefile.PL to # get some context or not ... my ($package, $file, $line) = caller; die <<"EOT"; Unknown function is found at $file line $line. Execution of $file aborted due to runtime errors. If you're a contributor to a project, you may need to install some Module::Install extensions from CPAN (or other repository). If you're a user of a module, please contact the author. EOT } my $method = $1; if ( uc($method) eq $method ) { # Do nothing return; } elsif ( $method =~ /^_/ and $self->can($method) ) { # Dispatch to the root M:I class return $self->$method(@_); } # Dispatch to the appropriate plugin unshift @_, ( $self, $1 ); goto &{$self->can('call')}; }; } sub preload { my $self = shift; unless ( $self->{extensions} ) { $self->load_extensions( "$self->{prefix}/$self->{path}", $self ); } my @exts = @{$self->{extensions}}; unless ( @exts ) { @exts = $self->{admin}->load_all_extensions; } my %seen; foreach my $obj ( @exts ) { while (my ($method, $glob) = each %{ref($obj) . '::'}) { next unless $obj->can($method); next if $method =~ /^_/; next if $method eq uc($method); $seen{$method}++; } } my $who = $self->_caller; foreach my $name ( sort keys %seen ) { local $^W; *{"${who}::$name"} = sub { ${"${who}::AUTOLOAD"} = "${who}::$name"; goto &{"${who}::AUTOLOAD"}; }; } } sub new { my ($class, %args) = @_; delete $INC{'FindBin.pm'}; { # to suppress the redefine warning local $SIG{__WARN__} = sub {}; require FindBin; } # ignore the prefix on extension modules built from top level. my $base_path = Cwd::abs_path($FindBin::Bin); unless ( Cwd::abs_path(Cwd::getcwd()) eq $base_path ) { delete $args{prefix}; } return $args{_self} if $args{_self}; $args{dispatch} ||= 'Admin'; $args{prefix} ||= 'inc'; $args{author} ||= ($^O eq 'VMS' ? '_author' : '.author'); $args{bundle} ||= 'inc/BUNDLES'; $args{base} ||= $base_path; $class =~ s/^\Q$args{prefix}\E:://; $args{name} ||= $class; $args{version} ||= $class->VERSION; unless ( $args{path} ) { $args{path} = $args{name}; $args{path} =~ s!::!/!g; } $args{file} ||= "$args{base}/$args{prefix}/$args{path}.pm"; $args{wrote} = 0; bless( \%args, $class ); } sub call { my ($self, $method) = @_; my $obj = $self->load($method) or return; splice(@_, 0, 2, $obj); goto &{$obj->can($method)}; } sub load { my ($self, $method) = @_; $self->load_extensions( "$self->{prefix}/$self->{path}", $self ) unless $self->{extensions}; foreach my $obj (@{$self->{extensions}}) { return $obj if $obj->can($method); } my $admin = $self->{admin} or die <<"END_DIE"; The '$method' method does not exist in the '$self->{prefix}' path! Please remove the '$self->{prefix}' directory and run $0 again to load it. END_DIE my $obj = $admin->load($method, 1); push @{$self->{extensions}}, $obj; $obj; } sub load_extensions { my ($self, $path, $top) = @_; my $should_reload = 0; unless ( grep { ! ref $_ and lc $_ eq lc $self->{prefix} } @INC ) { unshift @INC, $self->{prefix}; $should_reload = 1; } foreach my $rv ( $self->find_extensions($path) ) { my ($file, $pkg) = @{$rv}; next if $self->{pathnames}{$pkg}; local $@; my $new = eval { local $^W; require $file; $pkg->can('new') }; unless ( $new ) { warn $@ if $@; next; } $self->{pathnames}{$pkg} = $should_reload ? delete $INC{$file} : $INC{$file}; push @{$self->{extensions}}, &{$new}($pkg, _top => $top ); } $self->{extensions} ||= []; } sub find_extensions { my ($self, $path) = @_; my @found; File::Find::find( sub { my $file = $File::Find::name; return unless $file =~ m!^\Q$path\E/(.+)\.pm\Z!is; my $subpath = $1; return if lc($subpath) eq lc($self->{dispatch}); $file = "$self->{path}/$subpath.pm"; my $pkg = "$self->{name}::$subpath"; $pkg =~ s!/!::!g; # If we have a mixed-case package name, assume case has been preserved # correctly. Otherwise, root through the file to locate the case-preserved # version of the package name. if ( $subpath eq lc($subpath) || $subpath eq uc($subpath) ) { my $content = Module::Install::_read($subpath . '.pm'); my $in_pod = 0; foreach ( split /\n/, $content ) { $in_pod = 1 if /^=\w/; $in_pod = 0 if /^=cut/; next if ($in_pod || /^=cut/); # skip pod text next if /^\s*#/; # and comments if ( m/^\s*package\s+($pkg)\s*;/i ) { $pkg = $1; last; } } } push @found, [ $file, $pkg ]; }, $path ) if -d $path; @found; } ##################################################################### # Common Utility Functions sub _caller { my $depth = 0; my $call = caller($depth); while ( $call eq __PACKAGE__ ) { $depth++; $call = caller($depth); } return $call; } # Done in evals to avoid confusing Perl::MinimumVersion eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@; sub _read { local *FH; open( FH, '<', $_[0] ) or die "open($_[0]): $!"; binmode FH; my $string = do { local $/; }; close FH or die "close($_[0]): $!"; return $string; } END_NEW sub _read { local *FH; open( FH, "< $_[0]" ) or die "open($_[0]): $!"; binmode FH; my $string = do { local $/; }; close FH or die "close($_[0]): $!"; return $string; } END_OLD sub _readperl { my $string = Module::Install::_read($_[0]); $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg; $string =~ s/(\n)\n*__(?:DATA|END)__\b.*\z/$1/s; $string =~ s/\n\n=\w+.+?\n\n=cut\b.+?\n+/\n\n/sg; return $string; } sub _readpod { my $string = Module::Install::_read($_[0]); $string =~ s/(?:\015{1,2}\012|\015|\012)/\n/sg; return $string if $_[0] =~ /\.pod\z/; $string =~ s/(^|\n=cut\b.+?\n+)[^=\s].+?\n(\n=\w+|\z)/$1$2/sg; $string =~ s/\n*=pod\b[^\n]*\n+/\n\n/sg; $string =~ s/\n*=cut\b[^\n]*\n+/\n\n/sg; $string =~ s/^\n+//s; return $string; } # Done in evals to avoid confusing Perl::MinimumVersion eval( $] >= 5.006 ? <<'END_NEW' : <<'END_OLD' ); die $@ if $@; sub _write { local *FH; open( FH, '>', $_[0] ) or die "open($_[0]): $!"; binmode FH; foreach ( 1 .. $#_ ) { print FH $_[$_] or die "print($_[0]): $!"; } close FH or die "close($_[0]): $!"; } END_NEW sub _write { local *FH; open( FH, "> $_[0]" ) or die "open($_[0]): $!"; binmode FH; foreach ( 1 .. $#_ ) { print FH $_[$_] or die "print($_[0]): $!"; } close FH or die "close($_[0]): $!"; } END_OLD # _version is for processing module versions (eg, 1.03_05) not # Perl versions (eg, 5.8.1). sub _version { my $s = shift || 0; my $d =()= $s =~ /(\.)/g; if ( $d >= 2 ) { # Normalise multipart versions $s =~ s/(\.)(\d{1,3})/sprintf("$1%03d",$2)/eg; } $s =~ s/^(\d+)\.?//; my $l = $1 || 0; my @v = map { $_ . '0' x (3 - length $_) } $s =~ /(\d{1,3})\D?/g; $l = $l . '.' . join '', @v if @v; return $l + 0; } sub _cmp { _version($_[1]) <=> _version($_[2]); } # Cloned from Params::Util::_CLASS sub _CLASS { ( defined $_[0] and ! ref $_[0] and $_[0] =~ m/^[^\W\d]\w*(?:::\w+)*\z/s ) ? $_[0] : undef; } 1; # Copyright 2008 - 2012 Adam Kennedy. Time-Moment-0.44/inc/Module/Install/Base.pm000644 000765 000024 00000002147 13274643621 021206 0ustar00chansenstaff000000 000000 #line 1 package Module::Install::Base; use strict 'vars'; use vars qw{$VERSION}; BEGIN { $VERSION = '1.16'; } # Suspend handler for "redefined" warnings BEGIN { my $w = $SIG{__WARN__}; $SIG{__WARN__} = sub { $w }; } #line 42 sub new { my $class = shift; unless ( defined &{"${class}::call"} ) { *{"${class}::call"} = sub { shift->_top->call(@_) }; } unless ( defined &{"${class}::load"} ) { *{"${class}::load"} = sub { shift->_top->load(@_) }; } bless { @_ }, $class; } #line 61 sub AUTOLOAD { local $@; my $func = eval { shift->_top->autoload } or return; goto &$func; } #line 75 sub _top { $_[0]->{_top}; } #line 90 sub admin { $_[0]->_top->{admin} or Module::Install::Base::FakeAdmin->new; } #line 106 sub is_admin { ! $_[0]->admin->isa('Module::Install::Base::FakeAdmin'); } sub DESTROY {} package Module::Install::Base::FakeAdmin; use vars qw{$VERSION}; BEGIN { $VERSION = $Module::Install::Base::VERSION; } my $fake; sub new { $fake ||= bless(\@_, $_[0]); } sub AUTOLOAD {} sub DESTROY {} # Restore warning handler BEGIN { $SIG{__WARN__} = $SIG{__WARN__}->(); } 1; #line 159 Time-Moment-0.44/inc/Module/Install/Can.pm000644 000765 000024 00000006157 13274643622 021043 0ustar00chansenstaff000000 000000 #line 1 package Module::Install::Can; use strict; use Config (); use ExtUtils::MakeMaker (); use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.16'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } # check if we can load some module ### Upgrade this to not have to load the module if possible sub can_use { my ($self, $mod, $ver) = @_; $mod =~ s{::|\\}{/}g; $mod .= '.pm' unless $mod =~ /\.pm$/i; my $pkg = $mod; $pkg =~ s{/}{::}g; $pkg =~ s{\.pm$}{}i; local $@; eval { require $mod; $pkg->VERSION($ver || 0); 1 }; } # Check if we can run some command sub can_run { my ($self, $cmd) = @_; my $_cmd = $cmd; return $_cmd if (-x $_cmd or $_cmd = MM->maybe_command($_cmd)); for my $dir ((split /$Config::Config{path_sep}/, $ENV{PATH}), '.') { next if $dir eq ''; require File::Spec; my $abs = File::Spec->catfile($dir, $cmd); return $abs if (-x $abs or $abs = MM->maybe_command($abs)); } return; } # Can our C compiler environment build XS files sub can_xs { my $self = shift; # Ensure we have the CBuilder module $self->configure_requires( 'ExtUtils::CBuilder' => 0.27 ); # Do we have the configure_requires checker? local $@; eval "require ExtUtils::CBuilder;"; if ( $@ ) { # They don't obey configure_requires, so it is # someone old and delicate. Try to avoid hurting # them by falling back to an older simpler test. return $self->can_cc(); } # Do we have a working C compiler my $builder = ExtUtils::CBuilder->new( quiet => 1, ); unless ( $builder->have_compiler ) { # No working C compiler return 0; } # Write a C file representative of what XS becomes require File::Temp; my ( $FH, $tmpfile ) = File::Temp::tempfile( "compilexs-XXXXX", SUFFIX => '.c', ); binmode $FH; print $FH <<'END_C'; #include "EXTERN.h" #include "perl.h" #include "XSUB.h" int main(int argc, char **argv) { return 0; } int boot_sanexs() { return 1; } END_C close $FH; # Can the C compiler access the same headers XS does my @libs = (); my $object = undef; eval { local $^W = 0; $object = $builder->compile( source => $tmpfile, ); @libs = $builder->link( objects => $object, module_name => 'sanexs', ); }; my $result = $@ ? 0 : 1; # Clean up all the build files foreach ( $tmpfile, $object, @libs ) { next unless defined $_; 1 while unlink; } return $result; } # Can we locate a (the) C compiler sub can_cc { my $self = shift; my @chunks = split(/ /, $Config::Config{cc}) or return; # $Config{cc} may contain args; try to find out the program part while (@chunks) { return $self->can_run("@chunks") || (pop(@chunks), next); } return; } # Fix Cygwin bug on maybe_command(); if ( $^O eq 'cygwin' ) { require ExtUtils::MM_Cygwin; require ExtUtils::MM_Win32; if ( ! defined(&ExtUtils::MM_Cygwin::maybe_command) ) { *ExtUtils::MM_Cygwin::maybe_command = sub { my ($self, $file) = @_; if ($file =~ m{^/cygdrive/}i and ExtUtils::MM_Win32->can('maybe_command')) { ExtUtils::MM_Win32->maybe_command($file); } else { ExtUtils::MM_Unix->maybe_command($file); } } } } 1; __END__ #line 236 Time-Moment-0.44/inc/Module/Install/Compiler.pm000644 000765 000024 00000002126 13274643622 022104 0ustar00chansenstaff000000 000000 #line 1 package Module::Install::Compiler; use strict; use File::Basename (); use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.16'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } sub ppport { my $self = shift; if ( $self->is_admin ) { return $self->admin->ppport(@_); } else { # Fallback to just a check my $file = shift || 'ppport.h'; unless ( -f $file ) { die "Packaging error, $file is missing"; } } } sub cc_files { require Config; my $self = shift; $self->makemaker_args( OBJECT => join ' ', map { substr($_, 0, -2) . $Config::Config{_o} } @_ ); } sub cc_inc_paths { my $self = shift; $self->makemaker_args( INC => join ' ', map { "-I$_" } @_ ); } sub cc_lib_paths { my $self = shift; $self->makemaker_args( LIBS => join ' ', map { "-L$_" } @_ ); } sub cc_lib_links { my $self = shift; $self->makemaker_args( LIBS => join ' ', $self->makemaker_args->{LIBS}, map { "-l$_" } @_ ); } sub cc_optimize_flags { my $self = shift; $self->makemaker_args( OPTIMIZE => join ' ', @_ ); } 1; __END__ #line 123 Time-Moment-0.44/inc/Module/Install/External.pm000644 000765 000024 00000003545 13274643622 022122 0ustar00chansenstaff000000 000000 #line 1 package Module::Install::External; # Provides dependency declarations for external non-Perl things use strict; use Module::Install::Base (); use vars qw{$VERSION $ISCORE @ISA}; BEGIN { $VERSION = '1.16'; $ISCORE = 1; @ISA = qw{Module::Install::Base}; } sub requires_xs { my $self = shift; # First check for the basic C compiler $self->requires_external_cc; # We need a C compiler that can build XS files unless ( $self->can_xs ) { print "Unresolvable missing external dependency.\n"; print "This package requires perl's header files.\n"; print STDERR "NA: Unable to build distribution on this platform.\n"; exit(0); } 1; } sub requires_external_cc { my $self = shift; # We need a C compiler, use the can_cc method for this unless ( $self->can_cc ) { print "Unresolvable missing external dependency.\n"; print "This package requires a C compiler.\n"; print STDERR "NA: Unable to build distribution on this platform.\n"; exit(0); } # Unlike some of the other modules, while we need to specify a # C compiler as a dep, it needs to be a build-time dependency. 1; } sub requires_external_bin { my ($self, $bin, $version) = @_; if ( $version ) { die "requires_external_bin does not support versions yet"; } # Load the package containing can_run early, # to avoid breaking the message below. $self->load('can_run'); # Locate the bin print "Locating bin:$bin..."; my $found_bin = $self->can_run( $bin ); if ( $found_bin ) { print " found at $found_bin.\n"; } else { print " missing.\n"; print "Unresolvable missing external dependency.\n"; print "Please install '$bin' seperately and try again.\n"; print STDERR "NA: Unable to build distribution on this platform.\n"; exit(0); } # Once we have some way to specify external deps, do it here. # In the mean time, continue as normal. 1; } 1; __END__ #line 171 Time-Moment-0.44/inc/Module/Install/Fetch.pm000644 000765 000024 00000004627 13274643622 021373 0ustar00chansenstaff000000 000000 #line 1 package Module::Install::Fetch; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.16'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } sub get_file { my ($self, %args) = @_; my ($scheme, $host, $path, $file) = $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; if ( $scheme eq 'http' and ! eval { require LWP::Simple; 1 } ) { $args{url} = $args{ftp_url} or (warn("LWP support unavailable!\n"), return); ($scheme, $host, $path, $file) = $args{url} =~ m|^(\w+)://([^/]+)(.+)/(.+)| or return; } $|++; print "Fetching '$file' from $host... "; unless (eval { require Socket; Socket::inet_aton($host) }) { warn "'$host' resolve failed!\n"; return; } return unless $scheme eq 'ftp' or $scheme eq 'http'; require Cwd; my $dir = Cwd::getcwd(); chdir $args{local_dir} or return if exists $args{local_dir}; if (eval { require LWP::Simple; 1 }) { LWP::Simple::mirror($args{url}, $file); } elsif (eval { require Net::FTP; 1 }) { eval { # use Net::FTP to get past firewall my $ftp = Net::FTP->new($host, Passive => 1, Timeout => 600); $ftp->login("anonymous", 'anonymous@example.com'); $ftp->cwd($path); $ftp->binary; $ftp->get($file) or (warn("$!\n"), return); $ftp->quit; } } elsif (my $ftp = $self->can_run('ftp')) { eval { # no Net::FTP, fallback to ftp.exe require FileHandle; my $fh = FileHandle->new; local $SIG{CHLD} = 'IGNORE'; unless ($fh->open("|$ftp -n")) { warn "Couldn't open ftp: $!\n"; chdir $dir; return; } my @dialog = split(/\n/, <<"END_FTP"); open $host user anonymous anonymous\@example.com cd $path binary get $file $file quit END_FTP foreach (@dialog) { $fh->print("$_\n") } $fh->close; } } else { warn "No working 'ftp' program available!\n"; chdir $dir; return; } unless (-f $file) { warn "Fetching failed: $@\n"; chdir $dir; return; } return if exists $args{size} and -s $file != $args{size}; system($args{run}) if exists $args{run}; unlink($file) if $args{remove}; print(((!exists $args{check_for} or -e $args{check_for}) ? "done!" : "failed! ($!)"), "\n"); chdir $dir; return !$?; } 1; Time-Moment-0.44/inc/Module/Install/Makefile.pm000644 000765 000024 00000027437 13274643621 022062 0ustar00chansenstaff000000 000000 #line 1 package Module::Install::Makefile; use strict 'vars'; use ExtUtils::MakeMaker (); use Module::Install::Base (); use Fcntl qw/:flock :seek/; use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.16'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } sub Makefile { $_[0] } my %seen = (); sub prompt { shift; # Infinite loop protection my @c = caller(); if ( ++$seen{"$c[1]|$c[2]|$_[0]"} > 3 ) { die "Caught an potential prompt infinite loop ($c[1]|$c[2]|$_[0])"; } # In automated testing or non-interactive session, always use defaults if ( ($ENV{AUTOMATED_TESTING} or -! -t STDIN) and ! $ENV{PERL_MM_USE_DEFAULT} ) { local $ENV{PERL_MM_USE_DEFAULT} = 1; goto &ExtUtils::MakeMaker::prompt; } else { goto &ExtUtils::MakeMaker::prompt; } } # Store a cleaned up version of the MakeMaker version, # since we need to behave differently in a variety of # ways based on the MM version. my $makemaker = eval $ExtUtils::MakeMaker::VERSION; # If we are passed a param, do a "newer than" comparison. # Otherwise, just return the MakeMaker version. sub makemaker { ( @_ < 2 or $makemaker >= eval($_[1]) ) ? $makemaker : 0 } # Ripped from ExtUtils::MakeMaker 6.56, and slightly modified # as we only need to know here whether the attribute is an array # or a hash or something else (which may or may not be appendable). my %makemaker_argtype = ( C => 'ARRAY', CONFIG => 'ARRAY', # CONFIGURE => 'CODE', # ignore DIR => 'ARRAY', DL_FUNCS => 'HASH', DL_VARS => 'ARRAY', EXCLUDE_EXT => 'ARRAY', EXE_FILES => 'ARRAY', FUNCLIST => 'ARRAY', H => 'ARRAY', IMPORTS => 'HASH', INCLUDE_EXT => 'ARRAY', LIBS => 'ARRAY', # ignore '' MAN1PODS => 'HASH', MAN3PODS => 'HASH', META_ADD => 'HASH', META_MERGE => 'HASH', PL_FILES => 'HASH', PM => 'HASH', PMLIBDIRS => 'ARRAY', PMLIBPARENTDIRS => 'ARRAY', PREREQ_PM => 'HASH', CONFIGURE_REQUIRES => 'HASH', SKIP => 'ARRAY', TYPEMAPS => 'ARRAY', XS => 'HASH', # VERSION => ['version',''], # ignore # _KEEP_AFTER_FLUSH => '', clean => 'HASH', depend => 'HASH', dist => 'HASH', dynamic_lib=> 'HASH', linkext => 'HASH', macro => 'HASH', postamble => 'HASH', realclean => 'HASH', test => 'HASH', tool_autosplit => 'HASH', # special cases where you can use makemaker_append CCFLAGS => 'APPENDABLE', DEFINE => 'APPENDABLE', INC => 'APPENDABLE', LDDLFLAGS => 'APPENDABLE', LDFROM => 'APPENDABLE', ); sub makemaker_args { my ($self, %new_args) = @_; my $args = ( $self->{makemaker_args} ||= {} ); foreach my $key (keys %new_args) { if ($makemaker_argtype{$key}) { if ($makemaker_argtype{$key} eq 'ARRAY') { $args->{$key} = [] unless defined $args->{$key}; unless (ref $args->{$key} eq 'ARRAY') { $args->{$key} = [$args->{$key}] } push @{$args->{$key}}, ref $new_args{$key} eq 'ARRAY' ? @{$new_args{$key}} : $new_args{$key}; } elsif ($makemaker_argtype{$key} eq 'HASH') { $args->{$key} = {} unless defined $args->{$key}; foreach my $skey (keys %{ $new_args{$key} }) { $args->{$key}{$skey} = $new_args{$key}{$skey}; } } elsif ($makemaker_argtype{$key} eq 'APPENDABLE') { $self->makemaker_append($key => $new_args{$key}); } } else { if (defined $args->{$key}) { warn qq{MakeMaker attribute "$key" is overriden; use "makemaker_append" to append values\n}; } $args->{$key} = $new_args{$key}; } } return $args; } # For mm args that take multiple space-separated args, # append an argument to the current list. sub makemaker_append { my $self = shift; my $name = shift; my $args = $self->makemaker_args; $args->{$name} = defined $args->{$name} ? join( ' ', $args->{$name}, @_ ) : join( ' ', @_ ); } sub build_subdirs { my $self = shift; my $subdirs = $self->makemaker_args->{DIR} ||= []; for my $subdir (@_) { push @$subdirs, $subdir; } } sub clean_files { my $self = shift; my $clean = $self->makemaker_args->{clean} ||= {}; %$clean = ( %$clean, FILES => join ' ', grep { length $_ } ($clean->{FILES} || (), @_), ); } sub realclean_files { my $self = shift; my $realclean = $self->makemaker_args->{realclean} ||= {}; %$realclean = ( %$realclean, FILES => join ' ', grep { length $_ } ($realclean->{FILES} || (), @_), ); } sub libs { my $self = shift; my $libs = ref $_[0] ? shift : [ shift ]; $self->makemaker_args( LIBS => $libs ); } sub inc { my $self = shift; $self->makemaker_args( INC => shift ); } sub _wanted_t { } sub tests_recursive { my $self = shift; my $dir = shift || 't'; unless ( -d $dir ) { die "tests_recursive dir '$dir' does not exist"; } my %tests = map { $_ => 1 } split / /, ($self->tests || ''); require File::Find; File::Find::find( sub { /\.t$/ and -f $_ and $tests{"$File::Find::dir/*.t"} = 1 }, $dir ); $self->tests( join ' ', sort keys %tests ); } sub write { my $self = shift; die "&Makefile->write() takes no arguments\n" if @_; # Check the current Perl version my $perl_version = $self->perl_version; if ( $perl_version ) { eval "use $perl_version; 1" or die "ERROR: perl: Version $] is installed, " . "but we need version >= $perl_version"; } # Make sure we have a new enough MakeMaker require ExtUtils::MakeMaker; if ( $perl_version and $self->_cmp($perl_version, '5.006') >= 0 ) { # This previous attempted to inherit the version of # ExtUtils::MakeMaker in use by the module author, but this # was found to be untenable as some authors build releases # using future dev versions of EU:MM that nobody else has. # Instead, #toolchain suggests we use 6.59 which is the most # stable version on CPAN at time of writing and is, to quote # ribasushi, "not terminally fucked, > and tested enough". # TODO: We will now need to maintain this over time to push # the version up as new versions are released. $self->build_requires( 'ExtUtils::MakeMaker' => 6.59 ); $self->configure_requires( 'ExtUtils::MakeMaker' => 6.59 ); } else { # Allow legacy-compatibility with 5.005 by depending on the # most recent EU:MM that supported 5.005. $self->build_requires( 'ExtUtils::MakeMaker' => 6.36 ); $self->configure_requires( 'ExtUtils::MakeMaker' => 6.36 ); } # Generate the MakeMaker params my $args = $self->makemaker_args; $args->{DISTNAME} = $self->name; $args->{NAME} = $self->module_name || $self->name; $args->{NAME} =~ s/-/::/g; $args->{VERSION} = $self->version or die <<'EOT'; ERROR: Can't determine distribution version. Please specify it explicitly via 'version' in Makefile.PL, or set a valid $VERSION in a module, and provide its file path via 'version_from' (or 'all_from' if you prefer) in Makefile.PL. EOT if ( $self->tests ) { my @tests = split ' ', $self->tests; my %seen; $args->{test} = { TESTS => (join ' ', grep {!$seen{$_}++} @tests), }; } elsif ( $Module::Install::ExtraTests::use_extratests ) { # Module::Install::ExtraTests doesn't set $self->tests and does its own tests via harness. # So, just ignore our xt tests here. } elsif ( -d 'xt' and ($Module::Install::AUTHOR or $ENV{RELEASE_TESTING}) ) { $args->{test} = { TESTS => join( ' ', map { "$_/*.t" } grep { -d $_ } qw{ t xt } ), }; } if ( $] >= 5.005 ) { $args->{ABSTRACT} = $self->abstract; $args->{AUTHOR} = join ', ', @{$self->author || []}; } if ( $self->makemaker(6.10) ) { $args->{NO_META} = 1; #$args->{NO_MYMETA} = 1; } if ( $self->makemaker(6.17) and $self->sign ) { $args->{SIGN} = 1; } unless ( $self->is_admin ) { delete $args->{SIGN}; } if ( $self->makemaker(6.31) and $self->license ) { $args->{LICENSE} = $self->license; } my $prereq = ($args->{PREREQ_PM} ||= {}); %$prereq = ( %$prereq, map { @$_ } # flatten [module => version] map { @$_ } grep $_, ($self->requires) ); # Remove any reference to perl, PREREQ_PM doesn't support it delete $args->{PREREQ_PM}->{perl}; # Merge both kinds of requires into BUILD_REQUIRES my $build_prereq = ($args->{BUILD_REQUIRES} ||= {}); %$build_prereq = ( %$build_prereq, map { @$_ } # flatten [module => version] map { @$_ } grep $_, ($self->configure_requires, $self->build_requires) ); # Remove any reference to perl, BUILD_REQUIRES doesn't support it delete $args->{BUILD_REQUIRES}->{perl}; # Delete bundled dists from prereq_pm, add it to Makefile DIR my $subdirs = ($args->{DIR} || []); if ($self->bundles) { my %processed; foreach my $bundle (@{ $self->bundles }) { my ($mod_name, $dist_dir) = @$bundle; delete $prereq->{$mod_name}; $dist_dir = File::Basename::basename($dist_dir); # dir for building this module if (not exists $processed{$dist_dir}) { if (-d $dist_dir) { # List as sub-directory to be processed by make push @$subdirs, $dist_dir; } # Else do nothing: the module is already present on the system $processed{$dist_dir} = undef; } } } unless ( $self->makemaker('6.55_03') ) { %$prereq = (%$prereq,%$build_prereq); delete $args->{BUILD_REQUIRES}; } if ( my $perl_version = $self->perl_version ) { eval "use $perl_version; 1" or die "ERROR: perl: Version $] is installed, " . "but we need version >= $perl_version"; if ( $self->makemaker(6.48) ) { $args->{MIN_PERL_VERSION} = $perl_version; } } if ($self->installdirs) { warn qq{old INSTALLDIRS (probably set by makemaker_args) is overriden by installdirs\n} if $args->{INSTALLDIRS}; $args->{INSTALLDIRS} = $self->installdirs; } my %args = map { ( $_ => $args->{$_} ) } grep {defined($args->{$_} ) } keys %$args; my $user_preop = delete $args{dist}->{PREOP}; if ( my $preop = $self->admin->preop($user_preop) ) { foreach my $key ( keys %$preop ) { $args{dist}->{$key} = $preop->{$key}; } } my $mm = ExtUtils::MakeMaker::WriteMakefile(%args); $self->fix_up_makefile($mm->{FIRST_MAKEFILE} || 'Makefile'); } sub fix_up_makefile { my $self = shift; my $makefile_name = shift; my $top_class = ref($self->_top) || ''; my $top_version = $self->_top->VERSION || ''; my $preamble = $self->preamble ? "# Preamble by $top_class $top_version\n" . $self->preamble : ''; my $postamble = "# Postamble by $top_class $top_version\n" . ($self->postamble || ''); local *MAKEFILE; open MAKEFILE, "+< $makefile_name" or die "fix_up_makefile: Couldn't open $makefile_name: $!"; eval { flock MAKEFILE, LOCK_EX }; my $makefile = do { local $/; }; $makefile =~ s/\b(test_harness\(\$\(TEST_VERBOSE\), )/$1'inc', /; $makefile =~ s/( -I\$\(INST_ARCHLIB\))/ -Iinc$1/g; $makefile =~ s/( "-I\$\(INST_LIB\)")/ "-Iinc"$1/g; $makefile =~ s/^(FULLPERL = .*)/$1 "-Iinc"/m; $makefile =~ s/^(PERL = .*)/$1 "-Iinc"/m; # Module::Install will never be used to build the Core Perl # Sometimes PERL_LIB and PERL_ARCHLIB get written anyway, which breaks # PREFIX/PERL5LIB, and thus, install_share. Blank them if they exist $makefile =~ s/^PERL_LIB = .+/PERL_LIB =/m; #$makefile =~ s/^PERL_ARCHLIB = .+/PERL_ARCHLIB =/m; # Perl 5.005 mentions PERL_LIB explicitly, so we have to remove that as well. $makefile =~ s/(\"?)-I\$\(PERL_LIB\)\1//g; # XXX - This is currently unused; not sure if it breaks other MM-users # $makefile =~ s/^pm_to_blib\s+:\s+/pm_to_blib :: /mg; seek MAKEFILE, 0, SEEK_SET; truncate MAKEFILE, 0; print MAKEFILE "$preamble$makefile$postamble" or die $!; close MAKEFILE or die $!; 1; } sub preamble { my ($self, $text) = @_; $self->{preamble} = $text . $self->{preamble} if defined $text; $self->{preamble}; } sub postamble { my ($self, $text) = @_; $self->{postamble} ||= $self->admin->postamble; $self->{postamble} .= $text if defined $text; $self->{postamble} } 1; __END__ #line 544 Time-Moment-0.44/inc/Module/Install/Metadata.pm000644 000765 000024 00000043302 13274643621 022052 0ustar00chansenstaff000000 000000 #line 1 package Module::Install::Metadata; use strict 'vars'; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.16'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } my @boolean_keys = qw{ sign }; my @scalar_keys = qw{ name module_name abstract version distribution_type tests installdirs }; my @tuple_keys = qw{ configure_requires build_requires requires recommends bundles resources }; my @resource_keys = qw{ homepage bugtracker repository }; my @array_keys = qw{ keywords author }; *authors = \&author; sub Meta { shift } sub Meta_BooleanKeys { @boolean_keys } sub Meta_ScalarKeys { @scalar_keys } sub Meta_TupleKeys { @tuple_keys } sub Meta_ResourceKeys { @resource_keys } sub Meta_ArrayKeys { @array_keys } foreach my $key ( @boolean_keys ) { *$key = sub { my $self = shift; if ( defined wantarray and not @_ ) { return $self->{values}->{$key}; } $self->{values}->{$key} = ( @_ ? $_[0] : 1 ); return $self; }; } foreach my $key ( @scalar_keys ) { *$key = sub { my $self = shift; return $self->{values}->{$key} if defined wantarray and !@_; $self->{values}->{$key} = shift; return $self; }; } foreach my $key ( @array_keys ) { *$key = sub { my $self = shift; return $self->{values}->{$key} if defined wantarray and !@_; $self->{values}->{$key} ||= []; push @{$self->{values}->{$key}}, @_; return $self; }; } foreach my $key ( @resource_keys ) { *$key = sub { my $self = shift; unless ( @_ ) { return () unless $self->{values}->{resources}; return map { $_->[1] } grep { $_->[0] eq $key } @{ $self->{values}->{resources} }; } return $self->{values}->{resources}->{$key} unless @_; my $uri = shift or die( "Did not provide a value to $key()" ); $self->resources( $key => $uri ); return 1; }; } foreach my $key ( grep { $_ ne "resources" } @tuple_keys) { *$key = sub { my $self = shift; return $self->{values}->{$key} unless @_; my @added; while ( @_ ) { my $module = shift or last; my $version = shift || 0; push @added, [ $module, $version ]; } push @{ $self->{values}->{$key} }, @added; return map {@$_} @added; }; } # Resource handling my %lc_resource = map { $_ => 1 } qw{ homepage license bugtracker repository }; sub resources { my $self = shift; while ( @_ ) { my $name = shift or last; my $value = shift or next; if ( $name eq lc $name and ! $lc_resource{$name} ) { die("Unsupported reserved lowercase resource '$name'"); } $self->{values}->{resources} ||= []; push @{ $self->{values}->{resources} }, [ $name, $value ]; } $self->{values}->{resources}; } # Aliases for build_requires that will have alternative # meanings in some future version of META.yml. sub test_requires { shift->build_requires(@_) } sub install_requires { shift->build_requires(@_) } # Aliases for installdirs options sub install_as_core { $_[0]->installdirs('perl') } sub install_as_cpan { $_[0]->installdirs('site') } sub install_as_site { $_[0]->installdirs('site') } sub install_as_vendor { $_[0]->installdirs('vendor') } sub dynamic_config { my $self = shift; my $value = @_ ? shift : 1; if ( $self->{values}->{dynamic_config} ) { # Once dynamic we never change to static, for safety return 0; } $self->{values}->{dynamic_config} = $value ? 1 : 0; return 1; } # Convenience command sub static_config { shift->dynamic_config(0); } sub perl_version { my $self = shift; return $self->{values}->{perl_version} unless @_; my $version = shift or die( "Did not provide a value to perl_version()" ); # Normalize the version $version = $self->_perl_version($version); # We don't support the really old versions unless ( $version >= 5.005 ) { die "Module::Install only supports 5.005 or newer (use ExtUtils::MakeMaker)\n"; } $self->{values}->{perl_version} = $version; } sub all_from { my ( $self, $file ) = @_; unless ( defined($file) ) { my $name = $self->name or die( "all_from called with no args without setting name() first" ); $file = join('/', 'lib', split(/-/, $name)) . '.pm'; $file =~ s{.*/}{} unless -e $file; unless ( -e $file ) { die("all_from cannot find $file from $name"); } } unless ( -f $file ) { die("The path '$file' does not exist, or is not a file"); } $self->{values}{all_from} = $file; # Some methods pull from POD instead of code. # If there is a matching .pod, use that instead my $pod = $file; $pod =~ s/\.pm$/.pod/i; $pod = $file unless -e $pod; # Pull the different values $self->name_from($file) unless $self->name; $self->version_from($file) unless $self->version; $self->perl_version_from($file) unless $self->perl_version; $self->author_from($pod) unless @{$self->author || []}; $self->license_from($pod) unless $self->license; $self->abstract_from($pod) unless $self->abstract; return 1; } sub provides { my $self = shift; my $provides = ( $self->{values}->{provides} ||= {} ); %$provides = (%$provides, @_) if @_; return $provides; } sub auto_provides { my $self = shift; return $self unless $self->is_admin; unless (-e 'MANIFEST') { warn "Cannot deduce auto_provides without a MANIFEST, skipping\n"; return $self; } # Avoid spurious warnings as we are not checking manifest here. local $SIG{__WARN__} = sub {1}; require ExtUtils::Manifest; local *ExtUtils::Manifest::manicheck = sub { return }; require Module::Build; my $build = Module::Build->new( dist_name => $self->name, dist_version => $self->version, license => $self->license, ); $self->provides( %{ $build->find_dist_packages || {} } ); } sub feature { my $self = shift; my $name = shift; my $features = ( $self->{values}->{features} ||= [] ); my $mods; if ( @_ == 1 and ref( $_[0] ) ) { # The user used ->feature like ->features by passing in the second # argument as a reference. Accomodate for that. $mods = $_[0]; } else { $mods = \@_; } my $count = 0; push @$features, ( $name => [ map { ref($_) ? ( ref($_) eq 'HASH' ) ? %$_ : @$_ : $_ } @$mods ] ); return @$features; } sub features { my $self = shift; while ( my ( $name, $mods ) = splice( @_, 0, 2 ) ) { $self->feature( $name, @$mods ); } return $self->{values}->{features} ? @{ $self->{values}->{features} } : (); } sub no_index { my $self = shift; my $type = shift; push @{ $self->{values}->{no_index}->{$type} }, @_ if $type; return $self->{values}->{no_index}; } sub read { my $self = shift; $self->include_deps( 'YAML::Tiny', 0 ); require YAML::Tiny; my $data = YAML::Tiny::LoadFile('META.yml'); # Call methods explicitly in case user has already set some values. while ( my ( $key, $value ) = each %$data ) { next unless $self->can($key); if ( ref $value eq 'HASH' ) { while ( my ( $module, $version ) = each %$value ) { $self->can($key)->($self, $module => $version ); } } else { $self->can($key)->($self, $value); } } return $self; } sub write { my $self = shift; return $self unless $self->is_admin; $self->admin->write_meta; return $self; } sub version_from { require ExtUtils::MM_Unix; my ( $self, $file ) = @_; $self->version( ExtUtils::MM_Unix->parse_version($file) ); # for version integrity check $self->makemaker_args( VERSION_FROM => $file ); } sub abstract_from { require ExtUtils::MM_Unix; my ( $self, $file ) = @_; $self->abstract( bless( { DISTNAME => $self->name }, 'ExtUtils::MM_Unix' )->parse_abstract($file) ); } # Add both distribution and module name sub name_from { my ($self, $file) = @_; if ( Module::Install::_read($file) =~ m/ ^ \s* package \s* ([\w:]+) [\s|;]* /ixms ) { my ($name, $module_name) = ($1, $1); $name =~ s{::}{-}g; $self->name($name); unless ( $self->module_name ) { $self->module_name($module_name); } } else { die("Cannot determine name from $file\n"); } } sub _extract_perl_version { if ( $_[0] =~ m/ ^\s* (?:use|require) \s* v? ([\d_\.]+) \s* ; /ixms ) { my $perl_version = $1; $perl_version =~ s{_}{}g; return $perl_version; } else { return; } } sub perl_version_from { my $self = shift; my $perl_version=_extract_perl_version(Module::Install::_read($_[0])); if ($perl_version) { $self->perl_version($perl_version); } else { warn "Cannot determine perl version info from $_[0]\n"; return; } } sub author_from { my $self = shift; my $content = Module::Install::_read($_[0]); if ($content =~ m/ =head \d \s+ (?:authors?)\b \s* ([^\n]*) | =head \d \s+ (?:licen[cs]e|licensing|copyright|legal)\b \s* .*? copyright .*? \d\d\d[\d.]+ \s* (?:\bby\b)? \s* ([^\n]*) /ixms) { my $author = $1 || $2; # XXX: ugly but should work anyway... if (eval "require Pod::Escapes; 1") { # Pod::Escapes has a mapping table. # It's in core of perl >= 5.9.3, and should be installed # as one of the Pod::Simple's prereqs, which is a prereq # of Pod::Text 3.x (see also below). $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> } { defined $2 ? chr($2) : defined $Pod::Escapes::Name2character_number{$1} ? chr($Pod::Escapes::Name2character_number{$1}) : do { warn "Unknown escape: E<$1>"; "E<$1>"; }; }gex; } elsif (eval "require Pod::Text; 1" && $Pod::Text::VERSION < 3) { # Pod::Text < 3.0 has yet another mapping table, # though the table name of 2.x and 1.x are different. # (1.x is in core of Perl < 5.6, 2.x is in core of # Perl < 5.9.3) my $mapping = ($Pod::Text::VERSION < 2) ? \%Pod::Text::HTML_Escapes : \%Pod::Text::ESCAPES; $author =~ s{ E<( (\d+) | ([A-Za-z]+) )> } { defined $2 ? chr($2) : defined $mapping->{$1} ? $mapping->{$1} : do { warn "Unknown escape: E<$1>"; "E<$1>"; }; }gex; } else { $author =~ s{E}{<}g; $author =~ s{E}{>}g; } $self->author($author); } else { warn "Cannot determine author info from $_[0]\n"; } } #Stolen from M::B my %license_urls = ( perl => 'http://dev.perl.org/licenses/', apache => 'http://apache.org/licenses/LICENSE-2.0', apache_1_1 => 'http://apache.org/licenses/LICENSE-1.1', artistic => 'http://opensource.org/licenses/artistic-license.php', artistic_2 => 'http://opensource.org/licenses/artistic-license-2.0.php', lgpl => 'http://opensource.org/licenses/lgpl-license.php', lgpl2 => 'http://opensource.org/licenses/lgpl-2.1.php', lgpl3 => 'http://opensource.org/licenses/lgpl-3.0.html', bsd => 'http://opensource.org/licenses/bsd-license.php', gpl => 'http://opensource.org/licenses/gpl-license.php', gpl2 => 'http://opensource.org/licenses/gpl-2.0.php', gpl3 => 'http://opensource.org/licenses/gpl-3.0.html', mit => 'http://opensource.org/licenses/mit-license.php', mozilla => 'http://opensource.org/licenses/mozilla1.1.php', open_source => undef, unrestricted => undef, restrictive => undef, unknown => undef, ); sub license { my $self = shift; return $self->{values}->{license} unless @_; my $license = shift or die( 'Did not provide a value to license()' ); $license = __extract_license($license) || lc $license; $self->{values}->{license} = $license; # Automatically fill in license URLs if ( $license_urls{$license} ) { $self->resources( license => $license_urls{$license} ); } return 1; } sub _extract_license { my $pod = shift; my $matched; return __extract_license( ($matched) = $pod =~ m/ (=head \d \s+ L(?i:ICEN[CS]E|ICENSING)\b.*?) (=head \d.*|=cut.*|)\z /xms ) || __extract_license( ($matched) = $pod =~ m/ (=head \d \s+ (?:C(?i:OPYRIGHTS?)|L(?i:EGAL))\b.*?) (=head \d.*|=cut.*|)\z /xms ); } sub __extract_license { my $license_text = shift or return; my @phrases = ( '(?:under )?the same (?:terms|license) as (?:perl|the perl (?:\d )?programming language)' => 'perl', 1, '(?:under )?the terms of (?:perl|the perl programming language) itself' => 'perl', 1, 'Artistic and GPL' => 'perl', 1, 'GNU general public license' => 'gpl', 1, 'GNU public license' => 'gpl', 1, 'GNU lesser general public license' => 'lgpl', 1, 'GNU lesser public license' => 'lgpl', 1, 'GNU library general public license' => 'lgpl', 1, 'GNU library public license' => 'lgpl', 1, 'GNU Free Documentation license' => 'unrestricted', 1, 'GNU Affero General Public License' => 'open_source', 1, '(?:Free)?BSD license' => 'bsd', 1, 'Artistic license 2\.0' => 'artistic_2', 1, 'Artistic license' => 'artistic', 1, 'Apache (?:Software )?license' => 'apache', 1, 'GPL' => 'gpl', 1, 'LGPL' => 'lgpl', 1, 'BSD' => 'bsd', 1, 'Artistic' => 'artistic', 1, 'MIT' => 'mit', 1, 'Mozilla Public License' => 'mozilla', 1, 'Q Public License' => 'open_source', 1, 'OpenSSL License' => 'unrestricted', 1, 'SSLeay License' => 'unrestricted', 1, 'zlib License' => 'open_source', 1, 'proprietary' => 'proprietary', 0, ); while ( my ($pattern, $license, $osi) = splice(@phrases, 0, 3) ) { $pattern =~ s#\s+#\\s+#gs; if ( $license_text =~ /\b$pattern\b/i ) { return $license; } } return ''; } sub license_from { my $self = shift; if (my $license=_extract_license(Module::Install::_read($_[0]))) { $self->license($license); } else { warn "Cannot determine license info from $_[0]\n"; return 'unknown'; } } sub _extract_bugtracker { my @links = $_[0] =~ m#L<( https?\Q://rt.cpan.org/\E[^>]+| https?\Q://github.com/\E[\w_]+/[\w_]+/issues| https?\Q://code.google.com/p/\E[\w_\-]+/issues/list )>#gx; my %links; @links{@links}=(); @links=keys %links; return @links; } sub bugtracker_from { my $self = shift; my $content = Module::Install::_read($_[0]); my @links = _extract_bugtracker($content); unless ( @links ) { warn "Cannot determine bugtracker info from $_[0]\n"; return 0; } if ( @links > 1 ) { warn "Found more than one bugtracker link in $_[0]\n"; return 0; } # Set the bugtracker bugtracker( $links[0] ); return 1; } sub requires_from { my $self = shift; my $content = Module::Install::_readperl($_[0]); my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+(v?[\d\.]+)/mg; while ( @requires ) { my $module = shift @requires; my $version = shift @requires; $self->requires( $module => $version ); } } sub test_requires_from { my $self = shift; my $content = Module::Install::_readperl($_[0]); my @requires = $content =~ m/^use\s+([^\W\d]\w*(?:::\w+)*)\s+([\d\.]+)/mg; while ( @requires ) { my $module = shift @requires; my $version = shift @requires; $self->test_requires( $module => $version ); } } # Convert triple-part versions (eg, 5.6.1 or 5.8.9) to # numbers (eg, 5.006001 or 5.008009). # Also, convert double-part versions (eg, 5.8) sub _perl_version { my $v = $_[-1]; $v =~ s/^([1-9])\.([1-9]\d?\d?)$/sprintf("%d.%03d",$1,$2)/e; $v =~ s/^([1-9])\.([1-9]\d?\d?)\.(0|[1-9]\d?\d?)$/sprintf("%d.%03d%03d",$1,$2,$3 || 0)/e; $v =~ s/(\.\d\d\d)000$/$1/; $v =~ s/_.+$//; if ( ref($v) ) { # Numify $v = $v + 0; } return $v; } sub add_metadata { my $self = shift; my %hash = @_; for my $key (keys %hash) { warn "add_metadata: $key is not prefixed with 'x_'.\n" . "Use appopriate function to add non-private metadata.\n" unless $key =~ /^x_/; $self->{values}->{$key} = $hash{$key}; } } ###################################################################### # MYMETA Support sub WriteMyMeta { die "WriteMyMeta has been deprecated"; } sub write_mymeta_yaml { my $self = shift; # We need YAML::Tiny to write the MYMETA.yml file unless ( eval { require YAML::Tiny; 1; } ) { return 1; } # Generate the data my $meta = $self->_write_mymeta_data or return 1; # Save as the MYMETA.yml file print "Writing MYMETA.yml\n"; YAML::Tiny::DumpFile('MYMETA.yml', $meta); } sub write_mymeta_json { my $self = shift; # We need JSON to write the MYMETA.json file unless ( eval { require JSON; 1; } ) { return 1; } # Generate the data my $meta = $self->_write_mymeta_data or return 1; # Save as the MYMETA.yml file print "Writing MYMETA.json\n"; Module::Install::_write( 'MYMETA.json', JSON->new->pretty(1)->canonical->encode($meta), ); } sub _write_mymeta_data { my $self = shift; # If there's no existing META.yml there is nothing we can do return undef unless -f 'META.yml'; # We need Parse::CPAN::Meta to load the file unless ( eval { require Parse::CPAN::Meta; 1; } ) { return undef; } # Merge the perl version into the dependencies my $val = $self->Meta->{values}; my $perl = delete $val->{perl_version}; if ( $perl ) { $val->{requires} ||= []; my $requires = $val->{requires}; # Canonize to three-dot version after Perl 5.6 if ( $perl >= 5.006 ) { $perl =~ s{^(\d+)\.(\d\d\d)(\d*)}{join('.', $1, int($2||0), int($3||0))}e } unshift @$requires, [ perl => $perl ]; } # Load the advisory META.yml file my @yaml = Parse::CPAN::Meta::LoadFile('META.yml'); my $meta = $yaml[0]; # Overwrite the non-configure dependency hashes delete $meta->{requires}; delete $meta->{build_requires}; delete $meta->{recommends}; if ( exists $val->{requires} ) { $meta->{requires} = { map { @$_ } @{ $val->{requires} } }; } if ( exists $val->{build_requires} ) { $meta->{build_requires} = { map { @$_ } @{ $val->{build_requires} } }; } return $meta; } 1; Time-Moment-0.44/inc/Module/Install/ReadmeFromPod.pm000644 000765 000024 00000006311 13274643621 023015 0ustar00chansenstaff000000 000000 #line 1 package Module::Install::ReadmeFromPod; use 5.006; use strict; use warnings; use base qw(Module::Install::Base); use vars qw($VERSION); $VERSION = '0.22'; sub readme_from { my $self = shift; return unless $self->is_admin; # Input file my $in_file = shift || $self->_all_from or die "Can't determine file to make readme_from"; # Get optional arguments my ($clean, $format, $out_file, $options); my $args = shift; if ( ref $args ) { # Arguments are in a hashref if ( ref($args) ne 'HASH' ) { die "Expected a hashref but got a ".ref($args)."\n"; } else { $clean = $args->{'clean'}; $format = $args->{'format'}; $out_file = $args->{'output_file'}; $options = $args->{'options'}; } } else { # Arguments are in a list $clean = $args; $format = shift; $out_file = shift; $options = \@_; } # Default values; $clean ||= 0; $format ||= 'txt'; # Generate README print "readme_from $in_file to $format\n"; if ($format =~ m/te?xt/) { $out_file = $self->_readme_txt($in_file, $out_file, $options); } elsif ($format =~ m/html?/) { $out_file = $self->_readme_htm($in_file, $out_file, $options); } elsif ($format eq 'man') { $out_file = $self->_readme_man($in_file, $out_file, $options); } elsif ($format eq 'pdf') { $out_file = $self->_readme_pdf($in_file, $out_file, $options); } if ($clean) { $self->clean_files($out_file); } return 1; } sub _readme_txt { my ($self, $in_file, $out_file, $options) = @_; $out_file ||= 'README'; require Pod::Text; my $parser = Pod::Text->new( @$options ); open my $out_fh, '>', $out_file or die "Could not write file $out_file:\n$!\n"; $parser->output_fh( *$out_fh ); $parser->parse_file( $in_file ); close $out_fh; return $out_file; } sub _readme_htm { my ($self, $in_file, $out_file, $options) = @_; $out_file ||= 'README.htm'; require Pod::Html; Pod::Html::pod2html( "--infile=$in_file", "--outfile=$out_file", @$options, ); # Remove temporary files if needed for my $file ('pod2htmd.tmp', 'pod2htmi.tmp') { if (-e $file) { unlink $file or warn "Warning: Could not remove file '$file'.\n$!\n"; } } return $out_file; } sub _readme_man { my ($self, $in_file, $out_file, $options) = @_; $out_file ||= 'README.1'; require Pod::Man; my $parser = Pod::Man->new( @$options ); $parser->parse_from_file($in_file, $out_file); return $out_file; } sub _readme_pdf { my ($self, $in_file, $out_file, $options) = @_; $out_file ||= 'README.pdf'; eval { require App::pod2pdf; } or die "Could not generate $out_file because pod2pdf could not be found\n"; my $parser = App::pod2pdf->new( @$options ); $parser->parse_from_file($in_file); open my $out_fh, '>', $out_file or die "Could not write file $out_file:\n$!\n"; select $out_fh; $parser->output; select STDOUT; close $out_fh; return $out_file; } sub _all_from { my $self = shift; return unless $self->admin->{extensions}; my ($metadata) = grep { ref($_) eq 'Module::Install::Metadata'; } @{$self->admin->{extensions}}; return unless $metadata; return $metadata->{values}{all_from} || ''; } 'Readme!'; __END__ #line 254 Time-Moment-0.44/inc/Module/Install/Win32.pm000644 000765 000024 00000003403 13274643622 021233 0ustar00chansenstaff000000 000000 #line 1 package Module::Install::Win32; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.16'; @ISA = 'Module::Install::Base'; $ISCORE = 1; } # determine if the user needs nmake, and download it if needed sub check_nmake { my $self = shift; $self->load('can_run'); $self->load('get_file'); require Config; return unless ( $^O eq 'MSWin32' and $Config::Config{make} and $Config::Config{make} =~ /^nmake\b/i and ! $self->can_run('nmake') ); print "The required 'nmake' executable not found, fetching it...\n"; require File::Basename; my $rv = $self->get_file( url => 'http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe', ftp_url => 'ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe', local_dir => File::Basename::dirname($^X), size => 51928, run => 'Nmake15.exe /o > nul', check_for => 'Nmake.exe', remove => 1, ); die <<'END_MESSAGE' unless $rv; ------------------------------------------------------------------------------- Since you are using Microsoft Windows, you will need the 'nmake' utility before installation. It's available at: http://download.microsoft.com/download/vc15/Patch/1.52/W95/EN-US/Nmake15.exe or ftp://ftp.microsoft.com/Softlib/MSLFILES/Nmake15.exe Please download the file manually, save it to a directory in %PATH% (e.g. C:\WINDOWS\COMMAND\), then launch the MS-DOS command line shell, "cd" to that directory, and run "Nmake15.exe" from there; that will create the 'nmake.exe' file needed by this module. You may then resume the installation process described in README. ------------------------------------------------------------------------------- END_MESSAGE } 1; Time-Moment-0.44/inc/Module/Install/WriteAll.pm000644 000765 000024 00000002376 13274643622 022064 0ustar00chansenstaff000000 000000 #line 1 package Module::Install::WriteAll; use strict; use Module::Install::Base (); use vars qw{$VERSION @ISA $ISCORE}; BEGIN { $VERSION = '1.16'; @ISA = qw{Module::Install::Base}; $ISCORE = 1; } sub WriteAll { my $self = shift; my %args = ( meta => 1, sign => 0, inline => 0, check_nmake => 1, @_, ); $self->sign(1) if $args{sign}; $self->admin->WriteAll(%args) if $self->is_admin; $self->check_nmake if $args{check_nmake}; unless ( $self->makemaker_args->{PL_FILES} ) { # XXX: This still may be a bit over-defensive... unless ($self->makemaker(6.25)) { $self->makemaker_args( PL_FILES => {} ) if -f 'Build.PL'; } } # Until ExtUtils::MakeMaker support MYMETA.yml, make sure # we clean it up properly ourself. $self->realclean_files('MYMETA.yml'); if ( $args{inline} ) { $self->Inline->write; } else { $self->Makefile->write; } # The Makefile write process adds a couple of dependencies, # so write the META.yml files after the Makefile. if ( $args{meta} ) { $self->Meta->write; } # Experimental support for MYMETA if ( $ENV{X_MYMETA} ) { if ( $ENV{X_MYMETA} eq 'JSON' ) { $self->Meta->write_mymeta_json; } else { $self->Meta->write_mymeta_yaml; } } return 1; } 1; Time-Moment-0.44/inc/Module/Install/XSUtil.pm000644 000765 000024 00000045703 13274643622 021532 0ustar00chansenstaff000000 000000 #line 1 package Module::Install::XSUtil; use 5.005_03; $VERSION = '0.45'; use Module::Install::Base; @ISA = qw(Module::Install::Base); use strict; use Config; use File::Spec; use File::Find; use constant _VERBOSE => $ENV{MI_VERBOSE} ? 1 : 0; my %ConfigureRequires = ( 'ExtUtils::ParseXS' => 3.18, # shipped with Perl 5.18.0 ); my %BuildRequires = ( ); my %Requires = ( 'XSLoader' => 0.02, ); my %ToInstall; my $UseC99 = 0; my $UseCplusplus = 0; sub _verbose{ print STDERR q{# }, @_, "\n"; } sub _xs_debugging{ return $ENV{XS_DEBUG} || scalar( grep{ $_ eq '-g' } @ARGV ); } sub _xs_initialize{ my($self) = @_; unless($self->{xsu_initialized}){ $self->{xsu_initialized} = 1; if(!$self->cc_available()){ warn "This distribution requires a C compiler, but it's not available, stopped.\n"; exit; } $self->configure_requires(%ConfigureRequires); $self->build_requires(%BuildRequires); $self->requires(%Requires); $self->makemaker_args->{OBJECT} = '$(O_FILES)'; $self->clean_files('$(O_FILES)'); $self->clean_files('*.stackdump') if $^O eq 'cygwin'; if($self->_xs_debugging()){ # override $Config{optimize} if(_is_msvc()){ $self->makemaker_args->{OPTIMIZE} = '-Zi'; } else{ $self->makemaker_args->{OPTIMIZE} = '-g -ggdb -g3'; } $self->cc_define('-DXS_ASSERT'); } } return; } # GNU C Compiler sub _is_gcc{ return $Config{gccversion}; } # Microsoft Visual C++ Compiler (cl.exe) sub _is_msvc{ return $Config{cc} =~ /\A cl \b /xmsi; } { my $cc_available; sub cc_available { return defined $cc_available ? $cc_available : ($cc_available = shift->can_cc()) ; } # cf. https://github.com/sjn/toolchain-site/blob/219db464af9b2f19b04fec05547ac10180a469f3/lancaster-consensus.md my $want_xs; sub want_xs { my($self, $default) = @_; return $want_xs if defined $want_xs; # you're using this module, you must want XS by default # unless PERL_ONLY is true. $default = !$ENV{PERL_ONLY} if not defined $default; foreach my $arg(@ARGV){ my ($k, $v) = split '=', $arg; # MM-style named args if ($k eq 'PUREPERL_ONLY' && defined $v) { return $want_xs = !$v; } elsif($arg eq '--pp'){ # old-style return $want_xs = 0; } elsif($arg eq '--xs'){ return $want_xs = 1; } } if ($ENV{PERL_MM_OPT}) { my($v) = $ENV{PERL_MM_OPT} =~ /\b PUREPERL_ONLY = (\S+) /xms; if (defined $v) { return $want_xs = !$v; } } return $want_xs = $default; } } sub use_ppport{ my($self, $dppp_version) = @_; return if $self->{_ppport_ok}++; $self->_xs_initialize(); my $filename = 'ppport.h'; $dppp_version ||= 3.19; # the more, the better $self->configure_requires('Devel::PPPort' => $dppp_version); $self->build_requires('Devel::PPPort' => $dppp_version); print "Writing $filename\n"; my $e = do{ local $@; eval qq{ use Devel::PPPort; Devel::PPPort::WriteFile(q{$filename}); }; $@; }; if($e){ print "Cannot create $filename because: $@\n"; } if(-e $filename){ $self->clean_files($filename); $self->cc_define('-DUSE_PPPORT'); $self->cc_append_to_inc('.'); } return; } sub use_xshelper { my($self, $opt) = @_; $self->_xs_initialize(); $self->use_ppport(); my $file = 'xshelper.h'; open my $fh, '>', $file or die "Cannot open $file for writing: $!"; print $fh $self->_xshelper_h(); close $fh or die "Cannot close $file: $!"; if(defined $opt) { if($opt eq '-clean') { $self->clean_files($file); } else { $self->realclean_files($file); } } return; } sub _gccversion { my $res = `$Config{cc} --version`; my ($version) = $res =~ /\(GCC\) ([0-9.]+)/; no warnings 'numeric', 'uninitialized'; return sprintf '%g', $version; } sub cc_warnings{ my($self) = @_; $self->_xs_initialize(); if(_is_gcc()){ $self->cc_append_to_ccflags(qw(-Wall)); my $gccversion = _gccversion(); if($gccversion >= 4.0){ $self->cc_append_to_ccflags(qw(-Wextra)); if(!($UseC99 or $UseCplusplus)) { # Note: MSVC++ doesn't support C99, # so -Wdeclaration-after-statement helps # ensure C89 specs. $self->cc_append_to_ccflags(qw(-Wdeclaration-after-statement)); } if($gccversion >= 4.1 && !$UseCplusplus) { $self->cc_append_to_ccflags(qw(-Wc++-compat)); } } else{ $self->cc_append_to_ccflags(qw(-W -Wno-comment)); } } elsif(_is_msvc()){ $self->cc_append_to_ccflags(qw(-W3)); } else{ # TODO: support other compilers } return; } sub c99_available { my($self) = @_; return 0 if not $self->cc_available(); require File::Temp; require File::Basename; my $tmpfile = File::Temp->new(SUFFIX => '.c'); $tmpfile->print(<<'C99'); // include a C99 header #include inline // a C99 keyword with C99 style comments int test_c99() { int i = 0; i++; int j = i - 1; // another C99 feature: declaration after statement return j; } C99 $tmpfile->close(); system "$Config{cc} -c " . $tmpfile->filename; (my $objname = File::Basename::basename($tmpfile->filename)) =~ s/\Q.c\E$/$Config{_o}/; unlink $objname or warn "Cannot unlink $objname (ignored): $!"; return $? == 0; } sub requires_c99 { my($self) = @_; if(!$self->c99_available) { warn "This distribution requires a C99 compiler, but $Config{cc} seems not to support C99, stopped.\n"; exit; } $self->_xs_initialize(); $UseC99 = 1; return; } sub requires_cplusplus { my($self) = @_; if(!$self->cc_available) { warn "This distribution requires a C++ compiler, but $Config{cc} seems not to support C++, stopped.\n"; exit; } $self->_xs_initialize(); $UseCplusplus = 1; return; } sub cc_append_to_inc{ my($self, @dirs) = @_; $self->_xs_initialize(); for my $dir(@dirs){ unless(-d $dir){ warn("'$dir' not found: $!\n"); } _verbose "inc: -I$dir" if _VERBOSE; } my $mm = $self->makemaker_args; my $paths = join q{ }, map{ s{\\}{\\\\}g; qq{"-I$_"} } @dirs; if($mm->{INC}){ $mm->{INC} .= q{ } . $paths; } else{ $mm->{INC} = $paths; } return; } sub cc_libs { my ($self, @libs) = @_; @libs = map{ my($name, $dir) = ref($_) eq 'ARRAY' ? @{$_} : ($_, undef); my $lib; if(defined $dir) { $lib = ($dir =~ /^-/ ? qq{$dir } : qq{-L$dir }); } else { $lib = ''; } $lib .= ($name =~ /^-/ ? qq{$name} : qq{-l$name}); _verbose "libs: $lib" if _VERBOSE; $lib; } @libs; $self->cc_append_to_libs( @libs ); } sub cc_append_to_libs{ my($self, @libs) = @_; $self->_xs_initialize(); return unless @libs; my $libs = join q{ }, @libs; my $mm = $self->makemaker_args; if ($mm->{LIBS}){ $mm->{LIBS} .= q{ } . $libs; } else{ $mm->{LIBS} = $libs; } return $libs; } sub cc_assert_lib { my ($self, @dcl_args) = @_; if ( ! $self->{xsu_loaded_checklib} ) { my $loaded_lib = 0; foreach my $checklib (qw(inc::Devel::CheckLib Devel::CheckLib)) { eval "use $checklib 0.4"; if (!$@) { $loaded_lib = 1; last; } } if (! $loaded_lib) { warn "Devel::CheckLib not found in inc/ nor \@INC"; exit 0; } $self->{xsu_loaded_checklib}++; $self->configure_requires( "Devel::CheckLib" => "0.4" ); $self->build_requires( "Devel::CheckLib" => "0.4" ); } Devel::CheckLib::check_lib_or_exit(@dcl_args); } sub cc_append_to_ccflags{ my($self, @ccflags) = @_; $self->_xs_initialize(); my $mm = $self->makemaker_args; $mm->{CCFLAGS} ||= $Config{ccflags}; $mm->{CCFLAGS} .= q{ } . join q{ }, @ccflags; return; } sub cc_define{ my($self, @defines) = @_; $self->_xs_initialize(); my $mm = $self->makemaker_args; if(exists $mm->{DEFINE}){ $mm->{DEFINE} .= q{ } . join q{ }, @defines; } else{ $mm->{DEFINE} = join q{ }, @defines; } return; } sub requires_xs_module { my $self = shift; return $self->requires() unless @_; $self->_xs_initialize(); my %added = $self->requires(@_); my(@inc, @libs); my $rx_lib = qr{ \. (?: lib | a) \z}xmsi; my $rx_dll = qr{ \. dll \z}xmsi; # for Cygwin while(my $module = each %added){ my $mod_basedir = File::Spec->join(split /::/, $module); my $rx_header = qr{\A ( .+ \Q$mod_basedir\E ) .+ \. h(?:pp)? \z}xmsi; SCAN_INC: foreach my $inc_dir(@INC){ my @dirs = grep{ -e } File::Spec->join($inc_dir, 'auto', $mod_basedir), File::Spec->join($inc_dir, $mod_basedir); next SCAN_INC unless @dirs; my $n_inc = scalar @inc; find(sub{ if(my($incdir) = $File::Find::name =~ $rx_header){ push @inc, $incdir; } elsif($File::Find::name =~ $rx_lib){ my($libname) = $_ =~ /\A (?:lib)? (\w+) /xmsi; push @libs, [$libname, $File::Find::dir]; } elsif($File::Find::name =~ $rx_dll){ # XXX: hack for Cygwin my $mm = $self->makemaker_args; $mm->{macro}->{PERL_ARCHIVE_AFTER} ||= ''; $mm->{macro}->{PERL_ARCHIVE_AFTER} .= ' ' . $File::Find::name; } }, @dirs); if($n_inc != scalar @inc){ last SCAN_INC; } } } my %uniq = (); $self->cc_append_to_inc (grep{ !$uniq{ $_ }++ } @inc); %uniq = (); $self->cc_libs(grep{ !$uniq{ $_->[0] }++ } @libs); return %added; } sub cc_src_paths{ my($self, @dirs) = @_; $self->_xs_initialize(); return unless @dirs; my $mm = $self->makemaker_args; my $XS_ref = $mm->{XS} ||= {}; my $C_ref = $mm->{C} ||= []; my $_obj = $Config{_o}; my @src_files; find(sub{ if(/ \. (?: xs | c (?: c | pp | xx )? ) \z/xmsi){ # *.{xs, c, cc, cpp, cxx} push @src_files, $File::Find::name; } }, @dirs); my $xs_to = $UseCplusplus ? '.cpp' : '.c'; foreach my $src_file(@src_files){ my $c = $src_file; if($c =~ s/ \.xs \z/$xs_to/xms){ $XS_ref->{$src_file} = $c; _verbose "xs: $src_file" if _VERBOSE; } else{ _verbose "c: $c" if _VERBOSE; } push @{$C_ref}, $c unless grep{ $_ eq $c } @{$C_ref}; } $self->clean_files(map{ File::Spec->catfile($_, '*.gcov'), File::Spec->catfile($_, '*.gcda'), File::Spec->catfile($_, '*.gcno'), } @dirs); $self->cc_append_to_inc('.'); return; } sub cc_include_paths{ my($self, @dirs) = @_; $self->_xs_initialize(); push @{ $self->{xsu_include_paths} ||= []}, @dirs; my $h_map = $self->{xsu_header_map} ||= {}; foreach my $dir(@dirs){ my $prefix = quotemeta( File::Spec->catfile($dir, '') ); find(sub{ return unless / \.h(?:pp)? \z/xms; (my $h_file = $File::Find::name) =~ s/ \A $prefix //xms; $h_map->{$h_file} = $File::Find::name; }, $dir); } $self->cc_append_to_inc(@dirs); return; } sub install_headers{ my $self = shift; my $h_files; if(@_ == 0){ $h_files = $self->{xsu_header_map} or die "install_headers: cc_include_paths not specified.\n"; } elsif(@_ == 1 && ref($_[0]) eq 'HASH'){ $h_files = $_[0]; } else{ $h_files = +{ map{ $_ => undef } @_ }; } $self->_xs_initialize(); my @not_found; my $h_map = $self->{xsu_header_map} || {}; while(my($ident, $path) = each %{$h_files}){ $path ||= $h_map->{$ident} || File::Spec->join('.', $ident); $path = File::Spec->canonpath($path); unless($path && -e $path){ push @not_found, $ident; next; } $ToInstall{$path} = File::Spec->join('$(INST_ARCHAUTODIR)', $ident); _verbose "install: $path as $ident" if _VERBOSE; my @funcs = $self->_extract_functions_from_header_file($path); if(@funcs){ $self->cc_append_to_funclist(@funcs); } } if(@not_found){ die "Header file(s) not found: @not_found\n"; } return; } my $home_directory; sub _extract_functions_from_header_file{ my($self, $h_file) = @_; my @functions; ($home_directory) = <~> unless defined $home_directory; # get header file contents through cpp(1) my $contents = do { my $mm = $self->makemaker_args; my $cppflags = q{"-I}. File::Spec->join($Config{archlib}, 'CORE') . q{"}; $cppflags =~ s/~/$home_directory/g; $cppflags .= ' ' . $mm->{INC} if $mm->{INC}; $cppflags .= ' ' . ($mm->{CCFLAGS} || $Config{ccflags}); $cppflags .= ' ' . $mm->{DEFINE} if $mm->{DEFINE}; my $add_include = _is_msvc() ? '-FI' : '-include'; $cppflags .= ' ' . join ' ', map{ qq{$add_include "$_"} } qw(EXTERN.h perl.h XSUB.h); my $cppcmd = qq{$Config{cpprun} $cppflags $h_file}; # remove all the -arch options to workaround gcc errors: # "-E, -S, -save-temps and -M options are not allowed # with multiple -arch flags" $cppcmd =~ s/ -arch \s* \S+ //xmsg; _verbose("extract functions from: $cppcmd") if _VERBOSE; `$cppcmd`; }; unless(defined $contents){ die "Cannot call C pre-processor ($Config{cpprun}): $! ($?)"; } # remove other include file contents my $chfile = q/\# (?:line)? \s+ \d+ /; $contents =~ s{ ^$chfile \s+ (?!"\Q$h_file\E") .*? ^(?= $chfile) }{}xmsig; if(_VERBOSE){ local *H; open H, "> $h_file.out" and print H $contents and close H; } while($contents =~ m{ ([^\\;\s]+ # type \s+ ([a-zA-Z_][a-zA-Z0-9_]*) # function name \s* \( [^;#]* \) # argument list [\w\s\(\)]* # attributes or something ;) # end of declaration }xmsg){ my $decl = $1; my $name = $2; next if $decl =~ /\b typedef \b/xms; next if $name =~ /^_/xms; # skip something private push @functions, $name; if(_VERBOSE){ $decl =~ tr/\n\r\t / /s; $decl =~ s/ (\Q$name\E) /<$name>/xms; _verbose("decl: $decl"); } } return @functions; } sub cc_append_to_funclist{ my($self, @functions) = @_; $self->_xs_initialize(); my $mm = $self->makemaker_args; push @{$mm->{FUNCLIST} ||= []}, @functions; $mm->{DL_FUNCS} ||= { '$(NAME)' => [] }; return; } sub _xshelper_h { my $h = <<'XSHELPER_H'; :/* THIS FILE IS AUTOMATICALLY GENERATED BY Module::Install::XSUtil $VERSION. */ :/* :=head1 NAME : :xshelper.h - Helper C header file for XS modules : :=head1 DESCRIPTION : : // This includes all the perl header files and ppport.h : #include "xshelper.h" : :=head1 SEE ALSO : :L, where this file is distributed as a part of : :=head1 AUTHOR : :Fuji, Goro (gfx) Egfuji at cpan.orgE : :=head1 LISENCE : :Copyright (c) 2010, Fuji, Goro (gfx). All rights reserved. : :This library is free software; you can redistribute it and/or modify :it under the same terms as Perl itself. : :=cut :*/ : :#ifdef __cplusplus :extern "C" { :#endif : :#define PERL_NO_GET_CONTEXT /* we want efficiency */ :#include :#include :#define NO_XSLOCKS /* for exceptions */ :#include : :#ifdef __cplusplus :} /* extern "C" */ :#endif : :#include "ppport.h" : :/* portability stuff not supported by ppport.h yet */ : :#ifndef STATIC_INLINE /* from 5.13.4 */ :# if defined(__GNUC__) || defined(__cplusplus) || (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) :# define STATIC_INLINE static inline :# else :# define STATIC_INLINE static :# endif :#endif /* STATIC_INLINE */ : :#ifndef __attribute__format__ :#define __attribute__format__(a,b,c) /* nothing */ :#endif : :#ifndef LIKELY /* they are just a compiler's hint */ :#define LIKELY(x) (!!(x)) :#define UNLIKELY(x) (!!(x)) :#endif : :#ifndef newSVpvs_share :#define newSVpvs_share(s) Perl_newSVpvn_share(aTHX_ STR_WITH_LEN(s), 0U) :#endif : :#ifndef get_cvs :#define get_cvs(name, flags) get_cv(name, flags) :#endif : :#ifndef GvNAME_get :#define GvNAME_get GvNAME :#endif :#ifndef GvNAMELEN_get :#define GvNAMELEN_get GvNAMELEN :#endif : :#ifndef CvGV_set :#define CvGV_set(cv, gv) (CvGV(cv) = (gv)) :#endif : :/* general utility */ : :#if PERL_BCDVERSION >= 0x5008005 :#define LooksLikeNumber(x) looks_like_number(x) :#else :#define LooksLikeNumber(x) (SvPOKp(x) ? looks_like_number(x) : (I32)SvNIOKp(x)) :#endif : :#define newAV_mortal() (AV*)sv_2mortal((SV*)newAV()) :#define newHV_mortal() (HV*)sv_2mortal((SV*)newHV()) :#define newRV_inc_mortal(sv) sv_2mortal(newRV_inc(sv)) :#define newRV_noinc_mortal(sv) sv_2mortal(newRV_noinc(sv)) : :#define DECL_BOOT(name) EXTERN_C XS(CAT2(boot_, name)) :#define CALL_BOOT(name) STMT_START { \ : PUSHMARK(SP); \ : CALL_FPTR(CAT2(boot_, name))(aTHX_ cv); \ : } STMT_END XSHELPER_H $h =~ s/^://xmsg; $h =~ s/\$VERSION\b/$Module::Install::XSUtil::VERSION/xms; return $h; } package MY; # XXX: We must append to PM inside ExtUtils::MakeMaker->new(). sub init_PM { my $self = shift; $self->SUPER::init_PM(@_); while(my($k, $v) = each %ToInstall){ $self->{PM}{$k} = $v; } return; } # append object file names to CCCMD sub const_cccmd { my $self = shift; my $cccmd = $self->SUPER::const_cccmd(@_); return q{} unless $cccmd; if (Module::Install::XSUtil::_is_msvc()){ $cccmd .= ' -Fo$@'; } else { $cccmd .= ' -o $@'; } return $cccmd } sub xs_c { my($self) = @_; my $mm = $self->SUPER::xs_c(); $mm =~ s/ \.c /.cpp/xmsg if $UseCplusplus; return $mm; } sub xs_o { my($self) = @_; my $mm = $self->SUPER::xs_o(); $mm =~ s/ \.c /.cpp/xmsg if $UseCplusplus; return $mm; } 1; __END__ #line 1030 Time-Moment-0.44/eg/age.pl000755 000765 000024 00000005326 12650263654 016064 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Time::Moment; # Calculates age of a person in calendar years. # # Where a person has been born on February 29th in a leap year, the # anniversary in a non-leap year can be taken to be February 28th or # March 1st. Some countries have laws defining which date a person # born on February 29th comes of age in legal terms. In England and # Wales, for example, the legal age of a leapling is March 1st in # common years. The same applies in Hong Kong. In Taiwan and in # New Zealand, the legal age of a leapling is February 28th in # common years. # https://en.wikipedia.org/wiki/February_29#Births sub calculate_age { @_ == 2 or @_ == 3 or die q/Usage: calculate_age($birth, $event [, $march])/; my ($birth, $event, $march) = @_; my $years = $birth->delta_years($event); unless ($march) { # Increment if birth is 02-29 and event is 02-28 in a non-leap year ++$years if $birth->day_of_year == 31 + 29 && $birth->is_leap_year && $event->day_of_year == 31 + 28 && !$event->is_leap_year; } return $years; } my @tests = ( [ '2008-02-28T00Z', '2015-02-27T00Z', 0, 6 ], [ '2008-02-28T00Z', '2015-02-28T00Z', 0, 7 ], [ '2008-02-28T00Z', '2015-03-01T00Z', 0, 7 ], [ '2008-02-29T00Z', '2015-02-27T00Z', 0, 6 ], [ '2008-02-29T00Z', '2015-02-28T00Z', 0, 7 ], [ '2008-02-29T00Z', '2015-03-01T00Z', 0, 7 ], [ '2008-03-01T00Z', '2015-02-27T00Z', 0, 6 ], [ '2008-03-01T00Z', '2015-02-28T00Z', 0, 6 ], [ '2008-03-01T00Z', '2015-03-01T00Z', 0, 7 ], [ '2008-02-29T00Z', '2016-02-27T00Z', 0, 7 ], [ '2008-02-29T00Z', '2016-02-28T00Z', 0, 7 ], [ '2008-02-29T00Z', '2016-02-29T00Z', 0, 8 ], [ '2008-02-29T00Z', '2016-03-01T00Z', 0, 8 ], [ '2008-02-28T00Z', '2015-02-27T00Z', 1, 6 ], [ '2008-02-28T00Z', '2015-02-28T00Z', 1, 7 ], [ '2008-02-28T00Z', '2015-03-01T00Z', 1, 7 ], [ '2008-02-29T00Z', '2015-02-27T00Z', 1, 6 ], [ '2008-02-29T00Z', '2015-02-28T00Z', 1, 6 ], [ '2008-02-29T00Z', '2015-03-01T00Z', 1, 7 ], [ '2008-03-01T00Z', '2015-02-27T00Z', 1, 6 ], [ '2008-03-01T00Z', '2015-02-28T00Z', 1, 6 ], [ '2008-03-01T00Z', '2015-03-01T00Z', 1, 7 ], [ '2008-02-29T00Z', '2016-02-27T00Z', 1, 7 ], [ '2008-02-29T00Z', '2016-02-28T00Z', 1, 7 ], [ '2008-02-29T00Z', '2016-02-29T00Z', 1, 8 ], [ '2008-02-29T00Z', '2016-03-01T00Z', 1, 8 ], ); use Test::More 0.88; foreach my $test (@tests) { my ($birth, $event, $march, $age) = @$test; my $got = calculate_age(Time::Moment->from_string($birth), Time::Moment->from_string($event), $march); is($got, $age, "calculate_age($birth, $event, $march)"); } done_testing(); Time-Moment-0.44/eg/ago.pl000755 000765 000024 00000005044 13075675554 016103 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use v5.10; use Carp qw[]; use Time::Moment qw[]; sub YEAR () { 365 + 1/4 - 1/100 + 1/400 } sub MONTH () { YEAR / 12 } sub DAY () { 1 } sub HOUR () { DAY / 24 } sub MINUTE () { HOUR / 60 } sub SECOND () { MINUTE / 60 } sub ago { @_ == 1 || @_ == 2 or Carp::croak(q/Usage: ago(since [, event])/); my ($since, $event) = @_; $event //= Time::Moment->now; ($since->is_before($event)) or Carp::croak(q/Given moment is in the future/); my $d = $event->mjd - $since->mjd; if ($d < 0.75 * DAY) { if ($d < 0.75 * MINUTE) { return 'a few seconds ago'; } elsif ($d < 1.5 * MINUTE) { return 'a minute ago'; } elsif ($d < 0.75 * HOUR) { return sprintf '%d minutes ago', $d / MINUTE + 0.5; } elsif ($d < 1.5 * HOUR) { return 'an hour ago'; } else { return sprintf '%d hours ago', $d / HOUR + 0.5; } } else { if ($d < 1.5 * DAY) { return 'a day ago'; } elsif ($d < 0.75 * MONTH) { return sprintf '%d days ago', $d / DAY + 0.5; } elsif ($d < 1.5 * MONTH) { return 'a month ago'; } elsif ($d < 0.75 * YEAR) { return sprintf '%d months ago', $d / MONTH + 0.5; } elsif ($d < 1.5 * YEAR) { return 'a year ago'; } else { return sprintf '%d years ago', $d / YEAR + 0.5; } } } my @tests = ( [ 10 * SECOND, 'a few seconds ago' ], [ 75 * SECOND, 'a minute ago' ], [ 1 * MINUTE, 'a minute ago' ], [ 30 * MINUTE, '30 minutes ago' ], [ 1 * HOUR, 'an hour ago' ], [ 2 * HOUR, '2 hours ago' ], [ 1 * DAY, 'a day ago' ], [ 20 * DAY, '20 days ago' ], [ 1 * MONTH, 'a month ago' ], [ 2 * MONTH, '2 months ago' ], [ 13 * MONTH, 'a year ago' ], [ 1 * YEAR, 'a year ago' ], [ 2 * YEAR, '2 years ago' ], [ 10 * YEAR, '10 years ago' ], [ 100 * YEAR, '100 years ago' ], ); use Time::Moment 0.25; use Test::More 0.88; my $now = Time::Moment->now; foreach my $test (@tests) { my ($duration, $expected) = @$test; my $tm = Time::Moment->from_mjd($now->mjd - $duration); is(ago($tm, $now), $expected, "$tm ($duration)"); } done_testing(); Time-Moment-0.44/eg/beat.pl000755 000765 000024 00000001022 13250234721 016216 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Time::Moment; # Converts the given moment to Swatch Internet Time (beat time). # http://www.swatch.com/en/internet-time # https://en.wikipedia.org/wiki/Swatch_Internet_Time sub moment_to_beat { @_ == 1 or die q/Usage: moment_to_beat(moment)/; my ($tm) = @_; # Biel Meantime (BMT) is UTC+1 my $rd = $tm->with_offset_same_instant(1*60) ->rd; return ($rd - int $rd) * 1E3; } my $tm = Time::Moment->now; printf "@%3.3f\n", moment_to_beat($tm); Time-Moment-0.44/eg/cal.pl000755 000765 000024 00000004076 12676503450 016067 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use v5.10; use Getopt::Long qw[]; use Time::Moment qw[]; my $FirstDayOfWeek = 1; # Monday my $Moment = Time::Moment->now ->with_day_of_month(1) ->at_midnight; Getopt::Long::GetOptions( 'y|year=i' => sub { my ($name, $year) = @_; ($year >= 1 && $year <= 9999) or die qq/Option '$name' is out of the range [1, 9999]\n/; $Moment = $Moment->with_year($year); }, 'm|month=i' => sub { my ($name, $month) = @_; ($month >= 1 && $month <= 12) or die qq/Option '$name' is out of the range [1=January, 12=December]\n/; $Moment = $Moment->with_month($month); }, 'f|first=i' => sub { my ($name, $day) = @_; ($day >= 1 && $day <= 7) or die qq/Option '$name' is out of the range [1=Monday, 7=Sunday]\n/; $FirstDayOfWeek = $day; }, ) or do { say "usage: $0 [-y year] [-m month] [-f day]"; say " -y --year the year [1, 9999]"; say " -m --month the month of the year [1=January, 12=December]"; say " -f --first the first day of the week [1=Monday, 7=Sunday]"; exit(1); }; sub align { @_ == 2 or die q/Usage: align(string, width)/; my ($string, $width) = @_; return sprintf "%*s", ($width + length $string) / 2, $string; } say align($Moment->strftime('%B %Y'), 20); say join ' ', map { (qw[ Mo Tu We Th Fr Sa Su ])[ ($_ + $FirstDayOfWeek - 1) % 7 ] } (0..6); my $this_month = $Moment; my $next_month = $Moment->plus_months(1); my $date = $Moment->minus_weeks($FirstDayOfWeek > $Moment->day_of_week) ->with_day_of_week($FirstDayOfWeek); while ($date->is_before($next_month)) { my @week; foreach my $day (1..7) { if ($date->is_before($this_month)) { push @week, ' '; } elsif ($date->is_before($next_month)) { push @week, sprintf '%2d', $date->day_of_month; } $date = $date->plus_days(1); } say join ' ', @week; } Time-Moment-0.44/eg/cbor.pl000755 000765 000024 00000001566 12676504031 016252 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Time::Moment qw[]; use Time::HiRes qw[]; use CBOR::XS qw[encode_cbor]; sub filter { my ($tag) = @_; # http://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml if ($tag == 0) { return Time::Moment->from_string($_[1]) } elsif ($tag == 1) { return Time::Moment->from_epoch($_[1]) } else { return &CBOR::XS::default_filter } } my $encoded = encode_cbor([ # Tag 0 is standard date/time string; see Section 2.4.1 CBOR::XS::tag(0, '2013-12-24T12:30:45.123456789+01:00'), # Tag 1 is epoch-based date/time; see Section 2.4.1 CBOR::XS::tag(1, time), CBOR::XS::tag(1, Time::HiRes::time), # Serializes as tag 0 Time::Moment->now, ]); my $decoded = CBOR::XS->new->filter(\&filter)->decode($encoded); foreach my $moment (@$decoded) { print $moment->to_string, "\n"; } Time-Moment-0.44/eg/clocks.pl000755 000765 000024 00000002031 13107504076 016566 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Time::Moment; use DateTime::TimeZone; my @zones = qw( Africa/Cairo America/Chicago America/Los_Angeles America/New_York Asia/Dubai Asia/Hong_Kong Asia/Kathmandu Asia/Tokyo Australia/Sydney Europe/Brussels Europe/London Europe/Moscow Europe/Paris Europe/Stockholm Pacific/Apia ); my $now = Time::Moment->now; my @clocks; foreach my $name (@zones) { my $zone = DateTime::TimeZone->new(name => $name); my $offset = $zone->offset_for_datetime($now) / 60; my $time = $now->with_offset_same_instant($offset); $name =~ s![^/]+/!!; $name =~ s!_!\x20!g; push @clocks, [$name, $time]; } @clocks = sort { $a->[1]->offset <=> $b->[1]->offset or $a->[0] cmp $b->[0] } @clocks; for my $clock (@clocks) { my ($name, $time) = @$clock; my $delta = $time->offset - $now->offset; printf "%-12s %-16s (%+.2d:%.2d)\n", $name, $time->strftime("%a %H:%M %:z"), $delta / 60, abs($delta) % 60; } Time-Moment-0.44/eg/excel.pl000755 000765 000024 00000015032 12665641277 016432 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; # Convert between Excel serial dates and Time::Moment use Time::Moment; use constant EXCEL_EPOCH => Time::Moment->from_string('1899-12-30T00Z')->rd; sub moment_from_excel { @_ == 1 or die q/Usage: moment_from_excel(date)/; my ($date) = @_; return Time::Moment->from_rd($date + ($date < 61), epoch => EXCEL_EPOCH); } sub moment_to_excel { @_ == 1 or die q/Usage: moment_to_excel(moment)/; my ($moment) = @_; my $date = $moment->rd - EXCEL_EPOCH; return $date - ($date < 61); } my @tests = ( [ '1899-12-31T00:00:00Z', 0 ], [ '1900-01-01T00:00:00Z', 1 ], [ '1900-02-27T00:00:00Z', 58 ], [ '1900-02-28T00:00:00Z', 59 ], [ '1900-03-01T00:00:00Z', 61 ], [ '1900-03-02T00:00:00Z', 62 ], [ '1969-12-31T23:59:58Z', 25568.9999768519 ], [ '1969-12-31T23:59:58.500Z', 25568.9999826389 ], [ '1969-12-31T23:59:58.800Z', 25568.9999861111 ], [ '1969-12-31T23:59:58.900Z', 25568.9999872685 ], [ '1969-12-31T23:59:58.980Z', 25568.9999881944 ], [ '1969-12-31T23:59:58.990Z', 25568.9999883102 ], [ '1969-12-31T23:59:58.998Z', 25568.9999884028 ], [ '1969-12-31T23:59:58.999Z', 25568.9999884143 ], [ '1969-12-31T23:59:59Z', 25568.9999884259 ], [ '1969-12-31T23:59:59.001Z', 25568.9999884375 ], [ '1969-12-31T23:59:59.002Z', 25568.9999884490 ], [ '1969-12-31T23:59:59.010Z', 25568.9999885417 ], [ '1969-12-31T23:59:59.020Z', 25568.9999886574 ], [ '1969-12-31T23:59:59.100Z', 25568.9999895834 ], [ '1969-12-31T23:59:59.200Z', 25568.9999907408 ], [ '1969-12-31T23:59:59.300Z', 25568.9999918982 ], [ '1969-12-31T23:59:59.400Z', 25568.9999930556 ], [ '1969-12-31T23:59:59.490Z', 25568.9999940973 ], [ '1969-12-31T23:59:59.499Z', 25568.9999942014 ], [ '1969-12-31T23:59:59.500Z', 25568.9999942130 ], [ '1969-12-31T23:59:59.501Z', 25568.9999942245 ], [ '1969-12-31T23:59:59.510Z', 25568.9999943287 ], [ '1969-12-31T23:59:59.600Z', 25568.9999953704 ], [ '1969-12-31T23:59:59.700Z', 25568.9999965278 ], [ '1969-12-31T23:59:59.800Z', 25568.9999976852 ], [ '1969-12-31T23:59:59.900Z', 25568.9999988426 ], [ '1969-12-31T23:59:59.980Z', 25568.9999997686 ], [ '1969-12-31T23:59:59.990Z', 25568.9999998843 ], [ '1969-12-31T23:59:59.998Z', 25568.9999999768 ], [ '1969-12-31T23:59:59.999Z', 25568.9999999885 ], [ '1970-01-01T00:00:00Z', 25569 ], [ '1970-01-01T00:00:00.001Z', 25569.0000000115 ], [ '1970-01-01T00:00:00.002Z', 25569.0000000232 ], [ '1970-01-01T00:00:00.010Z', 25569.0000001157 ], [ '1970-01-01T00:00:00.020Z', 25569.0000002314 ], [ '1970-01-01T00:00:00.100Z', 25569.0000011574 ], [ '1970-01-01T00:00:00.200Z', 25569.0000023148 ], [ '1970-01-01T00:00:00.300Z', 25569.0000034722 ], [ '1970-01-01T00:00:00.400Z', 25569.0000046296 ], [ '1970-01-01T00:00:00.490Z', 25569.0000056713 ], [ '1970-01-01T00:00:00.499Z', 25569.0000057755 ], [ '1970-01-01T00:00:00.500Z', 25569.0000057870 ], [ '1970-01-01T00:00:00.501Z', 25569.0000057986 ], [ '1970-01-01T00:00:00.510Z', 25569.0000059027 ], [ '1970-01-01T00:00:00.600Z', 25569.0000069444 ], [ '1970-01-01T00:00:00.700Z', 25569.0000081018 ], [ '1970-01-01T00:00:00.800Z', 25569.0000092592 ], [ '1970-01-01T00:00:00.900Z', 25569.0000104166 ], [ '1970-01-01T00:00:00.980Z', 25569.0000113426 ], [ '1970-01-01T00:00:00.990Z', 25569.0000114583 ], [ '1970-01-01T00:00:00.998Z', 25569.0000115510 ], [ '1970-01-01T00:00:00.999Z', 25569.0000115625 ], [ '1970-01-01T00:00:01Z', 25569.0000115741 ], [ '1970-01-01T00:00:01.001Z', 25569.0000115857 ], [ '1970-01-01T00:00:01.002Z', 25569.0000115972 ], [ '1970-01-01T00:00:01.010Z', 25569.0000116898 ], [ '1970-01-01T00:00:01.020Z', 25569.0000118056 ], [ '1970-01-01T00:00:01.100Z', 25569.0000127315 ], [ '1970-01-01T00:00:01.200Z', 25569.0000138889 ], [ '9999-12-31T23:59:58Z', 2958465.9999768520 ], [ '9999-12-31T23:59:58.500Z', 2958465.9999826388 ], [ '9999-12-31T23:59:58.800Z', 2958465.9999861112 ], [ '9999-12-31T23:59:58.900Z', 2958465.9999872684 ], [ '9999-12-31T23:59:58.980Z', 2958465.9999881946 ], [ '9999-12-31T23:59:58.990Z', 2958465.9999883100 ], [ '9999-12-31T23:59:58.998Z', 2958465.9999884027 ], [ '9999-12-31T23:59:58.999Z', 2958465.9999884143 ], [ '9999-12-31T23:59:59Z', 2958465.9999884260 ], [ '9999-12-31T23:59:59.001Z', 2958465.9999884376 ], [ '9999-12-31T23:59:59.002Z', 2958465.9999884493 ], [ '9999-12-31T23:59:59.010Z', 2958465.9999885415 ], [ '9999-12-31T23:59:59.020Z', 2958465.9999886574 ], [ '9999-12-31T23:59:59.100Z', 2958465.9999895832 ], [ '9999-12-31T23:59:59.200Z', 2958465.9999907408 ], [ '9999-12-31T23:59:59.300Z', 2958465.9999918980 ], [ '9999-12-31T23:59:59.400Z', 2958465.9999930556 ], [ '9999-12-31T23:59:59.490Z', 2958465.9999940973 ], [ '9999-12-31T23:59:59.499Z', 2958465.9999942016 ], [ '9999-12-31T23:59:59.500Z', 2958465.9999942128 ], [ '9999-12-31T23:59:59.501Z', 2958465.9999942244 ], [ '9999-12-31T23:59:59.510Z', 2958465.9999943287 ], [ '9999-12-31T23:59:59.600Z', 2958465.9999953704 ], [ '9999-12-31T23:59:59.700Z', 2958465.9999965276 ], [ '9999-12-31T23:59:59.800Z', 2958465.9999976852 ], [ '9999-12-31T23:59:59.900Z', 2958465.9999988424 ], [ '9999-12-31T23:59:59.980Z', 2958465.9999997686 ], [ '9999-12-31T23:59:59.990Z', 2958465.9999998841 ], [ '9999-12-31T23:59:59.998Z', 2958465.9999999767 ], [ '9999-12-31T23:59:59.999Z', 2958465.9999999884 ], ); use Test::More 0.88; use Test::Number::Delta 1.06 relative => 1E-10; foreach my $test (@tests) { my ($string, $date) = @$test; my $tm = moment_from_excel($date); is($tm->to_string, $string, "moment_from_excel($date)"); delta_ok(moment_to_excel($tm), $date, "moment_to_excel($tm)"); } done_testing(); eval { require DateTime::Format::Excel; require Benchmark; { print "\nComparing DateTime::Format::Excel and Time::Moment\n"; my $date = 30188.010650613425; Benchmark::cmpthese( -10, { 'DateTime' => sub { my $dt = DateTime::Format::Excel->parse_datetime($date); }, 'Time::Moment' => sub { my $tm = moment_from_excel($date); }, }); } }; Time-Moment-0.44/eg/json.pl000755 000765 000024 00000000245 12577205411 016267 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Time::Moment qw[]; use JSON::XS qw[]; print JSON::XS->new->convert_blessed->encode([ Time::Moment->now ]), "\n"; Time-Moment-0.44/eg/se_bank_holidays.pl000755 000765 000024 00000020365 13017117767 020627 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Time::Moment; use Time::Moment::Adjusters qw[ NextOrSameDayOfWeek WesternEasterSunday ]; use enum qw[ Monday=1 Tuesday Wednesday Thursday Friday Saturday Sunday ]; # Lag (1989:253) om allmänna helgdagar (Act (1989:253) on public holidays) # https://lagen.nu/1989:253 sub compute_public_holidays { @_ == 1 or die q; my ($year) = @_; my @dates; my $tm = Time::Moment->new(year => $year); my $easter = $tm->with(WesternEasterSunday); # Nyårsdagen (New Year's Day), January 1. push @dates, $tm->with_month(1) ->with_day_of_month(1); # Trettondagen (Epiphany), January 6. push @dates, $tm->with_month(1) ->with_day_of_month(6); # Långfredagen (Good Friday), the Friday preceding Easter Sunday. push @dates, $easter->minus_days(2); # Påskdagen (Easter Sunday), the Sunday immediately following # the full moon that occurs on or next after 21 March. push @dates, $easter; # Annandag påsk (Easter Monday), the day after Easter Sunday. push @dates, $easter->plus_days(1); # Kristi himmelsfärds dag (Ascension Day), sixth Thursday # after Easter Sunday. push @dates, $easter->plus_days(5*7+4); # Pingstdagen (Pentecost), seventh Sunday after Easter Sunday. push @dates, $easter->plus_days(7*7); # Annandag pingst (Whit Monday), the day after Pentecost. if ($year <= 2004) { push @dates, $easter->plus_days(7*7+1); } # Första maj (First of May), May 1. push @dates, $tm->with_month(5) ->with_day_of_month(1); # Sveriges nationaldag (National Day of Sweden), June 6. if ($year >= 2005) { push @dates, $tm->with_month(6) ->with_day_of_month(6); } # Midsommardagen (Midsummer's Day), Saturday that falls # between June 20th to 26th. push @dates, $tm->with_month(6) ->with_day_of_month(20) ->with(NextOrSameDayOfWeek(Saturday)); # Alla helgons dag (All Saints' Day), Saturday that falls # between Oct 31st to Nov 6th. push @dates, $tm->with_month(10) ->with_day_of_month(31) ->with(NextOrSameDayOfWeek(Saturday)); # Juldagen (Christmas Day), December 25. push @dates, $tm->with_month(12) ->with_day_of_month(25); # Annandag jul (Boxing Day), December 26. push @dates, $tm->with_month(12) ->with_day_of_month(26); return @dates; } # Swedish bank holidays # All days except Saturdays, Sundays, Epiphany, Good Friday, # Easter Monday, First of May, Ascension Day, Sweden's National # Day, Midsummer Eve, Christmas Eve, Christmas Day, Boxing # Day, New Year's Eve and New Year's Day (all according to the # Swedish calendar), as well as any other days currently stipulated # by the Swedish Act (1989:253) on Public Holidays. sub compute_bank_holidays { @_ == 1 or die q; my ($year) = @_; my @dates = compute_public_holidays($year); my $tm = Time::Moment->new(year => $year); # Midsommarafton (Midsummer's Eve), Friday that falls # between June 19th to 25th. push @dates, $tm->with_month(6) ->with_day_of_month(19) ->with(NextOrSameDayOfWeek(Friday)); # Julafton (Christmas Eve), December 24. push @dates, $tm->with_month(12) ->with_day_of_month(24); # Nyårsafton (New Year's Eve), December 31. push @dates, $tm->with_month(12) ->with_day_of_month(31); return sort { $a <=> $b } grep { $_->day_of_week <= Friday } @dates; } my @tests = ( [ 2000, '2000-01-06', '2000-04-21', '2000-04-24', '2000-05-01', '2000-06-01', '2000-06-12', '2000-06-23', '2000-12-25', '2000-12-26' ], [ 2001, '2001-01-01', '2001-04-13', '2001-04-16', '2001-05-01', '2001-05-24', '2001-06-04', '2001-06-22', '2001-12-24', '2001-12-25', '2001-12-26', '2001-12-31' ], [ 2002, '2002-01-01', '2002-03-29', '2002-04-01', '2002-05-01', '2002-05-09', '2002-05-20', '2002-06-21', '2002-12-24', '2002-12-25', '2002-12-26', '2002-12-31' ], [ 2003, '2003-01-01', '2003-01-06', '2003-04-18', '2003-04-21', '2003-05-01', '2003-05-29', '2003-06-09', '2003-06-20', '2003-12-24', '2003-12-25', '2003-12-26', '2003-12-31' ], [ 2004, '2004-01-01', '2004-01-06', '2004-04-09', '2004-04-12', '2004-05-20', '2004-05-31', '2004-06-25', '2004-12-24', '2004-12-31' ], [ 2005, '2005-01-06', '2005-03-25', '2005-03-28', '2005-05-05', '2005-06-06', '2005-06-24', '2005-12-26' ], [ 2006, '2006-01-06', '2006-04-14', '2006-04-17', '2006-05-01', '2006-05-25', '2006-06-06', '2006-06-23', '2006-12-25', '2006-12-26' ], [ 2007, '2007-01-01', '2007-04-06', '2007-04-09', '2007-05-01', '2007-05-17', '2007-06-06', '2007-06-22', '2007-12-24', '2007-12-25', '2007-12-26', '2007-12-31' ], [ 2008, '2008-01-01', '2008-03-21', '2008-03-24', '2008-05-01', '2008-05-01', '2008-06-06', '2008-06-20', '2008-12-24', '2008-12-25', '2008-12-26', '2008-12-31' ], [ 2009, '2009-01-01', '2009-01-06', '2009-04-10', '2009-04-13', '2009-05-01', '2009-05-21', '2009-06-19', '2009-12-24', '2009-12-25', '2009-12-31' ], [ 2010, '2010-01-01', '2010-01-06', '2010-04-02', '2010-04-05', '2010-05-13', '2010-06-25', '2010-12-24', '2010-12-31' ], [ 2011, '2011-01-06', '2011-04-22', '2011-04-25', '2011-06-02', '2011-06-06', '2011-06-24', '2011-12-26' ], [ 2012, '2012-01-06', '2012-04-06', '2012-04-09', '2012-05-01', '2012-05-17', '2012-06-06', '2012-06-22', '2012-12-24', '2012-12-25', '2012-12-26', '2012-12-31' ], [ 2013, '2013-01-01', '2013-03-29', '2013-04-01', '2013-05-01', '2013-05-09', '2013-06-06', '2013-06-21', '2013-12-24', '2013-12-25', '2013-12-26', '2013-12-31' ], [ 2014, '2014-01-01', '2014-01-06', '2014-04-18', '2014-04-21', '2014-05-01', '2014-05-29', '2014-06-06', '2014-06-20', '2014-12-24', '2014-12-25', '2014-12-26', '2014-12-31' ], [ 2015, '2015-01-01', '2015-01-06', '2015-04-03', '2015-04-06', '2015-05-01', '2015-05-14', '2015-06-19', '2015-12-24', '2015-12-25', '2015-12-31' ], [ 2016, '2016-01-01', '2016-01-06', '2016-03-25', '2016-03-28', '2016-05-05', '2016-06-06', '2016-06-24', '2016-12-26' ], [ 2017, '2017-01-06', '2017-04-14', '2017-04-17', '2017-05-01', '2017-05-25', '2017-06-06', '2017-06-23', '2017-12-25', '2017-12-26' ], [ 2018, '2018-01-01', '2018-03-30', '2018-04-02', '2018-05-01', '2018-05-10', '2018-06-06', '2018-06-22', '2018-12-24', '2018-12-25', '2018-12-26', '2018-12-31' ], [ 2019, '2019-01-01', '2019-04-19', '2019-04-22', '2019-05-01', '2019-05-30', '2019-06-06', '2019-06-21', '2019-12-24', '2019-12-25', '2019-12-26', '2019-12-31' ], [ 2020, '2020-01-01', '2020-01-06', '2020-04-10', '2020-04-13', '2020-05-01', '2020-05-21', '2020-06-19', '2020-12-24', '2020-12-25', '2020-12-31' ], ); use Test::More 0.88; foreach my $test (@tests) { my ($year, @exp) = @$test; my @got = map { $_->strftime('%Y-%m-%d') } compute_bank_holidays($year); is_deeply([@got], [@exp], "Swedish bank holidays for year $year"); } done_testing(); Time-Moment-0.44/eg/sereal.pl000755 000765 000024 00000000552 12676504044 016576 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Time::Moment qw[]; use Sereal 2.030 qw[encode_sereal decode_sereal]; my @moments = (Time::Moment->now, Time::Moment->now_utc); my $encoded = encode_sereal([ @moments ], { freeze_callbacks => 1 }); my $decoded = decode_sereal($encoded); foreach my $moment (@$decoded) { print $moment->to_string, "\n"; } Time-Moment-0.44/eg/strftime.pl000755 000765 000024 00000002411 13015630623 017143 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Time::Moment; my $tm = Time::Moment->now; sub output { my ($type, $basic, $extended) = @_; print "\nCombinations of $type date and time of day:\n"; print "\nBasic format: Example:\n"; foreach my $format (@$basic) { printf "%-22s %s\n", $format, $tm->strftime($format); } print "\nExtended format: Example:\n"; foreach my $format (@$extended) { printf "%-22s %s\n", $format, $tm->strftime($format); } } { my @basic = qw( %Y%m%dT%H%M%S%z %Y%m%dT%H%M%S%f%z %Y%m%dT%H%M%z ); my @extended = qw( %Y-%m-%dT%H:%M:%S%Z %Y-%m-%dT%H:%M:%S%f%Z %Y-%m-%dT%H:%M%Z ); output('calendar', \@basic, \@extended); } { my @basic = qw( %Y%jT%H%M%S%z %Y%jT%H%M%S%f%z %Y%jT%H%M%z ); my @extended = qw( %Y-%jT%H:%M:%S%Z %Y-%jT%H:%M:%S%f%Z %Y-%jT%H:%M%Z ); output('ordinal', \@basic, \@extended); } { my @basic = qw( %GW%V%uT%H%M%S%z %GW%V%uT%H%M%S%f%z %GW%V%uT%H%M%z ); my @extended = qw( %G-W%V-%uT%H:%M:%S%Z %G-W%V-%uT%H:%M:%S%f%Z %G-W%V-%uT%H:%M%Z ); output('week', \@basic, \@extended); } Time-Moment-0.44/eg/us_federal_holidays.pl000755 000765 000024 00000016554 13017117767 021343 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Time::Moment; use Time::Moment::Adjusters qw[ NthDayOfWeekInMonth ]; use enum qw[ Monday=1 Tuesday Wednesday Thursday Friday Saturday Sunday ]; use enum qw[ First=1 Second Third Fourth Last=-1 ]; use constant FirstMondayInMonth => NthDayOfWeekInMonth(First, Monday); use constant SecondMondayInMonth => NthDayOfWeekInMonth(Second, Monday); use constant ThirdMondayInMonth => NthDayOfWeekInMonth(Third, Monday); use constant LastMondayInMonth => NthDayOfWeekInMonth(Last, Monday); use constant FourthThursdayInMonth => NthDayOfWeekInMonth(Fourth, Thursday); # Adjusts the date to the nearest workday use constant NearestWorkday => sub { my ($tm) = @_; return $tm unless $tm->day_of_week > Friday; return $tm->plus_days($tm->day_of_week == Saturday ? -1 : +1); }; # Federal law 5 USC § 6103 - HOLIDAYS # http://www.law.cornell.edu/uscode/text/5/6103 sub compute_us_federal_holidays { @_ == 1 or @_ == 2 or die q; my ($year, $inauguration) = @_; my @dates; my $tm = Time::Moment->new(year => $year); # New Year’s Day, January 1. push @dates, $tm->with_month(1) ->with_day_of_month(1) ->with(NearestWorkday); # Birthday of Martin Luther King, Jr., the third Monday in January. push @dates, $tm->with_month(1) ->with(ThirdMondayInMonth); # Inauguration Day, January 20 of each fourth year after 1965. if ($inauguration && $year % 4 == 1) { my $date = $tm->with_month(1) ->with_day_of_month(20); # When January 20 falls on Sunday, the next succeeding day is selected. $date = $date->plus_days(1) if $date->day_of_week == Sunday; push @dates, $date unless $date->day_of_week == Saturday or $date->is_equal($dates[-1]); # 1997, 2013, 2025 ... } # Washington’s Birthday, the third Monday in February. push @dates, $tm->with_month(2) ->with(ThirdMondayInMonth); # Memorial Day, the last Monday in May. push @dates, $tm->with_month(5) ->with(LastMondayInMonth); # Independence Day, July 4. push @dates, $tm->with_month(7) ->with_day_of_month(4) ->with(NearestWorkday); # Labor Day, the first Monday in September. push @dates, $tm->with_month(9) ->with(FirstMondayInMonth); # Columbus Day, the second Monday in October. push @dates, $tm->with_month(10) ->with(SecondMondayInMonth); # Veterans Day, November 11. push @dates, $tm->with_month(11) ->with_day_of_month(11) ->with(NearestWorkday); # Thanksgiving Day, the fourth Thursday in November. push @dates, $tm->with_month(11) ->with(FourthThursdayInMonth); # Christmas Day, December 25. push @dates, $tm->with_month(12) ->with_day_of_month(25) ->with(NearestWorkday); return @dates; } # Test cases extracted from my @tests = ( [ 1997, '1997-01-01', '1997-01-20', '1997-02-17', '1997-05-26', '1997-07-04', '1997-09-01', '1997-10-13', '1997-11-11', '1997-11-27', '1997-12-25' ], [ 1998, '1998-01-01', '1998-01-19', '1998-02-16', '1998-05-25', '1998-07-03', '1998-09-07', '1998-10-12', '1998-11-11', '1998-11-26', '1998-12-25' ], [ 1999, '1999-01-01', '1999-01-18', '1999-02-15', '1999-05-31', '1999-07-05', '1999-09-06', '1999-10-11', '1999-11-11', '1999-11-25', '1999-12-24' ], [ 2000, '1999-12-31', '2000-01-17', '2000-02-21', '2000-05-29', '2000-07-04', '2000-09-04', '2000-10-09', '2000-11-10', '2000-11-23', '2000-12-25' ], [ 2001, '2001-01-01', '2001-01-15', '2001-02-19', '2001-05-28', '2001-07-04', '2001-09-03', '2001-10-08', '2001-11-12', '2001-11-22', '2001-12-25' ], [ 2002, '2002-01-01', '2002-01-21', '2002-02-18', '2002-05-27', '2002-07-04', '2002-09-02', '2002-10-14', '2002-11-11', '2002-11-28', '2002-12-25' ], [ 2003, '2003-01-01', '2003-01-20', '2003-02-17', '2003-05-26', '2003-07-04', '2003-09-01', '2003-10-13', '2003-11-11', '2003-11-27', '2003-12-25' ], [ 2004, '2004-01-01', '2004-01-19', '2004-02-16', '2004-05-31', '2004-07-05', '2004-09-06', '2004-10-11', '2004-11-11', '2004-11-25', '2004-12-24' ], [ 2005, '2004-12-31', '2005-01-17', '2005-02-21', '2005-05-30', '2005-07-04', '2005-09-05', '2005-10-10', '2005-11-11', '2005-11-24', '2005-12-26' ], [ 2006, '2006-01-02', '2006-01-16', '2006-02-20', '2006-05-29', '2006-07-04', '2006-09-04', '2006-10-09', '2006-11-10', '2006-11-23', '2006-12-25' ], [ 2007, '2007-01-01', '2007-01-15', '2007-02-19', '2007-05-28', '2007-07-04', '2007-09-03', '2007-10-08', '2007-11-12', '2007-11-22', '2007-12-25' ], [ 2008, '2008-01-01', '2008-01-21', '2008-02-18', '2008-05-26', '2008-07-04', '2008-09-01', '2008-10-13', '2008-11-11', '2008-11-27', '2008-12-25' ], [ 2009, '2009-01-01', '2009-01-19', '2009-02-16', '2009-05-25', '2009-07-03', '2009-09-07', '2009-10-12', '2009-11-11', '2009-11-26', '2009-12-25' ], [ 2010, '2010-01-01', '2010-01-18', '2010-02-15', '2010-05-31', '2010-07-05', '2010-09-06', '2010-10-11', '2010-11-11', '2010-11-25', '2010-12-24' ], [ 2011, '2010-12-31', '2011-01-17', '2011-02-21', '2011-05-30', '2011-07-04', '2011-09-05', '2011-10-10', '2011-11-11', '2011-11-24', '2011-12-26' ], [ 2012, '2012-01-02', '2012-01-16', '2012-02-20', '2012-05-28', '2012-07-04', '2012-09-03', '2012-10-08', '2012-11-12', '2012-11-22', '2012-12-25' ], [ 2013, '2013-01-01', '2013-01-21', '2013-02-18', '2013-05-27', '2013-07-04', '2013-09-02', '2013-10-14', '2013-11-11', '2013-11-28', '2013-12-25' ], [ 2014, '2014-01-01', '2014-01-20', '2014-02-17', '2014-05-26', '2014-07-04', '2014-09-01', '2014-10-13', '2014-11-11', '2014-11-27', '2014-12-25' ], [ 2015, '2015-01-01', '2015-01-19', '2015-02-16', '2015-05-25', '2015-07-03', '2015-09-07', '2015-10-12', '2015-11-11', '2015-11-26', '2015-12-25' ], [ 2016, '2016-01-01', '2016-01-18', '2016-02-15', '2016-05-30', '2016-07-04', '2016-09-05', '2016-10-10', '2016-11-11', '2016-11-24', '2016-12-26' ], [ 2017, '2017-01-02', '2017-01-16', '2017-02-20', '2017-05-29', '2017-07-04', '2017-09-04', '2017-10-09', '2017-11-10', '2017-11-23', '2017-12-25' ], [ 2018, '2018-01-01', '2018-01-15', '2018-02-19', '2018-05-28', '2018-07-04', '2018-09-03', '2018-10-08', '2018-11-12', '2018-11-22', '2018-12-25' ], [ 2019, '2019-01-01', '2019-01-21', '2019-02-18', '2019-05-27', '2019-07-04', '2019-09-02', '2019-10-14', '2019-11-11', '2019-11-28', '2019-12-25' ], [ 2020, '2020-01-01', '2020-01-20', '2020-02-17', '2020-05-25', '2020-07-03', '2020-09-07', '2020-10-12', '2020-11-11', '2020-11-26', '2020-12-25' ], ); use Test::More 0.88; foreach my $test (@tests) { my ($year, @exp) = @$test; my @got = map { $_->strftime('%Y-%m-%d') } compute_us_federal_holidays($year); is_deeply([@got], [@exp], "U.S. federal holidays for year $year"); } done_testing(); Time-Moment-0.44/dev/bench.pl000755 000765 000024 00000015476 12604727176 016604 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use Benchmark qw[]; use DateTime qw[]; use Time::Moment qw[]; use Time::Piece qw[]; use POSIX qw[]; use Params::Coerce qw[]; { print "Benchmarking constructor: ->new()\n"; my $zone = DateTime::TimeZone->new(name => 'UTC'); Benchmark::cmpthese( -10, { 'DateTime' => sub { my $dt = DateTime->new( year => 2012, month => 12, day => 24, hour => 15, minute => 30, second => 45, nanosecond => 123456789, time_zone => $zone, ); }, 'Time::Moment' => sub { my $tm = Time::Moment->new( year => 2012, month => 12, day => 24, hour => 15, minute => 30, second => 45, nanosecond => 123456789, offset => 0 ); }, }); } { print "\nBenchmarking constructor: ->now()\n"; my $zone = DateTime::TimeZone->new(name => 'local'); Benchmark::cmpthese( -10, { 'DateTime' => sub { my $dt = DateTime->now(time_zone => $zone); }, 'Time::Moment' => sub { my $tm = Time::Moment->now; }, 'Time::Piece' => sub { my $tp = Time::Piece::localtime(); }, 'localtime()' => sub { my @tm = localtime(); }, }); } { print "\nBenchmarking constructor: ->now_utc()\n"; Benchmark::cmpthese( -10, { 'DateTime' => sub { my $dt = DateTime->now; }, 'Time::Moment' => sub { my $tm = Time::Moment->now_utc; }, 'Time::Piece' => sub { my $tp = Time::Piece::gmtime(); }, 'gmtime()' => sub { my @tm = gmtime(); }, }); } { print "\nBenchmarking constructor: ->from_epoch()\n"; Benchmark::cmpthese( -10, { 'DateTime' => sub { my $dt = DateTime->from_epoch(epoch => 0); }, 'Time::Moment' => sub { my $tm = Time::Moment->from_epoch(0); }, 'Time::Piece' => sub { my $tp = Time::Piece::gmtime(0); }, }); } { print "\nBenchmarking accessor: ->year()\n"; my $dt = DateTime->now; my $tm = Time::Moment->now; my $tp = Time::Piece::localtime(); Benchmark::cmpthese( -10, { 'DateTime' => sub { my $year = $dt->year; }, 'Time::Moment' => sub { my $year = $tm->year; }, 'Time::Piece' => sub { my $year = $tp->year; }, }); } { print "\nBenchmarking arithmetic: +10 hours -10 hours\n"; my $dt = DateTime->now; my $tm = Time::Moment->now_utc; my $tp = Time::Piece::gmtime(); Benchmark::cmpthese( -10, { 'DateTime' => sub { my $r = $dt->add(hours => 10)->subtract(hours => 10); }, 'Time::Moment' => sub { my $r = $tm->plus_hours(10)->minus_hours(10); }, 'Time::Piece' => sub { my $r = $tp->add(10*60*60)->add(-10*60*60); }, }); } { print "\nBenchmarking arithmetic: delta hours\n"; my $tm1 = Time::Moment->from_string('2015-05-10T12+12'); my $tm2 = Time::Moment->from_string('2015-05-11T12-12'); my $dt1 = Params::Coerce::coerce('DateTime', $tm1); my $dt2 = Params::Coerce::coerce('DateTime', $tm2); my $tp1 = Params::Coerce::coerce('Time::Piece', $tm1); my $tp2 = Params::Coerce::coerce('Time::Piece', $tm2); Benchmark::cmpthese( -10, { 'DateTime' => sub { my $r = $dt1->delta_ms($dt2)->hours; }, 'Time::Moment' => sub { my $r = $tm1->delta_hours($tm2); }, 'Time::Piece' => sub { my $r = int($tp2->subtract($tp1)->hours); }, }); } { print "\nBenchmarking arithmetic: delta days\n"; my $tm1 = Time::Moment->from_string('2015-05-10T12+12'); my $tm2 = Time::Moment->from_string('2015-05-11T12-12'); my $dt1 = Params::Coerce::coerce('DateTime', $tm1); my $dt2 = Params::Coerce::coerce('DateTime', $tm2); Benchmark::cmpthese( -10, { 'DateTime' => sub { my $r = $dt1->delta_days($dt2)->delta_days; }, 'Time::Moment' => sub { my $r = $tm1->delta_days($tm2); }, }); } { print "\nBenchmarking: at end of current month\n"; my $dt = DateTime->now; my $tm = Time::Moment->now_utc; Benchmark::cmpthese( -10, { 'DateTime' => sub { $dt = $dt->set_day(1) ->add(months => 1) ->subtract(days => 1); }, 'Time::Moment' => sub { $tm = $tm->with_day_of_month(1) ->plus_months(1) ->minus_days(1); }, }); } { print "\nBenchmarking strftime: ->strftime('%FT%T')\n"; my $dt = DateTime->now; my $tm = Time::Moment->now; my $tp = Time::Piece::localtime(); my @lt = localtime(); Benchmark::cmpthese( -10, { 'DateTime' => sub { my $string = $dt->strftime('%FT%T'); }, 'Time::Moment' => sub { my $string = $tm->strftime('%FT%T'); }, 'Time::Piece' => sub { my $string = $tp->strftime('%FT%T'); }, 'POSIX::strftime' => sub { my $string = POSIX::strftime('%FT%T', @lt); }, }); } { print "\nBenchmarking sort: 1000 instants\n"; my @epochs = map { int(rand(365.2425 * 50) * 86400 + rand(86400)) } (1..1000); my @dt = map { DateTime->from_epoch(epoch => $_) } @epochs; my @tm = map { Time::Moment->from_epoch($_) } @epochs; my @tp = map { scalar Time::Piece::gmtime($_); } @epochs; Benchmark::cmpthese( -10, { 'DateTime' => sub { my @sorted = sort { $a->compare($b) } @dt; }, 'Time::Moment' => sub { my @sorted = sort { $a->compare($b) } @tm; }, 'Time::Piece' => sub { my @sorted = sort { $a->compare($b) } @tp; }, }); } eval { require DateTime::Format::ISO8601; require DateTime::Format::RFC3339; my $string = '2013-12-24T12:34:56.123456+02:00'; print "\nBenchmarking parsing: '$string'\n"; my $rfc_p = DateTime::Format::RFC3339->new; my $iso_p = DateTime::Format::ISO8601->new; Benchmark::cmpthese( -10, { 'Time::Moment' => sub { my $tm = Time::Moment->from_string($string); }, 'DT::F::ISO8601' => sub { my $dt = $iso_p->parse_datetime($string); }, 'DT::F::RFC3339' => sub { my $dt = $rfc_p->parse_datetime($string); }, }); }; Time-Moment-0.44/dev/sizeof.pl000755 000765 000024 00000001666 12252635612 017010 0ustar00chansenstaff000000 000000 #!/usr/bin/perl use strict; use warnings; use DateTime qw[]; use Time::Moment qw[]; use Time::Piece qw[]; use Devel::Size qw[total_size]; use Storable qw[nfreeze]; my $tm = Time::Moment->now; my $tp = Time::Piece::localtime(); my $dt = DateTime->now; my $lt = [localtime()]; print "Comparing instance size:\n"; printf "Time::Moment ............... : %4d B\n", total_size($tm); printf "Time::Piece ................ : %4d B\n", total_size($tp); printf "localtime() ................ : %4d B\n", total_size($lt) - total_size([]); printf "DateTime ................... : %4d B\n", total_size($dt); printf "DateTime w/o zone and locale : %4d B\n", total_size do { my $clone = $dt->clone; delete @{$clone}{qw(time_zone locale)}; $clone; }; print "\nComparing Storable::nfreeze() size:\n"; printf "Time::Moment ............... : %4d B\n", length nfreeze $tm; printf "DateTime ................... : %4d B\n", length nfreeze $dt;