NAME

BSD::Time - BSD gettimeofday, settimeofday functions

SYNOPSIS

use BSD::Time;

# gettimeofday

$time = gettimeofday();

($seconds, $microseconds, $minuteswest, $dsttype) = gettimeofday();

# settimeofday

settimeofday($seconds, $microseconds, $minuteswest, $dsttime) or
    die "cannot set time";

DESCRIPTION

gettimeofday

$time = gettimeofday();

In scalar context gettimeofday returns the number of seconds since the midnight (0 hour), January 1, 1970 UTC (Coordinated Universal Time, formerly known as Greenwich Mean Time, GMT). This is identical to the usual Perl time() function except that also the subsecond fractional is returned. The accuracy is nominally one microsecond, one millionth of a second, but normally the accuracy is lower than that, maybe few dozen microseconds.

($seconds, $microseconds, $minuteswest, $dsttype) = gettimeofday();

In list context gettimeofday returns the seconds and microseconds and the timezone information: the minutes west of the Greenwich Meridian and the Daylight Savings Time Type. The type is a system-dependent integer value that is not actually much of use these days: it a historical relic.

settimeofday

$success = settimeofday($seconds, $microseconds,
			$minuteswest, $dsttime);

settimeofday sets the time, the arguments being as in the list context of gettimeofday. settimeofday may be used only by the superuser. It returns true if setting succeeded, false if not.

Overloading time()

The time() function can be overridden to return the subsecond part of the second. NOTE: THIS IS ONLY FOR THOSE WHO REALLY, *REALLY* KNOW WHAT THEY ARE DOING. THIS CAN BREAK CODE (ACTION-AT-A-DISTANCE, SOME CODE, ANY CODE, NOT EVEN YOUR CODE OR MINE CODE, SOME MODULE CODE THAT YOU INADVERTENTLY USE, THAT YOU EVEN DO NOT KNOW THAT YOU ARE USING) THAT TRUSTS THAT time() ONLY RETURNS INTEGERS. NOTHING IS GUARANTEED. YOU HAVE BEEN WARNED. Now that you know where you stand this can done done with: use BSD::Time 'time';

LIMITATIONS

The time accuracy is nominally one microsecond, one millionth of a second, but the implementation of your environment may not be that accurate.

The BSD time-adjusting function adjtime() is not implemented. This may affect in some environment the settimeofday() in such a way that setting time time with subsecond accuracy is not possible.

AUTHOR

Jarkko Hietaniemi <jhi@iki.fi>

ACKNOWLEDGEMENTS

Gisle Aas <gisle@aas.no>