http://qs321.pair.com?node_id=1231741


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

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