//
//
//   abstime.h - floating point time function.
//
//   Copyright (C) 2026 by Matt Roberts, KK5JY.
//   All rights reserved.
//
//   License: GPL3 (www.gnu.org)
//
//

#ifndef __KK5JY_ABSTIME_H
#define __KK5JY_ABSTIME_H

#include <time.h>

namespace KK5JY {
	namespace Time {
		//
		//  abstime() - return absolute clock in seconds; essentially a
		//              floating point version of time(2)
		//
		inline double abstime(int which = CLOCK_REALTIME) {
			// read the clock
			struct timespec ts;
			if (::clock_gettime(which, &ts) != 0)
				return 0.0;

			// convert the seconds and milliseconds into a double result
			double result = static_cast<double>(ts.tv_sec);
			result += static_cast<double>(ts.tv_nsec) / 1000000000.0;
			return result;
		}
	}
}

#endif // __KK5JY_ABSTIME_H
