cronstrue 3.29.0 → 3.31.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.
@@ -121,7 +121,7 @@ var CronParser = (function () {
121
121
  if (expressionParts[3].indexOf("1/") == 0) {
122
122
  expressionParts[3] = expressionParts[3].replace("1/", "*/");
123
123
  }
124
- if (expressionParts[4].indexOf("1/") == 0) {
124
+ if (!this.monthStartIndexZero && expressionParts[4].indexOf("1/") == 0) {
125
125
  expressionParts[4] = expressionParts[4].replace("1/", "*/");
126
126
  }
127
127
  if (expressionParts[6].indexOf("1/") == 0) {
@@ -146,8 +146,10 @@ var CronParser = (function () {
146
146
  if (expressionParts[3] == "?") {
147
147
  expressionParts[3] = "*";
148
148
  }
149
+ var weekdayOffsetRegex = /^\d{1,2}W[+-]\d{1,2}$/;
149
150
  if (expressionParts[3].indexOf("W") > -1 &&
150
- (expressionParts[3].indexOf(",") > -1 || expressionParts[3].indexOf("-") > -1)) {
151
+ (expressionParts[3].indexOf(",") > -1 || /[-+]/.test(expressionParts[3])) &&
152
+ !weekdayOffsetRegex.test(expressionParts[3])) {
151
153
  throw new Error("The 'W' character can be specified only when the day-of-month is a single day, not a range or list of days.");
152
154
  }
153
155
  var days = {
@@ -162,7 +164,7 @@ var CronParser = (function () {
162
164
  for (var day in days) {
163
165
  expressionParts[5] = expressionParts[5].replace(new RegExp(day, "gi"), days[day].toString());
164
166
  }
165
- expressionParts[4] = expressionParts[4].replace(/(^\d{1,2})|([^#/\s]\d{1,2})/g, function (t) {
167
+ expressionParts[4] = expressionParts[4].replace(/(^\d{1,2})|([^#/\s\d]\d{1,2})/g, function (t) {
166
168
  var dowDigits = t.replace(/\D/, "");
167
169
  var dowDigitsAdjusted = dowDigits;
168
170
  if (_this.monthStartIndexZero) {
@@ -233,7 +235,7 @@ var CronParser = (function () {
233
235
  this.validateOnlyExpectedCharactersFound(parsed[0], standardCronPartCharacters);
234
236
  this.validateOnlyExpectedCharactersFound(parsed[1], standardCronPartCharacters);
235
237
  this.validateOnlyExpectedCharactersFound(parsed[2], standardCronPartCharacters);
236
- this.validateOnlyExpectedCharactersFound(parsed[3], "0-9,\\-*\/LW");
238
+ this.validateOnlyExpectedCharactersFound(parsed[3].replace(/^(\d{1,2}W)[+-]\d{1,2}$/, "$1"), "0-9,\\-*\/LW");
237
239
  this.validateOnlyExpectedCharactersFound(parsed[4], standardCronPartCharacters);
238
240
  this.validateOnlyExpectedCharactersFound(parsed[5], "0-9,\\-*\/L#");
239
241
  this.validateOnlyExpectedCharactersFound(parsed[6], standardCronPartCharacters);
@@ -574,6 +576,7 @@ var ExpressionDescriptor = (function () {
574
576
  };
575
577
  ExpressionDescriptor.prototype.getDayOfMonthDescription = function () {
576
578
  var _this = this;
579
+ var _a, _b, _c, _d;
577
580
  var description = null;
578
581
  var expression = this.expressionParts[3];
579
582
  switch (expression) {
@@ -585,13 +588,22 @@ var ExpressionDescriptor = (function () {
585
588
  description = this.i18n.commaOnTheLastWeekdayOfTheMonth();
586
589
  break;
587
590
  default:
588
- var weekDayNumberMatches = expression.match(/(\d{1,2}W)|(W\d{1,2})/);
591
+ var weekDayNumberMatches = expression.match(/^(?:(\d{1,2})W|W(\d{1,2}))(?:([+-])(\d{1,2}))?$/);
589
592
  if (weekDayNumberMatches) {
590
- var dayNumber = parseInt(weekDayNumberMatches[0].replace("W", ""));
593
+ var dayNumber = parseInt(weekDayNumberMatches[1] || weekDayNumberMatches[2]);
591
594
  var dayString = dayNumber == 1
592
595
  ? this.i18n.firstWeekday()
593
596
  : stringUtilities_1.StringUtilities.format(this.i18n.weekdayNearestDayX0(), dayNumber.toString());
594
- description = stringUtilities_1.StringUtilities.format(this.i18n.commaOnTheX0OfTheMonth(), dayString);
597
+ var offsetDays = weekDayNumberMatches[4];
598
+ if (!offsetDays) {
599
+ description = stringUtilities_1.StringUtilities.format(this.i18n.commaOnTheX0OfTheMonth(), dayString);
600
+ }
601
+ else if (weekDayNumberMatches[3] == "-") {
602
+ description = stringUtilities_1.StringUtilities.format(((_b = (_a = this.i18n).commaDaysBeforeTheX0OfTheMonth) === null || _b === void 0 ? void 0 : _b.call(_a, offsetDays)) || ", %s days before the %s of the month", offsetDays, dayString);
603
+ }
604
+ else {
605
+ description = stringUtilities_1.StringUtilities.format(((_d = (_c = this.i18n).commaDaysAfterTheX0OfTheMonth) === null || _d === void 0 ? void 0 : _d.call(_c, offsetDays)) || ", %s days after the %s of the month", offsetDays, dayString);
606
+ }
595
607
  break;
596
608
  }
597
609
  else {
@@ -2893,6 +2905,12 @@ var en = (function () {
2893
2905
  en.prototype.commaOnTheX0OfTheMonth = function () {
2894
2906
  return ", on the %s of the month";
2895
2907
  };
2908
+ en.prototype.commaDaysBeforeTheX0OfTheMonth = function () {
2909
+ return ", %s days before the %s of the month";
2910
+ };
2911
+ en.prototype.commaDaysAfterTheX0OfTheMonth = function () {
2912
+ return ", %s days after the %s of the month";
2913
+ };
2896
2914
  en.prototype.commaEveryX0Days = function () {
2897
2915
  return ", every %s days in a month";
2898
2916
  };