in reply to Last Here Date
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).#!/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";
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 | |
by mdillon (Priest) on May 30, 2000 at 20:07 UTC |