Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

DateTime->now problem

by Grimey (Novice)
on Apr 01, 2011 at 20:50 UTC ( [id://896997]=perlquestion: print w/replies, xml ) Need Help??

Grimey has asked for the wisdom of the Perl Monks concerning the following question:

#!/usr/bin/perl -w use strict; use DateTime; my $now = DateTime->now;

-------------------------------------------------

When I attempt to run the program I get to following:

$ perl perltest.pl 'regex' validation parameter for 'DateTime::from_epoch must be a string or qr// regex at /usr/local/lib64/perl5/DateTime.pm line 486 DateTime::from_epoch(undef, 'epoch', 1301690690) called at /usr/local/lib64/perl5/DateTime.pm line 511 DateTime::now('DateTime') called at perltest.pl line 6

----------------------------------------------------------

I attempted to look at the DateTime.pm file, but I couldn't see the problem in from_epoch().

I have used this module on a different server before with success. On the new server (redhat 6.0) DateTime installed from CPAN without a fuss, but I can't use it.

Please let me know if I have done anything incorrectly, I am a first time poster here and would be grateful for any help as googling this issue has brought information.

This is perl 5, version 12, subversion 3 (v5.12.3) built for x86_64-linux-thread-multi

DateTime is up to date (0.66).

perl -le'use Params::Validate; print Params::Validate->VERSION'

0.95

Replies are listed 'Best First'.
Re: DateTime->now problem
by ikegami (Patriarch) on Apr 01, 2011 at 21:25 UTC
    Do you get the error when you run the following?
    use strict; use warnings; use Params::Validate qw( validate validate_pos UNDEF SCALAR BOOLEAN HASHREF OBJECT ); print($INC{'Params/ValidateXS.pm'} ?'XS':'PP',"\n"); my $spec = { epoch => { regex => qr/^-?(?:\d+(?:\.\d*)?|\.\d+)$/ }, locale => { type => SCALAR | OBJECT, optional => 1 }, language => { type => SCALAR | OBJECT, optional => 1 }, time_zone => { type => SCALAR | OBJECT, optional => 1 }, formatter => { type => SCALAR | OBJECT, can => 'format_datetime', optional => 1 }, }; validate( @{[ 'epoch', 1301690690 ]}, $spec );

    Does it say "PP" or "XS"?

    Update: Added PP/XS bit.

      XS 'regex' validation parameter for 'N/A must be a string or qr// regex at monktest.pl line 20

        What's the output of the following?

        use strict; use warnings; use Params::Validate qw( validate validate_pos UNDEF SCALAR BOOLEAN HASHREF OBJECT ); print($INC{'Params/ValidateXS.pm'} ?'XS':'PP',"\n"); my $spec = { epoch => { regex => qr/^-?(?:\d+(?:\.\d*)?|\.\d+)$/ }, locale => { type => SCALAR | OBJECT, optional => 1 }, language => { type => SCALAR | OBJECT, optional => 1 }, time_zone => { type => SCALAR | OBJECT, optional => 1 }, formatter => { type => SCALAR | OBJECT, can => 'format_datetime', optional => 1 }, }; use Devel::Peek; Dump($spec->{epoch}{regex}); my $x = $spec->{epoch}{regex}; Dump($spec->{epoch}{regex}); validate( @{[ 'epoch', 1301690690 ]}, $spec );
        Digging into the XS. In the meantime, you might want to try reinstalling Params::Validate.

      Yes

      'regex' validation parameter for 'N/A must be a string or qr// regex at monktest.pl line 18

        You're too fast! I added a check to see which of P::V's backends you use.
Re: DateTime->now problem
by ww (Archbishop) on Apr 01, 2011 at 21:07 UTC
    It might help to know your version of Perl and of Data::Time; there's certainly nothing wrong with your code (except your failure to follow the formatting guidelines above and below the text box where you entered you question) under any win32 or Linux immediately available to me (w2k, XP, Vista, Ubuntu 10.04/Gnome or (ancient RHs).

      Well, I'd say there could very well be a missing time_zone => 'local' argument, but it wouldn't cause the error.

      I would also like to know the version Params::Validate he has installed. The version can be obtained using

      perl -v | grep version perl -le'use DateTime; print DateTime->VERSION' perl -le'use Params::Validate; print Params::Validate->VERSION'

        Updated original post with, but will add these all here as well

        Perl version: 5.12.3

        DateTime version: 0.66

        Params::Validate version: 0.95

Re: DateTime->now problem
by eff_i_g (Curate) on Apr 01, 2011 at 21:03 UTC
      sub now { shift->from_epoch( epoch => ( scalar time ), @_ ) }
Re: DateTime->now problem
by Khen1950fx (Canon) on Apr 01, 2011 at 22:22 UTC
    DateTime works fine for me. (undef, epoch, 1301690690) isn't the correct way to do it. I did this using now and from_epoch:
    #!/usr/bin/perl use strict; use warnings; use DateTime; my $dt = DateTime->now( 'time_zone' => 'local' ) ->set_time_zone( 'floating' ); print $dt, "\n"; $dt = DateTime->from_epoch( 'epoch' => 1301690690 ); print $dt, "\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://896997]
Approved by ikegami
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (3)
As of 2025-12-16 23:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (98 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.