function addTimer(clock, timer) {
				if (timer.func === undefined) {
					throw new Error("Callback must be provided to timer calls");
				}

				if (addTimerReturnsObject) {
					// Node.js environment
					if (typeof timer.func !== "function") {
						throw new TypeError(
							`[ERR_INVALID_CALLBACK]: Callback must be a function. Received ${
								timer.func
							} of type ${typeof timer.func}`
						);
					}
				}

				if (isNearInfiniteLimit) {
					timer.error = new Error();
				}

				timer.type = timer.immediate ? "Immediate" : "Timeout";

				if (timer.hasOwnProperty("delay")) {
					if (typeof timer.delay !== "number") {
						timer.delay = parseInt(timer.delay, 10);
					}

					if (!isNumberFinite(timer.delay)) {
						timer.delay = 0;
					}
					timer.delay = timer.delay > maxTimeout ? 1 : timer.delay;
					timer.delay = Math.max(0, timer.delay);
				}

				if (timer.hasOwnProperty("interval")) {
					timer.type = "Interval";
					timer.interval = timer.interval > maxTimeout ? 1 : timer.interval;
				}

				if (timer.hasOwnProperty("animation")) {
					timer.type = "AnimationFrame";
					timer.animation = true;
				}

				if (timer.hasOwnProperty("idleCallback")) {
					timer.type = "IdleCallback";
					timer.idleCallback = true;
				}

				if (!clock.timers) {
					clock.timers = {};
				}

				timer.id = uniqueTimerId++;
				timer.createdAt = clock.now;
				timer.callAt =
					clock.now + (parseInt(timer.delay) || (clock.duringTick ? 1 : 0));

				clock.timers[timer.id] = timer;

				if (addTimerReturnsObject) {
					const res = {
						refed: true,
						ref: function () {
							this.refed = true;
							return res;
						},
						unref: function () {
							this.refed = false;
							return res;
						},
						hasRef: function () {
							return this.refed;
						},
						refresh: function () {
							timer.callAt =
								clock.now +
								(parseInt(timer.delay) || (clock.duringTick ? 1 : 0));

							// it _might_ have been removed, but if not the assignment is perfectly fine
							clock.timers[timer.id] = timer;

							return res;
						},
						[Symbol.toPrimitive]: function () {
							return timer.id;
						},
					};
					return res;
				}

				return timer.id;
			}
@param {Clock} clock
@param {Timer} timer
@returns {number} id of the created timer