Skip Menu |

This queue is for tickets about the Date-Manip CPAN distribution.

Report information
The Basics
Id: 111915
Status: resolved
Priority: 0/
Queue: Date-Manip

People
Owner: Nobody in particular
Requestors: MSTEVENS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: 6.52
Fixed in: (no value)



Subject: weird dates give warnings
Trying to parse dates which sometimes come from dodgy sources. Some odd dates generate perl warnings in Date::Manip: mstevens@clouddev1:~ % cat test-dm.pl #!/opt/dianomi/perl/bin/perl -w use strict; use Date::Manip::Date; my $date = "2014-08-26T07:27:42.000Zyyyy-MM-dd HH:mm:ss z"; my $d = new Date::Manip::Date(); $d->parse($date); $d->secs_since_1970_GMT(); mstevens@clouddev1:~ % perl test-dm.pl Use of uninitialized value $d in integer addition (+) at /opt/dianomi/perl/lib/site_perl/5.12.2/Date/Manip/Base.pm line 505. Use of uninitialized value in integer addition (+) at /opt/dianomi/perl/lib/site_perl/5.12.2/Date/Manip/Base.pm line 505. Use of uninitialized value $h in multiplication (*) at /opt/dianomi/perl/lib/site_perl/5.12.2/Date/Manip/Base.pm line 612. Use of uninitialized value $mn in multiplication (*) at /opt/dianomi/perl/lib/site_perl/5.12.2/Date/Manip/Base.pm line 612. Use of uninitialized value $s in addition (+) at /opt/dianomi/perl/lib/site_perl/5.12.2/Date/Manip/Base.pm line 612. I don't mind if the module rejects my dodgy dates but surely I shouldn't get warnings?
On Wed Feb 10 09:54:33 2016, MSTEVENS wrote: Show quoted text
> Trying to parse dates which sometimes come from dodgy sources. Some > odd dates generate perl warnings in Date::Manip: > > mstevens@clouddev1:~ % cat test-dm.pl > #!/opt/dianomi/perl/bin/perl -w > > use strict; > use Date::Manip::Date; > > my $date = "2014-08-26T07:27:42.000Zyyyy-MM-dd HH:mm:ss z"; > > my $d = new Date::Manip::Date(); > $d->parse($date); > $d->secs_since_1970_GMT(); > mstevens@clouddev1:~ % perl test-dm.pl > Use of uninitialized value $d in integer addition (+) at > /opt/dianomi/perl/lib/site_perl/5.12.2/Date/Manip/Base.pm line 505. > Use of uninitialized value in integer addition (+) at > /opt/dianomi/perl/lib/site_perl/5.12.2/Date/Manip/Base.pm line 505. > Use of uninitialized value $h in multiplication (*) at > /opt/dianomi/perl/lib/site_perl/5.12.2/Date/Manip/Base.pm line 612. > Use of uninitialized value $mn in multiplication (*) at > /opt/dianomi/perl/lib/site_perl/5.12.2/Date/Manip/Base.pm line 612. > Use of uninitialized value $s in addition (+) at > /opt/dianomi/perl/lib/site_perl/5.12.2/Date/Manip/Base.pm line 612. > > I don't mind if the module rejects my dodgy dates but surely I > shouldn't get warnings?
mstevens@clouddev1:~ % perl -V Summary of my perl5 (revision 5 version 12 subversion 2) configuration: Platform: osname=linux, osvers=2.6.18-194.26.1.el5, archname=x86_64-linux uname='linux 303646-web1.dianomi.co.uk 2.6.18-194.26.1.el5 #1 smp fri oct 29 14:21:16 edt 2010 x86_64 x86_64 x86_64 gnulinux ' config_args='-des -Dprefix=/opt/dianomi/perl -Accflags=-fPIC' hint=recommended, useposix=true, d_sigaction=define useithreads=undef, usemultiplicity=undef useperlio=define, d_sfio=undef, uselargefiles=define, usesocks=undef use64bitint=define, use64bitall=define, uselongdouble=undef usemymalloc=n, bincompat5005=undef Compiler: cc='cc', ccflags ='-fPIC -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64', optimize='-O2', cppflags='-fPIC -fno-strict-aliasing -pipe -fstack-protector -I/usr/local/include' ccversion='', gccversion='4.1.2 20080704 (Red Hat 4.1.2-48)', gccosandvers='' intsize=4, longsize=8, ptrsize=8, doublesize=8, byteorder=12345678 d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16 ivtype='long', ivsize=8, nvtype='double', nvsize=8, Off_t='off_t', lseeksize=8 alignbytes=8, prototype=define Linker and Libraries: ld='cc', ldflags =' -fstack-protector -L/usr/local/lib' libpth=/usr/local/lib /lib /usr/lib /lib64 /usr/lib64 /usr/local/lib64 libs=-lnsl -ldb -ldl -lm -lcrypt -lutil -lc perllibs=-lnsl -ldl -lm -lcrypt -lutil -lc libc=/lib/libc-2.5.so, so=so, useshrplib=false, libperl=libperl.a gnulibc_version='2.5' Dynamic Linking: dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags='-Wl,-E' cccdlflags='-fPIC', lddlflags='-shared -O2 -L/usr/local/lib -fstack-protector' Characteristics of this binary (from libperl): Compile-time options: PERL_DONT_CREATE_GVSV PERL_MALLOC_WRAP USE_64_BIT_ALL USE_64_BIT_INT USE_LARGE_FILES USE_PERLIO USE_PERL_ATOF Built under linux Compiled at Jan 11 2011 13:45:15 @INC: /opt/dianomi/perl/lib/site_perl/5.12.2/x86_64-linux /opt/dianomi/perl/lib/site_perl/5.12.2 /opt/dianomi/perl/lib/5.12.2/x86_64-linux /opt/dianomi/perl/lib/5.12.2 .
Thanks for catching this. All of the Date::Manip::Date methods contain a check of the form: if this isn't a valid date, then abort except that the secs_since_1970_GMT got overlooked. It was trying to run even though there was no valid date. I've corrected this and it will be in the next release. In the meantime, you can change your script to be: if ($d->err()) { INVALID DATE... handle however you want } else { $d->secs_since_1970_GMT(); } Even with the fix in place, you probably want to check for an error any time you parse dates where there is the possibility of invalid data so you can trap those problems appropriately.