Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

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

You have not made your code easy enough to test each pair of date-time string & format-to-parse (by using a list of either array references or hash references).

Do you have issues with both *::Strptime & *::Recurrence? If so, could you please address them in separate threads?

About *::Strptime output as listed, I do not see anything wrong as far as values of $lodt, $hidt, $dt1, & $dt2 are concerned. What am I missing?

About *:Recurrence, as I understood the documentation, each event happens at the start of the interval. If it is "daily", then the even will start at 00:00:00. It can be changed to a different time via options of "hours" & "minutes".

# vim: ts=2 sts=2 sw=2 sr ai nu et: # use strict; use warnings; use DateTime; use DateTime::Format::Strptime; use DateTime::Event::Recurrence; # Current time. my $dtnow = DateTime->now( time_zone => DateTime::TimeZone->new( name +=> 'local' ) ); showtime( $dtnow, q[now dt: ] ); # Various date-time strings & formats to parse. my $dt_format = '%d/%m/%Y %I:%M:%S %p' ; my $start = "18/03/2019 10:12:53 am" ; my @end = ( [ "24/03/2019 3:15:00 pm" , $dt_format ] , [ "24/03/2019 03:15:00 pm" , $dt_format ] , [ "24/03/2019 15:15:00 pm" , '%d/%m/%Y %H:%M:%S %p' ] , [ "24/03/2019 15:15:00" , '%d/%m/%Y %H:%M:%S' ] ); my $start_dt = make_datetime( $start , $dt_format ); showtime( $start_dt , q[start dt: ] ); print "\n"; for my $dt_pair ( @end ) { my $string = $dt_pair->[0]; my $dt = make_datetime( @{ $dt_pair } ); showtime( $dt , sprintf q[end dt (%s) : ] , $string ); } print "\n"; # Recurring event. my $end = $end[ int rand @end ]; my $end_dt = make_datetime( @{ $end } ); my ( $hour , $min ) = ( 11 , 23 ); my $day_ev = DateTime::Event::Recurrence->daily( 'hours' => $hour , 'm +inutes' => $min ); my @set = $day_ev->as_list( 'start' => $start_dt , 'end' => $end_dt ); printf "Recurring event at %d:%d from %s to %s ...\n" , $hour , $min , $start_dt->iso8601() , $end_dt->iso8601() ; showtime( $_ , q[ !! ] ) for @set ; print "\n"; exit; sub make_datetime { my ( $dt , $format ) = @_; return DateTime::Format::Strptime ->new( on_error => 'croak' , time_zone => 'local' , pattern => $format ) ->parse_datetime( $dt ); } sub showtime { my ( $dt , $label ) = @_; $label ||= ''; print $label , $dt->iso8601() , "\n"; return; } __END__
now dt: 2019-03-27T02:46:41 start dt: 2019-03-18T10:12:53 end dt (24/03/2019 3:15:00 pm) : 2019-03-24T15:15:00 end dt (24/03/2019 03:15:00 pm) : 2019-03-24T15:15:00 end dt (24/03/2019 15:15:00 pm) : 2019-03-24T15:15:00 end dt (24/03/2019 15:15:00) : 2019-03-24T15:15:00 Recurring event at 11:23 from 2019-03-18T10:12:53 to 2019-03-24T15:15: +00 ... !! 2019-03-18T11:23:00 !! 2019-03-19T11:23:00 !! 2019-03-20T11:23:00 !! 2019-03-21T11:23:00 !! 2019-03-22T11:23:00 !! 2019-03-23T11:23:00 !! 2019-03-24T11:23:00

In reply to Re^2: DateTime::Format::Strptime Parsing Seems to have a Problem? by parv
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":



  • 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 having a coffee break in the Monastery: (4)
As of 2024-04-23 22:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found