From 5e8d89604d167c1e51304419fc6f8ac4886dcc56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Mizi=C5=84ski?= Date: Thu, 28 Dec 2023 12:51:18 +0100 Subject: [PATCH] Bump to version 1.0.0 --- CHANGELOG.md | 7 ++++++- README.md | 16 ++++++++++++++++ lib/cron_calc.rb | 2 +- lib/cron_calc/version.rb | 2 +- 4 files changed, 24 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e5f9907..12c7a6e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [1.0.0] - 2023-12-28 + +- Add support for predefined definitions +- Add support for joining ,- + ## [0.4.0] - 2023-12-22 - Added support for named months and wdays @@ -5,7 +10,7 @@ ## [0.3.0] - 2023-12-22 -- Added support for DOWs +- Added support for DOWs (wdays) ## [0.2.0] - 2023-12-19 diff --git a/README.md b/README.md index 053fdc3..07e123a 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,22 @@ Calculates the last 'n' occurrences of the cron job until a given end time.\ # => [2023-12-31 05:05:00 +0100, 2023-12-30 05:05:00 +0100, 2023-12-29 05:05:00 +0100, 2023-12-28 05:05:00 +0100] ``` +### Other examples + +```ruby + # You can omit the count parameter + CronCalc.new('5 5 */5 * SUN').last(before: Time.new(2020, 1, 1, 0, 0)) + # => [2019-12-01 05:05:00 +0100] + + # You can combine ',' and '-' + CronCalc.new('5 5 5-7,10 FEB *').next(5) + # => [2024-02-05 05:05:00 +0100, 2024-02-06 05:05:00 +0100, 2024-02-07 05:05:00 +0100, 2024-02-10 05:05:00 +0100, 2025-02-05 05:05:00 +0100] + + # You can use predefined definitions like @daily, @monthly, etc. + CronCalc.new('@monthly').next(3, after: Time.new(2024, 1, 1, 0, 0)) + # => [2024-01-01 00:00:00 +0100, 2024-02-01 00:00:00 +0100, 2024-03-01 00:00:00 +0100] +``` + ## Contributing Bug reports and pull requests are welcome on GitHub at https://github.com/mizinsky/cron_calc. diff --git a/lib/cron_calc.rb b/lib/cron_calc.rb index 635afae..89b0ef0 100644 --- a/lib/cron_calc.rb +++ b/lib/cron_calc.rb @@ -154,7 +154,7 @@ def normalize_with(string, mapping) def cron_string_valid? predefined = /\A@(yearly|annually|monthly|weekly|daily|midnight|hourly)\z/ # rubocop:disable Layout/LineLength - standard = %r{\A(\*|(\*\/[0-5]?\d)|([0-5]?\d)(-(?:[0-5]?\d))?(,([0-5]?\d)(-(?:[0-5]?\d))?)*) (\*|(\*\/[01]?\d|2[0-3])|([01]?\d|2[0-3])(-(?:[01]?\d|2[0-3]))?(,([01]?\d|2[0-3])(-(?:[01]?\d|2[0-3]))?)*|(\*/\d+)) (\*|(\*\/[12]?\d|3[01])|([12]?\d|3[01])(-(?:[12]?\d|3[01]))?(,([12]?\d|3[01])(-(?:[12]?\d|3[01]))?)*|(\*/\d+)) (\*|(\*\/[1-9]|1[0-2])|(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|[1-9]|1[0-2])(-(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|[1-9]|1[0-2]))?(,(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|[1-9]|1[0-2])(-(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|[1-9]|1[0-2]))?)*|(\*/\d+)) (\*|(\*\/[0-6])|(SUN|MON|TUE|WED|THU|FRI|SAT|[0-6])(-(?:SUN|MON|TUE|WED|THU|FRI|SAT|[0-6]))?(,(SUN|MON|TUE|WED|THU|FRI|SAT|[0-6])(-(?:SUN|MON|TUE|WED|THU|FRI|SAT|[0-6]))?)*|(\*/[0-6]+))\z} + standard = %r{\A(\*|(\*/[0-5]?\d)|([0-5]?\d)(-(?:[0-5]?\d))?(,([0-5]?\d)(-(?:[0-5]?\d))?)*) (\*|(\*/[01]?\d|2[0-3])|([01]?\d|2[0-3])(-(?:[01]?\d|2[0-3]))?(,([01]?\d|2[0-3])(-(?:[01]?\d|2[0-3]))?)*|(\*/\d+)) (\*|(\*/[12]?\d|3[01])|([12]?\d|3[01])(-(?:[12]?\d|3[01]))?(,([12]?\d|3[01])(-(?:[12]?\d|3[01]))?)*|(\*/\d+)) (\*|(\*/[1-9]|1[0-2])|(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|[1-9]|1[0-2])(-(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|[1-9]|1[0-2]))?(,(JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|[1-9]|1[0-2])(-(?:JAN|FEB|MAR|APR|MAY|JUN|JUL|AUG|SEP|OCT|NOV|DEC|[1-9]|1[0-2]))?)*|(\*/\d+)) (\*|(\*/[0-6])|(SUN|MON|TUE|WED|THU|FRI|SAT|[0-6])(-(?:SUN|MON|TUE|WED|THU|FRI|SAT|[0-6]))?(,(SUN|MON|TUE|WED|THU|FRI|SAT|[0-6])(-(?:SUN|MON|TUE|WED|THU|FRI|SAT|[0-6]))?)*|(\*/[0-6]+))\z} # rubocop:enable Layout/LineLength cron_string.match?(predefined) || cron_string.match?(standard) end diff --git a/lib/cron_calc/version.rb b/lib/cron_calc/version.rb index 6cdfe21..2183b45 100644 --- a/lib/cron_calc/version.rb +++ b/lib/cron_calc/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module CronCalc - VERSION = '0.4.0' + VERSION = '1.0.0' end