Class CronMacro

java.lang.Object
cloud.opencode.base.cron.CronMacro

public final class CronMacro extends Object
Cron Macro - Predefined Cron Expression Shortcuts Cron宏 - 预定义的Cron表达式快捷方式

Resolves standard cron macros to their equivalent 5-field expressions. Macros are case-insensitive and start with @.

将标准Cron宏解析为等效的5字段表达式。 宏不区分大小写,以 @ 开头。

Features | 主要功能:

  • @yearly / @annually0 0 1 1 * (January 1st at midnight - 每年1月1日午夜)
  • @monthly0 0 1 * * (1st of each month - 每月1号午夜)
  • @weekly0 0 * * 0 (Sunday at midnight - 每周日午夜)
  • @daily / @midnight0 0 * * * (every day at midnight - 每天午夜)
  • @hourly0 * * * * (every hour - 每小时)

Usage Examples | 使用示例:

CronMacro.resolve("@daily")    // "0 0 * * *"
CronMacro.resolve("@yearly")   // "0 0 1 1 *"
CronMacro.isMacro("@hourly")   // true
CronMacro.isMacro("0 * * * *") // false

Security | 安全性:

  • Thread-safe: Yes (stateless static methods, immutable map) - 线程安全: 是
  • Null-safe: Yes - 空值安全: 是
Since:
JDK 25, opencode-base-cron V1.0.0
Author:
Leon Soo www.LeonSoo.com
See Also:
  • Method Details

    • resolve

      public static String resolve(String input)
      Resolves a macro to its cron expression 将宏解析为Cron表达式
      Parameters:
      input - the input string | 输入字符串
      Returns:
      the expanded expression, or null if not a macro | 展开的表达式,如果不是宏则返回null
    • isMacro

      public static boolean isMacro(String input)
      Checks if the input is a known macro 检查输入是否是已知宏
      Parameters:
      input - the input string | 输入字符串
      Returns:
      true if it is a macro | 如果是宏返回true