diff --git a/src/expressionDescriptor.ts b/src/expressionDescriptor.ts index d05b391..c8b3d3c 100644 --- a/src/expressionDescriptor.ts +++ b/src/expressionDescriptor.ts @@ -315,9 +315,26 @@ export class ExpressionDescriptor { exp = exp.replace("L", ""); } + let parsedExp = parseInt(exp); + if (this.options.tzOffset) { + const hourExpression = this.expressionParts[2]; + let hour: number = parseInt(hourExpression) + (this.options.tzOffset ? this.options.tzOffset : 0); + if (hour >= 24) { + parsedExp++; + } else if (hour < 0) { + parsedExp--; + } + + if (parsedExp > 6) { + parsedExp = 0; + } else if (parsedExp < 0) { + parsedExp = 6; + } + } + let description = this.i18n.daysOfTheWeekInCase - ? this.i18n.daysOfTheWeekInCase(form)[parseInt(exp)] - : daysOfWeekNames[parseInt(exp)]; + ? this.i18n.daysOfTheWeekInCase(form)[parsedExp] + : daysOfWeekNames[parsedExp]; if (s.indexOf("#") > -1) { let dayOfWeekOfMonthDescription: string | null = null; diff --git a/test/cronstrue.ts b/test/cronstrue.ts index ab3e11c..3a5712c 100644 --- a/test/cronstrue.ts +++ b/test/cronstrue.ts @@ -187,6 +187,18 @@ describe("Cronstrue", function () { }), "At 03:30"); }); + it("5 1 * * 1", function () { + assert.equal(cronstrue.toString(this.test?.title as string,{ + tzOffset:-2, + }), "At 11:05 PM, only on Sunday"); + }); + + it("5 23 * * 1", function () { + assert.equal(cronstrue.toString(this.test?.title as string,{ + tzOffset:2, + }), "At 01:05 AM, only on Tuesday"); + }); + it("30 11 * * *", function () { assert.equal(cronstrue.toString(this.test?.title as string), "At 11:30 AM"); });