#!/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.


In reply to RE: Last Here Date by mdillon
in thread Last Here Date by mdillon

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.