@@ -46,6 +46,7 @@ Command-line options:
46
46
-phases - analyze and provide statistics for ascent/descent phases
47
47
-segs [<n>..[<m>][(+|-)<d>]] - add statistics per segment n..m, may adapt indexes +/-d
48
48
-days [<n>..[<m>][(+|-)<d>]] - add statistics per day n..m, may adapt indexes +/-d
49
+ -tz <hours> - offset from UTC (timezone+DST) for -days, default taken from system
49
50
-split <basename> - produce GPX files per day or segment, with name <basename>_<i>.gpx
50
51
-lean_stat_wpts - only one stat. wpt per segment/day with data except ascent/descent
51
52
-info_wpts - provide info points also in the form of waypoints
@@ -295,6 +296,7 @@ my $min_lon, my $max_lon;
295
296
my ($min_sec , $max_sec );
296
297
my ($min_tim , $max_tim ) = (" " , " " ); # $max_tim is not really used
297
298
299
+ my ($tz , $sec_offset );
298
300
my ($segs , $days );
299
301
my ($part_start , $part_end , $part_offset );
300
302
my $split ;
@@ -847,6 +849,11 @@ for (my $i = 0; $#ARGV - $i >= 0;) {
847
849
($part_start , $part_end , $part_offset ) = ($1 , $2 , $3 ); # $part_end < $part_start will lead to empty selection, just like without $opt
848
850
splice @ARGV , $i + 1, 1; # remove from ARGV the option argument
849
851
}
852
+ } elsif ($opt eq " -tz" ) {
853
+ abort(" missing value argument for -$opt option" ) if $#ARGV - $i < 1;
854
+ abort(" cannot parse value argument in '$opt $arg1 '" ) unless looks_like_number($arg1 );
855
+ $tz = $arg1 + 0;
856
+ splice @ARGV , $i + 1, 1; # remove from ARGV the option argument
850
857
} elsif ($opt eq " -split" ) {
851
858
abort(" missing file argument for -$opt option" ) if $#ARGV - $i < 1;
852
859
$split = $arg1 ;
@@ -2026,11 +2033,22 @@ for (my $direction, my $prev_sec, my $timediff,
2026
2033
2027
2034
# local inititialization of optional statistics for parts (segements or days)
2028
2035
my $new_part = 0;
2029
- $date = $1 if $days && $tim =~ m / ^(.*?)T/ ;
2030
- $new_part = 1
2031
- if ($days && ($i == 0 || (defined $date && defined $prev_date
2032
- && $date ne $prev_date ))); # assuming that dates, as far as available, are ascending
2033
- $prev_date = $date if $days ;
2036
+ if ($days ) {
2037
+ if (defined $tz && !defined $min_sec && defined $sec ) {
2038
+ # https://stackoverflow.com/questions/2143528/whats-the-best-way-to-get-the-utc-offset-in-perl
2039
+ use Time::Local;
2040
+ my @t = localtime ($sec );
2041
+ my $system_offset_from_UTC_in_seconds = timegm(@t ) - timelocal(@t );
2042
+ $sec_offset = $tz * H2S - $system_offset_from_UTC_in_seconds ;
2043
+ # more accurate but more involed alternative: https://metacpan.org/pod/Geo::Location::TimeZone
2044
+ }
2045
+ $date = defined $sec ? join (" -" , (localtime (defined $sec_offset ? $sec + $sec_offset : $sec ))[3,4,5]) : undef ;
2046
+ $new_part = 1
2047
+ if $i == 0
2048
+ # assuming that dates, as far as available, are ascending:
2049
+ || (defined $date && defined $prev_date && $date ne $prev_date );
2050
+ $prev_date = $date if $days ;
2051
+ }
2034
2052
$new_part = 1 if $segs && $SEG [$i ];
2035
2053
$DURATION [$part ] = diff_defined($part_end_sec , $part_start_sec )
2036
2054
if defined $part && ($new_part || $i == $#TIM ); # implies $i != 0
0 commit comments