Thanks for the heads up. I already found that out and fixed my code to
accommodate it.
I guess the point I was trying to make is that *str2time* function silently
fails by producing unpredictable results instead of failing hard by
returning *undef* for input formats that are not supported or not entirely
correct in its form.
Since epoch values are scalars that are not as easily distinguishable as
other-more readable date formats (*1454023633995* VS *2016-01-28
23:27:13,995*), especially when the first couple of digits are correct, it
is not immediately obvious to the developer that the result is wrong.
It would be very helpful if functions fail hard in a conspicuous fashion
when they fail.
On Wed, Apr 13, 2016 at 2:45 AM, Slaven_Rezic via RT <
bug-TimeDate@rt.cpan.org> wrote:
Show quoted text> <URL:
https://rt.cpan.org/Ticket/Display.html?id=113726 >
>
> On 2016-04-12 20:43:54, sebastianokur@gmail.com wrote:
> > Hi,
> >
> > As much as I can see from the documentation, there is no information
> > regarding to inability to parse "YYYY-MM-DD hh:mm:ss.SSS" format. Also, I
> > noticed it is mentioned that the str2time function should return undef if
> > it doesn't support string for parsing.
> >
> > Below is the code and its output:
> >
> > *===*
> > #!/usr/bin/perl
> >
> > use strict;
> > use warnings;
> > use Date::Parse;
> >
> > my $date1_str = "2016-01-28 23:27:13,995";
> > my $date1_epoch = str2time($date1_str);
> > print "date1_epoch: [$date1_epoch]\n";
> >
> > my $date2_str = "2016-01-28 23:27:13,996";
> > my $date2_epoch = str2time($date2_str);
> > print "date2_epoch: [$date2_epoch]\n";
> >
> > # OUTPUT:
> > #
> > # date1_epoch: [1453985533]
> > # date2_epoch: [1453985473]
> > *===*
> >
> > Notice that *date2_epoch* is earlier than *date1_epoch*, and –if
> anything–
> > epoch values should be the same.
> >
> > Thanks for your time and assistance in advance,
> >
> > --Sebastian Okur
>
> Actually, if the comma in the test script is replaced with a dot, then
> things work fine. I wouldn't expect that Date::Parse should parse the comma
> as a decimal dot.
>
>
>