summaryrefslogtreecommitdiff
path: root/bucky2/t/lastlog.pl
blob: 5defaf331659a02105297eb8ed9dd9ddd87f909f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/perl
use lib "../lib";
use Bucky;
my $bucky = new Bucky;
my $today = time - 86400;
my $lastlog = $bucky->db->select("user", "lastseen > $today order by lastseen desc");
foreach my $user (@$lastlog)
	{
	my $name = $user->{'username'};
	my $age = get_age($user->{'lastseen'});
	print "$name => $age\n";
	}
sub get_age
	{
	my ($time) = @_;
	my $age = time - $time;
	if ($age < 60)
		{
		return int($age)."s";
		}
	$age /= 60;
	if ($age < 60)
		{
		return int($age)."m";
		}
	$age /= 60;
	if ($age < 60)
		{
		return int($age)."h";
		}
	$age /= 24;
	return int($age)."d";
	}