{"id":49895021,"url":"https://github.com/yylego/cronzh","last_synced_at":"2026-05-15T23:04:54.095Z","repository":{"id":350066283,"uuid":"1178779929","full_name":"yylego/cronzh","owner":"yylego","description":"Chinese-named cron scheduling package extending robfig/cron with intuitive APIs","archived":false,"fork":false,"pushed_at":"2026-04-08T17:59:28.000Z","size":24,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-08T19:27:02.572Z","etag":null,"topics":["chinese-programming","cron-scheduling","robfig-cron","scheduled-tasks"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yylego.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-03-11T11:07:45.000Z","updated_at":"2026-04-08T17:56:31.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/yylego/cronzh","commit_stats":null,"previous_names":["yylego/cronzh"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/yylego/cronzh","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yylego%2Fcronzh","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yylego%2Fcronzh/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yylego%2Fcronzh/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yylego%2Fcronzh/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yylego","download_url":"https://codeload.github.com/yylego/cronzh/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yylego%2Fcronzh/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33082777,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-15T20:25:35.270Z","status":"ssl_error","status_checked_at":"2026-05-15T20:25:34.732Z","response_time":103,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["chinese-programming","cron-scheduling","robfig-cron","scheduled-tasks"],"created_at":"2026-05-15T23:04:50.574Z","updated_at":"2026-05-15T23:04:54.084Z","avatar_url":"https://github.com/yylego.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![GitHub Workflow Status (branch)](https://img.shields.io/github/actions/workflow/status/yylego/cronzh/release.yml?branch=main\u0026label=BUILD)](https://github.com/yylego/cronzh/actions/workflows/release.yml?query=branch%3Amain)\n[![GoDoc](https://pkg.go.dev/badge/github.com/yylego/cronzh)](https://pkg.go.dev/github.com/yylego/cronzh)\n[![Coverage Status](https://img.shields.io/coveralls/github/yylego/cronzh/main.svg)](https://coveralls.io/github/yylego/cronzh?branch=main)\n[![Supported Go Versions](https://img.shields.io/badge/Go-1.25+-lightgrey.svg)](https://go.dev/)\n[![GitHub Release](https://img.shields.io/github/release/yylego/cronzh.svg)](https://github.com/yylego/cronzh/releases)\n[![Go Report Card](https://goreportcard.com/badge/github.com/yylego/cronzh)](https://goreportcard.com/report/github.com/yylego/cronzh)\n\n# cronzh\n\nChinese-named package extending `github.com/robfig/cron/v3` with intuitive APIs to manage scheduled tasks\n\n---\n\n\u003c!-- TEMPLATE (EN) BEGIN: LANGUAGE NAVIGATION --\u003e\n## CHINESE README\n\n[中文说明](README.zh.md)\n\u003c!-- TEMPLATE (EN) END: LANGUAGE NAVIGATION --\u003e\n\n## DISCLAIMER\n\nWriting Go code in Chinese is a viable technique, but something to avoid in production engineering. This approach should not be used in serious and business settings. Teams and companies that embrace it could face contempt from peers and negative judgment across the profession. In business companies, this practice is even more prone to becoming a target of public criticism. This project is dedicated to research and academic studies. Do not use this approach in production.\n\n## Main Features\n\n🎯 **Chinese Function Names**: Intuitive Chinese-named wrappers around robfig/cron\n⏰ **Multiple Schedules**: Each task supports multiple cron expressions\n📊 **Schedule Preview**: Debug mode to visualize future execution times\n🔧 **Flexible Parsers**: Both second-precision (6-field) and minute-precision (5-field) support\n📝 **Detailed Logging**: Built-in zaplog integration for tracking task execution\n\n## Installation\n\n```bash\ngo get github.com/yylego/cronzh\n```\n\n## Quick Start\n\n### Basic Task Registration\n\nCreate scheduled tasks and add them to the cron instance with cron expressions.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/yylego/cronzh/cronnextzh\"\n\t\"github.com/yylego/cronzh/crontaskzh\"\n\tcronv3 \"github.com/robfig/cron/v3\"\n)\n\nfunc main() {\n\t// Basic cron task registration (基础定时任务注册)\n\t// Create a task that runs on weekdays at specific times (创建在工作日特定时间运行的任务)\n\n\t// Define task execution function (定义任务执行函数)\n\ttaskFunction := func(taskName string) {\n\t\tfmt.Printf(\"[%s] Executing task: %s\\n\", time.Now().Format(\"15:04:05\"), taskName)\n\t}\n\n\t// Create task list with cron expressions (使用 cron 表达式创建任务列表)\n\ttaskList := crontaskzh.NewS定时任务列表([]*crontaskzh.T定时任务{\n\t\t{\n\t\t\tE任务名称:    \"Morning Report\",\n\t\t\tS定时表达式列表: []string{\"0 30 8 * * 1-5\"}, // Weekdays at 8:30 AM (工作日上午8:30)\n\t\t\tF执行函数:    taskFunction,\n\t\t},\n\t\t{\n\t\t\tE任务名称:    \"Evening Summary\",\n\t\t\tS定时表达式列表: []string{\"0 0 20 * * 1-5\"}, // Weekdays at 8:00 PM (工作日晚上8:00)\n\t\t\tF执行函数:    taskFunction,\n\t\t},\n\t})\n\n\t// Display future execution schedule (显示未来执行计划)\n\tfmt.Println(\"=== Scheduled Tasks for Next 7 Days ===\")\n\tif err := taskList.Debug(cronnextzh.P带秒数的表达式解析器, 7); err != nil {\n\t\tpanic(err)\n\t}\n\n\t// Register and run the cron scheduler (注册并运行定时调度器)\n\tcron := cronv3.New(cronv3.WithSeconds())\n\tif err := taskList.Set注册定时任务(cron); err != nil {\n\t\tpanic(err)\n\t}\n\tcron.Start()\n\n\t// Run for 10 seconds to demonstrate (演示运行10秒)\n\tfmt.Println(\"\\nCron scheduler running... (will stop after 10 seconds)\")\n\ttime.Sleep(10 * time.Second)\n\n\t// Stop the scheduler (停止调度器)\n\tctx := cron.Stop()\n\t\u003c-ctx.Done()\n\tfmt.Println(\"Cron scheduler stopped\")\n}\n```\n\n⬆️ **Source:** [Source](internal/demos/demo1x/main.go)\n\n### Multiple Expressions Within Single Task\n\nA single task can have different schedules for weekdays and weekends.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/yylego/cronzh/cronnextzh\"\n\t\"github.com/yylego/cronzh/crontaskzh\"\n\tcronv3 \"github.com/robfig/cron/v3\"\n)\n\nfunc main() {\n\t// Multiple cron expressions for a single task (单个任务使用多个 cron 表达式)\n\t// Different schedules for weekdays and weekends (工作日和周末使用不同的计划)\n\n\t// Define task execution functions (定义任务执行函数)\n\tbackupTask := func(taskName string) {\n\t\tfmt.Printf(\"[%s] Running backup: %s\\n\", time.Now().Format(\"15:04:05\"), taskName)\n\t}\n\n\tmonitorTask := func(taskName string) {\n\t\tfmt.Printf(\"[%s] Running monitor: %s\\n\", time.Now().Format(\"15:04:05\"), taskName)\n\t}\n\n\t// Create task list with multiple expressions per task (创建每个任务带多个表达式的任务列表)\n\ttaskList := crontaskzh.NewS定时任务列表([]*crontaskzh.T定时任务{\n\t\t{\n\t\t\tE任务名称: \"Database Backup\",\n\t\t\tS定时表达式列表: []string{\n\t\t\t\t\"0 0 2 * * 1-5\", // Weekdays at 2:00 AM (工作日凌晨2点)\n\t\t\t\t\"0 0 3 * * 0,6\", // Weekends at 3:00 AM (周末凌晨3点)\n\t\t\t},\n\t\t\tF执行函数: backupTask,\n\t\t},\n\t\t{\n\t\t\tE任务名称: \"System Monitor\",\n\t\t\tS定时表达式列表: []string{\n\t\t\t\t\"0 */30 * * * *\", // Every 30 minutes (每30分钟)\n\t\t\t},\n\t\t\tF执行函数: monitorTask,\n\t\t},\n\t})\n\n\t// Display future execution schedule (显示未来执行计划)\n\tfmt.Println(\"=== Scheduled Tasks for Next 5 Days ===\")\n\ttaskList.Debug(cronnextzh.P带秒数的表达式解析器, 5)\n\n\t// Register and run the cron scheduler (注册并运行定时调度器)\n\tcron := cronv3.New(cronv3.WithSeconds())\n\ttaskList.Set注册定时任务(cron)\n\tcron.Start()\n\n\t// Run for 10 seconds to demonstrate (演示运行10秒)\n\tfmt.Println(\"\\nCron scheduler running... (will stop after 10 seconds)\")\n\ttime.Sleep(10 * time.Second)\n\n\t// Stop the scheduler (停止调度器)\n\tctx := cron.Stop()\n\t\u003c-ctx.Done()\n\tfmt.Println(\"Cron scheduler stopped\")\n}\n```\n\n⬆️ **Source:** [Source](internal/demos/demo2x/main.go)\n\n### Expression Parsing and Preview\n\nParse cron expressions and calculate future execution times without running tasks.\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\t\"time\"\n\n\t\"github.com/yylego/cronzh/cronnextzh\"\n)\n\nfunc main() {\n\t// Parsing cron expressions and calculating future execution times (解析 cron 表达式并计算未来执行时间)\n\t// Useful for previewing schedules without running tasks (用于预览计划而无需运行任务)\n\n\t// Example 1: Single cron expression (示例1：单个 cron 表达式)\n\tfmt.Println(\"=== Example 1: Single Expression ===\")\n\tspec1 := \"0 15 10 * * 1-5\" // Weekdays at 10:15 AM (工作日上午10:15)\n\ttimes1, err := cronnextzh.P带秒数的表达式解析器.Get获取未来N天内的执行时间(spec1, time.Now(), 7)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Printf(\"Expression: %s\\n\", spec1)\n\tfmt.Printf(\"Next %d execution times:\\n\", len(times1))\n\tfor i, t := range times1 {\n\t\tfmt.Printf(\"  %2d. %s (Weekday: %d)\\n\", i+1, t.Format(\"2006-01-02 15:04:05\"), t.Weekday())\n\t}\n\n\t// Example 2: Multiple cron expressions (示例2：多个 cron 表达式)\n\tfmt.Println(\"\\n=== Example 2: Multiple Expressions ===\")\n\tspecs2 := []string{\n\t\t\"0 30 9 * * 1-5\",  // Weekdays at 9:30 AM (工作日上午9:30)\n\t\t\"0 0 14 * * 1-5\",  // Weekdays at 2:00 PM (工作日下午2:00)\n\t\t\"0 30 18 * * 1-5\", // Weekdays at 6:30 PM (工作日下午6:30)\n\t}\n\ttimes2, err := cronnextzh.P带秒数的表达式解析器.Get计算未来N天内的执行时间(specs2, time.Now(), 3)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Printf(\"Expressions: %v\\n\", specs2)\n\tfmt.Printf(\"Combined next %d execution times (sorted):\\n\", len(times2))\n\tfor i, t := range times2 {\n\t\tfmt.Printf(\"  %2d. %s (Weekday: %d)\\n\", i+1, t.Format(\"2006-01-02 15:04:05\"), t.Weekday())\n\t}\n\n\t// Example 3: Using minute-precision parser (示例3：使用分钟精度解析器)\n\tfmt.Println(\"\\n=== Example 3: Minute-Precision Parser ===\")\n\tspec3 := \"15 10 * * 1-5\" // 5-field format: Weekdays at 10:15 (5字段格式：工作日10:15)\n\ttimes3, err := cronnextzh.P只到分的表达式解析器.Get获取未来N天内的执行时间(spec3, time.Now(), 5)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\n\tfmt.Printf(\"Expression: %s (5-field format)\\n\", spec3)\n\tfmt.Printf(\"Next %d execution times:\\n\", len(times3))\n\tfor i, t := range times3 {\n\t\tfmt.Printf(\"  %2d. %s (Weekday: %d)\\n\", i+1, t.Format(\"2006-01-02 15:04:05\"), t.Weekday())\n\t}\n}\n```\n\n⬆️ **Source:** [Source](internal/demos/demo3x/main.go)\n\n## API Reference\n\n### Core Modules\n\n#### cronnextzh - Cron Expression Parser\n\n**Predefined Parsers:**\n\n- `P带秒数的表达式解析器` - Second-precision parser (6 fields: second, minute, hour, day, month, weekday)\n- `P只到分的表达式解析器` - Minute-precision parser (5 fields: minute, hour, day, month, weekday)\n\n**Main Type:**\n\n```go\ntype P表达式解析器 cron.Parser\n```\n\n**Main Methods:**\n\n- `New(parser cron.Parser) *P表达式解析器` - Create custom parser\n- `Get获取未来N天内的执行时间(spec string, since time.Time, nDate int) ([]time.Time, error)` - Calculate execution times given a single expression\n- `Get计算未来N天内的执行时间(specs []string, since time.Time, nDate int) ([]time.Time, error)` - Calculate execution times given multiple expressions (sorted)\n\n#### crontaskzh - Task List Management\n\n**Main Types:**\n\n```go\ntype T定时任务 struct {\n    S定时表达式列表 []string           // List of cron expressions\n    E任务名称      string             // Task name\n    F执行函数      func(e任务名称 string) // Execution function\n}\n\ntype S定时任务列表 []*T定时任务\n```\n\n**Main Methods:**\n\n- `NewS定时任务列表(s定时任务列表 []*T定时任务) S定时任务列表` - Create new task list\n- `Set注册定时任务(cron *cron.Cron) error` - Add all tasks to the cron instance\n- `Debug(p表达式解析器 *cronnextzh.P表达式解析器, nDate int) error` - Show the future execution schedule\n\n## Cron Expression Format\n\n**6-field format (with seconds):**\n```\n┌─── second (0-59)\n│ ┌─── minute (0-59)\n│ │ ┌─── hour (0-23)\n│ │ │ ┌─── day (1-31)\n│ │ │ │ ┌─── month (1-12)\n│ │ │ │ │ ┌─── weekday (0-6, Sunday=0)\n│ │ │ │ │ │\n* * * * * *\n```\n\n**5-field format (minute precision):**\n```\n┌─── minute (0-59)\n│ ┌─── hour (0-23)\n│ │ ┌─── day (1-31)\n│ │ │ ┌─── month (1-12)\n│ │ │ │ ┌─── weekday (0-6, Sunday=0)\n│ │ │ │ │\n* * * * *\n```\n\n**Common Examples:**\n\n- `\"0 30 8 * * 1-5\"` - Weekdays at 8:30 AM\n- `\"*/5 * * * * *\"` - Every 5 seconds\n- `\"0 0 2 * * *\"` - Every day at 2:00 AM\n- `\"0 0 0 * * 0\"` - Every Sunday at midnight\n- `\"0 */30 * * * *\"` - Every 30 minutes\n\n## Design Concept\n\nThis package follows these principles:\n\n1. **Chinese Naming**: Functions use intuitive Chinese names matching robfig/cron concepts\n2. **Multiple Schedules**: Single tasks can have multiple cron expressions\n3. **Debug-Friendly**: Built-in schedule visualization before deployment\n4. **Type-Safe Operations**: Leverages Go's type system for safe task management\n5. **Flexible Parsing**: Support both second-precision and minute-precision formats\n\n---\n\n\u003c!-- TEMPLATE (EN) BEGIN: STANDARD PROJECT FOOTER --\u003e\n\u003c!-- VERSION 2025-11-20 04:26:32.402216 +0000 UTC --\u003e\n\n## 📄 License\n\nMIT License - see [LICENSE](LICENSE).\n\n---\n\n## 💬 Contact \u0026 Feedback\n\nContributions are welcome! Report bugs, suggest features, and contribute code:\n\n- 🐛 **Mistake reports?** Open an issue on GitHub with reproduction steps\n- 💡 **Fresh ideas?** Create an issue to discuss\n- 📖 **Documentation confusing?** Report it so we can improve\n- 🚀 **Need new features?** Share the use cases to help us understand requirements\n- ⚡ **Performance issue?** Help us optimize through reporting slow operations\n- 🔧 **Configuration problem?** Ask questions about complex setups\n- 📢 **Follow project progress?** Watch the repo to get new releases and features\n- 🌟 **Success stories?** Share how this package improved the workflow\n- 💬 **Feedback?** We welcome suggestions and comments\n\n---\n\n## 🔧 Development\n\nNew code contributions, follow this process:\n\n1. **Fork**: Fork the repo on GitHub (using the webpage UI).\n2. **Clone**: Clone the forked project (`git clone https://github.com/yourname/repo-name.git`).\n3. **Navigate**: Navigate to the cloned project (`cd repo-name`)\n4. **Branch**: Create a feature branch (`git checkout -b feature/xxx`).\n5. **Code**: Implement the changes with comprehensive tests\n6. **Testing**: (Golang project) Ensure tests pass (`go test ./...`) and follow Go code style conventions\n7. **Documentation**: Update documentation to support client-facing changes and use significant commit messages\n8. **Stage**: Stage changes (`git add .`)\n9. **Commit**: Commit changes (`git commit -m \"Add feature xxx\"`) ensuring backward compatible code\n10. **Push**: Push to the branch (`git push origin feature/xxx`).\n11. **PR**: Open a merge request on GitHub (on the GitHub webpage) with detailed description.\n\nPlease ensure tests pass and include relevant documentation updates.\n\n---\n\n## 🌟 Support\n\nWelcome to contribute to this project via submitting merge requests and reporting issues.\n\n**Project Support:**\n\n- ⭐ **Give GitHub stars** if this project helps you\n- 🤝 **Share with teammates** and (golang) programming friends\n- 📝 **Write tech blogs** about development tools and workflows - we provide content writing support\n- 🌟 **Join the ecosystem** - committed to supporting open source and the (golang) development scene\n\n**Have Fun Coding with this package!** 🎉🎉🎉\n\n\u003c!-- TEMPLATE (EN) END: STANDARD PROJECT FOOTER --\u003e\n\n---\n\n## GitHub Stars\n\n[![Stargazers](https://starchart.cc/yylego/cronzh.svg?variant=adaptive)](https://starchart.cc/yylego/cronzh)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyylego%2Fcronzh","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyylego%2Fcronzh","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyylego%2Fcronzh/lists"}