nestjs / schedule

Schedule module for Nest framework (node.js) ⏰

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Month index (0-11) in cron expressions: Deliberated or Mistake

kb05 opened this issue · comments

I'm submitting a...


[ ] Regression 
[x] Bug report
[ ] Feature request
[x] Documentation issue or request
[ ] Support request => Please do not submit support request here, instead post your question on Stack Overflow.

The problem is related with the month index in cron expressions, in linux cron jobs the the month has a range between 1-12, being January the 1 and December the 12. But the @nestjs/schedule library seem like uses another format in which January is 0 and December is 11.

Is this deliberate or is it a mistake?

Current behavior

@Cron('0 12 11 1 *')

Configure a job that will be executed "At 12:00 on day-of-month 11 in February." instead january.

Expected behavior

The job will be executed in january.

Minimal reproduction of the problem with instructions

Configure a service that use the next cron:

@Cron('0 12 11 1 *', {
        name: 'test',
})
async testCron(){
        console.log('hi', new Date())
}

What is the motivation / use case for changing the behavior?

I was trying to make a job that would run every 3 months (before quarter ends), and I couldn't get it to work because in january, for example, I was using the index 1 instead 0.

Environment

# Dockerfile
ARG NODE_VERSION=14.15.1

FROM node:${NODE_VERSION}

ARG NESTJS_VERSION=7.5

WORKDIR /usr/src/project

# Install the required tools
RUN apt update;

RUN apt-get install nano;

RUN npm install -g nodemon

RUN npm install -g @nestjs/cli@${NESTJS_VERSION};

The objective of the issue is to check if this is the correct functioning, and if so, to document it.

Hi @kamilmysliwiec.

In the link that you passed me appears as a range of values 1-12, and I'm reporting that, that the library uses 0 to 11.

image

@kb05 You are right but I guess its not going to change since schedule depends on cron library which has
wrong range for month.

time js

This should be written in the doc.

@kamilmysliwiec the URL you have sent is wrong.

has wrong range for month.

isn't wrong, it's just how the month part of Date is encoded (0-based)

image

I suggest reporting this to node-cron side instead. I can't tell if they're translating those 1-12 to 0-11 or not.

On NestJS docs there is a mention tp that package, so I guess there's nothing to do on our side.

Thanks @micalevisk

Sure, are we talking about same cron lib since:
@kamilmysliwiec sent

https://github.com/node-cron/node-cron

but

@nestjs/schedule has dependency on

oh, then we should update the docs. PRs are more than welcomed

https://github.com/kelektiv/node-cron#cron-ranges

Sure, what repo?

image

https://docs.nestjs.com/techniques/task-scheduling

Change that node-cron to cron. The hyperlink is correct