Giter VIP home page Giter VIP logo

cronstrue's Introduction

Hi there 👋

My name is Brady. I’m a software developer by day and geek by night. Writing software is my profession, hobby, and passion. During the day, I am a developer at YNAB and at night I am usually spending time with my family or hacking on one of my many pet projects. You might catch me playing with TypeScript, PostgreSQL, Ruby, Node.js, Linux, C#, ASP.NET, SQL Server, Docker or the new shiny tech that just popped up.

cronstrue's People

Contributors

a33068843 avatar artigat1 avatar benzleung avatar bradymholt avatar dalex-am avatar danielgindi avatar dependabot[bot] avatar devxiaolan avatar fjbarrena avatar hanbar avatar hasanbasri1993 avatar khorevnikita avatar leyluj avatar marsibarsi avatar mduqueoviedo avatar metavige avatar mhemrg avatar mohamednehad450 avatar morfey13 avatar muhammad-magdi avatar mvniekerk avatar nioc avatar northber avatar randallreedjr avatar rikkapro0128 avatar seveves avatar tnsardesai avatar usingsky avatar wlribeiro avatar xeusteerapat avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

cronstrue's Issues

v1.54.0 Cannot find module 'cronstrue'.

Hi @bradymholt
Just connected your package to my Angular project!
npm install cronstrue

import { Component } from '@angular/core';
import cronstrue from 'cronstrue';

@Component({
    selector: 'my-app',
    template: `<router-outlet></router-outlet>`,
})
export class AppComponent implements OnInit {
    constructor() { }

  ngOnInit() {
     console.log('cronstrue', cronstrue.toString("* * * * *"));
  }
}

Error appears when building a project:
ERROR in src/app/app.component.ts(5,26): error TS2307: Cannot find module 'cronstrue'.

Can't load location file

I'm using type script with angular 5 and I'm importing like this:

import cronstrue from 'cronstrue';

It's hard to figure out where to load the locale file.

console.log(cronstrue.locales);

outputs the following:
{ en: {} }

So when I use the command like this:

this.cronText = cronstrue.toString("*/5 * * * *", { locale: 'pt_BR' });

Locale 'pt_BR' could not be found; falling back to 'en'.

There's no where to find out where to load files.

By the way, good application.

Bug parsing numeric day value

When using the examples provided by Quartz, it appears there's an issue with parsing the day values correctly.

Using an example from: https://www.quartz-scheduler.net/documentation/quartz-3.x/tutorial/crontrigger.html

Expression: "0 15 10 ? * 6L"
Result: "Fire at 10:15am on the last Friday of every month"

In cRonstrue the same expression results in:
"At 10:15 AM, on the last Saturday of the month".

Additionally, when testing an example from the Usage section, we get the same issue:
cronstrue.toString("* * * ? * 2-6/2", { dayOfWeekStartIndexZero: false });

"Every second, every 2 days of the week, Monday through Friday"

When parsing using 1.40.0, it returns " Every second, every 2 days of the week, Tuesday through Saturday"

Display hours in 24 format

Hello,
the library and its i18n features are very cool for non-english users. It could be even more nice if it could display hours on different format commonly used in other countries such as 23:55 instead of 11:55 PM. :)

Bug parsing minute range with interval

Version: 1.51.0
I found some unexpected output when parsing minute range with interval (eg: 1-20/3)

Examples:

  • Input: 0-20/3 9 * * *
  • Received: Every minute between 09:00 AM and 09:/3 AM
  • Expected: Every 3 minutes between 09:00 AM and 09:20 AM

Moreover, this still returns correct value:

  • Input: 0-20/3 9-9 * * *
  • Received: Every 3 minutes, minutes 0 through 20 past the hour, between 09:00 AM and 09:59 AM

Break out locales into own JS files for browser

Hey there, thanks for making this fantastic library! I'd like to conditionally load locales based on the user's settings so that those with slower connections don't have to wait for resources they don't need. So could you provide a separate js file per locale that automatically adds itself to the library once loaded? Would appreciate this very much!

named amd modules are not portable

AMD modules that are named are much less portable than anonymous AMD modules. Instead of forcing AMD users to use the name that is hardcoded it is best practice to not do this. Are you open to removing the named AMD module and instead allowing it to be anonymous?

DOW parse bug with dayOfWeekStartIndexZero = false

expressionParts[5] = expressionParts[5].replace(/(^\d)|([^#/\s]\d)+/g, (t) => {
regular expression should not contain +. Now it splits such string '1,2,3,4,5' into ['1', '2,3,4,5']
and this part dowDigitsAdjusted = (parseInt(dowDigits) - 1).toString(); makes 1 digit from 4 so
'1,2,3,4,5' becomes '1,2'

Failing when run on Node (error:window is not defined)

Getting "window is not defined"
at Object. (D:\Git\Src\App1\node_modules\cronstrue\dist\cronstrue.js:1:262)

Running this program in Node. Did not had a problem with earlier version (like 1.30.0). Is there some thing changed so that I should tell cronstrue to use Node and not Browser context?

--
One more problem in Typescript is not able to load types:
import * as cronstrue from "cronstrue"; -> resulted in error (saying error TS7016: Could not find a declaration file for module 'cronstrue'
This used to work earlier without any explicit type declarations.

So, used var cronstrue = require('cronstrue');

construe.toString("* * * * *"); // -> this resulted in 'windows is not defined" error.

Can you please advise?

Thanks, Praveen

Get the result as a `Date` object instead of a `string`

Hello 😄,

Thank you for your library, very helpful. I have a question though. Is it possible to get a Date object instead of a string? Looking at the code, it seems not, but it would be very interesting to compute a “next schedule in …” string. Thanks!

Extending or changing translation files

For example sometimes the German translation does not fit perfectly to our use case or is not as clear as our users would expect it ('At 8 o'clock' should be 'Daily at 8 o'clock' sometimes).
But I don't want to override the language files with some hacky webpack trick so maybe you/we could find a way to extend the API so it would be possible to change specific translations at runtime.

What do you think about this? Of course I would be pleased if I can help you with this 😸

The whole danish translation is missing? (locale:"da")

It states that you support danish (locale:"da") in the i18n release. But the cronstrue-i18n.min.js script can't find it (falling back to 'en')

Example: cronstrue.toString("0 12 1 * *", { use24HourTimeFormat:true, locale:"da" })

Only on undefined

Hi, thanks for this package, works great! Small issue:

$ node -e 'console.log(require("cronstrue").toString("* * * * MO"))'
Every minute, only on undefined
$ grep cronstrue yarn.lock 
cronstrue@^0.10.9:
  resolved "https://registry.yarnpkg.com/cronstrue/-/cronstrue-0.10.9.tgz#dd6a7f58b2619e3b0a6a1b35c10a7102c5fb73d8"

It would be nice if it would throw an error instead.

An hour of 08 or 09 results in aN in the ouput

Having an hours value of 08 or 09 produces aN in the hours portion of the result.

As an example: 00 08 * * 2
Produces: At aN:00 AM, only on Tuesday

What's odd is if I use the demo website you provide to test that statement it produces the correct result.

I am using cronstrue.min.js from 0.8.0 with this library to execute JS: org.mozilla.javascript

seconds expression combined with hours list with single minute

Thanks for fixing the previous issue.
However, with secondExpression added, there is still one case where it produces incorrect result

here:

description += this.formatTime(hourParts[i], minuteExpression, "");

hours list with single minute, it ignores the second part.

some test cases:

5 30 6,14,16 5 * *
*/20 30 6,14,16 5 * *
* 30 6,14,16 5 * *
0 30 6,14,16 5 * *

proposed fix:

+ if (!StringUtilities.containsAny(secondsExpression, ExpressionDescriptor.specialCharacters)) {

      //hours list with single minute (i.e. 30 6,14,16)
      let hourParts: string[] = hourExpression.split(",");
      description += this.i18n.at();

      for (let i = 0; i < hourParts.length; i++) {
        description += " ";
-        description += this.formatTime(hourParts[i], minuteExpression, "");
+        description += this.formatTime(hourParts[i], minuteExpression, secondsExpression || "");

        if (i < hourParts.length - 2) {
          description += ",";
        }

        if (i == hourParts.length - 2) {
          description += this.i18n.spaceAnd();
        }
      }
+ } else {
+      let secondDescription = this.getSecondsDescription();
+      description += secondDescription;
+      description += this.i18n.commaAt();
+      let hourParts: string[] = hourExpression.split(",");
+      for (let i = 0; i < hourParts.length; i++) {
+        description += " ";
+        description += this.formatTime(hourParts[i], minuteExpression, "");
+
+        if (i < hourParts.length - 2) {
+          description += ",";
+        }
+
+        if (i == hourParts.length - 2) {
+          description += this.i18n.spaceAnd();
+        }
+      }
 }

"only on" used incorrectly

Given:

0 * 31 * 1

Then the job will run:

Every hour, on day 31 of the month, and on Mondays

But cronstrue translates the cron expression instead as:

Every hour, on day 31 of the month, only on Monday

Reference from http://www.unixgeeks.org/security/newbie/unix/cron-1.html (itself referenced on https://en.wikipedia.org/wiki/Cron#References ):

If both the dom and dow are specified, the command will be executed when
either of the events happen.
e.g.

  • 12 16 * Mon root cmd
    Will run cmd at midday every Monday and every 16th, and will produce the
    same result as both of these entries put together would:
  • 12 16 * * root cmd
  • 12 * * Mon root cmd

Breaks on comma separated ranged values

Input

0 0 0-5/1,8-23/1 * * ?

Expected: Every hour between 12:00 AM and 5:59 AM, and every hour between 08:00 and 11:59 PM

Actual: Every 1,8-23 hours, between 12:00 AM and 05:59 AM


Many thanks for this library by the way, it is really fantastic and helpful.

Bower usage

Would it be possible for you to put this up on bower?

cronstrue not defined in window

Hello,

I add the scripts from the CDN and i check their status, after the 302 redirect i hav the 200 ok status code.
But when i try to use window.cronstrue, cronstrue is not defined.

<script src="https://unpkg.com/cronstrue@latest/dist/cronstrue.min.js" type="text/javascript"></script>
<script src="https://unpkg.com/cronstrue@latest/dist/cronstrue-i18n.min.js" type="text/javascript"></script>

Example implementation of i18n does not match reality

Hello,

I tried to implement the cronstrue package and use it which worked out fine but when I wanted to add the i18n language package i tried to use your example implementing only the minified js-file which didn't work as expected.

I found an old blog post from you were you used this example. This worked out fine:

// i18n support
var cronstrue_i18n = require('cronstrue/i18n');
console.log(cronstrue_i18n.toString("*/5 15 * * MON-FRI", { locale: "zh_CN" }));
> "每 5 分钟, 在 03:00 PM, 星期一 到 星期五"

Maybe this example should be present in your README ?

Anyways, thank you!

Error not thrown - when it should be?

Hi,
Great repo!!!
try to put this input:
0/q * * 1 2/w

you will get the following message:
Every q minutes, every w days of the week, Tuesday through Saturday, only in January

Isn't it a bad formatted input?

Spelling error

"fourth" is misspelled as "forth". As in "on the fourth of July"

Bug: not human readable

I got

> const cronstrue = require('cronstrue');
> cronstrue.toString('0 15 10 * * L')
'At 10:15 AM, on the last undefined of the month'

But Quartz specs says:

  • L (“last”) - has different meaning in each of the two fields in which it is allowed. For example, the value “L” in the day-of-month field means “the last day of the month” - day 31 for January, day 28 for February on non-leap years. If used in the day-of-week field by itself, it simply means “7” or “SAT”. But if used in the day-of-week field after another value, it means “the last xxx day of the month” - for example “6L” means “the last friday of the month”. When using the ‘L’ option, it is important not to specify lists, or ranges of values, as you’ll get confusing results.

Option to validate cron expression for exact 5/6/7 part

Thanks for the library. Its very helpful.

I have found one option missing and doing that validation on top of using cRonstrue.
In certain cases cron expression needs to be in exact 5 parts [ or 6 or 7] based on system you are passing cron expression to. Do you think its a good idea to add an option for this check in cRonstrue?

Let me know your thoughts. Happy to raise PR!

extra comma when minutes = 0

Example expressions with valid syntax, but have extra comma:

  • * 0 */4 * * * Every second, , every 4 hours
  • */10 0 * * * * Every 10 seconds,
  • * 0 0 * * * Every second, , at 00:00
  • * 0 * * * * Every second,

Comparing non-zero minute examples:

  • * 4 * * * * Every second, at 4 minutes past the hour
  • 0 1 * * * * At 1 minutes past the hour

One might expect to see something like
at 0 minutes past the hour
or maybe on the hour?

cRonstrue version 1.31.0

Cannot use module in Angular-CLI

I'm trying to integrate this into my Angular 2 project. I use the Angular-CLI (which under the covers is using webpack). When I install it from npm and use it, I get the following error:

Module '"C:/git/mporium.client/node_modules/cronstrue/dist/cronstrue"' resolves to a non-module entity and cannot be imported using this construct.

If I update the cronstrue.d.ts file to include default, then everything works fine:

import { ExpressionDescriptor } from "./expressionDescriptor";
export default ExpressionDescriptor;

Is this a change that can be made?

Correct Cron format returns 'undefined'

Hi,

I have an issue, when i insert probably correct cron format, but i get undefined value. Validation doesn't return an error. Is this a bug?

image

Thank you,
Kristjan

Script fails if 7 is used for Sunday instead of 0

In most cron implementation it is valid to represent Sunday as 0 or 7. For example 2-7 (for days of week) represents Tuesday through Sunday).

If an entry uses the 7 version of this syntax the script errors.

Using the execution engine I am using the error stack is this:

Javascript error:
org.mozilla.javascript.JavaScriptException: TypeError: Cannot call method "replace" of undefined (script#5)
at org.mozilla.javascript.gen.script_11._c_anonymous_11(script:5)
at org.mozilla.javascript.gen.script_11.call(script)
at org.mozilla.javascript.optimizer.OptRuntime.callProp0(OptRuntime.java:119)
at org.mozilla.javascript.gen.script_11._c_anonymous_9(script:5)
at org.mozilla.javascript.gen.script_11.call(script)
at org.mozilla.javascript.optimizer.OptRuntime.call2(OptRuntime.java:76)
at org.mozilla.javascript.gen.script_11._c_script_0(script:11)
at org.mozilla.javascript.gen.script_11.call(script)
at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3178)
at org.mozilla.javascript.gen.script_11.call(script)
at org.mozilla.javascript.gen.script_11.exec(script)

0 0 * * 0

Returns

At 00:00 AM, only on Sunday

00:00 AM is not a valid time, should be 12:00 AM

12-50 0-10 6 * * * 2022

Thank you for the awesome work! It has been of tremendous help, and I'm creating a MIT-licensed react component based on in.

It works very well for linux crontabs (5 segments), but when it comes to 7 segment crontabs, there is a bug

12-50 0-10 6 * * * 2022

produces

Every minute between 06:00 and 06:10, every day, only in 2022

But it shouldn't be every minute, should be 12-50 seconds

leading 0 not removed

Hi,

if there are leading '0' in the cron expression, I expect them to be removed in the description.

Ex: for the input*/000005 * * * *, it returns: Every 000005 minutes instead of Every 5 minutes

German translation for day-of-week repetition is misleading

I decided to open an issue to be able to track the problem discussed in f3da9d1 better.
As I said I looked into the translation and I think I am not in the position to find a good solution.
For now (and in my Use-Case) it would be preferable to revert the changes from #63, but as discussed by @seveves in #60 this is not the ultimate solution.

This may be a bit tricky in german overall, so I will give an example for the problem.
The cron-expression 0 0 12 ? * SUN * will read

Täglich um 12:00, nur am Sonntag

which translates to

Daily, at 12:00 PM, only on Sunday

Without localisation I get

At 12:00 PM, only on Sunday

which would in turn translate back to

Um 12:00, nur am Sonntag

which was the output before #60.
Of course, technically it is still correct, but as users may stop reading early, having the "Daily" up front would lead to misleading information

I do not know @seveves Use-Case but in my Use-Case this is not acceptable. I understand that "Um 12:00" ("At 12:00 PM") does not give any information on the daily repetition, but it is IMHO much preferable to the disaster in my example.

I think a better solution would be to put the daily-info after the time. Something like "At 12:00 PM, every Day" would be much preferable to "At 12:00 PM" but I know there are limitations on what info is to be displayed so we don't end up with "At 12:00 PM, every Day, every Month, any Year"

What is your opinion on the matter? I did not want to propose any changes until I know in which direction the libraries translation should be taken.

False positive with invalid syntax

How to reproduce the issue

cronstrue.toString("* * * * *123");
> "Every minute, only on undefined"

I would expect the validator to throw an error in this case

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.