The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.
NAME
    Test::Recent - check a time is recent

SYNOPSIS
       use Test::More;
       use Test::Recent qw(recent);

       # check things happened in the last ten seconds
       recent DateTime->now, "now is recent!";
       recent "2012-12-23 00:00:00", "end of mayan calendar happened recently?";

       # check things happened in the last hour
       recent "2012-12-23 00:00:00", DateTime::Duration->new( hours => 1 ), "mayan";
       recent "2012-12-23 00:00:00", "1 hour", "mayan"

DESCRIPTION
    Simple module to check things happened recently.

  Functions
    These are exported on demand or may be called fully qualified

    recent $date_and_time
    recent $date_and_time, $test_description
    recent $date_and_time, $duration, $test_description
        Tests (using the Test::Builder framework) if the time occurred
        within the duration ago from the current time. If no duration is
        passed, ten seconds is assumed.

    occured_within_ago $date_and_time, $duration
        Returns true if and only if the time occurred within the duration
        ago from the current time.

  Parsing of DateTimes
    This module supports the following things being passed in as a date and
    time:

    epoch seconds
    A DateTime object
    An ISO8601 formatted date string
        i.e. anything that DateTime::Format::ISO8601 can parse

    A Postgres style TIMESTAMP WITH TIME ZONE
        i.e. something of the form "YYYY-MM-DD HH:MM:SS.ssssss+TZ"

    Older versions of this module used DateTimeX::Easy to parse the
    datetime, but this proved to be unreliable.

AUTHOR
    Written by Mark Fowler <mark@twoshortplanks.com>

COPYRIGHT
    Copyright OmniTI 2012. All Rights Reserved.

    This program is free software; you can redistribute it and/or modify it
    under the same terms as Perl itself.

BUGS
    This module ignores sub-seconds. This is primarily because the current
    implementation of DateTime's "now" method does not return nanoseconds,
    meaning that technically "now" returns a time that is in the past and
    might occur before a timestamp you hand in that contained nanoseconds
    (and therefore would erroneously be not concidered "recent")

    Bugs should be reported via this distribution's CPAN RT queue. This can
    be found at <https://rt.cpan.org/Dist/Display.html?Test-Recent>

    You can also address issues by forking this distribution on github and
    sending pull requests. It can be found at
    <http://github.com/2shortplanks/Test-Recent>

    In order not to depend on another DateTime library, this module converts
    postgres style TIMESTAMP WITH TIME ZONE by using a regular expression
    and simply ignoring microseconds. This potentially introduces a one
    second inaccuracy in the recent handling.

SEE ALSO
    DateTime::Format::ISO8601, Time::Duration::Parse