"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.hourOfDay = hourOfDay;

var tsplus_module_1 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Cause/errors"));

var tsplus_module_2 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/die"));

var tsplus_module_3 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Schedule/Interval"));

var tsplus_module_4 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Schedule/Decision"));

var tsplus_module_5 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@tsplus/stdlib/data/Tuple/make"));

var tsplus_module_6 = /*#__PURE__*/_interopRequireWildcard( /*#__PURE__*/require("@effect/core/io/Effect/operations/succeedNow"));

var _makeWithState = /*#__PURE__*/require("@effect/core/io/Schedule/operations/_internal/makeWithState");

var _time = /*#__PURE__*/require("@effect/core/io/Schedule/operations/_internal/time");

function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }

function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }

const fileName_1 = "(@effect/core) _src/io/Schedule/operations/hourOfDay.ts";

/**
 * Cron-like schedule that recurs every specified `hour` of each day. It
 * triggers at zero minute of the hour. Producing a count of repeats: 0, 1, 2.
 *
 * NOTE: `hour` parameter is validated lazily. Must be in range 0...23.
 *
 * @tsplus static ets/Schedule hourOfDay
 */
function hourOfDay(hour) {
  return (0, _makeWithState.makeWithState)(0, (now, _, state) => {
    if (!Number.isInteger(hour) || hour < 0 || 23 < hour) {
      return tsplus_module_2.die(() => new tsplus_module_1.IllegalArgumentException(`Invalid argument in: hourOfDay(${hour}). Must be in range 0...23`), fileName_1 + ":19:24");
    }

    const hr = (0, _time.nextHour)(now, hour);
    const start = Math.max((0, _time.beginningOfHour)(hr), now);
    const end = (0, _time.endOfHour)(hr);
    const interval = tsplus_module_3.fromStartEndMillis(start, end);
    return tsplus_module_6.succeedNow(tsplus_module_5.make(state + 1, state, tsplus_module_4._continue(interval)), fileName_1 + ":29:29");
  });
}
//# sourceMappingURL=hourOfDay.js.map