Skip to content

Commit

Permalink
Omit "every 1 days" and "every 1 months" text
Browse files Browse the repository at this point in the history
  • Loading branch information
bradymholt committed Jun 25, 2019
1 parent 3ebe1b6 commit b013556
Show file tree
Hide file tree
Showing 26 changed files with 28 additions and 137 deletions.
5 changes: 4 additions & 1 deletion src/cronParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,13 @@ export class CronParser {
}

protected normalize(expressionParts: string[]): void {
// Convert ? to * only for DOM and DOW
// Convert ? to * for DOM and DOW
expressionParts[3] = expressionParts[3].replace("?", "*");
expressionParts[5] = expressionParts[5].replace("?", "*");

// Convert ? to * for Hour. ? isn't valid for hour position but we can work around it.
expressionParts[2] = expressionParts[2].replace("?", "*");

// Convert 0/, 1/ to */
if (expressionParts[0].indexOf("0/") == 0) {
// Seconds
Expand Down
19 changes: 15 additions & 4 deletions src/expressionDescriptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,12 @@ export class ExpressionDescriptor {
return daysOfWeekNames[parseInt(exp)];
},
s => {
return StringUtilities.format(this.i18n.commaEveryX0DaysOfTheWeek(), s);
if (parseInt(s) == 1) {
// rather than "every 1 days" just return empty string
return "";
} else {
return StringUtilities.format(this.i18n.commaEveryX0DaysOfTheWeek(), s);
}
},
s => {
return this.i18n.commaX0ThroughX1();
Expand Down Expand Up @@ -340,7 +345,13 @@ export class ExpressionDescriptor {
return monthNames[parseInt(s) - 1];
},
s => {
return StringUtilities.format(this.i18n.commaEveryX0Months(), s);
//
if (parseInt(s) == 1) {
// rather than "every 1 months" just return empty string
return "";
} else {
return StringUtilities.format(this.i18n.commaEveryX0Months(), s);
}
},
s => {
return this.i18n.commaMonthX0ThroughMonthX1() || this.i18n.commaX0ThroughX1();
Expand Down Expand Up @@ -570,8 +581,8 @@ export class ExpressionDescriptor {

protected transformVerbosity(description: string, useVerboseFormat: boolean) {
if (!useVerboseFormat) {
description = description.replace(new RegExp(this.i18n.commaEveryMinute(), "g"), "");
description = description.replace(new RegExp(this.i18n.commaEveryHour(), "g"), "");
description = description.replace(new RegExp(`, ${this.i18n.everyMinute()}`, "g"), "");
description = description.replace(new RegExp(`, ${this.i18n.everyHour()}`, "g"), "");
description = description.replace(new RegExp(this.i18n.commaEveryDay(), "g"), "");
description = description.replace(/\, ?$/, "");
}
Expand Down
2 changes: 0 additions & 2 deletions src/i18n/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ export interface Locale {
commaEveryX0Days(): string;
commaBetweenDayX0AndX1OfTheMonth(): string;
commaOnDayX0OfTheMonth(): string;
commaEveryMinute(): string;
commaEveryHour(): string;
commaEveryX0Years(): string;
commaStartingX0(): string;
daysOfTheWeek(): string[];
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/cs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ export class cs implements Locale {
commaOnDayX0OfTheMonth() {
return ", %s. den v měsíci";
}
commaEveryMinute() {
return ", každou minutu";
}
commaEveryHour() {
return ", každou hodinu";
}
commaEveryX0Years() {
return ", každých %s roků";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/da.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ export class da implements Locale {
commaEveryDay() {
return ", hver dag";
}
commaEveryHour() {
return ", hver time";
}
commaEveryMinute() {
return ", hvert minut";
}
commaEveryX0Days() {
return ", hver %s. dag";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ export class de implements Locale {
commaOnDayX0OfTheMonth() {
return ", am %s Tag des Monats";
}
commaEveryMinute() {
return ", jede Minute";
}
commaEveryHour() {
return ", jede Stunde";
}
commaEveryX0Years() {
return ", alle %s Jahre";
}
Expand Down
3 changes: 0 additions & 3 deletions src/i18n/locales/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,6 @@ export class en implements Locale {
commaOnDayX0OfTheMonth() {
return ", on day %s of the month";
}
commaEveryMinute() {
return ", every minute";
}
commaEveryHour() {
return ", every hour";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ export class es implements Locale {
commaEveryDay() {
return ", cada día";
}
commaEveryHour() {
return ", cada hora";
}
commaEveryMinute() {
return ", cada minuto";
}
commaEveryX0Days() {
return ", cada %s días";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ export class fr implements Locale {
commaOnDayX0OfTheMonth() {
return ", le %s du mois";
}
commaEveryMinute() {
return ", toutes les minutes";
}
commaEveryHour() {
return ", toutes les heures";
}
commaEveryX0Years() {
return ", tous les %s ans";
}
Expand Down
8 changes: 1 addition & 7 deletions src/i18n/locales/he.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,12 +144,6 @@ export class he implements Locale {
commaOnDayX0OfTheMonth() {
return ", ביום ה%s של החודש";
}
commaEveryMinute() {
return ", כל דקה";
}
commaEveryHour() {
return ", כל שעה";
}
commaEveryX0Years() {
return ", כל %s שנים";
}
Expand All @@ -175,4 +169,4 @@ export class he implements Locale {
"דצמבר"
];
}
}
}
6 changes: 0 additions & 6 deletions src/i18n/locales/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,6 @@ export class it implements Locale {
commaEveryDay() {
return ", ogni giorno";
}
commaEveryHour() {
return ", ogni ora";
}
commaEveryMinute() {
return ", ogni minuto";
}
commaEveryX0Days() {
return ", ogni %s giorni";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/nb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ export class nb implements Locale {
commaEveryDay() {
return ", hver dag";
}
commaEveryHour() {
return ", hver time";
}
commaEveryMinute() {
return ", hvert minutt";
}
commaEveryX0Days() {
return ", hver %s dag";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ export class nl implements Locale {
commaOnDayX0OfTheMonth() {
return ", op dag %s van de maand";
}
commaEveryMinute() {
return ", elke minuut";
}
commaEveryHour() {
return ", elk uur";
}
commaEveryX0Years() {
return ", elke %s jaren";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ export class pl implements Locale {
commaEveryDay() {
return ", co dzień";
}
commaEveryHour() {
return ", co godzinę";
}
commaEveryMinute() {
return ", co minutę";
}
commaEveryX0Days() {
return ", co %s dni";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/pt_BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,6 @@ export class pt_BR implements Locale {
commaEveryDay() {
return ", a cada dia";
}
commaEveryHour() {
return ", a cada hora";
}
commaEveryMinute() {
return ", a cada minuto";
}
commaEveryX0Days() {
return ", a cada %s dias";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/ro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@ export class ro implements Locale {
commaEveryDay() {
return ", în fiecare zi";
}
commaEveryHour() {
return ", în fiecare oră";
}
commaEveryMinute() {
return ", în fiecare minut";
}
commaEveryX0Days() {
return ", la fiecare %s zile";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/ru.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ export class ru implements Locale {
commaOnDayX0OfTheMonth() {
return ", в %s число месяца";
}
commaEveryMinute() {
return ", каждую минуту";
}
commaEveryHour() {
return ", каждый час";
}
commaEveryX0Years() {
return ", каждые %s лет";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/sk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,6 @@ export class sk implements Locale {
commaOnDayX0OfTheMonth() {
return ", %s. deň v mesiaci";
}
commaEveryMinute() {
return ", každú minutu";
}
commaEveryHour() {
return ", každú hodinu";
}
commaEveryX0Years() {
return ", každých %s rokov";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/sl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,6 @@ export class sl implements Locale {
commaEveryDay() {
return ", vsak dan";
}
commaEveryHour() {
return ", vsako uro";
}
commaEveryMinute() {
return ", vsako minuto";
}
commaEveryX0Days() {
return ", vsakih %s dni";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/sv.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ export class sv implements Locale {
commaOnDayX0OfTheMonth() {
return ", på dag %s av månaden";
}
commaEveryMinute() {
return ", varje minut";
}
commaEveryHour() {
return ", varje timme";
}
commaEveryX0Years() {
return ", var %s år";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/sw.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,6 @@ export class sw implements Locale {
commaOnDayX0OfTheMonth() {
return ", siku ya %s ya mwezi";
}
commaEveryMinute() {
return ", kila dakika";
}
commaEveryHour() {
return ", kila saa";
}
commaEveryX0Years() {
return ", kila miaka %s";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/tr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ export class tr implements Locale {
commaOnDayX0OfTheMonth() {
return ", ayın %s. günü";
}
commaEveryMinute() {
return ", her dakika";
}
commaEveryHour() {
return ", her saat";
}
commaEveryX0Years() {
return ", %s yılda bir";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/uk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ export class uk implements Locale {
commaOnDayX0OfTheMonth() {
return ", на %s день місяця";
}
commaEveryMinute() {
return ", щохвилини";
}
commaEveryHour() {
return ", щогодини";
}
commaEveryX0Years() {
return ", кожні %s роки";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/zh_CN.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ export class zh_CN implements Locale {
commaOnDayX0OfTheMonth() {
return ", 每月的 %s 号";
}
commaEveryMinute() {
return ", 每分钟";
}
commaEveryHour() {
return ", 每小时";
}
commaEveryX0Years() {
return ", 每 %s 年";
}
Expand Down
6 changes: 0 additions & 6 deletions src/i18n/locales/zh_TW.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,6 @@ export class zh_TW implements Locale {
commaOnDayX0OfTheMonth() {
return ", 每月的 %s 號";
}
commaEveryMinute() {
return ", 每分鐘";
}
commaEveryHour() {
return ", 每小時";
}
commaEveryX0Years() {
return ", 每 %s 年";
}
Expand Down
8 changes: 8 additions & 0 deletions test/cronstrue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ describe("Cronstrue", function() {
it("0 9-17 * * *", function() {
assert.equal(construe.toString(this.test.title), "Every hour, between 09:00 AM and 05:59 PM");
});

it("0 * ? * 2/1 *", function() {
assert.equal(construe.toString(this.test.title), "Every minute, February through December");
});

it("0 * ? * 2/1", function() {
assert.equal(construe.toString(this.test.title), "Every hour, Tuesday through Saturday");
});
});

describe("ranges", function() {
Expand Down

0 comments on commit b013556

Please sign in to comment.