mirror of
https://github.com/fhem/fhem-mirror.git
synced 2025-05-04 22:19:38 +00:00
UConv.pm: add ::duration()
git-svn-id: https://svn.fhem.de/fhem/trunk/fhem@17589 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
parent
5737167b11
commit
ce1fdad901
@ -8,6 +8,7 @@ use Scalar::Util qw(looks_like_number);
|
|||||||
use POSIX qw(strftime);
|
use POSIX qw(strftime);
|
||||||
use Data::Dumper;
|
use Data::Dumper;
|
||||||
|
|
||||||
|
|
||||||
####################
|
####################
|
||||||
# Translations
|
# Translations
|
||||||
|
|
||||||
@ -728,6 +729,30 @@ sub distance($$$$;$$) {
|
|||||||
( $unit eq "nmi" ? km2nmi($km) : ( $unit ? km2mi($km) : $km ) ), $rnd );
|
( $unit eq "nmi" ? km2nmi($km) : ( $unit ? km2mi($km) : $km ) ), $rnd );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub duration ($$;$) {
|
||||||
|
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 = main::time_str2num($datetimeNow);
|
||||||
|
my $timestampOld = main::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 s2hms( _round( $timeDiff, 0 ) );
|
||||||
|
}
|
||||||
|
|
||||||
#################################
|
#################################
|
||||||
### Textual unit conversions
|
### Textual unit conversions
|
||||||
###
|
###
|
||||||
|
Loading…
x
Reference in New Issue
Block a user