in reply to Last Here Date

#!/usr/bin/perl -w use strict; use vars qw($SECOND $MINUTE $HOUR $DAY $WEEK); $SECOND = 1; $MINUTE = 60 * $SECOND; # i know, i know $HOUR = 60 * $MINUTE; $DAY = 24 * $HOUR; $WEEK = 7 * $DAY; sub get_lapse { my $last_here = shift; my $difference = time - $last_here; my @params = (); if ($difference >= $WEEK) { push @params, $WEEK, 'week', 'weeks'; } elsif ($difference >= $DAY) { push @params, $DAY, 'day', 'days'; } elsif ($difference >= $HOUR) { push @params, $HOUR, 'hour', 'hours'; } elsif ($difference >= $MINUTE) { push @params, $MINUTE, 'minute', 'minutes'; } else { push @params, $SECOND, 'second', 'seconds'; } # assume $difference is positive my $lapse = int($difference / $params[0] + 0.5); sprintf "%d %s ago", $lapse, $params[$lapse == 1 ? 1 : 2]; } my $last_here = time - $DAY - 10 * $MINUTE; print get_lapse($last_here), "\n";
since i presume vroom can get the timestamp easily enough, hopefully this code is a full enough implementation that this feature can be added (that is if people would actually say what they think of the idea).

i think that weeks are fine for the chunkiest granularity, but months could be added if necessary. the main problem with that being that months differ in length.

Replies are listed 'Best First'.
RE: RE: Last Here Date
by Adam (Vicar) on May 30, 2000 at 20:05 UTC
    I think its a good idea.

    I also think you could use months. But my method would be to take advantage of the fact that localtime() will do all the math for you. Simply store the time stamp in non-leap seconds from Jan 1, 1970 UTC for the last login. (This is the format of time in Perl.) Feed that to localtime() and get the year, month #, hour, minute, etc... Then subtract that from the current state.

      ah, localtime. it is both friend and enemy to me all at once.

      if you want, make the necessary changes to my code and /msg vroom with the node_id of your code or changes to get it in there (although, i don't think that months is much more usefull than weeks, so i would probably leave it out).