RESIDENTStk: use UConv::duration()

git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@17590 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
jpawlowski 2018-10-22 13:37:49 +00:00
parent ce1fdad901
commit f9577747a2

View File

@ -4,7 +4,6 @@ package main;
use strict; use strict;
use warnings; use warnings;
use Data::Dumper; use Data::Dumper;
use Time::Local;
use Unit; use Unit;
our (@RESIDENTStk_attr); our (@RESIDENTStk_attr);
@ -415,14 +414,14 @@ sub RESIDENTStk_Set($@) {
readingsBulkUpdate( readingsBulkUpdate(
$hash, $hash,
"lastDurSleep", "lastDurSleep",
RESIDENTStk_TimeDiff( UConv::duration(
$datetime, ReadingsVal( $name, "lastSleep", "" ) $datetime, ReadingsVal( $name, "lastSleep", "" )
) )
); );
readingsBulkUpdate( readingsBulkUpdate(
$hash, $hash,
"lastDurSleep_cr", "lastDurSleep_cr",
RESIDENTStk_TimeDiff( UConv::duration(
$datetime, ReadingsVal( $name, "lastSleep", "" ), $datetime, ReadingsVal( $name, "lastSleep", "" ),
"min" "min"
) )
@ -517,7 +516,7 @@ sub RESIDENTStk_Set($@) {
readingsBulkUpdate( readingsBulkUpdate(
$hash, $hash,
"lastDurAbsence", "lastDurAbsence",
RESIDENTStk_TimeDiff( UConv::duration(
$datetime, $datetime,
ReadingsVal( $name, "lastDeparture", "-" ) ReadingsVal( $name, "lastDeparture", "-" )
) )
@ -525,7 +524,7 @@ sub RESIDENTStk_Set($@) {
readingsBulkUpdate( readingsBulkUpdate(
$hash, $hash,
"lastDurAbsence_cr", "lastDurAbsence_cr",
RESIDENTStk_TimeDiff( UConv::duration(
$datetime, $datetime,
ReadingsVal( $name, "lastDeparture", "-" ), ReadingsVal( $name, "lastDeparture", "-" ),
"min" "min"
@ -541,7 +540,7 @@ sub RESIDENTStk_Set($@) {
readingsBulkUpdate( readingsBulkUpdate(
$hash, $hash,
"lastDurPresence", "lastDurPresence",
RESIDENTStk_TimeDiff( UConv::duration(
$datetime, $datetime,
ReadingsVal( $name, "lastArrival", "-" ) ReadingsVal( $name, "lastArrival", "-" )
) )
@ -549,7 +548,7 @@ sub RESIDENTStk_Set($@) {
readingsBulkUpdate( readingsBulkUpdate(
$hash, $hash,
"lastDurPresence_cr", "lastDurPresence_cr",
RESIDENTStk_TimeDiff( UConv::duration(
$datetime, $datetime,
ReadingsVal( $name, "lastArrival", "-" ), "min" ReadingsVal( $name, "lastArrival", "-" ), "min"
) )
@ -3464,30 +3463,6 @@ sub RESIDENTStk_TimeSum($$) {
} }
sub RESIDENTStk_TimeDiff ($$;$) {
my ( $datetimeNow, $datetimeOld, $format ) = @_;
if ( $datetimeNow eq "" || $datetimeOld eq "" ) {
$datetimeNow = "1970-01-01 00:00:00";
$datetimeOld = "1970-01-01 00:00:00";
}
my $timestampNow = time_str2num($datetimeNow);
my $timestampOld = time_str2num($datetimeOld);
my $timeDiff = $timestampNow - $timestampOld;
# return seconds
return round( $timeDiff, 0 )
if ( defined($format) && $format eq "sec" );
# return minutes
return round( $timeDiff / 60, 0 )
if ( defined($format) && $format eq "min" );
# return human readable format
return UConv::s2hms( round( $timeDiff, 0 ) );
}
sub RESIDENTStk_InternalTimer($$$$$) { sub RESIDENTStk_InternalTimer($$$$$) {
my ( $modifier, $tim, $callback, $hash, $waitIfInitNotDone ) = @_; my ( $modifier, $tim, $callback, $hash, $waitIfInitNotDone ) = @_;