Re: How to format dates prior to 1970?
by Corion (Patriarch) on Jul 10, 2017 at 13:33 UTC
|
> perl -MTime::Piece -wE "say $Time::Piece::VERSION; my $t=Time::Piece
+->strptime('05/10/1969','%m/%d/%Y'); say $t->ymd; say $t->strftime('%
+Y-%m-%d')"
1.20_01
1969-05-10
1969-05-10
> perl -v
This is perl 5, version 14, subversion 2 (v5.14.2) built for MSWin32-x
+86-multi-thread
| [reply] [Watch: Dir/Any] [d/l] [select] |
Re: How to format dates prior to 1970?
by hippo (Bishop) on Jul 10, 2017 at 13:21 UTC
|
I, too, am unable to reproduce your segfault using perl 5.20.3 on 64-bit Linux. Maybe it's a Windows thing?
- DateTime 1.20
- Time::Piece 1.31_04
| [reply] [Watch: Dir/Any] |
|
I really hope it's not a Windows thing, but will try on Linux when I get a chance and report back :/
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
|
Re: How to format dates prior to 1970?
by NetWallah (Canon) on Jul 10, 2017 at 17:40 UTC
|
Perl 5.24 on win7/64-bit blows up for me:
perl -v
This is perl 5, version 24, subversion 0 (v5.24.0) built for MSWin32-x
+64-multi-thread
>perl -MTime::Piece -wE "say $Time::Piece::VERSION; my $t=Time::Piece-
+>strptime('05/10/1969','%m/%d/%Y'); say $t->ymd; say $t->strftime('%Y
+-%m-%d')"
1.31
1969-05-10
<<< *popup* - perl stopped responding
Faulting application name: perl.exe, version: 5.24.0.2400, time stamp:
+ 0x575a1be0
Faulting module name: Piece.dll, version: 0.0.0.0, time stamp: 0x575a1
+c19
Exception code: 0xc0000005
Fault offset: 0x00000000000022e9
Faulting process id: 0x44b0
Faulting application start time: 0x01d2f9a2b44679e1
Faulting application path: C:\Perl64\bin\perl.exe
Faulting module path: C:\Perl64\lib\auto\Time\Piece\Piece.dll
Report Id: 7213cb17-38fa-4446-823a-d4990b1501b7
Faulting package full name:
Faulting package-relative application ID:
All power corrupts, but we need electricity.
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
Hope this gets fixed someday!
| [reply] [Watch: Dir/Any] |
|
| [reply] [Watch: Dir/Any] |
Re: How to format dates prior to 1970?
by 1nickt (Canon) on Jul 10, 2017 at 13:11 UTC
|
$ perl 1194689.pl
1969-05-10
1969-05-10
The way forward always starts with a minimal test.
| [reply] [Watch: Dir/Any] [d/l] |
|
Thanks for the response.
But that is bizarre. I get a Windows pop-up that says
Perl interpreter has stopped working
A problem caused the program to stop working correctly. Windows will c
+lose the program and notify you if a solution is available.
What system are you running the code on?
If I click "Debug" and open this with Microsoft Visual Studio, I get
Unhandled exception at 0x000000006F4C230B (Piece.xs.dll) in perl.exe:
+0xC0000005: Access violation reading location 0x0000000000000000.
If there is a handler for this exception, the program may be safely co
+ntinued.
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
#!/usr/bin/perl
use v5.10; # (OP's code, verbatim)
use strict;
use warnings;
use Data::Dumper;
use DateTime::Format::Strptime;
use Time::Piece;
$Data::Dumper::Sortkeys = 1;
my $date = '05/10/1969';
my $ymd = '%Y-%m-%d';
my $mdy = '%m/%d/%Y';
my $t = Time::Piece->strptime($date,$mdy);
say $t->ymd; # Prints as normal
say $t->strftime($ymd); # Segmentation fault
Execution:
C:\>F:\_Perl_\PMonks\1194689.pl
1969-05-10
C:\>
And, the same popup as cited above with the following content:
Problem signature:
Problem Event Name: APPCRASH
Application Name: perl.exe
Application Version: 5.24.0.2400
Application Timestamp: 578689b9
Fault Module Name: Piece.dll
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 57868a01
Exception Code: c0000005
Exception Offset: 00002398
OS Version: 6.1.7601.2.1.0.256.48
Locale ID: 1033
Additional Information 1: 0a9e
Additional Information 2: 0a9e372d3b4ad19135b953a78882e789
Additional Information 3: 0a9e
Additional Information 4: 0a9e372d3b4ad19135b953a78882e789
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
|
|
use strict; use warnings; use feature 'say';
use DateTime::Format::Strptime;
my $parser = DateTime::Format::Strptime->new(pattern => '%m/%d/%Y', on
+_error => 'croak');
my $date = '05/10/1969';
my $dt = $parser->parse_datetime( $date );
say $dt->ymd;
What does that do on your Windows system?
The way forward always starts with a minimal test.
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
|
Re: How to format dates prior to 1970?
by karthikkumar (Initiate) on Nov 30, 2018 at 14:29 UTC
|
This Time::Piece strftime, seems problem in windows OS even now with version 1.33
So alternate functions available, which works well.
Example this is not giving any output:
$t->strftime("%b %d %Y, %A [%H:%M:%S]")
So, I am re-writing without strftime, and this is working fine for me even on windows OS.
$t->monname . " " . sprintf("%.2d", $t->mday) . " " . $t->year . ", " . $t->fullday . " [" . $t->hms . "]"
| [reply] [Watch: Dir/Any] [d/l] [select] |
|
| [reply] [Watch: Dir/Any] |
Re: How to format dates prior to 1970?
by thechartist (Monk) on Dec 01, 2018 at 03:32 UTC
|
I ran this on Windows 10 and did not experience any error. I am running
perl 5.26.1 build for MSWin32-x64-multi-thread, module version 1.3202
| [reply] [Watch: Dir/Any] |