fugit 1.4.1 → 1.5.0

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: e0c9e5123de2ba25d006290c43946a4028fc3467ec3f424bf57b23ce5c41cd65
4
- data.tar.gz: c9f6a5bdc8d40e7b6c585dca633066df98ff22b298c9158c333c54c2fbb2bab3
3
+ metadata.gz: ae056967c15463b2aed7a2839f383b9965968ae19414d214f37841ccabdeb7e5
4
+ data.tar.gz: 33ddf5842af78f3bba3a477800dfde053bee82cde318575f7c78d3e25df8e910
5
5
  SHA512:
6
- metadata.gz: 9135ff881b272674fb1768d2548efca04541f1aab790b04c6a9e060e172c722df7c73bd9dc98a221f7ab4e566b4600cb7e3f667ced5fbc92d7683667c7ab1c21
7
- data.tar.gz: 0f6e3113b06d2bc287a608f6215c3a902e3eedf410f6c83e5e7d9da79122b6562f9d400d3cf19f1cc45b662b72e1d740115aedf0502f9552e8af6bdb39db750f
6
+ metadata.gz: 13c7b00c76df998cac5c3ab8e754e7519b34c91c4653afa2da3d036d874c020ad10b34d596e20147f0d3c73e8b3904197896d0dd914b093e571d2e699df44632
7
+ data.tar.gz: 59422402187e49a0ffe1b53f4798f3cab4427aa734bad7cfac8eafdb001e08728a7577f7c5f83ad197a3eaa06007c3a871714ccc8036fca1cf6361a3ed9f7a23
data/CHANGELOG.md CHANGED
@@ -2,6 +2,34 @@
2
2
  # CHANGELOG.md
3
3
 
4
4
 
5
+ ## fugit 1.5.0 released 2021-06-08
6
+
7
+ * Accept "at 12 noon" and "at 12 midday" as "* 12 * * *", gh-57
8
+ * Accept "at 12pm" as "0 12 * * *", not "0 24 * * *", gh-57
9
+ * Accept "15/30 * * * *" as "15-59/30 * * * *", gh-56
10
+
11
+
12
+ ## fugit 1.4.5 released 2021-04-22
13
+
14
+ * Accept "* * * Mon%2+2", gh-47
15
+
16
+
17
+ ## fugit 1.4.4 released 2021-03-25
18
+
19
+ * Ensure leaving ZH DST is OK, gh-53
20
+
21
+
22
+ ## fugit 1.4.3 released 2021-03-23
23
+
24
+ * Fix entering DST issue, gh-53
25
+
26
+
27
+ ## fugit 1.4.2 released 2021-01-12
28
+
29
+ * Fix Fugit::Cron.previous_time vs last day of month, gh-51
30
+ * Let Fugit::Cron.parse('') return nil, gh-49
31
+
32
+
5
33
  ## fugit 1.4.1 released 2020-11-25
6
34
 
7
35
  * Suppress warning, gh-46, thanks @amatsuda
data/CREDITS.md CHANGED
@@ -1,13 +1,20 @@
1
1
 
2
2
  # fugit credits
3
3
 
4
+ * Khaled AbuShqear https://github.com/shqear93 gh-57, "12pm"
5
+ * John W Higgins https://github.com/wishdev gh-56, 15/30 cron decision
6
+ * Karen Sawrey https://github.com/karensawrey gh-47, Mon%2+1 rework idea
7
+ * Olle Jonsson https://github.com/olleolleolle gha Ruby 3.0
8
+ * Andy Pfister https://github.com/andyundso gh-53, entering DST
9
+ * Solteszad https://github.com/solteszad gh-51, fix previous_time vs last day of month
10
+ * Niklas https://github.com/gr8bit gh-49, Fugit::Cron.parse('')
4
11
  * Matsuda Akira https://github.com/amatsuda gh-46, warning suppression
5
12
  * Honglooker https://github.com/honglooker gh-43, New York cron skip
6
13
  * Jérôme Dalbert https://github.com/jeromedalbert gh-41, gh-42
7
14
  * Danny Ben Shitrit https://github.com/DannyBen nat variants, gh-38
8
15
  * Dominik Sander https://github.com/dsander #rough_frequency 0, gh-36
9
16
  * Milovan Zogovic https://github.com/assembler Cron#match? vs TZ, gh-31
10
- * Jessica Stokes https://github.com/ticky 0-24 issue with cron, gh-30
17
+ * Jessica Stokes https://github.com/ticky 0-24 issue with cron, gh-30 and gh-47
11
18
  * Shai Coleman https://github.com/shaicoleman parse_nat enhancements, gh-24, gh-25, gh-28, and gh-37
12
19
  * Jan Stevens https://github.com/JanStevens Fugit.parse('every 15 minutes') gh-22
13
20
  * Fabio Pitino https://github.com/hspazio nil on February 30 gh-21
data/LICENSE.txt CHANGED
@@ -1,5 +1,5 @@
1
1
 
2
- Copyright (c) 2017-2020, John Mettraux, jmettraux+flor@gmail.com
2
+ Copyright (c) 2017-2021, 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
@@ -1,7 +1,7 @@
1
1
 
2
2
  # fugit
3
3
 
4
- [![Build Status](https://secure.travis-ci.org/floraison/fugit.svg)](http://travis-ci.org/floraison/fugit)
4
+ [![tests](https://github.com/floraison/fugit/workflows/test/badge.svg)](https://github.com/floraison/fugit/actions)
5
5
  [![Gem Version](https://badge.fury.io/rb/fugit.svg)](http://badge.fury.io/rb/fugit)
6
6
  [![Join the chat at https://gitter.im/floraison/fugit](https://badges.gitter.im/floraison/fugit.svg)](https://gitter.im/floraison/fugit?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
7
7
 
@@ -138,6 +138,8 @@ Example of cron strings understood by fugit:
138
138
  # and more...
139
139
  ```
140
140
 
141
+ Please note that `'15/30 * * * *'` is interpreted as `'15-59/30 * * * *'` since fugit 1.4.6.
142
+
141
143
  ### the first Monday of the month
142
144
 
143
145
  Fugit tries to follow the `man 5 crontab` documentation.
@@ -203,8 +205,22 @@ p EtOrbi.parse('2019-01-01').rweek % 2 # => 1
203
205
  p EtOrbi.parse('2019-04-11').wday # => 4
204
206
  p EtOrbi.parse('2019-04-11').rweek # => 15
205
207
  p EtOrbi.parse('2019-04-11').rweek % 2 # => 1
208
+
209
+ c = Fugit.parse('* * * * tue%2')
210
+ c.match?('2019-01-01') # => false, since rweek % 2 == 1
211
+ c.match?('2019-01-08') # => true, since rweek % 2 == 0
212
+
213
+ c = Fugit.parse('* * * * tue%2+1')
214
+ c.match?('2019-01-01') # => true, since (rweek + 1) % 2 == 0
215
+ c.match?('2019-01-08') # => false, since (rweek + 1) % 2 == 1
216
+
217
+ # ...
206
218
  ```
207
219
 
220
+ `sun%2` matches if Sunday and `current_date.rweek % 2 == 0`
221
+ `tue%3+2` matches if Tuesday and `current_date.rweek + 2 % 3 == 0`
222
+ `tue%x+y` matches if Tuesday and `current_date.rweek + y % x == 0`
223
+
208
224
 
209
225
  ## `Fugit::Duration`
210
226
 
@@ -350,6 +366,10 @@ Fugit::Nat.parse('every day at 16:15 nada 18:30', multi: true)
350
366
 
351
367
  `multi: false` is the default behaviour, return a single `Fugit::Cron` instance or nil when it cannot parse.
352
368
 
369
+ ### Nat Midnight
370
+
371
+ `"Every day at midnight"` is supported, but `"Every monday at midnight"` will be interpreted (as of Fugit <= 1.4.x) as `"Every monday at 00:00"`. Sorry about that.
372
+
353
373
 
354
374
  ## LICENSE
355
375
 
data/lib/fugit.rb CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  module Fugit
4
4
 
5
- VERSION = '1.4.1'
5
+ VERSION = '1.5.0'
6
6
  end
7
7
 
8
8
  require 'time'
data/lib/fugit/cron.rb CHANGED
@@ -79,10 +79,7 @@ module Fugit
79
79
  %w[ year month day wday hour min sec wday_in_month rweek rday ]
80
80
  .collect(&:to_sym).each { |k| define_method(k) { @t.send(k) } }
81
81
 
82
- def inc(i)
83
- @t = @t + i
84
- self
85
- end
82
+ def inc(i); @t = @t + i; self; end
86
83
  def dec(i); inc(-i); end
87
84
 
88
85
  def inc_month
@@ -95,6 +92,8 @@ module Fugit
95
92
 
96
93
  def inc_day
97
94
  inc((24 - @t.hour) * 3600 - @t.min * 60 - @t.sec)
95
+ #inc( - @t.hour * 3600) if @t.hour != 0 # compensate for entering DST
96
+ inc( - @t.hour * 3600) if @t.hour > 0 && @t.hour < 7
98
97
  end
99
98
  def inc_hour
100
99
  inc((60 - @t.min) * 60 - @t.sec)
@@ -112,12 +111,7 @@ module Fugit
112
111
  end
113
112
 
114
113
  def dec_month
115
-
116
- #dec(@t.day * 24 * 3600 + @t.hour * 3600 + @t.min * 60 + @t.sec + 1)
117
- #
118
- # gh-18, so that '0 9 29 feb *' doesn't get skipped (over and over)
119
- #
120
- dec(@t.day * 24 * 3600 + 1)
114
+ dec((@t.day - 1) * DAY_S + @t.hour * 3600 + @t.min * 60 + @t.sec + 1)
121
115
  end
122
116
 
123
117
  def dec_day
@@ -156,7 +150,7 @@ module Fugit
156
150
 
157
151
  def weekday_modulo_match?(nt, mod)
158
152
 
159
- nt.rweek % mod[0] == mod[1]
153
+ (nt.rweek + mod[1]) % mod[0] == 0
160
154
  end
161
155
 
162
156
  def weekday_match?(nt)
@@ -337,7 +331,7 @@ module Fugit
337
331
  [ :seconds, 1, 60 ],
338
332
  [ :minutes, 60, 60 ],
339
333
  [ :hours, 3600, 24 ],
340
- [ :days, 24 * 3600, 365 ] ].freeze
334
+ [ :days, DAY_S, 365 ] ].freeze
341
335
 
342
336
  def rough_frequency
343
337
 
@@ -379,7 +373,7 @@ module Fugit
379
373
 
380
374
  @delta_min = deltas.min; @delta_max = deltas.max
381
375
  @occurrences = deltas.size
382
- @span_years = span / (365 * 24 * 3600)
376
+ @span_years = span / YEAR_S
383
377
  @yearly_occurrences = @occurrences.to_f / @span_years
384
378
  end
385
379
 
@@ -491,6 +485,8 @@ module Fugit
491
485
 
492
486
  sla = nil if sla == 1 # don't get fooled by /1
493
487
 
488
+ edn = max if sla && edn.nil?
489
+
494
490
  return [ nil ] if sta.nil? && edn.nil? && sla.nil?
495
491
  return [ sta ] if sta && edn.nil?
496
492
 
@@ -780,8 +776,12 @@ module Fugit
780
776
 
781
777
  def rewrite_cron(t)
782
778
 
783
- hcron = t
779
+ st = t
784
780
  .sublookup(nil) # go to :ccron or :scron
781
+
782
+ return nil unless st
783
+
784
+ hcron = st
785
785
  .subgather(nil) # list min, hou, mon, ...
786
786
  .inject({}) { |h, tt|
787
787
  h[tt.name] = tt.name == :tz ? rewrite_tz(tt) : rewrite_entry(tt)
@@ -61,10 +61,10 @@ module Fugit
61
61
  end
62
62
 
63
63
  KEYS = {
64
- yea: { a: 'Y', r: 'y', i: 'Y', s: 365 * 24 * 3600, x: 0, l: 'year' },
65
- mon: { a: 'M', r: 'M', i: 'M', s: 30 * 24 * 3600, x: 1, l: 'month' },
66
- wee: { a: 'W', r: 'w', i: 'W', s: 7 * 24 * 3600, I: true, l: 'week' },
67
- day: { a: 'D', r: 'd', i: 'D', s: 24 * 3600, I: true, l: 'day' },
64
+ yea: { a: 'Y', r: 'y', i: 'Y', s: YEAR_S, x: 0, l: 'year' },
65
+ mon: { a: 'M', r: 'M', i: 'M', s: 30 * DAY_S, x: 1, l: 'month' },
66
+ wee: { a: 'W', r: 'w', i: 'W', s: 7 * DAY_S, I: true, l: 'week' },
67
+ day: { a: 'D', r: 'd', i: 'D', s: DAY_S, I: true, l: 'day' },
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
data/lib/fugit/misc.rb CHANGED
@@ -2,6 +2,9 @@
2
2
 
3
3
  module Fugit
4
4
 
5
+ DAY_S = (24 * 3600).freeze
6
+ YEAR_S = (365 * DAY_S).freeze
7
+
5
8
  class << self
6
9
 
7
10
  def isostamp(show_date, show_time, show_usec, time)
data/lib/fugit/nat.rb CHANGED
@@ -201,7 +201,7 @@ module Fugit
201
201
  end
202
202
 
203
203
  def ampm(i)
204
- rex(:ampm, i, /[ \t]*(am|pm)/i)
204
+ rex(:ampm, i, /[ \t]*(am|pm|noon|midday|midnight)/i)
205
205
  end
206
206
  def dark(i)
207
207
  rex(:dark, i, /[ \t]*dark/i)
@@ -473,17 +473,21 @@ module Fugit
473
473
  slot(:monthday, "#{md0}-#{md1}")
474
474
  end
475
475
 
476
+ def adjust_h(h, ap)
477
+ h = h.to_i
478
+ ap = ap || ''
479
+ (h < 12 && ap == 'pm' || ap == 'midnight') ? h + 12 : h
480
+ end
481
+
476
482
  def rewrite_digital_hour(t)
477
483
  h, m, ap = t.strinpd.split(/[: \t]+/)
478
- h, m = h.to_i, m.to_i
479
- h += 12 if ap && ap == 'pm'
480
- slot(:hm, h.to_i, m.to_i)
484
+ h, m = adjust_h(h, ap), m.to_i
485
+ slot(:hm, h, m)
481
486
  end
482
487
 
483
488
  def rewrite_simple_hour(t)
484
489
  h, ap = t.subgather(nil).collect(&:strinpd)
485
- h = h.to_i
486
- h = h + 12 if ap == 'pm'
490
+ h = adjust_h(h, ap)
487
491
  slot(:hm, h, 0)
488
492
  end
489
493
 
@@ -500,7 +504,7 @@ module Fugit
500
504
  m = NMINUTES[m] || m
501
505
  #p [ 1, '-->', h, m ]
502
506
 
503
- h += 12 if h < 13 && apt && apt.strinpd == 'pm'
507
+ h = adjust_h(h, apt && apt.strinpd)
504
508
 
505
509
  slot(:hm, h, m)
506
510
  end
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.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-11-25 00:00:00.000000000 Z
11
+ date: 2021-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: raabro