formalize how to convert time values to string, with 2 digits after the dot
This commit is contained in:
parent
d5009eb269
commit
691753ef2d
@ -1,5 +1,5 @@
|
||||
# ex:ts=8 sw=4:
|
||||
# $OpenBSD: Util.pm,v 1.7 2017/06/20 15:47:49 espie Exp $
|
||||
# $OpenBSD: Util.pm,v 1.8 2019/10/23 10:04:06 espie Exp $
|
||||
#
|
||||
# Copyright (c) 2010-2013 Marc Espie <espie@openbsd.org>
|
||||
#
|
||||
@ -22,7 +22,7 @@ use feature qw(say);
|
||||
package DPB::Util;
|
||||
sub make_hot
|
||||
{
|
||||
my ($self, $fh) = @_;
|
||||
my ($class, $fh) = @_;
|
||||
my $oldfh = select($fh);
|
||||
$| = 1;
|
||||
select($oldfh);
|
||||
@ -31,7 +31,7 @@ sub make_hot
|
||||
|
||||
sub safe_join
|
||||
{
|
||||
my ($self, $sep, @l) = @_;
|
||||
my ($class, $sep, @l) = @_;
|
||||
$_ //= "undef" for @l;
|
||||
return join($sep, @l);
|
||||
}
|
||||
@ -39,7 +39,7 @@ sub safe_join
|
||||
my @name =qw(Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec);
|
||||
sub time2string
|
||||
{
|
||||
my ($self, $time) = @_;
|
||||
my ($class, $time) = @_;
|
||||
my ($sec, $min, $hour, $mday, $mon) = (localtime $time)[0 .. 4];
|
||||
return sprintf("%d %s %02d:%02d:%02d", $mday, $name[$mon],
|
||||
$hour, $min, $sec);
|
||||
@ -52,6 +52,18 @@ sub die_bang
|
||||
CORE::die("$msg: $!");
|
||||
}
|
||||
|
||||
sub ts2string
|
||||
{
|
||||
my ($class, $ts) = @_;
|
||||
return sprintf("%.2f", $ts);
|
||||
}
|
||||
|
||||
sub current_ts
|
||||
{
|
||||
my $class = shift;
|
||||
return $class->ts2string(Time::HiRes::time());
|
||||
}
|
||||
|
||||
sub die
|
||||
{
|
||||
my ($class, $msg) = @_;
|
||||
|
Loading…
Reference in New Issue
Block a user