@lighthouse/common 4.31.1 → 4.32.0

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.
@@ -45,6 +45,7 @@ function* occurrenceIntervalsGenerator(props) {
45
45
  isInitial,
46
46
  start,
47
47
  options,
48
- timezone
48
+ timezone,
49
+ type
49
50
  });
50
51
  }
@@ -81,7 +81,7 @@ function* generateRepeatingSchedule(props) {
81
81
  interval: occurrenceInterval,
82
82
  type: _scheduling.IntervalTypes.Occurrence
83
83
  };
84
- } // NOTE: we must reset isInitial to true follwing the first service
84
+ } // NOTE: we must reset isInitial to true following the first service
85
85
  // interval otherwise the occurrence will not start exactly on the next
86
86
  // service interval start time
87
87
 
@@ -19,7 +19,8 @@ function* getNext({
19
19
  isInitial,
20
20
  options,
21
21
  start,
22
- timezone
22
+ timezone,
23
+ type
23
24
  }) {
24
25
  const {
25
26
  duration,
@@ -37,9 +38,24 @@ function* getNext({
37
38
  let dateCursor = initial ? _momentTimezone.default.tz(start, timezone).valueOf() : _momentTimezone.default.tz(start, timezone).add(1, _scheduling.Unit.Millisecond).valueOf();
38
39
 
39
40
  while (dateCursor < end) {
40
- const nextOccurrenceEnd = _momentTimezone.default.tz(dateCursor, timezone).add(frequencyValue, frequencyUnit).valueOf();
41
+ let nextOccurrenceStart;
42
+ let nextOccurrenceEnd;
41
43
 
42
- const nextOccurrenceStart = _momentTimezone.default.tz(nextOccurrenceEnd, timezone).subtract(durationValue, durationUnit).valueOf();
44
+ if (type === _scheduling.StrategyTypes.Stopwatch) {
45
+ nextOccurrenceStart = dateCursor;
46
+ nextOccurrenceEnd = _momentTimezone.default.tz(dateCursor, timezone).add(durationValue, durationUnit).valueOf();
47
+ } else {
48
+ nextOccurrenceEnd = _momentTimezone.default.tz(dateCursor, timezone).add(frequencyValue, frequencyUnit).valueOf();
49
+
50
+ const nextOccurrenceStartByBackCalculation = _momentTimezone.default.tz(nextOccurrenceEnd, timezone).subtract(durationValue, durationUnit);
51
+
52
+ const earliestNextOccurrenceStart = _momentTimezone.default.tz(dateCursor, timezone); // NOTE: this is to ensure that the next occurrence start is always
53
+ // greater than or equal to the date cursor. Moment js handles month addition and subtraction
54
+ // with estimations (Dec 31st + 2 months gives Feb 28th/29th). This can lead to inaccurate start times when calculating forwards then backwards at the end of the month.
55
+
56
+
57
+ nextOccurrenceStart = _momentTimezone.default.max(earliestNextOccurrenceStart, nextOccurrenceStartByBackCalculation).valueOf();
58
+ }
43
59
 
44
60
  if (nextOccurrenceEnd <= nextOccurrenceStart || nextOccurrenceEnd > end) {
45
61
  return;
@@ -37,7 +37,8 @@ export function occurrenceIntervalsGenerator(props) {
37
37
  isInitial: isInitial,
38
38
  start: start,
39
39
  options: options,
40
- timezone: timezone
40
+ timezone: timezone,
41
+ type: type
41
42
  }), "t0", 8);
42
43
 
43
44
  case 8:
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/scheduling/generators/occurrenceIntervalsGenerator.ts"],"names":["occurrenceIntervalsGenerator","StrategyTypes","getNext","getNextExactDateOfMonth","getNextLastDayOfMonth","getNextLastWeekdayOfMonth","getNextNoRepeat","getNextWeekday","getNextXDayOfXWeekOfMonth","strategyTypeMap","ExactDateOfMonth","LastDayOfMonth","LastWeekdayOfMonth","NoRepeat","Stopwatch","Weekdays","Window","XDayOfXWeekOfMonth","props","isInitial","serviceInterval","strategy","timezone","options","type","start","end","getNextFn"],"mappings":";;;;;oDAiCiBA,4B;;AAjCjB,SAA6BC,aAA7B,QAAkD,qBAAlD;AAEA,SACEC,OADF,EAEEC,uBAFF,EAGEC,qBAHF,EAIEC,yBAJF,EAKEC,eALF,EAMEC,cANF,EAOEC,yBAPF,QAQO,eARP;AAUA,OAAO,IAAMC,eAAe,6DACzBR,aAAa,CAACS,gBADW,EACQP,uBADR,qCAEzBF,aAAa,CAACU,cAFW,EAEMP,qBAFN,qCAGzBH,aAAa,CAACW,kBAHW,EAGUP,yBAHV,qCAIzBJ,aAAa,CAACY,QAJW,EAIAP,eAJA,qCAKzBL,aAAa,CAACa,SALW,EAKCZ,OALD,qCAMzBD,aAAa,CAACc,QANW,EAMAR,cANA,qCAOzBN,aAAa,CAACe,MAPW,EAOFd,OAPE,qCAQzBD,aAAa,CAACgB,kBARW,EAQUT,yBARV,oBAArB;;AAkBP;;;AAGA,OAAO,SAAUR,4BAAV,CACLkB,KADK;AAAA;AAAA;AAAA;AAAA;AAAA;AAGGC,UAAAA,SAHH,GAGsDD,KAHtD,CAGGC,SAHH,EAGcC,eAHd,GAGsDF,KAHtD,CAGcE,eAHd,EAG+BC,QAH/B,GAGsDH,KAHtD,CAG+BG,QAH/B,EAGyCC,QAHzC,GAGsDJ,KAHtD,CAGyCI,QAHzC;AAIGC,UAAAA,OAJH,GAIqBF,QAJrB,CAIGE,OAJH,EAIYC,IAJZ,GAIqBH,QAJrB,CAIYG,IAJZ;AAMCC,UAAAA,KAND,GAMiBL,eAAe,CAAC,CAAD,CANhC;AAOCM,UAAAA,GAPD,GAOeN,eAAe,CAAC,CAAD,CAP9B;AASCO,UAAAA,SATD,GASalB,eAAe,CAACe,IAAD,CAT5B;;AAAA,cAWAG,SAXA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAaL,wCAAOA,SAAS,CAAC;AACfD,YAAAA,GAAG,EAAHA,GADe;AAEfP,YAAAA,SAAS,EAATA,SAFe;AAGfM,YAAAA,KAAK,EAALA,KAHe;AAIfF,YAAAA,OAAO,EAAPA,OAJe;AAKfD,YAAAA,QAAQ,EAARA;AALe,WAAD,CAAhB;;AAbK;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["import { Interval, Strategy, StrategyTypes } from '../scheduling.types'\n\nimport {\n getNext,\n getNextExactDateOfMonth,\n getNextLastDayOfMonth,\n getNextLastWeekdayOfMonth,\n getNextNoRepeat,\n getNextWeekday,\n getNextXDayOfXWeekOfMonth,\n} from '../strategies'\n\nexport const strategyTypeMap = {\n [StrategyTypes.ExactDateOfMonth]: getNextExactDateOfMonth,\n [StrategyTypes.LastDayOfMonth]: getNextLastDayOfMonth,\n [StrategyTypes.LastWeekdayOfMonth]: getNextLastWeekdayOfMonth,\n [StrategyTypes.NoRepeat]: getNextNoRepeat,\n [StrategyTypes.Stopwatch]: getNext,\n [StrategyTypes.Weekdays]: getNextWeekday,\n [StrategyTypes.Window]: getNext,\n [StrategyTypes.XDayOfXWeekOfMonth]: getNextXDayOfXWeekOfMonth,\n}\n\ninterface OccurrenceIntervalsGenerator {\n readonly isInitial: boolean\n readonly serviceInterval: Interval\n readonly strategy: Strategy\n readonly timezone: string\n}\n\n/**\n * Generates occurrence intervals for service intervals using strategy\n */\nexport function* occurrenceIntervalsGenerator(\n props: OccurrenceIntervalsGenerator\n): IterableIterator<Interval> {\n const { isInitial, serviceInterval, strategy, timezone } = props\n const { options, type } = strategy\n\n const start: number = serviceInterval[0]\n const end: number = serviceInterval[1]\n\n const getNextFn = strategyTypeMap[type]\n\n if (!getNextFn) return\n\n yield* getNextFn({\n end,\n isInitial,\n start,\n options,\n timezone,\n })\n}\n"],"file":"occurrenceIntervalsGenerator.js"}
1
+ {"version":3,"sources":["../../../src/scheduling/generators/occurrenceIntervalsGenerator.ts"],"names":["occurrenceIntervalsGenerator","StrategyTypes","getNext","getNextExactDateOfMonth","getNextLastDayOfMonth","getNextLastWeekdayOfMonth","getNextNoRepeat","getNextWeekday","getNextXDayOfXWeekOfMonth","strategyTypeMap","ExactDateOfMonth","LastDayOfMonth","LastWeekdayOfMonth","NoRepeat","Stopwatch","Weekdays","Window","XDayOfXWeekOfMonth","props","isInitial","serviceInterval","strategy","timezone","options","type","start","end","getNextFn"],"mappings":";;;;;oDAiCiBA,4B;;AAjCjB,SAA6BC,aAA7B,QAAkD,qBAAlD;AAEA,SACEC,OADF,EAEEC,uBAFF,EAGEC,qBAHF,EAIEC,yBAJF,EAKEC,eALF,EAMEC,cANF,EAOEC,yBAPF,QAQO,eARP;AAUA,OAAO,IAAMC,eAAe,6DACzBR,aAAa,C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DateOfMonth,\n getNextLastDayOfMonth,\n getNextLastWeekdayOfMonth,\n getNextNoRepeat,\n getNextWeekday,\n getNextXDayOfXWeekOfMonth,\n} from '../strategies'\n\nexport const strategyTypeMap = {\n [StrategyTypes.ExactDateOfMonth]: getNextExactDateOfMonth,\n [StrategyTypes.LastDayOfMonth]: getNextLastDayOfMonth,\n [StrategyTypes.LastWeekdayOfMonth]: getNextLastWeekdayOfMonth,\n [StrategyTypes.NoRepeat]: getNextNoRepeat,\n [StrategyTypes.Stopwatch]: getNext,\n [StrategyTypes.Weekdays]: getNextWeekday,\n [StrategyTypes.Window]: getNext,\n [StrategyTypes.XDayOfXWeekOfMonth]: getNextXDayOfXWeekOfMonth,\n}\n\ninterface OccurrenceIntervalsGenerator {\n readonly isInitial: boolean\n readonly serviceInterval: Interval\n readonly strategy: Strategy\n readonly timezone: string\n}\n\n/**\n * Generates occurrence intervals for service intervals using strategy\n */\nexport function* occurrenceIntervalsGenerator(\n props: OccurrenceIntervalsGenerator\n): IterableIterator<Interval> {\n const { isInitial, serviceInterval, strategy, timezone } = props\n const { options, type } = strategy\n\n const start: number = serviceInterval[0]\n const end: number = serviceInterval[1]\n\n const getNextFn = strategyTypeMap[type]\n\n if (!getNextFn) return\n\n yield* getNextFn({\n end,\n isInitial,\n start,\n options,\n timezone,\n type,\n })\n}\n"],"file":"occurrenceIntervalsGenerator.js"}
@@ -138,7 +138,7 @@ export function generateRepeatingSchedule(props) {
138
138
  return _context.finish(40);
139
139
 
140
140
  case 48:
141
- // NOTE: we must reset isInitial to true follwing the first service
141
+ // NOTE: we must reset isInitial to true following the first service
142
142
  // interval otherwise the occurrence will not start exactly on the next
143
143
  // service interval start time
144
144
  isInitial = true;
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/scheduling/helpers/generateRepeatingSchedule.ts"],"names":["generateRepeatingSchedule","includes","generateScheduleEnd","hasValidStartAndEnd","IntervalTypes","Unit","occurrenceIntervalsGenerator","serviceIntervalsGenerator","complyingServiceIntervalUnits","Second","Minute","Hour","props","serviceHours","start","strategy","end","isInitial","frequency","options","frequencyUnit","unit","timezone","isStartAndEndValid","serviceIntervalSequence","complyToServiceHours","serviceIntervals","serviceInterval","interval","type","Service","occurrenceIntervalsSequence","occurrenceInterval","Occurrence"],"mappings":";;;oDAsBiBA,yB;;AAtBjB,SAASC,QAAT,QAAyB,WAAzB;AAEA,SAASC,mBAAT,EAA8BC,mBAA9B,QAAyD,GAAzD;AACA,SACEC,aADF,EAGEC,IAHF,QAIO,qBAJP;AAKA,SACEC,4BADF,EAEEC,yBAFF,QAGO,eAHP;AAKA,OAAO,IAAMC,6BAA6B,GAAG,CAC3CH,IAAI,CAACI,MADsC,EAE3CJ,IAAI,CAACK,MAFsC,EAG3CL,IAAI,CAACM,IAHsC,CAAtC;AAMP;;;;AAGA,OAAO,SAAUX,yBAAV,CAAoCY,KAApC;AAAA;;AAAA;AAAA;AAAA;AAAA;AACGC,UAAAA,YADH,GACqCD,KADrC,CACGC,YADH,EACiBC,KADjB,GACqCF,KADrC,CACiBE,KADjB,EACwBC,QADxB,GACqCH,KADrC,CACwBG,QADxB;AAECC,UAAAA,GAFD,GAEoBJ,KAFpB,CAECI,GAFD,EAEMC,SAFN,GAEoBL,KAFpB,CAEMK,SAFN,EAIL;AACA;;AAEaC,UAAAA,SAPR,GAQDH,QARC,CAOHI,OAPG,CAOQD,SAPR;AASSE,UAAAA,aATT,GAS2BF,SAT3B,CASGG,IATH;AAUGC,UAAAA,QAVH,GAUgBT,YAVhB,CAUGS,QAVH;AAYLN,UAAAA,GAAG,GAAGA,GAAG,IAAId,mBAAmB,CAAC;AAAEgB,YAAAA,SAAS,EAATA,SAAF;AAAaJ,YAAAA,KAAK,EAALA,KAAb;AAAoBQ,YAAAA,QAAQ,EAARA;AAApB,WAAD,CAAhC;AAEMC,UAAAA,kBAdD,GAcsBpB,mBAAmB,CAAC;AAAEa,YAAAA,GAAG,EAAHA,GAAF;AAAOF,YAAAA,KAAK,EAALA;AA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AAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAiDH;AACA;AACA;AACAhB,UAAAA,SAAS,GAAG,IAAZ;;AApDG;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["import { includes } from 'lodash/fp'\n\nimport { generateScheduleEnd, hasValidStartAndEnd } from '.'\nimport {\n IntervalTypes,\n ScheduleIntervalsGenerator,\n Unit,\n} from '../scheduling.types'\nimport {\n occurrenceIntervalsGenerator,\n serviceIntervalsGenerator,\n} from '../generators'\n\nexport const complyingServiceIntervalUnits = [\n Unit.Second,\n Unit.Minute,\n Unit.Hour,\n]\n\n/**\n * Generates repeating schedule service and occurrence intervals\n */\nexport function* generateRepeatingSchedule(props: ScheduleIntervalsGenerator) {\n const { serviceHours, start, strategy } = props\n let { end, isInitial } = props\n\n // NOTE support never ending repeating schedule where no end date defined by\n // setting a custom end date using the frequency unit and value\n const {\n options: { frequency },\n } = strategy\n const { unit: frequencyUnit } = frequency\n const { timezone } = serviceHours\n\n end = end || generateScheduleEnd({ frequency, start, timezone })\n\n const isStartAndEndValid = hasValidStartAndEnd({ end, start })\n\n if (!isStartAndEndValid) return []\n\n const serviceIntervalSequence = serviceIntervalsGenerator({\n end,\n serviceHours,\n start,\n })\n\n // NOTE: when repeating and is complying to service hours we iterate through\n // all service intervals otherwise service interval is from the start and end\n const complyToServiceHours = includes(\n frequencyUnit,\n complyingServiceIntervalUnits\n )\n\n const serviceIntervals = complyToServiceHours\n ? [...serviceIntervalSequence]\n : [[start, end]]\n\n for (const serviceInterval of serviceIntervals) {\n yield { interval: serviceInterval, type: IntervalTypes.Service }\n\n const occurrenceIntervalsSequence = occurrenceIntervalsGenerator({\n isInitial,\n serviceInterval,\n strategy,\n timezone,\n })\n\n for (const occurrenceInterval of occurrenceIntervalsSequence) {\n yield { interval: occurrenceInterval, type: IntervalTypes.Occurrence }\n }\n\n // NOTE: we must reset isInitial to true follwing the first service\n // interval otherwise the occurrence will not start exactly on the next\n // service interval start time\n isInitial = true\n }\n}\n"],"file":"generateRepeatingSchedule.js"}
1
+ {"version":3,"sources":["../../../src/scheduling/helpers/generateRepeatingSchedule.ts"],"names":["generateRepeatingSchedule","includes","generateScheduleEnd","hasValidStartAndEnd","IntervalTypes","Unit","occurrenceIntervalsGenerator","serviceIntervalsGenerator","complyingServiceIntervalUnits","Second","Minute","Hour","props","serviceHours","start","strategy","end","isInitial","frequency","options","frequencyUnit","unit","timezone","isStartAndEndValid","serviceIntervalSequence","complyToServiceHours","serviceIntervals","serviceInterval","interval","type","Service","occurrenceIntervalsSequence","occurrenceInterval","Occurrence"],"mappings":";;;oDAsBiBA,yB;;AAtBjB,SAASC,QAAT,QAAyB,WAAzB;AAEA,SAASC,mBAAT,EAA8BC,mBAA9B,QAAyD,GAAzD;AACA,SACEC,aADF,EAGEC,IAHF,QAIO,qBAJP;AAKA,SACEC,4BADF,EAEEC,yBAFF,QAGO,eAHP;AAKA,OAAO,IAAMC,6BAA6B,GAAG,CAC3CH,IAAI,CAACI,MADsC,EAE3CJ,IAAI,CAACK,MAFsC,EAG3CL,IAAI,CAACM,IAHsC,CAAtC;AAMP;;;;AAGA,OAAO,SAAUX,yBAAV,CAAoCY,KAApC;AAAA;;AAAA;AAAA;AAAA;AAAA;AACGC,UAAAA,YADH,GACqCD,KADrC,CACGC,YADH,EACiBC,KADjB,GACqCF,KADrC,CACiBE,KADjB,EACwBC,QADxB,GACqCH,KADrC,CACwBG,QADxB;AAECC,UAAAA,GAFD,GAEoBJ,KAFpB,CAECI,GAFD,EAEMC,SAFN,GAEoBL,KAFpB,CAEMK,SAFN,EAIL;AACA;;A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,eAF+D;AAG/DZ,YAAAA,QAAQ,EAARA,QAH+D;AAI/DO,YAAAA,QAAQ,EAARA;AAJ+D,WAAD,CAtC7D;AAAA;AAAA;AAAA;AAAA;AAAA,uBA6C8BS,2BA7C9B;;AAAA;AAAA;AAAA;AAAA;AAAA;;AA6CQC,UAAAA,kBA7CR;AAAA;AA8CD,iBAAM;AAAEJ,YAAAA,QAAQ,EAAEI,kBAAZ;AAAgCH,YAAAA,IAAI,EAAEzB,aAAa,CAAC6B;AAApD,WAAN;;AA9CC;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAiDH;AACA;AACA;AACAhB,UAAAA,SAAS,GAAG,IAAZ;;AApDG;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA;;AAAA;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["import { includes } from 'lodash/fp'\n\nimport { generateScheduleEnd, hasValidStartAndEnd } from '.'\nimport {\n IntervalTypes,\n ScheduleIntervalsGenerator,\n Unit,\n} from '../scheduling.types'\nimport {\n occurrenceIntervalsGenerator,\n serviceIntervalsGenerator,\n} from '../generators'\n\nexport const complyingServiceIntervalUnits = [\n Unit.Second,\n Unit.Minute,\n Unit.Hour,\n]\n\n/**\n * Generates repeating schedule service and occurrence intervals\n */\nexport function* generateRepeatingSchedule(props: ScheduleIntervalsGenerator) {\n const { serviceHours, start, strategy } = props\n let { end, isInitial } = props\n\n // NOTE support never ending repeating schedule where no end date defined by\n // setting a custom end date using the frequency unit and value\n const {\n options: { frequency },\n } = strategy\n const { unit: frequencyUnit } = frequency\n const { timezone } = serviceHours\n\n end = end || generateScheduleEnd({ frequency, start, timezone })\n\n const isStartAndEndValid = hasValidStartAndEnd({ end, start })\n\n if (!isStartAndEndValid) return []\n\n const serviceIntervalSequence = serviceIntervalsGenerator({\n end,\n serviceHours,\n start,\n })\n\n // NOTE: when repeating and is complying to service hours we iterate through\n // all service intervals otherwise service interval is from the start and end\n const complyToServiceHours = includes(\n frequencyUnit,\n complyingServiceIntervalUnits\n )\n\n const serviceIntervals = complyToServiceHours\n ? [...serviceIntervalSequence]\n : [[start, end]]\n\n for (const serviceInterval of serviceIntervals) {\n yield { interval: serviceInterval, type: IntervalTypes.Service }\n\n const occurrenceIntervalsSequence = occurrenceIntervalsGenerator({\n isInitial,\n serviceInterval,\n strategy,\n timezone,\n })\n\n for (const occurrenceInterval of occurrenceIntervalsSequence) {\n yield { interval: occurrenceInterval, type: IntervalTypes.Occurrence }\n }\n\n // NOTE: we must reset isInitial to true following the first service\n // interval otherwise the occurrence will not start exactly on the next\n // service interval start time\n isInitial = true\n }\n}\n"],"file":"generateRepeatingSchedule.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/scheduling/scheduling.types.ts"],"names":["IntervalTypes","Unit","StrategyTypes"],"mappings":"AAEA,WAAYA,aAAZ;;WAAYA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;GAAAA,a,KAAAA,a;;AAKZ,WAAYC,IAAZ;;WAAYA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;GAAAA,I,KAAAA,I;;AAWZ,WAAYC,aAAZ;;WAAYA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;GAAAA,a,KAAAA,a","sourcesContent":["import { Schema as ServiceHoursSchema } from '../service-hours'\n\nexport enum IntervalTypes {\n Occurrence = 'occurrence',\n Service = 'service',\n}\n\nexport enum Unit {\n Millisecond = 'millisecond',\n Second = 'second',\n Minute = 'minute',\n Hour = 'hour',\n Day = 'day',\n Week = 'isoWeek',\n Month = 'month',\n Year = 'year',\n}\n\nexport enum StrategyTypes {\n ExactDateOfMonth = 'exactDateOfMonth',\n LastDayOfMonth = 'lastDayOfMonth',\n LastWeekdayOfMonth = 'lastWeekdayOfMonth',\n NoRepeat = 'noRepeat',\n Stopwatch = 'stopwatch',\n Weekdays = 'weekdays',\n Window = 'window',\n XDayOfXWeekOfMonth = 'xDayOfxWeekOfMonth',\n}\n\nexport interface GetNext {\n readonly end: number\n readonly isInitial?: boolean\n readonly options?: {\n date?: number\n dayOfWeek?: number\n duration: Period\n frequency: Period\n weekday?: number\n weekdays?: number[]\n weekOfMonth?: number\n }\n readonly start: number\n readonly timezone: string\n}\n\nexport interface Interval {\n readonly [index: number]: number\n}\n\nexport interface Period {\n readonly unit: Unit\n readonly value: number\n}\n\nexport interface ScheduleIntervalsGenerator {\n readonly end: number\n readonly isInitial: boolean\n readonly strategy: Strategy\n readonly serviceHours: ServiceHoursSchema\n readonly start: number\n}\n\nexport interface Strategy {\n readonly options: any\n readonly type: StrategyTypes\n}\n"],"file":"scheduling.types.js"}
1
+ {"version":3,"sources":["../../src/scheduling/scheduling.types.ts"],"names":["IntervalTypes","Unit","StrategyTypes"],"mappings":"AAEA,WAAYA,aAAZ;;WAAYA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;GAAAA,a,KAAAA,a;;AAKZ,WAAYC,IAAZ;;WAAYA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;AAAAA,EAAAA,I;GAAAA,I,KAAAA,I;;AAWZ,WAAYC,aAAZ;;WAAYA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;AAAAA,EAAAA,a;GAAAA,a,KAAAA,a","sourcesContent":["import { Schema as ServiceHoursSchema } from '../service-hours'\n\nexport enum IntervalTypes {\n Occurrence = 'occurrence',\n Service = 'service',\n}\n\nexport enum Unit {\n Millisecond = 'millisecond',\n Second = 'second',\n Minute = 'minute',\n Hour = 'hour',\n Day = 'day',\n Week = 'isoWeek',\n Month = 'month',\n Year = 'year',\n}\n\nexport enum StrategyTypes {\n ExactDateOfMonth = 'exactDateOfMonth',\n LastDayOfMonth = 'lastDayOfMonth',\n LastWeekdayOfMonth = 'lastWeekdayOfMonth',\n NoRepeat = 'noRepeat',\n Stopwatch = 'stopwatch',\n Weekdays = 'weekdays',\n Window = 'window',\n XDayOfXWeekOfMonth = 'xDayOfxWeekOfMonth',\n}\n\nexport interface Options {\n date?: number\n dayOfWeek?: number\n duration: Period\n frequency: Period\n weekday?: number\n weekdays?: number[]\n weekOfMonth?: number\n}\n\nexport interface GetNext {\n readonly end: number\n readonly isInitial?: boolean\n readonly options?: Options\n readonly start: number\n readonly timezone: string\n readonly type: StrategyTypes\n}\n\nexport interface Interval {\n readonly [index: number]: number\n}\n\nexport interface Period {\n readonly unit: Unit\n readonly value: number\n}\n\nexport interface ScheduleIntervalsGenerator {\n readonly end: number\n readonly isInitial: boolean\n readonly strategy: Strategy\n readonly serviceHours: ServiceHoursSchema\n readonly start: number\n}\n\nexport interface Strategy {\n readonly options: Options\n readonly type: StrategyTypes\n}\n"],"file":"scheduling.types.js"}
@@ -3,18 +3,18 @@ import _regeneratorRuntime from "@babel/runtime/regenerator";
3
3
  var _marked = /*#__PURE__*/_regeneratorRuntime.mark(getNext);
4
4
 
5
5
  import moment from 'moment-timezone';
6
- import { Unit } from '../scheduling.types';
6
+ import { StrategyTypes, Unit } from '../scheduling.types';
7
7
  /**
8
8
  * Generates next occurrence interval for stopwatch and window strategy
9
9
  */
10
10
 
11
11
  export function getNext(_ref) {
12
- var end, isInitial, options, start, timezone, duration, frequency, durationUnit, durationValue, frequencyUnit, frequencyValue, initial, dateCursor, nextOccurrenceEnd, nextOccurrenceStart, nextOccurrence;
12
+ var end, isInitial, options, start, timezone, type, duration, frequency, durationUnit, durationValue, frequencyUnit, frequencyValue, initial, dateCursor, nextOccurrenceStart, nextOccurrenceEnd, nextOccurrenceStartByBackCalculation, earliestNextOccurrenceStart, nextOccurrence;
13
13
  return _regeneratorRuntime.wrap(function getNext$(_context) {
14
14
  while (1) {
15
15
  switch (_context.prev = _context.next) {
16
16
  case 0:
17
- end = _ref.end, isInitial = _ref.isInitial, options = _ref.options, start = _ref.start, timezone = _ref.timezone;
17
+ end = _ref.end, isInitial = _ref.isInitial, options = _ref.options, start = _ref.start, timezone = _ref.timezone, type = _ref.type;
18
18
  duration = options.duration, frequency = options.frequency;
19
19
  durationUnit = duration.unit, durationValue = duration.value;
20
20
  frequencyUnit = frequency.unit, frequencyValue = frequency.value;
@@ -23,36 +23,49 @@ export function getNext(_ref) {
23
23
 
24
24
  case 6:
25
25
  if (!(dateCursor < end)) {
26
- _context.next = 18;
26
+ _context.next = 19;
27
27
  break;
28
28
  }
29
29
 
30
- nextOccurrenceEnd = moment.tz(dateCursor, timezone).add(frequencyValue, frequencyUnit).valueOf();
31
- nextOccurrenceStart = moment.tz(nextOccurrenceEnd, timezone).subtract(durationValue, durationUnit).valueOf();
30
+ nextOccurrenceStart = void 0;
31
+ nextOccurrenceEnd = void 0;
32
+
33
+ if (type === StrategyTypes.Stopwatch) {
34
+ nextOccurrenceStart = dateCursor;
35
+ nextOccurrenceEnd = moment.tz(dateCursor, timezone).add(durationValue, durationUnit).valueOf();
36
+ } else {
37
+ nextOccurrenceEnd = moment.tz(dateCursor, timezone).add(frequencyValue, frequencyUnit).valueOf();
38
+ nextOccurrenceStartByBackCalculation = moment.tz(nextOccurrenceEnd, timezone).subtract(durationValue, durationUnit);
39
+ earliestNextOccurrenceStart = moment.tz(dateCursor, timezone); // NOTE: this is to ensure that the next occurrence start is always
40
+ // greater than or equal to the date cursor. Moment js handles month addition and subtraction
41
+ // with estimations (Dec 31st + 2 months gives Feb 28th/29th). This can lead to inaccurate start times when calculating forwards then backwards at the end of the month.
42
+
43
+ nextOccurrenceStart = moment.max(earliestNextOccurrenceStart, nextOccurrenceStartByBackCalculation).valueOf();
44
+ }
32
45
 
33
46
  if (!(nextOccurrenceEnd <= nextOccurrenceStart || nextOccurrenceEnd > end)) {
34
- _context.next = 11;
47
+ _context.next = 12;
35
48
  break;
36
49
  }
37
50
 
38
51
  return _context.abrupt("return");
39
52
 
40
- case 11:
53
+ case 12:
41
54
  if (!(nextOccurrenceStart >= start)) {
42
- _context.next = 15;
55
+ _context.next = 16;
43
56
  break;
44
57
  }
45
58
 
46
59
  nextOccurrence = [nextOccurrenceStart, nextOccurrenceEnd - 1];
47
- _context.next = 15;
60
+ _context.next = 16;
48
61
  return nextOccurrence;
49
62
 
50
- case 15:
63
+ case 16:
51
64
  dateCursor = nextOccurrenceEnd;
52
65
  _context.next = 6;
53
66
  break;
54
67
 
55
- case 18:
68
+ case 19:
56
69
  case "end":
57
70
  return _context.stop();
58
71
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../../src/scheduling/strategies/getNext.ts"],"names":["getNext","moment","Unit","end","isInitial","options","start","timezone","duration","frequency","durationUnit","unit","durationValue","value","frequencyUnit","frequencyValue","initial","dateCursor","tz","valueOf","add","Millisecond","nextOccurrenceEnd","nextOccurrenceStart","subtract","nextOccurrence"],"mappings":";;oDAOiBA,O;;AAPjB,OAAOC,MAAP,MAAmB,iBAAnB;AAEA,SAA4BC,IAA5B,QAAwC,qBAAxC;AAEA;;;;AAGA,OAAO,SAAUF,OAAV;AAAA;AAAA;AAAA;AAAA;AAAA;AACLG,UAAAA,GADK,QACLA,GADK,EAELC,SAFK,QAELA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CApCtB;AAAA;AAsCD,iBAAMG,cAAN;;AAtCC;AAyCHR,UAAAA,UAAU,GAAGK,iBAAb;AAzCG;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["import moment from 'moment-timezone'\n\nimport { GetNext, Interval, Unit } from '../scheduling.types'\n\n/**\n * Generates next occurrence interval for stopwatch and window strategy\n */\nexport function* getNext({\n end,\n isInitial,\n options,\n start,\n timezone,\n}: GetNext): IterableIterator<Interval> {\n const { duration, frequency } = options\n const { unit: durationUnit, value: durationValue } = duration\n const { unit: frequencyUnit, value: frequencyValue } = frequency\n\n let initial: boolean = isInitial\n\n let dateCursor: number = initial\n ? moment.tz(start, timezone).valueOf()\n : moment\n .tz(start, timezone)\n .add(1, Unit.Millisecond)\n .valueOf()\n\n while (dateCursor < end) {\n const nextOccurrenceEnd = moment\n .tz(dateCursor, timezone)\n .add(frequencyValue, frequencyUnit)\n .valueOf()\n\n const nextOccurrenceStart = moment\n .tz(nextOccurrenceEnd, timezone)\n .subtract(durationValue, durationUnit)\n .valueOf()\n\n if (nextOccurrenceEnd <= nextOccurrenceStart || nextOccurrenceEnd > end) {\n return\n }\n\n if (nextOccurrenceStart >= start) {\n const nextOccurrence = [nextOccurrenceStart, nextOccurrenceEnd - 1]\n\n yield nextOccurrence\n }\n\n dateCursor = nextOccurrenceEnd\n }\n}\n"],"file":"getNext.js"}
1
+ {"version":3,"sources":["../../../src/scheduling/strategies/getNext.ts"],"names":["getNext","moment","StrategyTypes","Unit","end","isInitial","options","start","timezone","type","duration","frequency","durationUnit","unit","durationValue","value","frequencyUnit","frequencyValue","initial","dateCursor","tz","valueOf","add","Millisecond","nextOccurrenceStart","nextOccurrenceEnd","Stopwatch","nextOccurrenceStartByBackCalculation","subtract","earliestNextOccurrenceStart","max","nextOccurrence"],"mappings":";;oDAOiBA,O;;AAPjB,OAAOC,MAAP,MAAmB,iBAAnB;AAEA,SAA4BC,aAA5B,EAA2CC,IAA3C,QAAuD,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,EAEGD,aAFH,EAGjBK,OAHiB,EAApB;AAKMM,YAAAA,oCAND,GAMwC1B,MAAM,CAChDmB,EAD0C,CACvCK,iBADuC,EACpBjB,QADoB,EAE1CoB,QAF0C,CAEjCd,aAFiC,EAElBF,YAFkB,CANxC;AAUCiB,YAAAA,2BAVD,GAU+B5B,MAAM,CACvCmB,EADiC,CAC9BD,UAD8B,EAClBX,QADkB,CAV/B,EAaH;AACA;AACA;;AACFgB,YAAAA,mBAAmB,GACjBvB,MAAM,CAAC6B,GAAP,CACAD,2BADA,EAEAF,oCAFA,EAGAN,OAHA,EADF;AAKD;;AArDE,gBAwDCI,iBAAiB,IAAID,mBAArB,IAA4CC,iBAAiB,GAAGrB,GAxDjE;AAAA;AAAA;AAAA;;AAAA;;AAAA;AAAA,gBA4DCoB,mBAAmB,IAAIjB,KA5DxB;AAAA;AAAA;AAAA;;AA6DKwB,UAAAA,cA7DL,GA6DsB,CAACP,mBAAD,EAAsBC,iBAAiB,GAAG,CAA1C,CA7DtB;AAAA;AA+DD,iBAAMM,cAAN;;AA/DC;AAkEHZ,UAAAA,UAAU,GAAGM,iBAAb;AAlEG;AAAA;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["import moment from 'moment-timezone'\n\nimport { GetNext, Interval, StrategyTypes, Unit } from '../scheduling.types'\n\n/**\n * Generates next occurrence interval for stopwatch and window strategy\n */\nexport function* getNext({\n end,\n isInitial,\n options,\n start,\n timezone,\n type,\n}: GetNext): IterableIterator<Interval> {\n const { duration, frequency } = options\n const { unit: durationUnit, value: durationValue } = duration\n const { unit: frequencyUnit, value: frequencyValue } = frequency\n\n let initial: boolean = isInitial\n\n let dateCursor: number = initial\n ? moment.tz(start, timezone).valueOf()\n : moment\n .tz(start, timezone)\n .add(1, Unit.Millisecond)\n .valueOf()\n\n while (dateCursor < end) {\n let nextOccurrenceStart: number\n let nextOccurrenceEnd: number\n\n if (type === StrategyTypes.Stopwatch) {\n nextOccurrenceStart = dateCursor\n nextOccurrenceEnd = moment\n .tz(dateCursor, timezone)\n .add(durationValue, durationUnit)\n .valueOf()\n\n } else {\n nextOccurrenceEnd = moment\n .tz(dateCursor, timezone)\n .add(frequencyValue, frequencyUnit)\n .valueOf()\n\n const nextOccurrenceStartByBackCalculation = moment\n .tz(nextOccurrenceEnd, timezone)\n .subtract(durationValue, durationUnit)\n\n const earliestNextOccurrenceStart = moment\n .tz(dateCursor, timezone)\n\n // NOTE: this is to ensure that the next occurrence start is always\n // greater than or equal to the date cursor. Moment js handles month addition and subtraction\n // with estimations (Dec 31st + 2 months gives Feb 28th/29th). This can lead to inaccurate start times when calculating forwards then backwards at the end of the month.\n nextOccurrenceStart =\n moment.max(\n earliestNextOccurrenceStart,\n nextOccurrenceStartByBackCalculation\n ).valueOf()\n }\n\n\n if (nextOccurrenceEnd <= nextOccurrenceStart || nextOccurrenceEnd > end) {\n return\n }\n\n if (nextOccurrenceStart >= start) {\n const nextOccurrence = [nextOccurrenceStart, nextOccurrenceEnd - 1]\n\n yield nextOccurrence\n }\n\n dateCursor = nextOccurrenceEnd\n }\n}\n"],"file":"getNext.js"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lighthouse/common",
3
- "version": "4.31.1",
3
+ "version": "4.32.0",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "module": "lib/index.js",
package/mise.toml DELETED
@@ -1,3 +0,0 @@
1
- [tools]
2
- node = "16"
3
- python = "3.9"