rufus-scheduler 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,6 +2,11 @@
2
2
  = rufus-scheduler CHANGELOG.txt
3
3
 
4
4
 
5
+ == rufus-scheduler - 1.0.3 released 2008/02/29
6
+
7
+ - todo #18472 : added Rufus::to_time_string - s181
8
+
9
+
5
10
  == rufus-scheduler - 1.0.2 released 2008/01/26
6
11
 
7
12
  - patch #17505 : added params :first_at and :first_in for schedule_every()
@@ -0,0 +1,8 @@
1
+
2
+ = CREDITS.txt
3
+
4
+ == Feedback
5
+
6
+ * many people gave feedback previously, see
7
+ http://openwferu.rubyforge.org/svn/trunk/openwfe-ruby/CREDITS.txt
8
+
data/README.txt CHANGED
@@ -17,7 +17,22 @@ http://rubyforge.org/frs/?group_id=4812
17
17
 
18
18
  == usage
19
19
 
20
- See the Rufus::Scheduler class rdoc itself or the original OpenWFEru scheduler documentation at http://openwferu.rubyforge.org/scheduler.html
20
+ For all the scheduling related information, see the Rufus::Scheduler class rdoc itself or the original OpenWFEru scheduler documentation at http://openwferu.rubyforge.org/scheduler.html
21
+
22
+ Apart from scheduling, There are also two interesting methods in this gem, they are named parse_time_string and to_time_string :
23
+
24
+ require 'rubygems'
25
+ require 'rufus/otime' # gem 'rufus_scheduler'
26
+
27
+ Rufus.parse_time_string "500" # => 0.5
28
+ Rufus.parse_time_string "1000" # => 1.0
29
+ Rufus.parse_time_string "1h" # => 3600.0
30
+ Rufus.parse_time_string "1h10s" # => 3610.0
31
+ Rufus.parse_time_string "1w2d" # => 777600.0
32
+
33
+ Rufus.to_time_string 60 # => '1m'
34
+ Rufus.to_time_string 3661 # => '1h1m1s'
35
+ Rufus.to_time_string 7 * 24 * 3600 # => '1w'
21
36
 
22
37
 
23
38
  == dependencies
@@ -97,7 +97,9 @@ module Rufus
97
97
  end
98
98
 
99
99
  #
100
- # turns a string like '1m10s' into a float like '70.0'
100
+ # Turns a string like '1m10s' into a float like '70.0', more formally,
101
+ # turns a time duration expressed as a string into a Float instance
102
+ # (millisecond count).
101
103
  #
102
104
  # w -> week
103
105
  # d -> day
@@ -108,6 +110,14 @@ module Rufus
108
110
  # y -> year
109
111
  # 'nada' -> millisecond
110
112
  #
113
+ # Some examples :
114
+ #
115
+ # Rufus.parse_time_string "500" # => 0.5
116
+ # Rufus.parse_time_string "1000" # => 1.0
117
+ # Rufus.parse_time_string "1h" # => 3600.0
118
+ # Rufus.parse_time_string "1h10s" # => 3610.0
119
+ # Rufus.parse_time_string "1w2d" # => 777600.0
120
+ #
111
121
  def Rufus.parse_time_string (string)
112
122
 
113
123
  string = string.strip
@@ -226,6 +236,64 @@ module Rufus
226
236
  Time.send(method, d.year, d.month, d.day, d.hour, d.min, d.sec, usec)
227
237
  end
228
238
 
239
+ #
240
+ # Turns a number of seconds into a a time string
241
+ #
242
+ # Rufus.to_time_string 0 # => '0s'
243
+ # Rufus.to_time_string 60 # => '1m'
244
+ # Rufus.to_time_string 3661 # => '1h1m1s'
245
+ # Rufus.to_time_string 7 * 24 * 3600 # => '1w'
246
+ # Rufus.to_time_string 30 * 24 * 3600 + 1 # => "4w2d1s"
247
+ #
248
+ # It goes from seconds to the year. Months are not counted (as they
249
+ # are of variable length). Weeks are counted.
250
+ #
251
+ # For 30 days months to be counted, the second parameter of this
252
+ # method can be set to true.
253
+ #
254
+ # Rufus.to_time_string 30 * 24 * 3600 + 1, true # => "1M1s"
255
+ #
256
+ # If a Float value is passed, milliseconds will be displayed without
257
+ # 'marker'
258
+ #
259
+ # Rufus.to_time_string 0.051 #=>"51"
260
+ # Rufus.to_time_string 7.051 #=>"7s51"
261
+ # Rufus.to_time_string 0.120 + 30 * 24 * 3600 + 1 #=>"4w2d1s120"
262
+ #
263
+ # (this behaviour mirrors the one found for parse_time_string()).
264
+ #
265
+ def Rufus.to_time_string (seconds, months=false)
266
+
267
+ return '0s' if seconds <= 0
268
+
269
+ ms = nil
270
+
271
+ if seconds.is_a?(Float)
272
+ ms = (seconds % 1 * 1000).to_i
273
+ seconds = seconds.to_i
274
+ end
275
+
276
+ durations = months ? DURATIONS2w : DURATIONS2
277
+
278
+ s = durations.inject([ seconds, "" ]) { |r, d|
279
+
280
+ #puts "result : " + r.inspect
281
+ #puts "duration : " + d.inspect
282
+
283
+ sec, str = r
284
+ s, d = d
285
+
286
+ count = sec / d
287
+ rest = sec % d
288
+
289
+ str << "#{count}#{s}" if count > 0
290
+
291
+ [ rest, str ]
292
+ }[1]
293
+
294
+ "#{s}#{ms}"
295
+ end
296
+
229
297
  protected
230
298
 
231
299
  DURATIONS = {
@@ -238,5 +306,17 @@ module Rufus
238
306
  "s" => 1
239
307
  }
240
308
 
309
+ DURATIONS2w = [
310
+ [ "y", DURATIONS["y"] ],
311
+ [ "M", DURATIONS["M"] ],
312
+ [ "w", DURATIONS["w"] ],
313
+ [ "d", DURATIONS["d"] ],
314
+ [ "h", DURATIONS["h"] ],
315
+ [ "m", DURATIONS["m"] ],
316
+ [ "s", DURATIONS["s"] ]
317
+ ]
318
+ DURATIONS2 = DURATIONS2w.dup
319
+ DURATIONS2.delete_at 1
320
+
241
321
  end
242
322
 
@@ -0,0 +1,51 @@
1
+
2
+ #
3
+ # Testing the 'rufus-scheduler'
4
+ #
5
+ # John Mettraux at openwfe.org
6
+ #
7
+ # Thu Feb 14 08:19:10 JST 2008
8
+ #
9
+
10
+ require 'test/unit'
11
+ require 'rufus/scheduler'
12
+
13
+
14
+ class Scheduler6Test < Test::Unit::TestCase
15
+
16
+ #def setup
17
+ #end
18
+
19
+ #def teardown
20
+ #end
21
+
22
+ #
23
+ # just a small test
24
+ #
25
+ def test_0
26
+
27
+ s = Rufus::Scheduler.new
28
+ s.start
29
+
30
+ st = ""
31
+ s0 = -1
32
+ s1 = -2
33
+
34
+ t = Time.now + 2
35
+
36
+ s.schedule_at t do
37
+ st << "0"
38
+ s0 = Time.now.to_i % 60
39
+ end
40
+ s.schedule_at t do
41
+ st << "1"
42
+ s1 = Time.now.to_i % 60
43
+ end
44
+
45
+ sleep 2.5
46
+
47
+ assert_equal "01", st
48
+ assert_equal s0, s1
49
+ end
50
+ end
51
+
@@ -1,5 +1,6 @@
1
1
 
2
- require 'time_test'
2
+ require 'time_0_test'
3
+ require 'time_1_test'
3
4
 
4
5
  require 'scheduler_0_test'
5
6
  require 'scheduler_1_test'
@@ -7,6 +8,7 @@ require 'scheduler_2_test'
7
8
  require 'scheduler_3_test'
8
9
  require 'scheduler_4_test'
9
10
  require 'scheduler_5_test'
11
+ require 'scheduler_6_test'
10
12
 
11
13
  require 'cron_test'
12
14
  require 'cronline_test'
@@ -12,10 +12,10 @@ require 'test/unit'
12
12
  require 'rufus/otime'
13
13
 
14
14
  #
15
- # testing otime and the scheduler
15
+ # testing otime
16
16
  #
17
17
 
18
- class TimeTest < Test::Unit::TestCase
18
+ class Time0Test < Test::Unit::TestCase
19
19
 
20
20
  #def setup
21
21
  #end
@@ -23,8 +23,7 @@ class TimeTest < Test::Unit::TestCase
23
23
  #def teardown
24
24
  #end
25
25
 
26
- #def test_to_iso_date
27
- def XXXX_to_iso_date
26
+ def _test_to_iso_date
28
27
  #
29
28
  # well... this test is not timezone friendly...
30
29
  # commented out thus...
@@ -34,17 +33,19 @@ class TimeTest < Test::Unit::TestCase
34
33
  s = Rufus.to_iso8601_date(t)
35
34
  puts s
36
35
 
37
- assert \
38
- Rufus.to_iso8601_date(t) == "2007-01-17 02:43:33-0500",
39
- "conversion to iso8601 date failed"
36
+ assert_equal(
37
+ "2007-01-17 02:43:33-0500",
38
+ Rufus.to_iso8601_date(t),
39
+ "conversion to iso8601 date failed")
40
40
 
41
41
  d = Rufus.to_ruby_time(s)
42
42
 
43
43
  #puts d.to_s
44
44
 
45
- assert \
46
- d.to_s == "2007-01-17T02:43:33-0500",
47
- "iso8601 date parsing failed"
45
+ assert_equal(
46
+ "2007-01-17T02:43:33-0500",
47
+ d.to_s,
48
+ "iso8601 date parsing failed")
48
49
  end
49
50
 
50
51
  def test_is_digit
@@ -66,19 +67,21 @@ class TimeTest < Test::Unit::TestCase
66
67
 
67
68
  def test_parse_time_string
68
69
 
69
- pts("500", 0.5)
70
- pts("1000", 1.0)
71
- pts("1h", 3600.0)
72
- pts("1h10s", 3610.0)
70
+ pts "500", 0.5
71
+ pts "1000", 1.0
72
+ pts "1h", 3600.0
73
+ pts "1h10s", 3610.0
74
+ pts "1w2d", 777600.0
73
75
  end
74
76
 
75
77
  protected
76
78
 
77
79
  def pts (time_string, seconds)
78
80
 
79
- assert \
80
- Rufus::parse_time_string(time_string) == seconds,
81
- "'#{time_string}' did not map to #{seconds} seconds"
81
+ assert_equal(
82
+ seconds,
83
+ Rufus::parse_time_string(time_string),
84
+ "'#{time_string}' did not map to #{seconds} seconds")
82
85
  end
83
86
 
84
87
  end
@@ -0,0 +1,58 @@
1
+
2
+ #
3
+ # Testing OpenWFE
4
+ #
5
+ # John Mettraux at openwfe.org
6
+ #
7
+ # Fri Feb 29 11:18:48 JST 2008
8
+ #
9
+
10
+ require 'test/unit'
11
+
12
+ require 'rufus/otime'
13
+
14
+ #
15
+ # testing otime
16
+ #
17
+
18
+ class Time1Test < Test::Unit::TestCase
19
+
20
+ #def setup
21
+ #end
22
+
23
+ #def teardown
24
+ #end
25
+
26
+ def test_0
27
+
28
+ tts 0, "0s"
29
+ tts 60, "1m"
30
+ tts 61, "1m1s"
31
+ tts 3661, "1h1m1s"
32
+ tts 24 * 3600, "1d"
33
+ tts 7 * 24 * 3600 + 1, "1w1s"
34
+ tts 30 * 24 * 3600 + 1, "4w2d1s"
35
+ end
36
+
37
+ def test_1
38
+
39
+ tts 30 * 24 * 3600 + 1, "1M1s", true
40
+ end
41
+
42
+ def test_2
43
+
44
+ tts 0.120 + 30 * 24 * 3600 + 1, "4w2d1s120"
45
+ tts 0.130, "130"
46
+ end
47
+
48
+ protected
49
+
50
+ def tts (seconds, time_string, months=false)
51
+
52
+ assert_equal(
53
+ time_string,
54
+ Rufus::to_time_string(seconds, months),
55
+ "#{seconds} seconds did not map to '#{time_string}'")
56
+ end
57
+
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rufus-scheduler
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Mettraux
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-01-26 00:00:00 +09:00
12
+ date: 2008-02-29 00:00:00 +09:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -22,6 +22,7 @@ extensions: []
22
22
  extra_rdoc_files:
23
23
  - README.txt
24
24
  - CHANGELOG.txt
25
+ - CREDITS.txt
25
26
  files:
26
27
  - lib/openwfe
27
28
  - lib/openwfe/util
@@ -37,10 +38,13 @@ files:
37
38
  - test/scheduler_3_test.rb
38
39
  - test/scheduler_4_test.rb
39
40
  - test/scheduler_5_test.rb
41
+ - test/scheduler_6_test.rb
40
42
  - test/test.rb
41
- - test/time_test.rb
43
+ - test/time_0_test.rb
44
+ - test/time_1_test.rb
42
45
  - README.txt
43
46
  - CHANGELOG.txt
47
+ - CREDITS.txt
44
48
  has_rdoc: true
45
49
  homepage: http://openwferu.rubyforge.org/scheduler.html
46
50
  post_install_message: