Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

Thanks again. So localtime()->strptime does behave differently.

So localtime()->strptime's handling of time zones is the underlying issue. Certainly these two should be equivalent, no?

#!/usr/bin/env perl use strict; use warnings; use Test::More ('no_plan'); use Time::Piece; $ENV{'TZ'} = 'America/Los_Angeles'; my @tests = ( ['2017-06-19 10:07:42', '%Y-%m-%d %H:%M:%S'], ['2017-06-19 10:07:42-0700', '%Y-%m-%d %H:%M:%S%z'], ); is($Time::Piece::VERSION, 1.31); foreach my $test (@tests) { my ($datestr, $fmt) = @$test; my $t = localtime->strptime($datestr, $fmt); is($t->epoch, 1497892062); is($t->tzoffset, -25200); is($t->strftime, 'Mon, 19 Jun 2017 10:07:42 PDT'); is($t->strftime('%Y-%m-%d %H:%M:%S'), $datestr); }

Result

ok 1 ok 2 ok 3 ok 4 ok 5 not ok 6 # Failed test at ./try7 line 22. # got: '1497917262' # expected: '1497892062' ok 7 not ok 8 # Failed test at ./try7 line 24. # got: 'Mon, 19 Jun 2017 17:07:42 PDT' # expected: 'Mon, 19 Jun 2017 10:07:42 PDT' not ok 9 # Failed test at ./try7 line 25. # got: '2017-06-19 17:07:42' # expected: '2017-06-19 10:07:42-0700' 1..9 # Looks like you failed 3 tests of 9.

In reply to Re^4: Time::Piece reversibility by mla12
in thread Time::Piece reversibility by mla12

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-20 12:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found