# This package forms a convenience namespace to locate some information for other parts
# of the code to find it.
package InstanceData;
use strict;
use File::Basename;
use Sys::Hostname;

sub _date {
    sprintf '%d-%02d-%02d', $_[5] + 1900, $_[4] + 1, $_[3];
}

sub _time {
    sprintf '%02d:%02d:%02d', reverse @_[0..2];
}

use constant HOSTNAME          => hostname;
use constant SCRIPT_NAME       => basename($0);
use constant RAW_START_TIME    => time;
use constant START_DATE        => _date(localtime RAW_START_TIME);
use constant START_TIME        => _time(localtime RAW_START_TIME);
use constant START_DATETIME    => join ' ' => START_DATE, START_TIME;

# Here are some pseudo-constants that can be used just like START_*.

sub CURRENT_DATE {
    _date(localtime);
}

sub CURRENT_TIME {
    _time(localtime);
}

sub CURRENT_DATETIME {
    join ' ' => CURRENT_DATE, CURRENT_TIME;
}

sub CURRENT_SUBROUTINE {
    (caller(1))[3];
}

use vars qw($effective_start_time);

# The "effective" start time of the script.  Some packages, notably LogHandles, like to lie
# to themselves about when the script really started.  This variable is dedicated to them.

$effective_start_time = RAW_START_TIME;

1;
