npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@zhin.js/schedule

v0.0.2

Published

Calendar semantic scheduler for Zhin.js — solar, lunar, statutory holidays, workdays, scatter

Readme

@zhin.js/schedule

Zhin.js 日历语义调度库:公历/农历 Cron、国务院节假日、工作日/休息日、scatter 分散触发、持久化 JobStore 等。位于 monorepo basic/ 层,由 @zhin.js/kernelScheduleEngine 与 Agent 层 ScheduleJobEngine 封装使用。

安装

pnpm add @zhin.js/schedule

架构位置

basic/ (@zhin.js/logger, schema, database, schedule, cli)
  ↓
@zhin.js/kernel          ScheduleEngine 包装 CalendarScheduler
  ↓
@zhin.js/core            Plugin.addSchedule
  ↓
@zhin.js/agent           ScheduleJobEngine、schedule_* 工具

用户向文档见 docs/advanced/schedule.md;Breaking 变更见 ADR 0028

快速开始

import { CalendarScheduler } from '@zhin.js/schedule';

const scheduler = new CalendarScheduler({ timezone: 'Asia/Shanghai' });

// 6 段 cron(秒 分 时 日 月 周)
scheduler.solar('0 0 9 * * *', async (ctx) => {
  console.log('公历 9 点', ctx.solarText);
});

scheduler.workday('0 0 9 * * *', async () => {
  console.log('工作日 9 点');
});

scheduler.holiday({ cron: '0 0 10 * * *', festival: '春节' }, async () => {
  console.log('春节期间 10 点');
});

scheduler.start();
// …
scheduler.stop();

调度类型(ScheduleKind

| kind | 说明 | |------|------| | solar | 公历 Cron | | lunar | 农历 Cron | | workday | 法定工作日(含调休上班) | | freeDay | 休息日 | | holiday | 指定节日区间 | | scatter | 时间窗内随机/分散触发 |

辅助解析:parseCronvalidateCalendarCroncron() / at() / everyMinutes() 等见 ./parsers/

节假日数据

内置 2019–2026 年国务院公示数据(src/data/holidays/*.json)。可运行时更新:

import { updateData, onHolidayDataUpdate } from '@zhin.js/schedule';

onHolidayDataUpdate(() => console.log('holiday data refreshed'));
await updateData({ year: 2027, force: true });

同步脚本:scripts/sync-holiday.mjsscripts/generate-holiday-registry.mjs

持久化 JobStore

import { CalendarScheduler, createLocalJsonStore, createSqliteStore } from '@zhin.js/schedule';

const store = createLocalJsonStore({ path: './data/schedule-jobs.json' });
const scheduler = new CalendarScheduler({ store, timezone: 'Asia/Shanghai' });

亦支持 createRedisStore(多 worker claim)与 createHandlerRegistry(handler 与 job 解耦)。

开发与测试

pnpm --filter @zhin.js/schedule build
pnpm vitest run basic/schedule/tests

主要导出

  • CalendarScheduler — 调度引擎
  • getNextRun / isJobDue — 单次/next-run 计算
  • resolveSolarJob / resolveLunarJob / … — 解析 schedule 输入
  • simulateNextRuns — 预览未来触发
  • updateData / fetchHolidayYearData — 节假日数据源
  • createLocalJsonStore / createSqliteStore / createRedisStore — 持久化

完整 API 见 src/index.ts