"use strict";
/* Socket Lib - Built with rolldown */
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const require_primordials_date = require('../primordials/date.js');
const require_primordials_globals = require('../primordials/globals.js');

//#region src/temporal/system.ts
/**
* @file Spec clause 21.x host hook — wallclock reader. Implements
*   `SystemUTCEpochNanoseconds()`, the spec's nanosecond- resolution wallclock
*   read. Hosts may use any source they like provided the result is
*   non-decreasing across calls. On Node we combine `Date.now()` (millisecond
*   wallclock) with `process.hrtime.bigint()` (sub-millisecond monotonic
*   counter) anchored at module load to deliver real nanosecond resolution.
*   Fallback path (non-Node hosts without `process.hrtime.bigint`): we multiply
*   `Date.now()` by 1_000_000n to fill the field with zeros. This trades
*   sub-millisecond precision for portability and is the same compromise the
*   polyfill makes for browser hosts. Spec:
*   https://tc39.es/proposal-temporal/#sec-temporal-systemutcepochnanoseconds.
*/
const _hrtimeBigint = globalThis.process?.hrtime?.bigint;
const _anchorWallMs = require_primordials_globals.BigIntCtor(require_primordials_date.DateNow());
const _anchorHrns = _hrtimeBigint ? _hrtimeBigint() : 0n;
const _NS_PER_MS = 1000000n;
/**
* Returns the current UTC time as nanoseconds since 1970-01-01T00:00:00Z.
*
* Resolution is nanosecond on Node (via `process.hrtime.bigint` anchored at
* module load), millisecond elsewhere.
*/
function systemUTCEpochNanoseconds() {
	if (_hrtimeBigint) {
		const elapsedNs = _hrtimeBigint() - _anchorHrns;
		return _anchorWallMs * _NS_PER_MS + elapsedNs;
	}
	/* c8 ignore next - Non-Node runtime fallback; tests always run under Node
	where _hrtimeBigint is bound from process.hrtime.bigint. */
	return require_primordials_globals.BigIntCtor(require_primordials_date.DateNow()) * _NS_PER_MS;
}

//#endregion
exports.systemUTCEpochNanoseconds = systemUTCEpochNanoseconds;