Skip Menu |

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

Report information
The Basics
Id: 112108
Status: open
Priority: 0/
Queue: Time-Piece

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

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



Subject: Dates prior to 1900 don't work in strptime

It seems like the blob of BSD code underlying strptime is a bit old.

 

Attached is a test that currently fails on the "1800" date, and a .c file that does *not* fail on the same 1800 date.

 

Subject: timepiece.pl
use strict; use warnings; use Time::Piece; use Test::More; for my $ts ("2000-11-12 18:31:01", "1900-11-12 18:31:01" ,"1800-11-12 18:31:01" ){ note "Studying $ts"; local $@; my $tm; eval { $tm = Time::Piece->strptime( $ts, "%Y-%m-%d %H:%M:%S" ); }; ok( !$@, "No Eval Errors" ) or diag( $@ ), next; my ($year) = $ts =~ /^(\d+)/; is( $tm->year, $year , "Extracted year correctly" ); } done_testing;
Subject: tp.c
#define _XOPEN_SOURCE #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> int main(void) { struct tm tm; char buf[255]; memset(&tm, 0, sizeof(struct tm)); strptime("1800-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm); printf("%d\n", 1900 + tm.tm_year ); strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm); puts(buf); exit(EXIT_SUCCESS); }
Subject: Re: [rt.cpan.org #112108] Dates prior to 1900 don't work in strptime
Date: Thu, 25 Feb 2016 10:43:24 -0600
To: bug-Time-Piece [...] rt.cpan.org
From: Samuel Smith <leon36 [...] gmail.com>
On 02/17/2016 07:01 PM, Kent Fredric via RT wrote: Show quoted text
> Wed Feb 17 20:01:12 2016: Request 112108 was acted upon. > Transaction: Ticket created by KENTNL > Queue: Time-Piece > Subject: Dates prior to 1900 don't work in strptime > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: KENTNL@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=112108 > > > > It seems like the blob of BSD code underlying strptime is a bit old. > > Attached is a test that currently fails on the "1800" date, and a .c file that > does *not* fail on the same 1800 date. >
Yes the cut n paste of the strptime in XS is a bit old and nasty. I've debated on enabling the call to native strptime which version < 1.17 used, but the function works somewhat differently on all platforms. I think a better way forward would be to just rewrite strptime in pure perl as I mentioned in RT 104322 https://rt.cpan.org/Public/Bug/Display.html?id=104322 I had a proof of concept mostly done last summer but never got to fully implement it before life took over. I'm going to try to revisit it again in a couple of months once I get some other projects out of the way. If strptime is handled correctly, it would clear up all the issues currently in RT I think. But another thing, Time-Piece is closely tied to the unix epoch. So not sure if handling dates below 1970 will be advisable but one can try.