UNPKG

5.32 kBSource Map (JSON)View Raw
1{"version":3,"sources":["../src/next.js"],"names":["NEXT_MAPPING","month","year","date","day","week","hour","minute","getFirst","values","undefined","setFirstAvailable","unit","curr","get","next","length","timestamp","set","add","schedule","fromDate","second","millisecond","dayOfMonth","dayOfWeek","loop","i","newDate","clone","dateDay","moment","min","Error"],"mappings":";;;;;;;AAAA;;AACA;;;;AAEA,MAAMA,YAAY,GAAG;AACnBC,EAAAA,KAAK,EAAE;AAAEC,IAAAA,IAAI,EAAE;AAAR,GADY;AAEnBC,EAAAA,IAAI,EAAE;AAAEF,IAAAA,KAAK,EAAE;AAAT,GAFa;AAGnBG,EAAAA,GAAG,EAAE;AAAEC,IAAAA,IAAI,EAAE;AAAR,GAHc;AAInBC,EAAAA,IAAI,EAAE;AAAEF,IAAAA,GAAG,EAAE;AAAP,GAJa;AAKnBG,EAAAA,MAAM,EAAE;AAAED,IAAAA,IAAI,EAAE;AAAR;AALW,CAArB;;AAQA,MAAME,QAAQ,GAAGC,MAAM,IAAKA,MAAM,KAAKC,SAAX,GAAuBD,MAAM,CAAC,CAAD,CAA7B,GAAmC,CAA/D;;AAEA,MAAME,iBAAiB,GAAG,CAACR,IAAD,EAAOS,IAAP,EAAaH,MAAb,KAAwB;AAChD,MAAIA,MAAM,KAAKC,SAAf,EAA0B;AACxB;AACD;;AAED,QAAMG,IAAI,GAAGV,IAAI,CAACW,GAAL,CAASF,IAAT,CAAb;AACA,QAAMG,IAAI,GAAGN,MAAM,CAAC,0BAAYA,MAAZ,EAAoBI,IAApB,IAA4BJ,MAAM,CAACO,MAApC,CAAnB;;AACA,MAAIH,IAAI,KAAKE,IAAb,EAAmB;AACjB;AACD;;AAED,QAAME,SAAS,GAAG,CAACd,IAAnB;AACAA,EAAAA,IAAI,CAACe,GAAL,CAASN,IAAT,EAAeG,IAAf;;AACA,MAAIE,SAAS,GAAG,CAACd,IAAjB,EAAuB;AACrBA,IAAAA,IAAI,CAACgB,GAAL,CAASnB,YAAY,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AAS,KAAKf,SAAlB,EAA6B;AAC3BC,QAAAA,iBAAiB,CAACiB,OAAD,EAAU,KAAV,EAAiBH,SAAjB,CAAjB;AACD;AACF,KAJD,MAIO,IAAIA,SAAS,KAAKf,SAAlB,EAA6B;AAClCC,MAAAA,iBAAiB,CAACiB,OAAD,EAAU,MAAV,EAAkBJ,UAAlB,CAAjB;AACD,KAFM,MAEA;AACL,YAAMM,OAAO,GAAGF,OAAO,CAACC,KAAR,EAAhB;AACAlB,MAAAA,iBAAiB,CAACmB,OAAD,EAAU,MAAV,EAAkBN,UAAlB,CAAjB;AACAb,MAAAA,iBAAiB,CAACiB,OAAD,EAAU,KAAV,EAAiBH,SAAjB,CAAjB;AACAG,MAAAA,OAAO,GAAGG,wBAAOC,GAAP,CAAWF,OAAX,EAAoBF,OAApB,CAAV;AACD;;AACD,QAAI,CAACzB,IAAD,KAAU,CAACyB,OAAf,EAAwB;AACtBF,MAAAA,IAAI,GAAGvB,IAAI,CAACF,KAAL,OAAiB2B,OAAO,CAAC3B,KAAR,EAAxB;AACAE,MAAAA,IAAI,GAAGyB,OAAO,CAACV,GAAR,CAAY;AACjBZ,QAAAA,IAAI,EAAEE,QAAQ,CAACF,IAAD,CADG;AAEjBC,QAAAA,MAAM,EAAEC,QAAQ,CAACD,MAAD;AAFC,OAAZ,CAAP;AAID;AACF,GA/BD,QA+BSmB,IAAI,IAAI,EAAEC,CAAF,GAAM,CA/BvB;;AAiCA,MAAID,IAAJ,EAAU;AACR,UAAM,IAAIO,KAAJ,CAAU,sCAAV,CAAN;AACD;;AAED,SAAO9B,IAAP;AACD,C","sourcesContent":["import moment from 'moment-timezone'\nimport sortedIndex from 'lodash/sortedIndex'\n\nconst NEXT_MAPPING = {\n month: { year: 1 },\n date: { month: 1 },\n day: { week: 1 },\n hour: { day: 1 },\n minute: { hour: 1 },\n}\n\nconst getFirst = values => (values !== undefined ? values[0] : 0)\n\nconst setFirstAvailable = (date, unit, values) => {\n if (values === undefined) {\n return\n }\n\n const curr = date.get(unit)\n const next = values[sortedIndex(values, curr) % values.length]\n if (curr === next) {\n return\n }\n\n const timestamp = +date\n date.set(unit, next)\n if (timestamp > +date) {\n date.add(NEXT_MAPPING[unit])\n }\n return true\n}\n\n// returns the next run, after the passed date\nexport default (schedule, fromDate) => {\n let date = moment(fromDate)\n .set({\n second: 0,\n millisecond: 0,\n })\n .add({ minute: 1 })\n\n const { minute, hour, dayOfMonth, month, dayOfWeek } = schedule\n setFirstAvailable(date, 'minute', minute)\n\n if (setFirstAvailable(date, 'hour', hour)) {\n date.set('minute', getFirst(minute))\n }\n\n let loop\n let i = 0\n do {\n loop = false\n\n if (setFirstAvailable(date, 'month', month)) {\n date.set({\n date: 1,\n hour: getFirst(hour),\n minute: getFirst(minute),\n })\n }\n\n let newDate = date.clone()\n if (dayOfMonth === undefined) {\n if (dayOfWeek !== undefined) {\n setFirstAvailable(newDate, 'day', dayOfWeek)\n }\n } else if (dayOfWeek === undefined) {\n setFirstAvailable(newDate, 'date', dayOfMonth)\n } else {\n const dateDay = newDate.clone()\n setFirstAvailable(dateDay, 'date', dayOfMonth)\n setFirstAvailable(newDate, 'day', dayOfWeek)\n newDate = moment.min(dateDay, newDate)\n }\n if (+date !== +newDate) {\n loop = date.month() !== newDate.month()\n date = newDate.set({\n hour: getFirst(hour),\n minute: getFirst(minute),\n })\n }\n } while (loop && ++i < 5)\n\n if (loop) {\n throw new Error('no solutions found for this schedule')\n }\n\n return date\n}\n"],"file":"next.js"}
\No newline at end of file