Appreciate the info... Seems I "couldn't see the forest for the trees" or something, as I was looking for the "12-hour" formatter... but didn't "see" the "%I"...(!)

The final part of the puzzle is to understand how to ensure we can set-up a sequence of datetimes that are 1 day apart. If the mentioned mods are made to the code... and I add some additional code for setting-up a Recurrence, the code becomes:-

use strict; use warnings; #use diagnostics; use DateTime; use DateTime::Format::Strptime; use DateTime::Event::Recurrence; # PART 2 our $LocalTZ = DateTime::TimeZone->new( name => 'local' ); my $dtnow = DateTime->now(time_zone => $LocalTZ); # Current *local* + time printf("\$dtnow: !%s!\n\n", $dtnow); my $lo = "18/03/2019 10:12:53 am"; # Always works my $hi = "24/03/2019 3:15:00 pm"; # Does not work... the format I + need to use # my $hi = "24/03/2019 03:15:00 pm"; # Does not work # my $hi = "24/03/2019 3:15:00 pm"; # Does not work # my $hi = "24/03/2019 15:15:00 pm"; # Works but 15hrs with 'pm' i +s silly # my $hi = "24/03/2019 15:15:00"; # Works my $dmy_fmt = DateTime::Format::Strptime->new( # Let DateTime use 'dd +/mm/yyyy' pattern => '%d/%m/%Y %I:%M:%S %p', # pattern => '%d/%m/%Y %I:%M:%S', # Use this when no 'am/pm' + in the date string # time_zone => 'Australia/Victoria', time_zone => 'local', on_error => 'croak' ); my $lodt = $dmy_fmt->parse_datetime($lo); printf(" \$lodt: !%s!\n", $lodt); my $hidt = $dmy_fmt->parse_datetime($hi); printf(" \$hidt: !%s!\n", $hidt); # ========== PART 2 ========== my $rec1 = DateTime::Event::Recurrence->daily(start => $lodt); # $rec1->set_time_zone('local'); # Doesn't change the 'mis-conversion' my @days = $rec1->as_list( start => $lodt, end => $hidt ); printf("1st Format DAYS:\n"); foreach my $day (@days) { printf(" %s\n", $day->dmy("-")); } printf("\n"); # ---- A different (truncated) format my $strp = DateTime::Format::Strptime->new( pattern => '%d/%m/%Y', time_zone => 'local', on_error => 'croak' ); my $dt1 = $strp->parse_datetime("18/03/2019"); #my $dt1 = $strp->parse_datetime($lo); printf(" \$dt1: !%s!\n", $dt1); my $dt2 = $strp->parse_datetime("24/03/2019"); #my $dt2 = $strp->parse_datetime($hi); printf(" \$dt2: !%s!\n", $dt2); my $rec2 = DateTime::Event::Recurrence->daily(start => $dt1); @days = $rec2->as_list( start => $dt1, end => $dt2 ); printf("2nd Format DAYS:\n"); foreach my $day (@days) { printf(" %s\n", $day->dmy("-")); } printf("\n");

Here, the output is:-

$dtnow: !2019-03-26T15:05:02! $lodt: !2019-03-18T10:12:53! $hidt: !2019-03-24T15:15:00! 1st Format DAYS: 19-03-2019 20-03-2019 21-03-2019 22-03-2019 23-03-2019 24-03-2019 $dt1: !2019-03-18T00:00:00! $dt2: !2019-03-24T00:00:00! 2nd Format DAYS: 18-03-2019 19-03-2019 20-03-2019 21-03-2019 22-03-2019 23-03-2019 24-03-2019

So, it seems DateTime::Format::Strptime is looking at the input strings (which are local times) and converting them according to the 'time_zone' item (which is 'local')... and thus, the resultant objects contain the same time field values.

However, when the recurrence is set-up for the "dd/mm/yyyy hh:mm:ss p"-derived objects, the date is incorrect. I thought it might have to do with the time zone... but setting the time zone on the occurrence made no difference to the dates it came up with.

More confusing, if I set-up a recurrence using the "dd/mm/yyyy"-derived objects, the date is correct, although the time of day is set to 00:00:00 (obviously and reasonably).

So, how does the recurrence using "dd/mm/yyyy hh:mm:ss p"-derived objects need to be configured to display the correct dates, including time of day?

"It's all rather confusing, really...."


In reply to Re: DateTime::Format::Strptime Parsing Seems to have a Problem? by ozboomer
in thread DateTime::Format::Strptime Parsing Seems to have a Problem? by ozboomer

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.