Skip Menu |

This queue is for tickets about the Time-Piece CPAN distribution.

Report information
The Basics
Id: 56296
Status: resolved
Priority: 0/
Queue: Time-Piece

People
Owner: Nobody in particular
Requestors: valkoles [...] gmail.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: 1.31_04



Subject: strptime problem
Date: Mon, 5 Apr 2010 11:35:24 -0400
To: bug-Time-Piece [...] rt.cpan.org
From: val <valkoles [...] gmail.com>
-bash-3.1$ cat tttt.pl #!/usr/local/pascrm/perl/bin/perl use Time::Piece; print Time::Piece -> strptime('2010-04-05T11:22:00', '%FT%H:%M:%S'); print "\n"; -bash-3.1$ ./tttt.pl Error parsing time at /usr/local/perl/5.10.1/lib/5.10.1/i686-linux/Time/Piece.pm line 469. bash-3.1$ perl -v This is perl, v5.10.1 (*) built for i686-linux bash-3.1$ uname -a Linux ***** 2.6.15-1.2054_FC5 #1 Tue Mar 14 15:48:33 EST 2006 i686 i686 i386 GNU/Linux
Subject: [rt.cpan.org #56296] Additional info regarding this bug
Date: Mon, 14 Jun 2010 18:30:38 +0100
To: bug-Time-Piece [...] rt.cpan.org
From: Anthony Fisher <aef [...] 2799.org>
Confirmed this bug on versions 1.19 and 1.20. Versions 1.12 and 1.15 seem ok. Anthony
Also fails in simpler case: use Time::Piece; my $t = Time::Piece->strptime('2009-12-18', '%F'); # garbage at end of string in strptime: 2009-12-18 at [...]/Time/Piece.pm line 469. print $t; # Thu Jan 1 00:00:00 1970
I wrote a patch for this problem. Plz review it.
Subject: tp.patch
diff --git Piece.xs Piece.xs index 0bbefd3..2e6cbbd 100644 --- Piece.xs +++ Piece.xs @@ -547,6 +547,11 @@ label: goto label; case 'F': + buf = _strptime(aTHX_ buf, "%Y-%m-%d", tm); + if (buf == 0) + return 0; + break; + case 'f': if (!Ealternative) break; diff --git t/08strftime_F.t t/08strftime_F.t new file mode 100644 index 0000000..f5e2059 --- /dev/null +++ t/08strftime_F.t @@ -0,0 +1,20 @@ +use Test::More tests => 3; + +BEGIN { use_ok('Time::Piece'); } + +{ + local $@; + my $date = eval { + Time::Piece->strptime('2015-01-01 00:00:00', "%F %T"); + }; + ok !$@ or diag $@; +} + +{ + my $date_str = '2015-01-01'; + my $date1 = Time::Piece->strptime($date_str, "%F"); + my $date2 = Time::Piece->strptime($date_str, "%Y-%m-%d"); + + is $date1, $date2; +} +
Thanks. I will consider this. Time::Piece tries to provide POSIX strptime, and %F is a glibc extension. Still, it may be worth adding, if we add documentation of the extensions provided. -- rjbs
On 2013-07-06 11:00:48, RJBS wrote: Show quoted text
> Thanks. I will consider this. > > Time::Piece tries to provide POSIX strptime, and %F is a glibc > extension. Still, it may be worth adding, if we add documentation of > the extensions provided.
This patch no longer applies, as the signature of _strptime has changed. -- rjbs
Subject: [rt.cpan.org #56296]
Date: Wed, 6 Apr 2016 16:03:23 -0600
To: bug-Time-Piece [...] rt.cpan.org
From: Maxwell Carey <mcarey [...] ucar.edu>
Whether glibc extensions are supported or not, I think the documentation needs to be clearer. The docs link to FreeBSD's strftime manpage and people who don't realize that strftime != strptime are naturally surprised when strptime fails with %F. If we only support POSIX format specifiers, maybe we should link here instead: http://pubs.opengroup.org/onlinepubs/009695399/functions/strptime.html Also, it would be nice to emit a warning when %F (or any other unsupported specifier) is used since in the current implementation, any use of %F causes parsing to stop immediately and you get the vague "garbage at end of string" warning. Interestingly, the locale-dependent %EF *does* work, even though I don't see that documented for strftime or strptime in the FreeBSD or Linux manpages. Thoughts?