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);
}