@Override public String toString() { // 返回形如: 30s/5m@2m30s,读作: 以30秒切割5分钟周期,当前偏移量为第2分钟30秒 return TimeInterval.parse(interval) + "/" + TimeInterval.parse(total) + "@" + TimeInterval.parse(currentOffset); }
/** * * * <h2>返回当前偏移量在特定cron位置上面的表达</h2> * * @param i cron位置 * @return 偏移量表达 */ public String getSegment(int i) { // 0(second): 1 (s) // 1(minute): 60 (s) // 2(hour) : 36,00 (s) if (i > 2) throw new UnsupportedOperationException("Can't support offset greater than hour"); // 1h1m30s String offset = TimeInterval.parse(currentOffset); Pattern pattern = patterns[i]; Matcher matcher = pattern.matcher(offset); if (matcher.find()) { return matcher.group(1); } else { return "0"; } }