fugit 1.7.2 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d28dc94bc31e025df55b67c79f2f59eed365940872e287479e788cb9023178dd
4
- data.tar.gz: 6f8d62b8d8921831a4de92d60a23c4cf83cfe79eea852c625744951156cb3d05
3
+ metadata.gz: b1839fa07acc6287be95f8076c19afa2c9d6c9b5500ac1b03febab61959b5057
4
+ data.tar.gz: 839ff5c0f85ccd51625febfdbfedd017e46962d288cf313307b706830dc838c9
5
5
  SHA512:
6
- metadata.gz: 3afc5fd6553abed3c73d7526e25b871ba0f5f26b8f415fccfec183b261e5ccb4e9f3fc6b176b550fa47de385f8991efe08936d2d96d6951a15dba81533f2ebcc
7
- data.tar.gz: e5cbdb64a9f6ee28e8f938c76dcdf44211ce751ca0dc1834d669b8494e40424fb7c5e8e98f7eb608e8855c29648b9c99e9faf06436ab05a795a87bffc771118c
6
+ metadata.gz: 5336bf251441fa3f7372d48aec2196cf86831b24c64110955f2ccf2df2e6e1ec84a68b318b53be8282f87794f40c09778bddd47abec3f65fe1469544a758fabb
7
+ data.tar.gz: 0fdd70455097838c21c3f03c9dca20889b4aba07f67d790136e40be2d8686b0a6ad8a594fff1fe28e7cd4d322ad66a8a31aa71750cd435c7601345487ae89bdb
data/CHANGELOG.md CHANGED
@@ -2,6 +2,17 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## fugit 1.8.1 released 2023-01-20
6
+
7
+ * Fix for month subtraction, gh-84, @mreinsch
8
+ * Fix duration - time, gh-85, @mreinsch
9
+
10
+
11
+ ## fugit 1.8.0 released 2022-12-06
12
+
13
+ * Introduce Fugit.parse_cronish and .do_parse_cronish, gh-70
14
+
15
+
5
16
  ## fugit 1.7.2 released 2022-11-03
6
17
 
7
18
  * Fix 'every day at 12:15 am', gh-81
data/CREDITS.md CHANGED
@@ -1,6 +1,8 @@
1
1
 
2
2
  # fugit credits
3
3
 
4
+ * Michael Reinsch, https://github.com/mreinsch, gh-84 and gh-85
5
+ * Marc Anguera, https://github.com/markets, gh-70 and Sidekiq-Cron
4
6
  * ski-nine, https://github.com/ski-nine, gh-81
5
7
  * Joseph Halter, https://github.com/JosephHalter, gh-79
6
8
  * James Healy, https://github.com/yob, gh-76
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2017-2022, John Mettraux, jmettraux+flor@gmail.com
2
+ Copyright (c) 2017-2023, John Mettraux, jmettraux+flor@gmail.com
3
3
 
4
4
  Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -89,6 +89,25 @@ Fugit.parse_nat('every day at noon').class # ==> ::Fugit::Cron
89
89
 
90
90
  As `Fugit.parse(s)` returns nil when it doesn't grok its input, and `Fugit.do_parse(s)` fails when it doesn't grok, each of the `parse_` methods has its partner `do_parse_` method.
91
91
 
92
+ ## parse_cronish and do_parse_cronish
93
+
94
+ Sometimes you know a cron expression or an "every" natural expression will come in and you want to discard the rest.
95
+
96
+ ```
97
+ require 'fugit'
98
+
99
+ Fugit.parse_cronish('0 0 1 jan *').class # ==> ::Fugit::Cron
100
+ Fugit.parse_cronish('every saturday at noon').class # ==> ::Fugit::Cron
101
+
102
+ Fugit.parse_cronish('12y12M') # ==> nil
103
+ ```
104
+
105
+ `.parse_cronish(s)` will return a `Fugit::Cron` instance or else nil.
106
+
107
+ `.do_parse_cronish(s)` will return a `Fugit::Cron` instance or else fail with an `ArgumentError`.
108
+
109
+ Introduced in fugit 1.8.0.
110
+
92
111
  ## `Fugit::Cron`
93
112
 
94
113
  A class `Fugit::Cron` to parse cron strings and then `#next_time` and `#previous_time` to compute the next or the previous occurrence respectively.
@@ -68,8 +68,10 @@ module Fugit
68
68
  hou: { a: 'h', r: 'h', i: 'H', s: 3600, I: true, l: 'hour' },
69
69
  min: { a: 'm', r: 'm', i: 'M', s: 60, I: true, l: 'minute' },
70
70
  sec: { a: 's', r: 's', i: 'S', s: 1, I: true, l: 'second' } }.freeze
71
- INFLA_KEYS, NON_INFLA_KEYS =
72
- KEYS.partition { |k, v| v[:I] }.freeze
71
+
72
+ INFLA_KEYS, NON_INFLA_KEYS = KEYS
73
+ .partition { |k, v| v[:I] }
74
+ .collect(&:freeze)
73
75
 
74
76
  def _to_s(key)
75
77
 
@@ -240,7 +242,7 @@ module Fugit
240
242
  n, m = at[1] / 12, at[1] % 12
241
243
  at[0], at[1] = at[0] + n, m
242
244
  elsif at[1] < 1
243
- n, m = -at[1] / 12, -at[1] % 12
245
+ n, m = (-at[1]) / 12 + 1, (11+at[1]) % 12 + 1
244
246
  at[0], at[1] = at[0] - n, m
245
247
  end
246
248
 
@@ -269,7 +271,7 @@ module Fugit
269
271
  when Numeric then add_numeric(-a)
270
272
  when Fugit::Duration then add_duration(-a)
271
273
  when String then add_duration(-self.class.parse(a))
272
- when ::Time, ::EtOrbi::EoTime then add_to_time(a)
274
+ when ::Time, ::EtOrbi::EoTime then opposite.add_to_time(a)
273
275
  else fail ArgumentError.new(
274
276
  "cannot subtract #{a.class} instance to a Fugit::Duration")
275
277
  end
data/lib/fugit/parse.rb CHANGED
@@ -33,6 +33,19 @@ module Fugit
33
33
  fail(ArgumentError.new("found no time information in #{s.inspect}"))
34
34
  end
35
35
 
36
+ def parse_cronish(s, opts={})
37
+
38
+ r = parse_cron(s) || parse_nat(s, opts)
39
+
40
+ r.is_a?(::Fugit::Cron) ? r : nil
41
+ end
42
+
43
+ def do_parse_cronish(s, opts={})
44
+
45
+ parse_cronish(s) ||
46
+ fail(ArgumentError.new("not cron or 'natural' cron string: #{s.inspect}"))
47
+ end
48
+
36
49
  def determine_type(s)
37
50
 
38
51
  case self.parse(s)
data/lib/fugit.rb CHANGED
@@ -3,7 +3,7 @@
3
3
 
4
4
  module Fugit
5
5
 
6
- VERSION = '1.7.2'
6
+ VERSION = '1.8.1'
7
7
  end
8
8
 
9
9
  require 'time'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fugit
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.2
4
+ version: 1.8.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-11-03 00:00:00.000000000 Z
11
+ date: 2023-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: raabro