Skip to content

Commit 590a991

Browse files
committed
Make up for logger producing invalid times when clocks go forward
1 parent 76764a6 commit 590a991

File tree

1 file changed

+27
-10
lines changed

1 file changed

+27
-10
lines changed

bin/read.pl

+27-10
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,33 @@
6060
my $changing = 0; my $lastdata;
6161
foreach my $d ( @{$data} )
6262
{
63-
# Don't use unixtime parameter, as it depends on
64-
# timezone of PC, not datalogger
65-
my $dt = DateTime->new(
66-
year => $d->{year},
67-
month => $d->{month},
68-
day => $d->{day},
69-
hour => $d->{hour},
70-
minute => $d->{min},
71-
time_zone => $timezone,
72-
);
63+
my $dt;
64+
# Make up for retarded weather station that produces
65+
# invalid times
66+
try {
67+
# Don't use unixtime parameter, as it depends on
68+
# timezone of PC, not datalogger
69+
$dt = DateTime->new(
70+
year => $d->{year},
71+
month => $d->{month},
72+
day => $d->{day},
73+
hour => $d->{hour},
74+
minute => $d->{min},
75+
time_zone => $timezone,
76+
);
77+
} catch {
78+
# Possible invalid time, because logger forwards
79+
# its clocks one hour too late (for GMT/BST at least).
80+
# Attempt again, with time one hour forward.
81+
$dt = DateTime->new(
82+
year => $d->{year},
83+
month => $d->{month},
84+
day => $d->{day},
85+
hour => $d->{hour} + 1,
86+
minute => $d->{min},
87+
time_zone => $timezone,
88+
);
89+
};
7390

7491
# Monitor for a DST "ambiguous" time, when the clocks change.
7592
# For an hour when the clocks go back, the winter time minus

0 commit comments

Comments
 (0)