cronli5 0.1.4 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +25 -0
- package/cronli5.min.js +2 -2
- package/dist/cronli5.cjs +180 -36
- package/dist/cronli5.js +180 -36
- package/dist/lang/de.cjs +172 -8
- package/dist/lang/de.js +172 -8
- package/dist/lang/en.cjs +175 -29
- package/dist/lang/en.js +175 -29
- package/dist/lang/es.cjs +180 -25
- package/dist/lang/es.js +180 -25
- package/dist/lang/fi.cjs +188 -40
- package/dist/lang/fi.js +188 -40
- package/dist/lang/zh.cjs +165 -19
- package/dist/lang/zh.js +165 -19
- package/package.json +2 -1
- package/src/core/analyze.ts +7 -0
- package/src/core/ir.ts +1 -1
- package/src/core/util.ts +31 -1
- package/src/lang/de/index.ts +360 -16
- package/src/lang/en/index.ts +333 -33
- package/src/lang/es/index.ts +373 -40
- package/src/lang/fi/index.ts +404 -72
- package/src/lang/zh/index.ts +327 -35
- package/types/core/ir.d.ts +1 -1
- package/types/core/util.d.ts +6 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,31 @@ adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
|
6
6
|
|
|
7
7
|
## [Unreleased]
|
|
8
8
|
|
|
9
|
+
## [0.1.5]
|
|
10
|
+
|
|
11
|
+
### Changed
|
|
12
|
+
|
|
13
|
+
- **A regular step reads as a bounded cadence instead of an enumerated list.** A
|
|
14
|
+
step like `3/2` (every other minute starting at :03) listed out all 29 of its
|
|
15
|
+
fires; it now reads "every two minutes from 3 through 59 minutes past the hour".
|
|
16
|
+
Offset steps (`5/6` → "every six minutes from five minutes past the hour"),
|
|
17
|
+
uneven steps (`*/7` → "every seven minutes from 0 through 56 minutes past the
|
|
18
|
+
hour"), and a stepped hour composed with a fixed time (`30 0 */2` → "at 30
|
|
19
|
+
seconds past the hour, every two hours", was twelve clock times) are all
|
|
20
|
+
covered, in every context — standalone and composed. So `3/2 1/2` reads "every
|
|
21
|
+
two minutes from 3 through 59 minutes past the hour, every two hours from 1
|
|
22
|
+
a.m." with no enumeration. Clean strides (`*/2` → "every two minutes") and
|
|
23
|
+
irregular lists (`5,10,30`) are unchanged. All languages. Spanish, German,
|
|
24
|
+
Finnish, and Chinese gain the idiom (Chinese and German previously enumerated
|
|
25
|
+
even uniform offset steps).
|
|
26
|
+
- **`* */2` under seconds binds its two cadences** in Spanish, German, Finnish,
|
|
27
|
+
and Chinese (English shipped this in 0.1.4): "cada segundo de cada dos minutos",
|
|
28
|
+
"jede Sekunde jeder zweiten Minute", "joka sekunti joka toisena minuuttina",
|
|
29
|
+
"每偶数分钟的每一秒" — no longer the juxtaposed "every second, every two minutes".
|
|
30
|
+
- **Chinese drops the redundant "0分" for noon** in the per-second confinement
|
|
31
|
+
form: `* 0 12` reads "每天正午的每一秒" (正午 already denotes 12:00); midnight keeps
|
|
32
|
+
"凌晨0点0分".
|
|
33
|
+
|
|
9
34
|
## [0.1.4]
|
|
10
35
|
|
|
11
36
|
### Fixed
|
package/cronli5.min.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
"use strict";(()=>{var Vn={SUN:0,MON:1,TUE:2,WED:3,THU:4,FRI:5,SAT:6},$n={JAN:1,FEB:2,MAR:3,APR:4,MAY:5,JUN:6,JUL:7,AUG:8,SEP:9,OCT:10,NOV:11,DEC:12},h={second:{cyclic:!0,max:59,min:0,top:59},minute:{cyclic:!0,max:59,min:0,top:59},hour:{cyclic:!0,max:23,min:0,top:23},date:{aliases:{"?":"*"},cyclic:!0,max:31,min:1,top:31},month:{cyclic:!0,max:12,min:1,numbers:$n,top:12},weekday:{aliases:{"?":"*",L:"6"},cyclic:!0,max:7,min:0,numbers:Vn,top:6},year:{max:9999,min:1970}},S=["second","minute","hour","date","month","weekday","year"],U={"@annually":"0 0 1 1 *","@yearly":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"},Q=6;function a(n,e){return(""+n).indexOf(e)!==-1}function T(n){return Array.from(new Set(n))}function I(n){return/^\d+$/.test(n)}function f(n,e){return I(n)?+n:e[n.toUpperCase()]}function an(n){return S.forEach(function(r){Jn(n[r],h[r],r)}),n}function Jn(n,e,r){typeof n!="string"&&typeof n!="number"&&sn(n,r);let t=""+n;t!=="*"&&(r==="date"&&w(t)||r==="weekday"&&R(t,e)||t.split(",").forEach(function(o){Yn(o,e)||sn(o,r)}))}function w(n){if(n==="L"||n==="LW"||n==="WL")return!0;let e=/^L-(\d{1,2})$/.exec(n);if(e)return+e[1]>=1&&+e[1]<=30;let r=/^(\d{1,2})W$|^W(\d{1,2})$/.exec(n);if(r){let t=+(r[1]||r[2]);return t>=1&&t<=31}return!1}function R(n,e){if(/L$/.test(n))return P(n.slice(0,-1),e);let r=n.split("#");return r.length===2?P(r[0],e)&&/^[1-5]$/.test(r[1]):!1}function Yn(n,e){return a(n,"/")?Bn(n,e):a(n,"-")?ln(n,e):P(n,e)}function Bn(n,e){let r=n.split("/");return r.length!==2||!I(r[1])||+r[1]<1?!1:r[0]==="*"||P(r[0],e)||ln(r[0],e,!0)}function ln(n,e,r){let t=n.split("-");return t.length!==2||!P(t[0],e)||!P(t[1],e)?!1:e.cyclic&&!r?!0:f(t[0],e.numbers)<=f(t[1],e.numbers)}function P(n,e){return n==="*"?!1:I(n)?+n>=e.min&&+n<=e.max:e.numbers?n.toUpperCase()in e.numbers:!1}function sn(n,e){throw new Error('`cronli5` was passed an invalid field value "'+n+'" for the '+e+" field.")}var Gn={hour:24,minute:60,second:60};function mn(n){S.forEach(function(r){let t=h[r].aliases,i=t&&t[""+n[r]];i&&(n[r]=i)})}function fn(n){return S.forEach(function(r){let t=""+n[r];if(r==="date"&&w(t)||r==="weekday"&&R(t,h[r])){n[r]=t;return}n[r]=Kn(t,r,h[r])}),n}function Kn(n,e,r){let t=""+n;if(t==="*")return t;let i=Gn[e],o=t.split(",").map(function(s){return Zn(dn(ee(re(te(ne(_n(s,r),r),r),r),r,i),r),r)}).join(",").split(",");return o.indexOf("*")!==-1?"*":T(o).sort(function(s,m){return cn(s,r)-cn(m,r)}).join(",")}function Zn(n,e){if(!e.numbers)return n;let r=n.split("/"),t=r[0].split("-").map(function(o){return Xn(o,e)}).join("-");return r.length===2?t+"/"+r[1]:t}function Xn(n,e){if(n==="*")return n;let r=f(n,e.numbers);return""+(r>e.top?e.min:r)}function _n(n,e){let r=n.split("/");if(!e.cyclic||r.length!==2||+r[1]!=1)return n;let t=r[0];return a(t,"-")?t:t==="*"||f(t,e.numbers)===e.min?"*":t+"-"+e.top}function ne(n,e){let r=n.split("/");if(!e.cyclic||typeof e.top!="number"||r.length!==2||a(r[0],"-"))return n;let t=r[0];return(t==="*"?e.min:f(t,e.numbers))+ +r[1]<=e.top?n:t==="*"?""+e.min:t}function ee(n,e,r){let t=n.split("/");if(typeof r!="number"||t.length!==2||a(t[0],"-"))return n;let i=+t[1],o=t[0]==="*"?e.min:f(t[0]);if(r%i===0&&o<i)return n;let u=[];for(let s=o;s<=e.top;s+=i)u.push(s);return u.join(",")}function re(n,e){let r=n.split("/");return r.length!==2||!a(r[0],"-")?n:dn(r[0],e)==="*"?"*/"+r[1]:n}function dn(n,e){if(typeof e.top!="number"||a(n,"/")||!a(n,"-"))return n;let r=n.split("-"),t=f(r[0],e.numbers),i=f(r[1],e.numbers);if(t>i)return n;let o=e.top,u={};for(let s=t;s<=i;s+=1)u[s>o?e.min:s]=!0;for(let s=e.min;s<=o;s+=1)if(!u[s])return n;return"*"}function te(n,e){let r=n.split("/")[0];if(!a(r,"-"))return n;let t=r.split("-");return f(t[0],e.numbers)!==f(t[1],e.numbers)?n:t[0]}function cn(n,e){let r=n.split("/")[0].split("-")[0];return r==="*"?e.min:f(r,e.numbers)}function gn(n,e){let r=n instanceof Array;if(n===null||typeof n>"u"||n===""||r&&n.length===0)throw new Error("`cronli5` expects a non-empty cron pattern as the first argument.");if(r)return hn(n,e);if(typeof n=="object")return ie(n);if(typeof n=="string")return oe(n,e);throw new Error("`cronli5` was passed an unexpected type.")}function hn(n,e){if(n.length>7)throw new Error("`cronli5` was passed a cron pattern with more than seven fields.");return!e.seconds&&n.length<(e.years?7:6)&&n.unshift("0"),{second:n[0]||"0",minute:n[1]||"*",hour:n[2]||"*",date:n[3]||"*",month:n[4]||"*",weekday:n[5]||"*",year:n[6]||"*"}}function ie(n){if(!n.second&&!n.minute&&!n.hour)throw new Error("`cronli5` expects that any object being interpreted as a cron pattern have at least one of the following properties: `second`, `minute`, or `hour`");let e=typeof n.second<"u",r=typeof n.minute<"u",t=e?"*":"0",i=e||r?"*":"0";return{second:O(n.second,"0"),minute:O(n.minute,t),hour:O(n.hour,i),date:O(n.date,"*"),month:O(n.month,"*"),weekday:O(n.weekday,"*"),year:O(n.year,"*")}}function O(n,e){return typeof n>"u"?e:n}function oe(n,e){let r=ue(n).split(/\s+/);return hn(r,e)}function ue(n){let e=n.trim();if(e.charAt(0)!=="@")return n;let r=e.toLowerCase();if(Object.hasOwn(U,r))return U[r];throw new Error("`cronli5` does not recognize the macro `"+e+"`.")}function pn(n){return n!=="*"&&!a(n,",")&&!a(n,"-")&&!a(n,"/")}function q(n){return a(n,"-")&&!a(n,",")&&!a(n,"/")}function se(n){return a(n,"/")&&!a(n,",")}function V(n){return n!=="*"&&!a(n,"-")&&!a(n,"/")}function $(n){return n!=="*"&&!q(n)&&!se(n)}function C(n,e,r){let t=[],i=n;for(;i<=r;)t.push(i),i+=e;return t}function yn(n,e,r,t){let i=n.split("/"),o=+i[1];if(a(i[0],"-")){let s=i[0].split("-");return C(f(s[0],t),o,f(s[1],t))}let u=i[0]==="*"?e:f(i[0],t);return C(u,o,r)}function J(n,e,r){let t=[];return n.split(",").forEach(function(o){if(a(o,"/"))t.push(...yn(o,e,r));else if(a(o,"-")){let u=o.split("-");+u[0]<=+u[1]?t.push(...C(+u[0],1,+u[1])):(t.push(...C(+u[0],1,r)),t.push(...C(e,1,+u[1])))}else t.push(+o)}),T(t)}function ae(n){return V(n)?n.split(",").map(Number):[0]}function le(n){if(n==="*")return[0,59];if(q(n)){let e=n.split("-");if(+e[0]<=+e[1])return[+e[0],+e[1]]}return null}function ce(n){return n==="*"?59:Math.max(...J(n,0,59))}function me(n){if(pn(n)&&n!=="0")return+n}function fe(n,e){return n==="*"?"wildcard":e==="date"&&w(n)||e==="weekday"&&R(n,h.weekday)?"quartz":a(n,",")?"list":a(n,"/")?"step":a(n,"-")?"range":"single"}function de(n,e,r){return e==="wildcard"||e==="quartz"?null:n.split(",").map(function(i){if(a(i,"/")){let o=i.split("/");return{fires:yn(i,r.min,r.top,r.numbers),interval:+o[1],kind:"step",startToken:o[0]}}return a(i,"-")?{bounds:i.split("-"),kind:"range"}:{kind:"single",value:i}})}function bn(n){let e={},r={};S.forEach(function(u){e[u]=fe(n[u],u),r[u]=de(n[u],e[u],h[u])});let i={analyses:{clockSecond:me(n.second),lastMinuteFire:ce(n.minute),minuteSpan:le(n.minute),segments:r},pattern:n,shapes:e};return{...i,plan:ge(i)}}function ge(n){let{analyses:e,pattern:r,shapes:t}=n;if(r.second!=="0"){let i=he(r,t,e);if(i)return i}return Sn(r,t,e)||kn(r,t,e)}function he(n,e,r){let t=pe(n,e);return t||(n.hour==="*"&&e.minute==="single"&&n.second!=="*"?{kind:"secondsWithinMinute",singleSecond:e.second==="single"}:e.second==="single"&&V(n.minute)&&$(n.hour)?null:{kind:"composeSeconds",rest:Sn(n,e,r,!0)||kn(n,e,r,!0)})}function pe(n,e){return n.minute!=="*"||n.hour!=="*"?null:n.second==="*"?{kind:"everySecond"}:e.second==="single"?{kind:"secondPastMinute"}:{kind:"standaloneSeconds"}}function Sn(n,e,r,t=!1){if(e.minute==="step")return{hours:be(n,e,r),kind:"minuteFrequency"};if(e.hour==="single"&&r.minuteSpan)return{hour:+n.hour,kind:"minuteSpanInHour",span:r.minuteSpan};let i=Se(n,e);if(i)return i;let o=ye(n,e);if(o)return o;if(n.hour==="*")return Oe(n,e,t)}function On(n){let[e,r]=n.split("/"),t=e==="*"?0:+e;return e.indexOf("-")===-1&&24%+r===0&&t<+r}function ye(n,e){return e.hour!=="step"?null:n.minute==="*"?On(n.hour)?{form:"wildcard",kind:"minuteSpanAcrossHourStep"}:{form:"wildcard",kind:"minutesAcrossHours",times:x(n.hour)}:e.minute==="range"?{form:"range",kind:"minuteSpanAcrossHourStep"}:null}function be(n,e,r){if(e.hour==="list")return{kind:"during",times:x(n.hour)};if(e.hour==="range"){let t=n.hour.split("-");return{from:+t[0],kind:"window",last:r.lastMinuteFire,to:+t[1]}}return e.hour==="single"?{from:+n.hour,kind:"window",last:r.lastMinuteFire,to:+n.hour}:e.hour==="step"?On(n.hour)?{kind:"step"}:{kind:"during",times:x(n.hour)}:{kind:"none"}}function Se(n,e){return $(n.hour)?n.minute==="*"?{form:"wildcard",kind:"minutesAcrossHours",times:x(n.hour)}:e.minute==="range"||e.minute==="list"&&a(n.minute,"-")&&!a(n.minute,"/")?{form:e.minute==="range"?"range":"list",kind:"minutesAcrossHours",times:x(n.hour)}:null:null}function Oe(n,e,r){if(e.minute==="range")return{kind:"rangeOfMinutes"};if(e.minute==="list")return{kind:"multipleMinutes"};if(n.minute==="*")return{kind:"everyMinute"};if(n.minute!=="0"||r)return{kind:"singleMinute"}}function kn(n,e,r,t=!1){let i=t&&n.minute==="0";return e.hour==="range"&&!i?ke(n,e,r):e.hour==="step"&&n.minute==="0"&&!t?{kind:"hourStep"}:n.hour==="*"&&!i?{kind:"everyHour"}:Ne(n,r,i)}function ke(n,e,r){let t=n.hour.split("-"),i="lead";return n.minute==="*"?i="wildcard":e.minute==="range"&&(i="range"),{boundMinute:e.minute==="range"||e.minute==="list"?null:r.lastMinuteFire,from:+t[0],kind:"hourRange",last:r.lastMinuteFire,minuteForm:i,to:+t[1]}}function Ne(n,e,r=!1){let t=J(n.hour,0,23),i=ae(n.minute);if(!r&&t.length*i.length>Q)return{fold:i.length===1,kind:"compactClockTimes",minute:i[0]};let o=[];return t.forEach(function(s){i.forEach(function(A){o.push({hour:s,minute:A,second:e.clockSecond})})}),{kind:"clockTimes",times:o}}function x(n){let e=J(n,0,23);return e.length<=Q?{fires:e,kind:"fires"}:{kind:"segments"}}function Nn(n,e){let r=gn(n,e);return mn(r),an(r),fn(r)}function Y(n){return n=""+n,n.length<2?"0"+n:n}function zn(n,e,r){return r.short?n:e[n]||n}function B(n,{sep:e,pad:r,lean:t}){let i=r?Y(n.hour):""+n.hour;return t&&!n.minute&&!n.second?i:i+e+Y(n.minute)+(n.second?e+Y(n.second):"")}var G={gb:{am:"am",closeUp:!0,dayFirst:!0,midday:"midday",midnight:"midnight",ordinals:!1,pm:"pm",sep:".",serialComma:!1,through:" to "},us:{am:"a.m.",closeUp:!1,dayFirst:!1,midday:"noon",midnight:"midnight",ordinals:!1,pm:"p.m.",sep:":",serialComma:!0,through:" through "},house:{am:"AM",closeUp:!1,dayFirst:!1,midday:"noon",midnight:"midnight",ordinals:!0,pm:"PM",sep:":",serialComma:!0,through:" - "}};function Pn(n){return typeof n=="object"&&n!==null?{...G.us,...n}:G[n==="uk"?"gb":n]||G.us}var ze=["zero","one","two","three","four","five","six","seven","eight","nine","ten"],K=["th","st","nd","rd"],Pe=[null,["January","Jan"],["February","Feb"],["March","Mar"],["April","Apr"],["May","May"],["June","Jun"],["July","Jul"],["August","Aug"],["September","Sep"],["October","Oct"],["November","Nov"],["December","Dec"]],y=[["Sunday","Sun"],["Monday","Mon"],["Tuesday","Tue"],["Wednesday","Wed"],["Thursday","Thu"],["Friday","Fri"],["Saturday","Sat"]],ve={SUN:y[0],MON:y[1],TUE:y[2],WED:y[3],THU:y[4],FRI:y[5],SAT:y[6]},we=[null,"first","second","third","fourth","fifth"];function Re(n){return n=n||{},{ampm:typeof n.ampm=="boolean"?n.ampm:!0,lenient:!!n.lenient,seconds:!!n.seconds,short:!!n.short,style:Pn(n.dialect),years:!!n.years}}function Ce(n,e){return ur(wn(n,n.plan,e),n,e)}function wn(n,e,r){let t=Xe[e.kind];return t(n,e,r)}function xe(n,e,r){return"every second"+l(n,r)}function Fe(n,e,r){return v(n,r)+l(n,r)}function Me(n,e,r){let t=n.pattern.second;return d(t,r)+" "+z(t,"second")+" past the minute, every minute"+l(n,r)}function Te(n,e,r){let t=n.pattern.minute,i=d(t,r),o=z(t,"minute");if(e.singleSecond){let u=n.pattern.second;return i+" "+o+" and "+d(u,r)+" "+z(u,"second")+" past the hour, every hour"+l(n,r)}return v(n,r)+", "+i+" "+o+" past the hour, every hour"+l(n,r)}function Ie(n,e,r){return e.rest.kind==="clockTimes"&&(n.shapes.second==="wildcard"||n.shapes.second==="step")?+e.rest.times[0].minute==0?v(n,r)+" for one minute at "+He(n,e.rest,r):v(n,r)+" of "+Le(n,e.rest,r):n.shapes.second==="wildcard"&&e.rest.kind==="minuteFrequency"&&e.rest.hours.kind==="none"&&n.pattern.minute==="*/2"?"every second of every other minute"+l(n,r):v(n,r)+", "+wn(n,e.rest,r)}function He(n,e,r){let t=e.times.map(function(u){return c({hour:u.hour,minute:0},r)}),i=W(n,tn,r);return g(t,r)+(i&&", "+i)}function Le(n,e,r){let t=e.times.map(function(u){return c({hour:u.hour,minute:u.minute,second:u.second,explicit:!0},r)}),i=W(n,tn,r);return g(t,r)+(i&&", "+i)}function v(n,e){let r=n.pattern.second,t=n.shapes.second;if(r==="*")return"every second";if(t==="step")return Fn(n.analyses.segments.second[0],"second","minute",e);if(t==="range"){let i=r.split("-"),o=L(i,e);return"every second from "+o(i[0])+b(e)+o(i[1])+" past the minute"}return t==="single"?"at "+d(r,e)+" "+z(r,"second")+" past the minute":N(M(n.analyses.segments.second,e),"second","minute",e)}function We(n,e,r){return"every minute"+l(n,r)}function je(n,e,r){let t=n.pattern.minute;return d(t,r)+" "+z(t,"minute")+" past the hour, every hour"+l(n,r)}function Ee(n,e,r){return H(n.pattern.minute,r)+l(n,r)}function Ae(n,e,r){return N(M(n.analyses.segments.minute,r),"minute","hour",r)+l(n,r)}function De(n,e,r){let t=Fn(n.analyses.segments.minute[0],"minute","hour",r);return e.hours.kind==="during"?t+=" during the "+X(n,e.hours.times,!1,r)+" hours":e.hours.kind==="window"?t+=" "+xn(e.hours,r):e.hours.kind==="step"&&(t+=" "+Rn(n.analyses.segments.hour[0],r)),t+l(n,r)}function Ue(n,e,r){return n.pattern.minute==="*"?"every minute of the "+c({hour:e.hour,minute:0},r)+" hour"+l(n,r):"every minute from "+c({hour:e.hour,minute:e.span[0]},r)+b(r)+c({hour:e.hour,minute:e.span[1]},r)+l(n,r)}function Qe(n,e,r){if(e.form==="wildcard")return"every minute during the "+X(n,e.times,!1,r)+" hours"+l(n,r);let t=X(n,e.times,!0,r);return(e.form==="range"?H(n.pattern.minute,r):N(M(n.analyses.segments.minute,r),"minute","hour",r))+", at "+t+l(n,r)}var qe={2:"other",3:"third",4:"fourth",6:"sixth",8:"eighth",12:"twelfth"};function Rn(n,e){let r="during every "+qe[n.interval]+" hour",t=n.startToken==="*"?0:+n.startToken;return t===0?r:r+" starting at "+c({hour:t,minute:0},e)}function Ve(n,e,r){let t=n.analyses.segments.hour[0];return e.form==="wildcard"?"every minute "+Rn(t,r)+l(n,r):H(n.pattern.minute,r)+", "+Mn(t,r)+l(n,r)}function H(n,e){let r=n.split("-"),t=L(r,e);return"every minute from "+t(r[0])+b(e)+t(r[1])+" past the hour"}function $e(n,e,r){return"every hour"+l(n,r)}function Je(n,e,r){let t=xn(Be(e),r);return e.minuteForm==="wildcard"?"every minute "+t+l(n,r):e.minuteForm==="range"?H(n.pattern.minute,r)+", "+t+l(n,r):Cn(n,r)+" "+t+l(n,r)}function Cn(n,e){return n.pattern.minute==="0"?"every hour":N(M(n.analyses.segments.minute,e),"minute","hour",e)}function Ye(n,e,r){return Mn(n.analyses.segments.hour[0],r)+l(n,r)}function Be(n){return{from:n.from,last:n.boundMinute??0,to:n.to}}function xn(n,e){return"from "+c({hour:n.from,minute:0},e)+b(e)+c({hour:n.to,minute:n.last},e)}function Ge(n,e,r){let t=rn(e.times),i=e.times.map(function(u){return c({hour:u.hour,minute:u.minute,second:u.second,plain:t},r)});return Tn(n,r)+"at "+g(i,r)}function Ke(n,e,r){if(e.fold){if(n.analyses.segments.hour.some(function(s){return s.kind==="range"})&&!n.analyses.clockSecond)return Ze(n,e,r)+l(n,r);let o={minute:e.minute,second:n.analyses.clockSecond};return Tn(n,r)+"at "+_(n,o,!0,r)}let t=N(M(n.analyses.segments.minute,r),"minute","hour",r)+", at "+_(n,{minute:0,second:null},!0,r)+l(n,r);return n.analyses.clockSecond?v(n,r)+", "+t:t}function Ze(n,e,r){let t=e.minute,i=[],o=[];n.analyses.segments.hour.forEach(function(m){m.kind==="range"?i.push("from "+c({hour:m.bounds[0],minute:0},r)+b(r)+c({hour:m.bounds[1],minute:t},r)):m.kind==="step"?o.push(...m.fires):o.push(+m.value)});let u=Cn(n,r)+" "+g(i,r);return o.length&&(u+=" and at "+g(o.map(function(m){return c({hour:m,minute:t},r)}),r)),u}var Xe={clockTimes:Ge,compactClockTimes:Ke,composeSeconds:Ie,everyHour:$e,everyMinute:We,everySecond:xe,hourRange:Je,hourStep:Ye,minuteFrequency:De,minuteSpanAcrossHourStep:Ve,minuteSpanInHour:Ue,minutesAcrossHours:Qe,multipleMinutes:Ae,rangeOfMinutes:Ee,secondPastMinute:Me,secondsWithinMinute:Te,singleMinute:je,standaloneSeconds:Fe};function Fn(n,e,r,t){if(n.startToken.indexOf("-")!==-1)return N(vn(n.fires,t),e,r,t);let i=n.startToken==="*"?0:+n.startToken,o=n.interval;return i!==0?n.fires.length<=3?N(vn(n.fires,t),e,r,t):"every "+d(o,t)+" "+e+"s from "+d(i,t)+" "+z(i,e)+" past the "+r:"every "+d(o,t)+" "+e+"s"}function Mn(n,e){if(n.startToken.indexOf("-")!==-1)return"at "+Z(n.fires,e);let r=n.startToken==="*"?0:+n.startToken,t=n.interval;return r===0?"every "+d(t,e)+" hours":n.fires.length<=3?"at "+Z(n.fires,e):"every "+d(t,e)+" hours from "+c({hour:r,minute:0},e)}function L(n,e){let r=n.some(function(i){return+i>10});return function(i){return r?""+i:d(i,e)}}function vn(n,e){return n.map(L(n,e))}function M(n,e){let r=n.flatMap(function(o){return o.kind==="range"?o.bounds:o.kind==="step"?o.fires:[o.value]}),t=L(r,e);return n.flatMap(function(o){return o.kind==="range"?[t(o.bounds[0])+b(e)+t(o.bounds[1])]:o.kind==="step"?o.fires.map(t):[t(o.value)]})}function N(n,e,r,t){return"at "+g(n,t)+" "+e+"s past the "+r}function _e(n,e,r){return(+n==0||+n==12)&&+e==0&&!(typeof r=="number"&&r>0)}function rn(n){let e=n.filter(function(t){return _e(t.hour,t.minute,t.second)});return e.length>0&&e.length<n.length}function Z(n,e){let r=rn(n.map(function(o){return{hour:o,minute:0}})),t=n.map(function(o){return c({hour:o,minute:0,plain:r},e)});return g(t,e)}function X(n,e,r,t){return e.kind==="fires"?Z(e.fires,t):_(n,{minute:0,second:null},r,t)}function nr(n){return n.kind==="range"?n.bounds:n.kind==="step"?n.fires:[n.value]}function _(n,e,r,t){let{minute:i,second:o}=e,u=n.analyses.segments.hour,s=rn(u.flatMap(function(p){return nr(p).map(function(D){return{hour:+D,minute:i,second:o}})})),m=[];return u.forEach(function(p){p.kind==="step"?m.push(...p.fires.map(function(D){return c({hour:D,minute:i,second:o,plain:s},t)})):p.kind==="range"?m.push(c({hour:p.bounds[0],minute:i,second:o,plain:s},t)+b(t)+c({hour:p.bounds[1],minute:i,second:o,plain:s},t)):m.push(c({hour:p.value,minute:i,second:o,plain:s},t))}),g(er(m,u,r),t)}function er(n,e,r){let t=e.some(function(o){return o.kind==="range"});return!r||!t?n:n.map(function(o,u){return u===0?o:"at "+o})}function g(n,e){if(n.length<=1)return n.join("");if(n.length===2)return n[0]+" and "+n[1];let r=e.style.serialComma?", and ":" and ";return n.slice(0,-1).join(", ")+r+n[n.length-1]}var rr={all:"",month:"in ",stepDate:"on ",weekday:"on "},tn={all:"every day",month:"every day in ",stepDate:"",weekday:"every "};function l(n,e){let r=W(n,rr,e);return r&&" "+r}function Tn(n,e){return W(n,tn,e)+" "}function W(n,e,r){let t=n.pattern;return t.date!=="*"&&t.weekday!=="*"?ir(n,r):t.date!=="*"?tr(n,e,r):t.weekday!=="*"?(Ln(t.weekday,r)||e.weekday+An(n,r))+k(n,r):t.month!=="*"?e.month+j(n,r):e.all}function tr(n,e,r){let t=n.pattern,i=Hn(t.date,r);return i?i+k(n,r):on(t.date)?e.stepDate+jn(t.date)+k(n,r):t.month!=="*"&&!In(n)?"on the "+nn(n,r)+k(n,r):t.month!=="*"?"on "+Wn(n,r):"on the "+nn(n,r)}function In(n){return!En(n.pattern.month)&&n.analyses.segments.month.every(function(r){return r.kind!=="range"})}function ir(n,e){let r=n.pattern,t=Ln(r.weekday,e)||"on "+An(n,e),i=Hn(r.date,e);return i?i+k(n,e)+" or "+t:on(r.date)?jn(r.date)+k(n,e)+" or "+t:r.month!=="*"&&In(n)?"on "+Wn(n,e)+" or "+t+" in "+j(n,e):"on the "+nn(n,e)+" or "+t+k(n,e)}function Hn(n,e){if(n==="L")return"on the last day of the month";if(n==="LW"||n==="WL")return"on the last weekday of the month";let r=/^L-(\d{1,2})$/.exec(n);if(r)return d(+r[1],e)+" "+z(r[1],"day")+" before the last day of the month";let t=/^(\d{1,2})W$|^W(\d{1,2})$/.exec(n);if(t)return"on the weekday nearest the "+F(t[1]||t[2])}function Ln(n,e){let r=n.split("#");if(r.length===2)return"on the "+we[+r[1]]+" "+en(r[0],e)+" of the month";if(/L$/.test(n))return"on the last "+en(n.slice(0,-1),e)+" of the month"}function Wn(n,e){let r=j(n,e),t=E(n.analyses.segments.date,e.style.ordinals?F:or,e);return e.style.dayFirst?t+" "+r:r+" "+t}function or(n){return""+n}function k(n,e){return n.pattern.month==="*"?"":" in "+j(n,e)}function jn(n){let e=n.split("/"),r=+e[1],t=e[0],o=(r===2?"every other":"every "+F(r))+" day of the month";return t!=="*"&&t!=="1"&&(o+=" from the "+F(t)),o}function nn(n,e){return E(n.analyses.segments.date,F,e)}function j(n,e){let r=En(n.pattern.month);return r||E(n.analyses.segments.month,function(i){return cr(i,e)},e)}function En(n){if(!on(n))return null;let[e,r]=n.split("/");return+r!=2?null:e==="*"||e==="1"?"every odd-numbered month":e==="2"?"every even-numbered month":null}function An(n,e){return E(n.analyses.segments.weekday,function(t){return en(t,e)},e)}function E(n,e,r){let t=[];return n.forEach(function(o){o.kind==="step"?t.push(...o.fires.map(e)):o.kind==="range"?t.push(o.bounds.map(e).join(b(r))):t.push(e(o.value))}),g(t,r)}function on(n){return n.indexOf("/")!==-1&&n.indexOf("-")===-1&&n.indexOf(",")===-1}function ur(n,e,r){let t=e.pattern.year;if(t==="*")return n;if(t.indexOf("/")!==-1)return n+" "+ar(t,r);let i=sr(t,r);if(t.indexOf("-")===-1&&t.indexOf(",")===-1&&e.pattern.date!=="*"&&n.indexOf(" at ")!==-1){let o=r.style.dayFirst?" ":", ";return n.replace(" at ",o+i+" at ")}return n+" in "+i}function sr(n,e){return n.indexOf(",")!==-1?g(n.split(","),e):n}function ar(n,e){let r=n.split("/"),t=+r[1],i=r[0];if(t<=1)return"every year";let o="every "+d(t,e)+" years";return i!=="*"&&i!=="0"&&(o+=" from "+i),o}function c(n,e){let{hour:r,minute:t,plain:i,explicit:o}=n,u=typeof n.second=="number"&&n.second>0?n.second:0;return e.ampm?lr({hour:r,minute:t,second:u,plain:i,explicit:o},e):B({hour:r,minute:t,second:u},{pad:!0,sep:e.style.sep})}function lr(n,e){let{hour:r,minute:t,second:i,plain:o,explicit:u}=n,s=e.style;if(!o&&!u&&+t==0&&!i){if(+r==0)return s.midnight;if(+r==12)return s.midday}return B({hour:r%12||12,minute:t,second:i},{lean:!u,sep:s.sep})+(s.closeUp?"":" ")+(r<12?s.am:s.pm)}function d(n,e){return zn(n,ze,e)}function z(n,e){return+n==1?e:e+"s"}function b(n){return n.short?"-":n.style.through}function F(n){let e=Math.abs(n),r=K[e];return r||(e=(e%100-20)%10,r=K[e]||K[0]),n+r}function cr(n,e){let r=Pe[+n];return r&&r[e.short?1:0]}function en(n,e){let r=n===7||n==="7"?0:n,t=y[r]||ve[r];return t&&t[e.short?1:0]}var mr={describe:Ce,fallback:"an unrecognizable cron pattern",options:Re,reboot:"at system startup",sentence:n=>"Runs "+n+(n.endsWith(".")?"":".")},Dn=mr;/**
|
|
1
|
+
"use strict";(()=>{var Xn={SUN:0,MON:1,TUE:2,WED:3,THU:4,FRI:5,SAT:6},_n={JAN:1,FEB:2,MAR:3,APR:4,MAY:5,JUN:6,JUL:7,AUG:8,SEP:9,OCT:10,NOV:11,DEC:12},y={second:{cyclic:!0,max:59,min:0,top:59},minute:{cyclic:!0,max:59,min:0,top:59},hour:{cyclic:!0,max:23,min:0,top:23},date:{aliases:{"?":"*"},cyclic:!0,max:31,min:1,top:31},month:{cyclic:!0,max:12,min:1,numbers:_n,top:12},weekday:{aliases:{"?":"*",L:"6"},cyclic:!0,max:7,min:0,numbers:Xn,top:6},year:{max:9999,min:1970}},k=["second","minute","hour","date","month","weekday","year"],V={"@annually":"0 0 1 1 *","@yearly":"0 0 1 1 *","@monthly":"0 0 1 * *","@weekly":"0 0 * * 0","@daily":"0 0 * * *","@midnight":"0 0 * * *","@hourly":"0 * * * *"},x=6;function a(n,e){return(""+n).indexOf(e)!==-1}function j(n){return Array.from(new Set(n))}function E(n){return/^\d+$/.test(n)}function $(n){if(n.length<5)return null;let e=n[1]-n[0];if(e<2)return null;for(let t=2;t<n.length;t+=1)if(n[t]-n[t-1]!==e)return null;return{start:n[0],interval:e,last:n[n.length-1]}}function f(n,e){return E(n)?+n:e[n.toUpperCase()]}function gn(n){return k.forEach(function(t){ne(n[t],y[t],t)}),n}function ne(n,e,t){typeof n!="string"&&typeof n!="number"&&dn(n,t);let r=""+n;r!=="*"&&(t==="date"&&T(r)||t==="weekday"&&F(r,e)||r.split(",").forEach(function(o){ee(o,e)||dn(o,t)}))}function T(n){if(n==="L"||n==="LW"||n==="WL")return!0;let e=/^L-(\d{1,2})$/.exec(n);if(e)return+e[1]>=1&&+e[1]<=30;let t=/^(\d{1,2})W$|^W(\d{1,2})$/.exec(n);if(t){let r=+(t[1]||t[2]);return r>=1&&r<=31}return!1}function F(n,e){if(/L$/.test(n))return v(n.slice(0,-1),e);let t=n.split("#");return t.length===2?v(t[0],e)&&/^[1-5]$/.test(t[1]):!1}function ee(n,e){return a(n,"/")?te(n,e):a(n,"-")?hn(n,e):v(n,e)}function te(n,e){let t=n.split("/");return t.length!==2||!E(t[1])||+t[1]<1?!1:t[0]==="*"||v(t[0],e)||hn(t[0],e,!0)}function hn(n,e,t){let r=n.split("-");return r.length!==2||!v(r[0],e)||!v(r[1],e)?!1:e.cyclic&&!t?!0:f(r[0],e.numbers)<=f(r[1],e.numbers)}function v(n,e){return n==="*"?!1:E(n)?+n>=e.min&&+n<=e.max:e.numbers?n.toUpperCase()in e.numbers:!1}function dn(n,e){throw new Error('`cronli5` was passed an invalid field value "'+n+'" for the '+e+" field.")}var re={hour:24,minute:60,second:60};function yn(n){k.forEach(function(t){let r=y[t].aliases,i=r&&r[""+n[t]];i&&(n[t]=i)})}function bn(n){return k.forEach(function(t){let r=""+n[t];if(t==="date"&&T(r)||t==="weekday"&&F(r,y[t])){n[t]=r;return}n[t]=ie(r,t,y[t])}),n}function ie(n,e,t){let r=""+n;if(r==="*")return r;let i=re[e],o=r.split(",").map(function(s){return oe(Sn(le(ce(me(ae(se(s,t),t),t),t),t,i),t),t)}).join(",").split(",");return o.indexOf("*")!==-1?"*":j(o).sort(function(s,c){return pn(s,t)-pn(c,t)}).join(",")}function oe(n,e){if(!e.numbers)return n;let t=n.split("/"),r=t[0].split("-").map(function(o){return ue(o,e)}).join("-");return t.length===2?r+"/"+t[1]:r}function ue(n,e){if(n==="*")return n;let t=f(n,e.numbers);return""+(t>e.top?e.min:t)}function se(n,e){let t=n.split("/");if(!e.cyclic||t.length!==2||+t[1]!=1)return n;let r=t[0];return a(r,"-")?r:r==="*"||f(r,e.numbers)===e.min?"*":r+"-"+e.top}function ae(n,e){let t=n.split("/");if(!e.cyclic||typeof e.top!="number"||t.length!==2||a(t[0],"-"))return n;let r=t[0];return(r==="*"?e.min:f(r,e.numbers))+ +t[1]<=e.top?n:r==="*"?""+e.min:r}function le(n,e,t){let r=n.split("/");if(typeof t!="number"||r.length!==2||a(r[0],"-"))return n;let i=+r[1],o=r[0]==="*"?e.min:f(r[0]);if(t%i===0&&o<i)return n;let u=[];for(let s=o;s<=e.top;s+=i)u.push(s);return u.join(",")}function ce(n,e){let t=n.split("/");return t.length!==2||!a(t[0],"-")?n:Sn(t[0],e)==="*"?"*/"+t[1]:n}function Sn(n,e){if(typeof e.top!="number"||a(n,"/")||!a(n,"-"))return n;let t=n.split("-"),r=f(t[0],e.numbers),i=f(t[1],e.numbers);if(r>i)return n;let o=e.top,u={};for(let s=r;s<=i;s+=1)u[s>o?e.min:s]=!0;for(let s=e.min;s<=o;s+=1)if(!u[s])return n;return"*"}function me(n,e){let t=n.split("/")[0];if(!a(t,"-"))return n;let r=t.split("-");return f(r[0],e.numbers)!==f(r[1],e.numbers)?n:r[0]}function pn(n,e){let t=n.split("/")[0].split("-")[0];return t==="*"?e.min:f(t,e.numbers)}function On(n,e){let t=n instanceof Array;if(n===null||typeof n>"u"||n===""||t&&n.length===0)throw new Error("`cronli5` expects a non-empty cron pattern as the first argument.");if(t)return kn(n,e);if(typeof n=="object")return fe(n);if(typeof n=="string")return de(n,e);throw new Error("`cronli5` was passed an unexpected type.")}function kn(n,e){if(n.length>7)throw new Error("`cronli5` was passed a cron pattern with more than seven fields.");return!e.seconds&&n.length<(e.years?7:6)&&n.unshift("0"),{second:n[0]||"0",minute:n[1]||"*",hour:n[2]||"*",date:n[3]||"*",month:n[4]||"*",weekday:n[5]||"*",year:n[6]||"*"}}function fe(n){if(!n.second&&!n.minute&&!n.hour)throw new Error("`cronli5` expects that any object being interpreted as a cron pattern have at least one of the following properties: `second`, `minute`, or `hour`");let e=typeof n.second<"u",t=typeof n.minute<"u",r=e?"*":"0",i=e||t?"*":"0";return{second:N(n.second,"0"),minute:N(n.minute,r),hour:N(n.hour,i),date:N(n.date,"*"),month:N(n.month,"*"),weekday:N(n.weekday,"*"),year:N(n.year,"*")}}function N(n,e){return typeof n>"u"?e:n}function de(n,e){let t=ge(n).split(/\s+/);return kn(t,e)}function ge(n){let e=n.trim();if(e.charAt(0)!=="@")return n;let t=e.toLowerCase();if(Object.hasOwn(V,t))return V[t];throw new Error("`cronli5` does not recognize the macro `"+e+"`.")}function Nn(n){return n!=="*"&&!a(n,",")&&!a(n,"-")&&!a(n,"/")}function J(n){return a(n,"-")&&!a(n,",")&&!a(n,"/")}function he(n){return a(n,"/")&&!a(n,",")}function Y(n){return n!=="*"&&!a(n,"-")&&!a(n,"/")}function B(n){return n!=="*"&&!J(n)&&!he(n)}function M(n,e,t){let r=[],i=n;for(;i<=t;)r.push(i),i+=e;return r}function zn(n,e,t,r){let i=n.split("/"),o=+i[1];if(a(i[0],"-")){let s=i[0].split("-");return M(f(s[0],r),o,f(s[1],r))}let u=i[0]==="*"?e:f(i[0],r);return M(u,o,t)}function K(n,e,t){let r=[];return n.split(",").forEach(function(o){if(a(o,"/"))r.push(...zn(o,e,t));else if(a(o,"-")){let u=o.split("-");+u[0]<=+u[1]?r.push(...M(+u[0],1,+u[1])):(r.push(...M(+u[0],1,t)),r.push(...M(e,1,+u[1])))}else r.push(+o)}),j(r)}function pe(n){return Y(n)?n.split(",").map(Number):[0]}function ye(n){if(n==="*")return[0,59];if(J(n)){let e=n.split("-");if(+e[0]<=+e[1])return[+e[0],+e[1]]}return null}function be(n){return n==="*"?59:Math.max(...K(n,0,59))}function Se(n){if(Nn(n)&&n!=="0")return+n}function Oe(n,e){return n==="*"?"wildcard":e==="date"&&T(n)||e==="weekday"&&F(n,y.weekday)?"quartz":a(n,",")?"list":a(n,"/")?"step":a(n,"-")?"range":"single"}function ke(n,e,t){return e==="wildcard"||e==="quartz"?null:n.split(",").map(function(i){if(a(i,"/")){let o=i.split("/");return{fires:zn(i,t.min,t.top,t.numbers),interval:+o[1],kind:"step",startToken:o[0]}}return a(i,"-")?{bounds:i.split("-"),kind:"range"}:{kind:"single",value:i}})}function Pn(n){let e={},t={};k.forEach(function(u){e[u]=Oe(n[u],u),t[u]=ke(n[u],e[u],y[u])});let i={analyses:{clockSecond:Se(n.second),lastMinuteFire:be(n.minute),minuteSpan:ye(n.minute),segments:t},pattern:n,shapes:e};return{...i,plan:Ne(i)}}function Ne(n){let{analyses:e,pattern:t,shapes:r}=n;if(t.second!=="0"){let i=ze(t,r,e);if(i)return i}return vn(t,r,e)||Rn(t,r,e)}function ze(n,e,t){let r=Pe(n,e);return r||(n.hour==="*"&&e.minute==="single"&&n.second!=="*"?{kind:"secondsWithinMinute",singleSecond:e.second==="single"}:e.second==="single"&&Y(n.minute)&&B(n.hour)?null:{kind:"composeSeconds",rest:vn(n,e,t,!0)||Rn(n,e,t,!0)})}function Pe(n,e){return n.minute!=="*"||n.hour!=="*"?null:n.second==="*"?{kind:"everySecond"}:e.second==="single"?{kind:"secondPastMinute"}:{kind:"standaloneSeconds"}}function vn(n,e,t,r=!1){if(e.minute==="step")return{hours:Re(n,e,t),kind:"minuteFrequency"};if(e.hour==="single"&&t.minuteSpan)return{hour:+n.hour,kind:"minuteSpanInHour",span:t.minuteSpan};let i=Ce(n,e);if(i)return i;let o=ve(n,e);if(o)return o;if(n.hour==="*")return we(n,e,r)}function G(n){let[e,t]=n.split("/"),r=e==="*"?0:+e;return e.indexOf("-")===-1&&24%+t===0&&r<+t}function ve(n,e){return e.hour!=="step"?null:n.minute==="*"?G(n.hour)?{form:"wildcard",kind:"minuteSpanAcrossHourStep"}:{form:"wildcard",kind:"minutesAcrossHours",times:I(n.hour)}:e.minute==="range"?{form:"range",kind:"minuteSpanAcrossHourStep"}:e.minute==="list"&&G(n.hour)?{form:"list",kind:"minuteSpanAcrossHourStep"}:null}function Re(n,e,t){if(e.hour==="list")return{kind:"during",times:I(n.hour)};if(e.hour==="range"){let r=n.hour.split("-");return{from:+r[0],kind:"window",last:t.lastMinuteFire,to:+r[1]}}return e.hour==="single"?{from:+n.hour,kind:"window",last:t.lastMinuteFire,to:+n.hour}:e.hour==="step"?G(n.hour)?{kind:"step"}:{kind:"during",times:I(n.hour)}:{kind:"none"}}function Ce(n,e){return B(n.hour)?n.minute==="*"?{form:"wildcard",kind:"minutesAcrossHours",times:I(n.hour)}:e.minute==="range"||e.minute==="list"&&a(n.minute,"-")&&!a(n.minute,"/")?{form:e.minute==="range"?"range":"list",kind:"minutesAcrossHours",times:I(n.hour)}:null:null}function we(n,e,t){if(e.minute==="range")return{kind:"rangeOfMinutes"};if(e.minute==="list")return{kind:"multipleMinutes"};if(n.minute==="*")return{kind:"everyMinute"};if(n.minute!=="0"||t)return{kind:"singleMinute"}}function Rn(n,e,t,r=!1){let i=r&&n.minute==="0";return e.hour==="range"&&!i?xe(n,e,t):e.hour==="step"&&n.minute==="0"&&!r?{kind:"hourStep"}:n.hour==="*"&&!i?{kind:"everyHour"}:Te(n,t,i)}function xe(n,e,t){let r=n.hour.split("-"),i="lead";return n.minute==="*"?i="wildcard":e.minute==="range"&&(i="range"),{boundMinute:e.minute==="range"||e.minute==="list"?null:t.lastMinuteFire,from:+r[0],kind:"hourRange",last:t.lastMinuteFire,minuteForm:i,to:+r[1]}}function Te(n,e,t=!1){let r=K(n.hour,0,23),i=pe(n.minute);if(!t&&r.length*i.length>x)return{fold:i.length===1,kind:"compactClockTimes",minute:i[0]};let o=[];return r.forEach(function(s){i.forEach(function(P){o.push({hour:s,minute:P,second:e.clockSecond})})}),{kind:"clockTimes",times:o}}function I(n){let e=K(n,0,23);return e.length<=x?{fires:e,kind:"fires"}:{kind:"segments"}}function Cn(n,e){let t=On(n,e);return yn(t),gn(t),bn(t)}function Z(n){return n=""+n,n.length<2?"0"+n:n}function wn(n,e,t){return t.short?n:e[n]||n}function X(n,{sep:e,pad:t,lean:r}){let i=t?Z(n.hour):""+n.hour;return r&&!n.minute&&!n.second?i:i+e+Z(n.minute)+(n.second?e+Z(n.second):"")}var _={gb:{am:"am",closeUp:!0,dayFirst:!0,midday:"midday",midnight:"midnight",ordinals:!1,pm:"pm",sep:".",serialComma:!1,through:" to "},us:{am:"a.m.",closeUp:!1,dayFirst:!1,midday:"noon",midnight:"midnight",ordinals:!1,pm:"p.m.",sep:":",serialComma:!0,through:" through "},house:{am:"AM",closeUp:!1,dayFirst:!1,midday:"noon",midnight:"midnight",ordinals:!0,pm:"PM",sep:":",serialComma:!0,through:" - "}};function xn(n){return typeof n=="object"&&n!==null?{..._.us,...n}:_[n==="uk"?"gb":n]||_.us}var Fe=["zero","one","two","three","four","five","six","seven","eight","nine","ten"],nn=["th","st","nd","rd"],Me=[null,["January","Jan"],["February","Feb"],["March","Mar"],["April","Apr"],["May","May"],["June","Jun"],["July","Jul"],["August","Aug"],["September","Sep"],["October","Oct"],["November","Nov"],["December","Dec"]],S=[["Sunday","Sun"],["Monday","Mon"],["Tuesday","Tue"],["Wednesday","Wed"],["Thursday","Thu"],["Friday","Fri"],["Saturday","Sat"]],Ie={SUN:S[0],MON:S[1],TUE:S[2],WED:S[3],THU:S[4],FRI:S[5],SAT:S[6]},He=[null,"first","second","third","fourth","fifth"];function Le(n){return n=n||{},{ampm:typeof n.ampm=="boolean"?n.ampm:!0,lenient:!!n.lenient,seconds:!!n.seconds,short:!!n.short,style:xn(n.dialect),years:!!n.years}}function We(n,e){return bt(Fn(n,n.plan,e),n,e)}function Fn(n,e,t){let r=ut[e.kind];return r(n,e,t)}function je(n,e,t){return"every second"+l(n,t)}function Ee(n,e,t){return R(n,t)+l(n,t)}function Ae(n,e,t){let r=n.pattern.second;return d(r,t)+" "+b(r,"second")+" past the minute, every minute"+l(n,t)}function De(n,e,t){let r=n.pattern.minute,i=d(r,t),o=b(r,"minute");if(e.singleSecond){let u=n.pattern.second;return i+" "+o+" and "+d(u,t)+" "+b(u,"second")+" past the hour, every hour"+l(n,t)}return R(n,t)+", "+i+" "+o+" past the hour, every hour"+l(n,t)}function Ue(n,e,t){return(e.rest.kind==="clockTimes"||e.rest.kind==="compactClockTimes")&&n.shapes.minute==="single"?an(n,+n.pattern.minute,t):null}function Qe(n,e,t){let r=Ue(n,e,t);return r!==null?r:e.rest.kind==="clockTimes"&&(n.shapes.second==="wildcard"||n.shapes.second==="step")?+e.rest.times[0].minute==0?R(n,t)+" for one minute at "+qe(n,e.rest,t):R(n,t)+" of "+Ve(n,e.rest,t):n.shapes.second==="wildcard"&&e.rest.kind==="minuteFrequency"&&e.rest.hours.kind==="none"&&n.pattern.minute==="*/2"?"every second of every other minute"+l(n,t):R(n,t)+", "+Fn(n,e.rest,t)}function qe(n,e,t){let r=e.times.map(function(u){return m({hour:u.hour,minute:0},t)}),i=D(n,cn,t);return h(r,t)+(i&&", "+i)}function Ve(n,e,t){let r=e.times.map(function(u){return m({hour:u.hour,minute:u.minute,second:u.second,explicit:!0},t)}),i=D(n,cn,t);return h(r,t)+(i&&", "+i)}function R(n,e){return H(n,"minute",e)}function H(n,e,t){let r=n.pattern.second,i=n.shapes.second;if(r==="*")return"every second";if(i==="step")return jn(n.analyses.segments.second[0],"second",e,t);if(i==="range"){let o=r.split("-"),u=W(o,t);return"every second from "+u(o[0])+p(t)+u(o[1])+" past the "+e}return i==="single"?"at "+d(r,t)+" "+b(r,"second")+" past the "+e:C(n.analyses.segments.second,"second",e,t)??O(w(n.analyses.segments.second,t),"second",e,t)}function $e(n,e,t){return"every minute"+l(n,t)}function Je(n,e,t){let r=n.pattern.minute;return d(r,t)+" "+b(r,"minute")+" past the hour, every hour"+l(n,t)}function Ye(n,e,t){return A(n.pattern.minute,t)+l(n,t)}function Be(n,e,t){return(C(n.analyses.segments.minute,"minute","hour",t)??O(w(n.analyses.segments.minute,t),"minute","hour",t))+l(n,t)}function Ge(n,e,t){let r=jn(n.analyses.segments.minute[0],"minute","hour",t);return e.hours.kind==="during"?r+=" during the "+tn(n,e.hours.times,!1,t)+" hours":e.hours.kind==="window"?r+=" "+Hn(e.hours,t):e.hours.kind==="step"&&(r+=" "+sn(n.analyses.segments.hour[0],t)),r+l(n,t)}function Ke(n,e,t){return n.pattern.minute==="*"?"every minute of the "+m({hour:e.hour,minute:0},t)+" hour"+l(n,t):"every minute from "+m({hour:e.hour,minute:e.span[0]},t)+p(t)+m({hour:e.hour,minute:e.span[1]},t)+l(n,t)}function Ze(n,e,t){if(e.form==="wildcard")return"every minute during the "+tn(n,e.times,!1,t)+" hours"+l(n,t);let r=tn(n,e.times,!0,t);return(e.form==="range"?A(n.pattern.minute,t):C(n.analyses.segments.minute,"minute","hour",t)??O(w(n.analyses.segments.minute,t),"minute","hour",t))+", at "+r+l(n,t)}var Mn={2:"other",3:"third",4:"fourth",6:"sixth",8:"eighth",12:"twelfth"};function sn(n,e){let t="during every "+Mn[n.interval]+" hour",r=n.startToken==="*"?0:+n.startToken;return r===0?t:t+" starting at "+m({hour:r,minute:0},e)}function Xe(n,e,t){let r=n.analyses.segments.hour[0];return e.form==="wildcard"?"every minute "+sn(r,t)+l(n,t):(e.form==="list"?C(n.analyses.segments.minute,"minute","hour",t)??O(w(n.analyses.segments.minute,t),"minute","hour",t):A(n.pattern.minute,t))+", "+En(r,t)+l(n,t)}function A(n,e){let t=n.split("-"),r=W(t,e);return"every minute from "+r(t[0])+p(e)+r(t[1])+" past the hour"}function _e(n,e,t){return"every hour"+l(n,t)}function nt(n,e,t){let r=Hn(tt(e),t);return e.minuteForm==="wildcard"?"every minute "+r+l(n,t):e.minuteForm==="range"?A(n.pattern.minute,t)+", "+r+l(n,t):In(n,t)+" "+r+l(n,t)}function In(n,e){return n.pattern.minute==="0"?"every hour":C(n.analyses.segments.minute,"minute","hour",e)??O(w(n.analyses.segments.minute,e),"minute","hour",e)}function et(n,e,t){return En(n.analyses.segments.hour[0],t)+l(n,t)}function tt(n){return{from:n.from,last:n.boundMinute??0,to:n.to}}function Hn(n,e){return"from "+m({hour:n.from,minute:0},e)+p(e)+m({hour:n.to,minute:n.last},e)}function rt(n,e,t){if(n.shapes.minute==="single"){let o=an(n,+n.pattern.minute,t);if(o!==null)return o}let r=ln(e.times),i=e.times.map(function(u){return m({hour:u.hour,minute:u.minute,second:u.second,plain:r},t)});return Dn(n,t)+"at "+h(i,t)}function it(n,e,t){if(e.fold){let i=an(n,+e.minute,t);if(i!==null)return i;if(n.analyses.segments.hour.some(function(c){return c.kind==="range"})&&!n.analyses.clockSecond)return ot(n,e,t)+l(n,t);let u={minute:e.minute,second:n.analyses.clockSecond};return Dn(n,t)+"at "+rn(n,u,!0,t)}let r=(C(n.analyses.segments.minute,"minute","hour",t)??O(w(n.analyses.segments.minute,t),"minute","hour",t))+", at "+rn(n,{minute:0,second:null},!0,t)+l(n,t);return n.analyses.clockSecond?R(n,t)+", "+r:r}function ot(n,e,t){let r=e.minute,i=[],o=[];n.analyses.segments.hour.forEach(function(c){c.kind==="range"?i.push("from "+m({hour:c.bounds[0],minute:0},t)+p(t)+m({hour:c.bounds[1],minute:r},t)):c.kind==="step"?o.push(...c.fires):o.push(+c.value)});let u=In(n,t)+" "+h(i,t);return o.length&&(u+=" and at "+h(o.map(function(c){return m({hour:c,minute:r},t)}),t)),u}var ut={clockTimes:rt,compactClockTimes:it,composeSeconds:Qe,everyHour:_e,everyMinute:$e,everySecond:je,hourRange:nt,hourStep:et,minuteFrequency:Ge,minuteSpanAcrossHourStep:Xe,minuteSpanInHour:Ke,minutesAcrossHours:Ze,multipleMinutes:Be,rangeOfMinutes:Ye,secondPastMinute:Ae,secondsWithinMinute:De,singleMinute:Je,standaloneSeconds:Ee};function Ln(n,e){let{interval:t,start:r,last:i,cycle:o,unit:u,anchor:s}=n,c="every "+d(t,e)+" "+u+"s",P=o%t===0;if(r===0&&P)return c;if(r<t&&P)return c+" from "+d(r,e)+" "+b(r,u)+" past the "+s;let g=W([r,i],e);return c+" from "+g(r)+p(e)+g(i)+" "+b(i,u)+" past the "+s}function Wn(n){let e=[];for(let t of n){if(t.kind!=="single")return null;e.push(+t.value)}return e}function C(n,e,t,r){let i=Wn(n),o=i&&$(i);return o?Ln({...o,cycle:60,unit:e,anchor:t},r):null}function jn(n,e,t,r){if(n.startToken.indexOf("-")!==-1)return O(Tn(n.fires,r),e,t,r);let i=n.startToken==="*"?0:+n.startToken;return i!==0&&n.fires.length<=3?O(Tn(n.fires,r),e,t,r):Ln({interval:n.interval,start:i,last:n.fires[n.fires.length-1],cycle:60,unit:e,anchor:t},r)}function En(n,e){if(n.startToken.indexOf("-")!==-1)return"at "+en(n.fires,e);let t=n.startToken==="*"?0:+n.startToken,r=n.interval;return t===0?"every "+d(r,e)+" hours":n.fires.length<=3?"at "+en(n.fires,e):"every "+d(r,e)+" hours from "+m({hour:t,minute:0},e)}function st(n,e){let{start:t,interval:r,last:i}=n,o="every "+d(r,e)+" hours",u=24%r===0;return t===0&&u?o:t<r&&u?o+" from "+m({hour:t,minute:0},e):o+" from "+m({hour:t,minute:0},e)+p(e)+m({hour:i,minute:0},e)}function at(n){let e=n.analyses.segments.hour;if(e.length===1&&e[0].kind==="step"){let i=e[0],o=i.startToken==="*"?0:+i.startToken.split("-")[0];return{interval:i.interval,last:i.fires[i.fires.length-1],start:o}}let t=Wn(e);return t&&$(t)||null}function An(n){return n.pattern.second==="*"||n.shapes.second==="step"}function lt(n,e,t){if(e===0)return An(n)?H(n,"minute",t)+" for one minute":H(n,"hour",t);let r=d(e,t)+" "+b(e,"minute")+" past the hour";return n.pattern.second==="0"?r:H(n,"minute",t)+", "+r}function an(n,e,t){let r=at(n);if(!r)return null;let i=(r.last-r.start)/r.interval+1;if(n.pattern.second==="0"&&i<=x)return null;let o=e===0&&An(n)&&ct(n);return o?H(n,"minute",t)+" for one minute "+sn(o,t)+l(n,t):lt(n,e,t)+", "+st(r,t)+l(n,t)}function ct(n){let e=n.analyses.segments.hour,t=e.length===1&&e[0];return!t||t.kind!=="step"||t.startToken.indexOf("-")!==-1||!(t.interval in Mn)?null:t}function W(n,e){let t=n.some(function(i){return+i>10});return function(i){return t?""+i:d(i,e)}}function Tn(n,e){return n.map(W(n,e))}function w(n,e){let t=n.flatMap(function(o){return o.kind==="range"?o.bounds:o.kind==="step"?o.fires:[o.value]}),r=W(t,e);return n.flatMap(function(o){return o.kind==="range"?[r(o.bounds[0])+p(e)+r(o.bounds[1])]:o.kind==="step"?o.fires.map(r):[r(o.value)]})}function O(n,e,t,r){return"at "+h(n,r)+" "+e+"s past the "+t}function mt(n,e,t){return(+n==0||+n==12)&&+e==0&&!(typeof t=="number"&&t>0)}function ln(n){let e=n.filter(function(r){return mt(r.hour,r.minute,r.second)});return e.length>0&&e.length<n.length}function en(n,e){let t=ln(n.map(function(o){return{hour:o,minute:0}})),r=n.map(function(o){return m({hour:o,minute:0,plain:t},e)});return h(r,e)}function tn(n,e,t,r){return e.kind==="fires"?en(e.fires,r):rn(n,{minute:0,second:null},t,r)}function ft(n){return n.kind==="range"?n.bounds:n.kind==="step"?n.fires:[n.value]}function rn(n,e,t,r){let{minute:i,second:o}=e,u=n.analyses.segments.hour,s=ln(u.flatMap(function(g){return ft(g).map(function(q){return{hour:+q,minute:i,second:o}})})),c=[];return u.forEach(function(g){g.kind==="step"?c.push(...g.fires.map(function(q){return m({hour:q,minute:i,second:o,plain:s},r)})):g.kind==="range"?c.push(m({hour:g.bounds[0],minute:i,second:o,plain:s},r)+p(r)+m({hour:g.bounds[1],minute:i,second:o,plain:s},r)):c.push(m({hour:g.value,minute:i,second:o,plain:s},r))}),h(dt(c,u,t),r)}function dt(n,e,t){let r=e.some(function(o){return o.kind==="range"});return!t||!r?n:n.map(function(o,u){return u===0?o:"at "+o})}function h(n,e){if(n.length<=1)return n.join("");if(n.length===2)return n[0]+" and "+n[1];let t=e.style.serialComma?", and ":" and ";return n.slice(0,-1).join(", ")+t+n[n.length-1]}var gt={all:"",month:"in ",stepDate:"on ",weekday:"on "},cn={all:"every day",month:"every day in ",stepDate:"",weekday:"every "};function l(n,e){let t=D(n,gt,e);return t&&" "+t}function Dn(n,e){return D(n,cn,e)+" "}function D(n,e,t){let r=n.pattern;return r.date!=="*"&&r.weekday!=="*"?pt(n,t):r.date!=="*"?ht(n,e,t):r.weekday!=="*"?(qn(r.weekday,t)||e.weekday+Yn(n,t))+z(n,t):r.month!=="*"?e.month+U(n,t):e.all}function ht(n,e,t){let r=n.pattern,i=Qn(r.date,t);return i?i+z(n,t):mn(r.date)?e.stepDate+$n(r.date)+z(n,t):r.month!=="*"&&!Un(n)?"on the "+on(n,t)+z(n,t):r.month!=="*"?"on "+Vn(n,t):"on the "+on(n,t)}function Un(n){return!Jn(n.pattern.month)&&n.analyses.segments.month.every(function(t){return t.kind!=="range"})}function pt(n,e){let t=n.pattern,r=qn(t.weekday,e)||"on "+Yn(n,e),i=Qn(t.date,e);return i?i+z(n,e)+" or "+r:mn(t.date)?$n(t.date)+z(n,e)+" or "+r:t.month!=="*"&&Un(n)?"on "+Vn(n,e)+" or "+r+" in "+U(n,e):"on the "+on(n,e)+" or "+r+z(n,e)}function Qn(n,e){if(n==="L")return"on the last day of the month";if(n==="LW"||n==="WL")return"on the last weekday of the month";let t=/^L-(\d{1,2})$/.exec(n);if(t)return d(+t[1],e)+" "+b(t[1],"day")+" before the last day of the month";let r=/^(\d{1,2})W$|^W(\d{1,2})$/.exec(n);if(r)return"on the weekday nearest the "+L(r[1]||r[2])}function qn(n,e){let t=n.split("#");if(t.length===2)return"on the "+He[+t[1]]+" "+un(t[0],e)+" of the month";if(/L$/.test(n))return"on the last "+un(n.slice(0,-1),e)+" of the month"}function Vn(n,e){let t=U(n,e),r=Q(n.analyses.segments.date,e.style.ordinals?L:yt,e);return e.style.dayFirst?r+" "+t:t+" "+r}function yt(n){return""+n}function z(n,e){return n.pattern.month==="*"?"":" in "+U(n,e)}function $n(n){let e=n.split("/"),t=+e[1],r=e[0],o=(t===2?"every other":"every "+L(t))+" day of the month";return r!=="*"&&r!=="1"&&(o+=" from the "+L(r)),o}function on(n,e){return Q(n.analyses.segments.date,L,e)}function U(n,e){let t=Jn(n.pattern.month);return t||Q(n.analyses.segments.month,function(i){return Nt(i,e)},e)}function Jn(n){if(!mn(n))return null;let[e,t]=n.split("/");return+t!=2?null:e==="*"||e==="1"?"every odd-numbered month":e==="2"?"every even-numbered month":null}function Yn(n,e){return Q(n.analyses.segments.weekday,function(r){return un(r,e)},e)}function Q(n,e,t){let r=[];return n.forEach(function(o){o.kind==="step"?r.push(...o.fires.map(e)):o.kind==="range"?r.push(o.bounds.map(e).join(p(t))):r.push(e(o.value))}),h(r,t)}function mn(n){return n.indexOf("/")!==-1&&n.indexOf("-")===-1&&n.indexOf(",")===-1}function bt(n,e,t){let r=e.pattern.year;if(r==="*")return n;if(r.indexOf("/")!==-1)return n+" "+Ot(r,t);let i=St(r,t);if(r.indexOf("-")===-1&&r.indexOf(",")===-1&&e.pattern.date!=="*"&&n.indexOf(" at ")!==-1){let o=t.style.dayFirst?" ":", ";return n.replace(" at ",o+i+" at ")}return n+" in "+i}function St(n,e){return n.indexOf(",")!==-1?h(n.split(","),e):n}function Ot(n,e){let t=n.split("/"),r=+t[1],i=t[0];if(r<=1)return"every year";let o="every "+d(r,e)+" years";return i!=="*"&&i!=="0"&&(o+=" from "+i),o}function m(n,e){let{hour:t,minute:r,plain:i,explicit:o}=n,u=typeof n.second=="number"&&n.second>0?n.second:0;return e.ampm?kt({hour:t,minute:r,second:u,plain:i,explicit:o},e):X({hour:t,minute:r,second:u},{pad:!0,sep:e.style.sep})}function kt(n,e){let{hour:t,minute:r,second:i,plain:o,explicit:u}=n,s=e.style;if(!o&&!u&&+r==0&&!i){if(+t==0)return s.midnight;if(+t==12)return s.midday}return X({hour:t%12||12,minute:r,second:i},{lean:!u,sep:s.sep})+(s.closeUp?"":" ")+(t<12?s.am:s.pm)}function d(n,e){return wn(n,Fe,e)}function b(n,e){return+n==1?e:e+"s"}function p(n){return n.short?"-":n.style.through}function L(n){let e=Math.abs(n),t=nn[e];return t||(e=(e%100-20)%10,t=nn[e]||nn[0]),n+t}function Nt(n,e){let t=Me[+n];return t&&t[e.short?1:0]}function un(n,e){let t=n===7||n==="7"?0:n,r=S[t]||Ie[t];return r&&r[e.short?1:0]}var zt={describe:We,fallback:"an unrecognizable cron pattern",options:Le,reboot:"at system startup",sentence:n=>"Runs "+n+(n.endsWith(".")?"":".")},Bn=zt;/**
|
|
2
2
|
* @license MIT, Copyright (c) 2026 Andrew Brož
|
|
3
|
-
*/function
|
|
3
|
+
*/function Pt(n,e){let t=e&&e.lang||Bn,r=t.options(e);if(!r.lenient)return Gn(Kn(n,t,r),t,e);try{return Gn(Kn(n,t,r),t,e)}catch{return t.fallback}}function Gn(n,e,t){return t&&t.sentence?e.sentence(n):n}function Kn(n,e,t){if(typeof n=="string"&&n.trim().toLowerCase()==="@reboot")return e.reboot;let r=Pn(Cn(n,t)),i=e.strategy?e.strategy(r,r.plan):r.plan;return e.describe({...r,plan:i},t)}var fn=Pt;typeof globalThis<"u"&&Object.assign(globalThis,{cronli5:fn});var ar=fn;})();
|
package/dist/cronli5.cjs
CHANGED
|
@@ -95,6 +95,21 @@ function isNonNegativeInteger(value) {
|
|
|
95
95
|
const digits = /^\d+$/;
|
|
96
96
|
return digits.test(value);
|
|
97
97
|
}
|
|
98
|
+
function arithmeticStep(values) {
|
|
99
|
+
if (values.length < 5) {
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
const interval = values[1] - values[0];
|
|
103
|
+
if (interval < 2) {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
for (let i = 2; i < values.length; i += 1) {
|
|
107
|
+
if (values[i] - values[i - 1] !== interval) {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
return { start: values[0], interval, last: values[values.length - 1] };
|
|
112
|
+
}
|
|
98
113
|
function toFieldNumber(token, numberMap) {
|
|
99
114
|
return isNonNegativeInteger(token) ? +token : numberMap[token.toUpperCase()];
|
|
100
115
|
}
|
|
@@ -625,7 +640,7 @@ function planStandaloneSeconds(pattern, shapes) {
|
|
|
625
640
|
}
|
|
626
641
|
return { kind: "standaloneSeconds" };
|
|
627
642
|
}
|
|
628
|
-
function planMinutes(pattern, shapes, analyses,
|
|
643
|
+
function planMinutes(pattern, shapes, analyses, subMinuteSecond2 = false) {
|
|
629
644
|
if (shapes.minute === "step") {
|
|
630
645
|
return {
|
|
631
646
|
hours: planFrequencyHours(pattern, shapes, analyses),
|
|
@@ -648,7 +663,7 @@ function planMinutes(pattern, shapes, analyses, subMinuteSecond = false) {
|
|
|
648
663
|
return underStep;
|
|
649
664
|
}
|
|
650
665
|
if (pattern.hour === "*") {
|
|
651
|
-
return planMinutesUnderOpenHour(pattern, shapes,
|
|
666
|
+
return planMinutesUnderOpenHour(pattern, shapes, subMinuteSecond2);
|
|
652
667
|
}
|
|
653
668
|
}
|
|
654
669
|
function cleanHourStride(hourField) {
|
|
@@ -670,6 +685,9 @@ function planMinuteUnderHourStep(pattern, shapes) {
|
|
|
670
685
|
if (shapes.minute === "range") {
|
|
671
686
|
return { form: "range", kind: "minuteSpanAcrossHourStep" };
|
|
672
687
|
}
|
|
688
|
+
if (shapes.minute === "list" && cleanHourStride(pattern.hour)) {
|
|
689
|
+
return { form: "list", kind: "minuteSpanAcrossHourStep" };
|
|
690
|
+
}
|
|
673
691
|
return null;
|
|
674
692
|
}
|
|
675
693
|
function planFrequencyHours(pattern, shapes, analyses) {
|
|
@@ -718,7 +736,7 @@ function planMinutesAcrossHours(pattern, shapes) {
|
|
|
718
736
|
}
|
|
719
737
|
return null;
|
|
720
738
|
}
|
|
721
|
-
function planMinutesUnderOpenHour(pattern, shapes,
|
|
739
|
+
function planMinutesUnderOpenHour(pattern, shapes, subMinuteSecond2) {
|
|
722
740
|
if (shapes.minute === "range") {
|
|
723
741
|
return { kind: "rangeOfMinutes" };
|
|
724
742
|
}
|
|
@@ -728,16 +746,16 @@ function planMinutesUnderOpenHour(pattern, shapes, subMinuteSecond) {
|
|
|
728
746
|
if (pattern.minute === "*") {
|
|
729
747
|
return { kind: "everyMinute" };
|
|
730
748
|
}
|
|
731
|
-
if (pattern.minute !== "0" ||
|
|
749
|
+
if (pattern.minute !== "0" || subMinuteSecond2) {
|
|
732
750
|
return { kind: "singleMinute" };
|
|
733
751
|
}
|
|
734
752
|
}
|
|
735
|
-
function planHours(pattern, shapes, analyses,
|
|
736
|
-
const absorbsMinuteZero =
|
|
753
|
+
function planHours(pattern, shapes, analyses, subMinuteSecond2 = false) {
|
|
754
|
+
const absorbsMinuteZero = subMinuteSecond2 && pattern.minute === "0";
|
|
737
755
|
if (shapes.hour === "range" && !absorbsMinuteZero) {
|
|
738
756
|
return planHourRange(pattern, shapes, analyses);
|
|
739
757
|
}
|
|
740
|
-
if (shapes.hour === "step" && pattern.minute === "0" && !
|
|
758
|
+
if (shapes.hour === "step" && pattern.minute === "0" && !subMinuteSecond2) {
|
|
741
759
|
return { kind: "hourStep" };
|
|
742
760
|
}
|
|
743
761
|
if (pattern.hour === "*" && !absorbsMinuteZero) {
|
|
@@ -952,7 +970,15 @@ function renderSecondsWithinMinute(ir, plan, opts) {
|
|
|
952
970
|
}
|
|
953
971
|
return secondsLeadClause(ir, opts) + ", " + minuteWord + " " + minuteUnit + " past the hour, every hour" + trailingQualifier(ir, opts);
|
|
954
972
|
}
|
|
973
|
+
function composeHourCadence(ir, plan, opts) {
|
|
974
|
+
const clockRest = plan.rest.kind === "clockTimes" || plan.rest.kind === "compactClockTimes";
|
|
975
|
+
return clockRest && ir.shapes.minute === "single" ? hourCadence(ir, +ir.pattern.minute, opts) : null;
|
|
976
|
+
}
|
|
955
977
|
function renderComposeSeconds(ir, plan, opts) {
|
|
978
|
+
const cadence = composeHourCadence(ir, plan, opts);
|
|
979
|
+
if (cadence !== null) {
|
|
980
|
+
return cadence;
|
|
981
|
+
}
|
|
956
982
|
if (plan.rest.kind === "clockTimes" && (ir.shapes.second === "wildcard" || ir.shapes.second === "step")) {
|
|
957
983
|
const minute = plan.rest.times[0].minute;
|
|
958
984
|
if (+minute === 0) {
|
|
@@ -985,6 +1011,9 @@ function clockTimesOf(ir, plan, opts) {
|
|
|
985
1011
|
return joinList(times, opts) + (trail && ", " + trail);
|
|
986
1012
|
}
|
|
987
1013
|
function secondsLeadClause(ir, opts) {
|
|
1014
|
+
return secondsClause(ir, "minute", opts);
|
|
1015
|
+
}
|
|
1016
|
+
function secondsClause(ir, anchor, opts) {
|
|
988
1017
|
const secondField = ir.pattern.second;
|
|
989
1018
|
const shape = ir.shapes.second;
|
|
990
1019
|
if (secondField === "*") {
|
|
@@ -994,22 +1023,27 @@ function secondsLeadClause(ir, opts) {
|
|
|
994
1023
|
return stepCycle60(
|
|
995
1024
|
ir.analyses.segments.second[0],
|
|
996
1025
|
"second",
|
|
997
|
-
|
|
1026
|
+
anchor,
|
|
998
1027
|
opts
|
|
999
1028
|
);
|
|
1000
1029
|
}
|
|
1001
1030
|
if (shape === "range") {
|
|
1002
1031
|
const bounds = secondField.split("-");
|
|
1003
1032
|
const num = seriesNumber(bounds, opts);
|
|
1004
|
-
return "every second from " + num(bounds[0]) + through(opts) + num(bounds[1]) + " past the
|
|
1033
|
+
return "every second from " + num(bounds[0]) + through(opts) + num(bounds[1]) + " past the " + anchor;
|
|
1005
1034
|
}
|
|
1006
1035
|
if (shape === "single") {
|
|
1007
|
-
return "at " + getNumber(secondField, opts) + " " + pluralize(secondField, "second") + " past the
|
|
1036
|
+
return "at " + getNumber(secondField, opts) + " " + pluralize(secondField, "second") + " past the " + anchor;
|
|
1008
1037
|
}
|
|
1009
|
-
return
|
|
1038
|
+
return strideFromSegments(
|
|
1039
|
+
ir.analyses.segments.second,
|
|
1040
|
+
"second",
|
|
1041
|
+
anchor,
|
|
1042
|
+
opts
|
|
1043
|
+
) ?? listPastThe(
|
|
1010
1044
|
segmentWords(ir.analyses.segments.second, opts),
|
|
1011
1045
|
"second",
|
|
1012
|
-
|
|
1046
|
+
anchor,
|
|
1013
1047
|
opts
|
|
1014
1048
|
);
|
|
1015
1049
|
}
|
|
@@ -1024,12 +1058,11 @@ function renderRangeOfMinutes(ir, plan, opts) {
|
|
|
1024
1058
|
return minuteRangeLead(ir.pattern.minute, opts) + trailingQualifier(ir, opts);
|
|
1025
1059
|
}
|
|
1026
1060
|
function renderMultipleMinutes(ir, plan, opts) {
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
"hour",
|
|
1061
|
+
const stride = strideFromSegments(ir.analyses.segments.minute, "minute", "hour", opts);
|
|
1062
|
+
return (stride ?? listPastThe(segmentWords(
|
|
1063
|
+
ir.analyses.segments.minute,
|
|
1031
1064
|
opts
|
|
1032
|
-
) + trailingQualifier(ir, opts);
|
|
1065
|
+
), "minute", "hour", opts)) + trailingQualifier(ir, opts);
|
|
1033
1066
|
}
|
|
1034
1067
|
function renderMinuteFrequency(ir, plan, opts) {
|
|
1035
1068
|
let phrase = stepCycle60(
|
|
@@ -1059,8 +1092,9 @@ function renderMinutesAcrossHours(ir, plan, opts) {
|
|
|
1059
1092
|
}
|
|
1060
1093
|
const times = hourTimesFromPlan(ir, plan.times, true, opts);
|
|
1061
1094
|
const lead = plan.form === "range" ? minuteRangeLead(ir.pattern.minute, opts) : (
|
|
1062
|
-
// The 'list' form is a minute list, which has segments
|
|
1063
|
-
|
|
1095
|
+
// The 'list' form is a minute list, which has segments; an offset/uneven
|
|
1096
|
+
// step enumerated to that list reads as a stride.
|
|
1097
|
+
strideFromSegments(ir.analyses.segments.minute, "minute", "hour", opts) ?? listPastThe(
|
|
1064
1098
|
segmentWords(ir.analyses.segments.minute, opts),
|
|
1065
1099
|
"minute",
|
|
1066
1100
|
"hour",
|
|
@@ -1087,7 +1121,13 @@ function renderMinuteSpanAcrossHourStep(ir, plan, opts) {
|
|
|
1087
1121
|
if (plan.form === "wildcard") {
|
|
1088
1122
|
return "every minute " + everyNthHour(segment, opts) + trailingQualifier(ir, opts);
|
|
1089
1123
|
}
|
|
1090
|
-
|
|
1124
|
+
const lead = plan.form === "list" ? strideFromSegments(ir.analyses.segments.minute, "minute", "hour", opts) ?? listPastThe(
|
|
1125
|
+
segmentWords(ir.analyses.segments.minute, opts),
|
|
1126
|
+
"minute",
|
|
1127
|
+
"hour",
|
|
1128
|
+
opts
|
|
1129
|
+
) : minuteRangeLead(ir.pattern.minute, opts);
|
|
1130
|
+
return lead + ", " + stepHours(segment, opts) + trailingQualifier(ir, opts);
|
|
1091
1131
|
}
|
|
1092
1132
|
function minuteRangeLead(minuteField, opts) {
|
|
1093
1133
|
const bounds = minuteField.split("-");
|
|
@@ -1111,7 +1151,12 @@ function rangeMinuteLead(ir, opts) {
|
|
|
1111
1151
|
if (ir.pattern.minute === "0") {
|
|
1112
1152
|
return "every hour";
|
|
1113
1153
|
}
|
|
1114
|
-
return
|
|
1154
|
+
return strideFromSegments(
|
|
1155
|
+
ir.analyses.segments.minute,
|
|
1156
|
+
"minute",
|
|
1157
|
+
"hour",
|
|
1158
|
+
opts
|
|
1159
|
+
) ?? listPastThe(
|
|
1115
1160
|
segmentWords(ir.analyses.segments.minute, opts),
|
|
1116
1161
|
"minute",
|
|
1117
1162
|
"hour",
|
|
@@ -1128,6 +1173,12 @@ function hourWindow(window, opts) {
|
|
|
1128
1173
|
return "from " + getTime({ hour: window.from, minute: 0 }, opts) + through(opts) + getTime({ hour: window.to, minute: window.last }, opts);
|
|
1129
1174
|
}
|
|
1130
1175
|
function renderClockTimes(ir, plan, opts) {
|
|
1176
|
+
if (ir.shapes.minute === "single") {
|
|
1177
|
+
const cadence = hourCadence(ir, +ir.pattern.minute, opts);
|
|
1178
|
+
if (cadence !== null) {
|
|
1179
|
+
return cadence;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1131
1182
|
const plain = mixedTwelve(plan.times);
|
|
1132
1183
|
const times = plan.times.map(function clock(time) {
|
|
1133
1184
|
return getTime({
|
|
@@ -1141,6 +1192,10 @@ function renderClockTimes(ir, plan, opts) {
|
|
|
1141
1192
|
}
|
|
1142
1193
|
function renderCompactClockTimes(ir, plan, opts) {
|
|
1143
1194
|
if (plan.fold) {
|
|
1195
|
+
const cadence = hourCadence(ir, +plan.minute, opts);
|
|
1196
|
+
if (cadence !== null) {
|
|
1197
|
+
return cadence;
|
|
1198
|
+
}
|
|
1144
1199
|
const hasRange = ir.analyses.segments.hour.some(function range(segment) {
|
|
1145
1200
|
return segment.kind === "range";
|
|
1146
1201
|
});
|
|
@@ -1151,13 +1206,14 @@ function renderCompactClockTimes(ir, plan, opts) {
|
|
|
1151
1206
|
return interpretDayQualifier(ir, opts) + "at " + hourSegmentTimes(ir, fold, true, opts);
|
|
1152
1207
|
}
|
|
1153
1208
|
const phrase = (
|
|
1154
|
-
// The non-fold branch is a minute list, which has segments.
|
|
1155
|
-
|
|
1209
|
+
// The non-fold branch is a minute list, which has segments. An
|
|
1210
|
+
// offset/uneven step enumerated to that list reads as a stride.
|
|
1211
|
+
(strideFromSegments(ir.analyses.segments.minute, "minute", "hour", opts) ?? listPastThe(
|
|
1156
1212
|
segmentWords(ir.analyses.segments.minute, opts),
|
|
1157
1213
|
"minute",
|
|
1158
1214
|
"hour",
|
|
1159
1215
|
opts
|
|
1160
|
-
) + ", at " + hourSegmentTimes(ir, { minute: 0, second: null }, true, opts) + trailingQualifier(ir, opts)
|
|
1216
|
+
)) + ", at " + hourSegmentTimes(ir, { minute: 0, second: null }, true, opts) + trailingQualifier(ir, opts)
|
|
1161
1217
|
);
|
|
1162
1218
|
return ir.analyses.clockSecond ? secondsLeadClause(ir, opts) + ", " + phrase : phrase;
|
|
1163
1219
|
}
|
|
@@ -1205,24 +1261,50 @@ var renderers = {
|
|
|
1205
1261
|
singleMinute: renderSingleMinute,
|
|
1206
1262
|
standaloneSeconds: renderStandaloneSeconds
|
|
1207
1263
|
};
|
|
1264
|
+
function renderStride(stride, opts) {
|
|
1265
|
+
const { interval, start, last, cycle, unit, anchor } = stride;
|
|
1266
|
+
const cadence = "every " + getNumber(interval, opts) + " " + unit + "s";
|
|
1267
|
+
const tiles = cycle % interval === 0;
|
|
1268
|
+
if (start === 0 && tiles) {
|
|
1269
|
+
return cadence;
|
|
1270
|
+
}
|
|
1271
|
+
if (start < interval && tiles) {
|
|
1272
|
+
return cadence + " from " + getNumber(start, opts) + " " + pluralize(start, unit) + " past the " + anchor;
|
|
1273
|
+
}
|
|
1274
|
+
const num = seriesNumber([start, last], opts);
|
|
1275
|
+
return cadence + " from " + num(start) + through(opts) + num(last) + " " + pluralize(last, unit) + " past the " + anchor;
|
|
1276
|
+
}
|
|
1277
|
+
function singleValues(segments) {
|
|
1278
|
+
const values = [];
|
|
1279
|
+
for (const segment of segments) {
|
|
1280
|
+
if (segment.kind !== "single") {
|
|
1281
|
+
return null;
|
|
1282
|
+
}
|
|
1283
|
+
values.push(+segment.value);
|
|
1284
|
+
}
|
|
1285
|
+
return values;
|
|
1286
|
+
}
|
|
1287
|
+
function strideFromSegments(segments, unit, anchor, opts) {
|
|
1288
|
+
const values = singleValues(segments);
|
|
1289
|
+
const step = values && arithmeticStep(values);
|
|
1290
|
+
return step ? renderStride({ ...step, cycle: 60, unit, anchor }, opts) : null;
|
|
1291
|
+
}
|
|
1208
1292
|
function stepCycle60(segment, unit, anchor, opts) {
|
|
1209
1293
|
if (segment.startToken.indexOf("-") !== -1) {
|
|
1210
1294
|
return listPastThe(numberWords(segment.fires, opts), unit, anchor, opts);
|
|
1211
1295
|
}
|
|
1212
1296
|
const start = segment.startToken === "*" ? 0 : +segment.startToken;
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
if (segment.fires.length <= 3) {
|
|
1216
|
-
return listPastThe(
|
|
1217
|
-
numberWords(segment.fires, opts),
|
|
1218
|
-
unit,
|
|
1219
|
-
anchor,
|
|
1220
|
-
opts
|
|
1221
|
-
);
|
|
1222
|
-
}
|
|
1223
|
-
return "every " + getNumber(interval, opts) + " " + unit + "s from " + getNumber(start, opts) + " " + pluralize(start, unit) + " past the " + anchor;
|
|
1297
|
+
if (start !== 0 && segment.fires.length <= 3) {
|
|
1298
|
+
return listPastThe(numberWords(segment.fires, opts), unit, anchor, opts);
|
|
1224
1299
|
}
|
|
1225
|
-
return
|
|
1300
|
+
return renderStride({
|
|
1301
|
+
interval: segment.interval,
|
|
1302
|
+
start,
|
|
1303
|
+
last: segment.fires[segment.fires.length - 1],
|
|
1304
|
+
cycle: 60,
|
|
1305
|
+
unit,
|
|
1306
|
+
anchor
|
|
1307
|
+
}, opts);
|
|
1226
1308
|
}
|
|
1227
1309
|
function stepHours(segment, opts) {
|
|
1228
1310
|
if (segment.startToken.indexOf("-") !== -1) {
|
|
@@ -1238,6 +1320,68 @@ function stepHours(segment, opts) {
|
|
|
1238
1320
|
}
|
|
1239
1321
|
return "every " + getNumber(interval, opts) + " hours from " + getTime({ hour: start, minute: 0 }, opts);
|
|
1240
1322
|
}
|
|
1323
|
+
function hourStrideCadence(stride, opts) {
|
|
1324
|
+
const { start, interval, last } = stride;
|
|
1325
|
+
const cadence = "every " + getNumber(interval, opts) + " hours";
|
|
1326
|
+
const tiles = 24 % interval === 0;
|
|
1327
|
+
if (start === 0 && tiles) {
|
|
1328
|
+
return cadence;
|
|
1329
|
+
}
|
|
1330
|
+
if (start < interval && tiles) {
|
|
1331
|
+
return cadence + " from " + getTime({ hour: start, minute: 0 }, opts);
|
|
1332
|
+
}
|
|
1333
|
+
return cadence + " from " + getTime({ hour: start, minute: 0 }, opts) + through(opts) + getTime({ hour: last, minute: 0 }, opts);
|
|
1334
|
+
}
|
|
1335
|
+
function hourStride(ir) {
|
|
1336
|
+
const segments = ir.analyses.segments.hour;
|
|
1337
|
+
if (segments.length === 1 && segments[0].kind === "step") {
|
|
1338
|
+
const segment = segments[0];
|
|
1339
|
+
const start = segment.startToken === "*" ? 0 : +segment.startToken.split("-")[0];
|
|
1340
|
+
return { interval: segment.interval, last: segment.fires[segment.fires.length - 1], start };
|
|
1341
|
+
}
|
|
1342
|
+
const values = singleValues(segments);
|
|
1343
|
+
const step = values && arithmeticStep(values);
|
|
1344
|
+
return step || null;
|
|
1345
|
+
}
|
|
1346
|
+
function subMinuteSecond(ir) {
|
|
1347
|
+
return ir.pattern.second === "*" || ir.shapes.second === "step";
|
|
1348
|
+
}
|
|
1349
|
+
function hourCadenceLead(ir, minute, opts) {
|
|
1350
|
+
if (minute === 0) {
|
|
1351
|
+
if (subMinuteSecond(ir)) {
|
|
1352
|
+
return secondsClause(ir, "minute", opts) + " for one minute";
|
|
1353
|
+
}
|
|
1354
|
+
return secondsClause(ir, "hour", opts);
|
|
1355
|
+
}
|
|
1356
|
+
const minutePhrase = getNumber(minute, opts) + " " + pluralize(minute, "minute") + " past the hour";
|
|
1357
|
+
if (ir.pattern.second === "0") {
|
|
1358
|
+
return minutePhrase;
|
|
1359
|
+
}
|
|
1360
|
+
return secondsClause(ir, "minute", opts) + ", " + minutePhrase;
|
|
1361
|
+
}
|
|
1362
|
+
function hourCadence(ir, minute, opts) {
|
|
1363
|
+
const stride = hourStride(ir);
|
|
1364
|
+
if (!stride) {
|
|
1365
|
+
return null;
|
|
1366
|
+
}
|
|
1367
|
+
const fires = (stride.last - stride.start) / stride.interval + 1;
|
|
1368
|
+
if (ir.pattern.second === "0" && fires <= maxClockTimes) {
|
|
1369
|
+
return null;
|
|
1370
|
+
}
|
|
1371
|
+
const confinement = minute === 0 && subMinuteSecond(ir) && cleanStrideSegment(ir);
|
|
1372
|
+
if (confinement) {
|
|
1373
|
+
return secondsClause(ir, "minute", opts) + " for one minute " + everyNthHour(confinement, opts) + trailingQualifier(ir, opts);
|
|
1374
|
+
}
|
|
1375
|
+
return hourCadenceLead(ir, minute, opts) + ", " + hourStrideCadence(stride, opts) + trailingQualifier(ir, opts);
|
|
1376
|
+
}
|
|
1377
|
+
function cleanStrideSegment(ir) {
|
|
1378
|
+
const segments = ir.analyses.segments.hour;
|
|
1379
|
+
const segment = segments.length === 1 && segments[0];
|
|
1380
|
+
if (!segment || segment.kind !== "step" || segment.startToken.indexOf("-") !== -1 || !(segment.interval in stepOrdinals)) {
|
|
1381
|
+
return null;
|
|
1382
|
+
}
|
|
1383
|
+
return segment;
|
|
1384
|
+
}
|
|
1241
1385
|
function seriesNumber(values, opts) {
|
|
1242
1386
|
const anyBig = values.some(function big(v) {
|
|
1243
1387
|
return +v > 10;
|