runt 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,132 @@
1
+
2
+ body {
3
+ color:#333;
4
+ background-color:#CCCCCC;
5
+ margin:20px;
6
+ padding:0px;
7
+ font:11px verdana, arial, helvetica, sans-serif;
8
+ }
9
+ h1 {
10
+ margin:0px 0px 15px 0px;
11
+ padding:0px;
12
+ font-size:14px;
13
+ font-weight:900;
14
+ color:#ccc;
15
+ }
16
+ h2 {
17
+ font:bold 12px/14px verdana, arial, helvetica, sans-serif;
18
+ margin:0px 0px 5px 0px;
19
+ padding:0px;
20
+ }
21
+ p {
22
+ font:11px/20px verdana, arial, helvetica, sans-serif;
23
+ margin:0px 0px 16px 0px;
24
+ padding:0px;
25
+ }
26
+ .Content>p {margin:0px;}
27
+ .Content>p+p {text-indent:30px;}
28
+
29
+ a {
30
+ color:#09c;
31
+ font-size:11px;
32
+ font-family:verdana, arial, helvetica, sans-serif;
33
+ font-weight:600;
34
+ text-decoration:none;
35
+ }
36
+ a:link {color:#09c;}
37
+ a:visited {color:#07a;}
38
+ a:hover {background-color:#eee;}
39
+
40
+
41
+ /* All the content boxes belong to the content class. */
42
+ .content {
43
+ position:relative; /* Position is declared "relative" to gain control of stacking order (z-index). */
44
+ width:auto;
45
+ min-width:120px;
46
+ margin:0px 210px 20px 170px;
47
+ border:1px solid black;
48
+ background-color:white;
49
+ padding:10px;
50
+ z-index:3; /* This allows the content to overlap the right menu in narrow windows in good browsers. */
51
+ }
52
+
53
+ /* 2004-03-12 MSL */
54
+ .ruby-link {
55
+ color: rgb(255, 0, 0);
56
+ }
57
+
58
+ .keyword {
59
+ font-weight:bold;
60
+ }
61
+
62
+
63
+ #navAlpha {
64
+ position:absolute;
65
+ width:150px;
66
+ top:20px;
67
+ left:20px;
68
+ border:1px dashed black;
69
+ background-color:#eee;
70
+ padding:10px;
71
+ z-index:2;
72
+
73
+ /* Here is the ugly brilliant hack that protects IE5/Win from its own stupidity.
74
+ Thanks to Tantek Celik for the hack and to Eric Costello for publicizing it.
75
+ IE5/Win incorrectly parses the "\"}"" value, prematurely closing the style
76
+ declaration. The incorrect IE5/Win value is above, while the correct value is
77
+ below. See http://glish.com/css/hacks.asp for details. */
78
+ voice-family: "\"}\"";
79
+ voice-family:inherit;
80
+ width:128px;
81
+ }
82
+ /* I've heard this called the "be nice to Opera 5" rule. Basically, it feeds correct
83
+ length values to user agents that exhibit the parsing error exploited above yet get
84
+ the CSS box model right and understand the CSS2 parent-child selector. ALWAYS include
85
+ a "be nice to Opera 5" rule every time you use the Tantek Celik hack (above). */
86
+ body>#navAlpha {width:128px;}
87
+
88
+ #navBeta {
89
+ position:absolute;
90
+ width:190px;
91
+ top:20px;
92
+ right:20px;
93
+ border:1px dashed black;
94
+ background-color:#eee;
95
+ padding:10px;
96
+ z-index:1;
97
+ /* Again, the ugly brilliant hack. */
98
+ voice-family: "\"}\"";
99
+ voice-family:inherit;
100
+ width:168px;
101
+ }
102
+ /* Again, "be nice to Opera 5". */
103
+ body>#navBeta {width:168px;}
104
+
105
+ /* 2004-03-12 MSL */
106
+
107
+ #contentFooter {
108
+ text-align: center;
109
+ font-size:10px;
110
+ }
111
+
112
+ #contentFooter a {
113
+ font-size:10px;
114
+ }
115
+
116
+
117
+ #logo {
118
+ border: 0px solid ;
119
+ width: 97px;
120
+ height: 33px;
121
+ vertical-align: -50%;
122
+ }
123
+
124
+
125
+ #dcl-logo {
126
+ border: 0px solid ;
127
+ width: 140px;
128
+ height: 29px;
129
+ vertical-align: -110%;
130
+ margin: 2px;
131
+ }
132
+
Binary file
data/site/index.html ADDED
@@ -0,0 +1,92 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2
+ "http://www.w3.org/TR/html4/strict.dtd">
3
+
4
+ <html>
5
+ <head>
6
+ <title>Runt - Ruby Temporal Expressions</title>
7
+ <style type="text/css" media="screen">@import "blue-robot3.css";</style>
8
+
9
+ </head>
10
+
11
+ <body>
12
+
13
+ <div class="content">
14
+ <h1><a href="http://runt.rubyforge.org"><img id="logo" src="runt-logo.gif" title="Choose your own damn acronym" alt="runt logo"></a>Ruby Temporal Expressions</h1>
15
+ <p><span class="keyword">Runt</span> is an implementation of select temporal patterns by <a href="http://www.martinfowler.com">Martin Fowler</a> in the super-fantastic <a href="http://ruby-lang.org"><span class="ruby-link">Ruby</span></a> language.
16
+ <span class="keyword">Runt</span> provides:
17
+ <ul>
18
+ <li>ability to define recurring events using simple, set-like expressions</li>
19
+ <li>an interfaced-based API for creating schedules for arbitrary events/objects</li>
20
+ <li>precisioned date types using <a href="http://martinfowler.com/ap2/timePoint.html">Time Point</a>s</li>
21
+ <li>date <a href="http://martinfowler.com/ap2/range.html">Range</a>s</li>
22
+ <li>everlasting peace and/or eternal life</li>
23
+ </ul>
24
+ </p>
25
+ <p>Visit our <a href="http://rubyforge.org/projects/runt/">project page</a> provided by the generous folks at <a href="http://rubyforge.org">Rubyforge</a>.</p>
26
+ </div>
27
+
28
+ <div class="content">
29
+
30
+ <h2>Known Issues</h2>
31
+ <p>
32
+ <ul>
33
+ <li>We are still learning <a href="http://ruby-lang.org"><span class="ruby-link">Ruby</span></a>. So far, this has been a distinctly painless experience.</li>
34
+ <li>Supposedly, this page looks nasty in IE4.5/Mac.</li>
35
+ </ul>
36
+ </p>
37
+ <h2>Credits</h2>
38
+ <p>
39
+ <ul>
40
+ <li><a href="http://rubyforge.org">Rubyforge</a> for hosting this project</li>
41
+ <li>
42
+ <a href="http://martinfowler.com">M.Fowler</a>,<a href="http://ruby-lang.org">Matz</a>,
43
+ T.Funaba(<a href="http://www.funaba.org/en/ruby.html">Date/DateTime</a>),
44
+ <a href="mailto:ruby-talk@ruby-lang.org">ruby-talk</a>,
45
+ <a href="http://pragmaticprogrammer.com">PragProgs</a>,
46
+ J.Weirich(<a href="http://rake.rubyforge.org">Rake</a>), Hal Fulton, Mauricio Fernandez, and
47
+ Mark Hubbart for the <a href="http://blade.nagaokaut.ac.jp/cgi-bin/scat.rb/ruby/ruby-talk/95465">thread</a> on c.l.r. that
48
+ inspired a more Ruby-esque syntax for creating TE's. 2X Thanks to Hal, for taking the time to exchange
49
+ ideas off-line.
50
+ </li>
51
+ <li><a href="http://www.bluerobot.com/web/layouts/">Blue Robot</a> for the CSS</li>
52
+ </ul>
53
+ </p>
54
+ </div>
55
+
56
+ <div id="contentFooter" class="content">
57
+ <a href="http://www.digitalclash.com">&lt;&lt;<img id="dcl-logo" src="dcl-small.gif" title="Digital Clash LLC" alt="Digital Clash logo">&copy;2004, Digital Clash LLC&gt;&gt;</a>
58
+ <br/><i>&quot;The weather is here, wish you were beautiful...&quot;</i>
59
+ </div>
60
+
61
+ <div id="navAlpha">
62
+ <h2>Links</h2>
63
+ <p>
64
+ <a href="http://rubyforge.org/projects/runt/" title="Download Runt">Download</a><br>
65
+ <a href="./doc/index.html" title="RDoc for Runt">RDocs</a><br>
66
+ <a href="./doc/files/doc/tutorial_te_rdoc.html" title="TE Tutorial">Tutorial</a><br>
67
+ <a href="./doc/files/README.html">README</a><br/>
68
+ <a href="./doc/files/TODO.html">TODO</a><br/>
69
+ <a href="./doc/files/CHANGES.html">CHANGES</a><br/>
70
+ ----<br/>
71
+ <a href="http://ChronicJ.org/" title="ChronicJ project">ChronicJ</a><br>
72
+ </p>
73
+ </div>
74
+
75
+ <div id="navBeta">
76
+ <h2>Suggested Reading</h2>
77
+ <p>Most of the usage and design patterns contained in this library are based on a series of articles by Martin Fowler. Some suggested reading:</p>
78
+ <p>
79
+ <a href="http://martinfowler.com/ap2/timeNarrative.html">Time Narrative</a><br/>
80
+ <a href="http://martinfowler.com/apsupp/recurring.pdf">Recurring Events</a><br/>
81
+ <a href="http://martinfowler.com/ap2/timePoint.html">Time Point</a><br/>
82
+ <a href="http://martinfowler.com/ap2/range.html">Range</a><br/>
83
+ ----<br/>
84
+ <p><span class="keyword">Runt</span> was originally hacked in Java. Documentation for that project may also be helpful:</p>
85
+ <a href="http://www.chronicj.org/apidocs/index.html" title="ChronicJ project">ChronicJ JavaDocs</a><br>
86
+ </p>
87
+ </div>
88
+
89
+ <!-- BlueRobot was here. -->
90
+
91
+ </body>
92
+ </html>
Binary file
Binary file
Binary file
data/test/alltests.rb ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:<<'../lib'
4
+
5
+ # All Runt unit tests
6
+ #
7
+ # Author:: Matthew Lipper
8
+ require 'dprecisiontest'
9
+ require 'temporalexpressiontest'
10
+ require 'pdatetest'
11
+ require 'scheduletest'
12
+ require 'daterangetest'
@@ -0,0 +1,82 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:<<'../lib'
4
+
5
+ require 'test/unit'
6
+ require 'runt'
7
+ require 'date'
8
+
9
+ # Unit tests for DateRange class
10
+ #
11
+ # Author:: Matthew Lipper
12
+ class DateRangeTest < Test::Unit::TestCase
13
+
14
+ include Runt
15
+
16
+ def test_sub_range
17
+ r_start = PDate.sec(2004,2,29,16,24,12)
18
+ r_end = PDate.sec(2004,3,2,4,22,58)
19
+ range = DateRange.new(r_start,r_end)
20
+ assert(range.min==r_start)
21
+ assert(range.max==r_end)
22
+ assert(range.include?(r_start+1))
23
+ assert(range.include?(r_end-1))
24
+ sub_range = DateRange.new((r_start+1),(r_end-1))
25
+ assert(range.include?(sub_range))
26
+ end
27
+
28
+ def test_date
29
+ r_start = PDate.min(1979,12,31,23,57)
30
+ r_end = PDate.min(1980,1,1,0,2)
31
+ range = DateRange.new(r_start,r_end)
32
+ assert(range.min==r_start)
33
+ assert(range.max==r_end)
34
+ assert(range.include?(r_start+1))
35
+ assert(range.include?(r_end-1))
36
+ sub_range = DateRange.new((r_start+1),(r_end-1))
37
+ assert(range.include?(sub_range))
38
+ end
39
+
40
+ def test_spaceship_operator
41
+ r_start = PDate.min(1984,8,31,22,00)
42
+ r_end = PDate.min(1984,9,15,0,2)
43
+ range = DateRange.new(r_start,r_end)
44
+ assert(-1==(range<=>(DateRange.new(r_start+2,r_end+5))))
45
+ assert(1==(range<=>(DateRange.new(r_start-24,r_end+5))))
46
+ assert(0==(range<=>(DateRange.new(r_start,r_end))))
47
+ end
48
+
49
+ def test_overlap
50
+ r_start = PDate.month(2010,12)
51
+ r_end = PDate.month(2011,12)
52
+ range = DateRange.new(r_start,r_end)
53
+ o_start = PDate.month(2010,11)
54
+ o_end = PDate.month(2012,2)
55
+ o_range = DateRange.new(o_start,o_end)
56
+ assert(range.overlap?(o_range))
57
+ assert(o_range.overlap?(range))
58
+ assert(o_range.overlap?(DateRange.new(r_start,o_end)))
59
+ assert(o_range.overlap?(DateRange.new(o_start,r_end)))
60
+ end
61
+
62
+ def test_empty
63
+ r_start = PDate.hour(2004,2,10,0)
64
+ r_end = PDate.hour(2004,2,9,23)
65
+ empty_range = DateRange.new(r_start,r_end)
66
+ assert(empty_range.empty?)
67
+ assert(DateRange::EMPTY.empty?)
68
+ end
69
+
70
+ def test_gap
71
+ r_start = PDate.day(2000,6,12)
72
+ r_end = PDate.day(2000,6,14)
73
+ range = DateRange.new(r_start,r_end)
74
+ g_start = PDate.day(2000,6,18)
75
+ g_end = PDate.day(2000,6,20)
76
+ g_range = DateRange.new(g_start,g_end)
77
+ the_gap=range.gap(g_range)
78
+ assert(the_gap.start_expr==(r_end+1))
79
+ assert(the_gap.end_expr==(g_start-1))
80
+ end
81
+
82
+ end
@@ -0,0 +1,46 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:<<'../lib'
4
+
5
+ require 'test/unit'
6
+ require 'runt'
7
+ require 'date'
8
+
9
+ # Unit tests for DPrecision class
10
+ #
11
+ # Author:: Matthew Lipper
12
+ class DPrecisionTest < Test::Unit::TestCase
13
+
14
+ include Runt
15
+
16
+ def test_comparable
17
+ assert(DPrecision::YEAR<DPrecision::MONTH, "DPrecision.year was not less than DPrecision.month")
18
+ assert(DPrecision::MONTH<DPrecision::DAY, "DPrecision.month was not less than DPrecision.day")
19
+ assert(DPrecision::DAY<DPrecision::HOUR, "DPrecision.day was not less than DPrecision.hour")
20
+ assert(DPrecision::HOUR<DPrecision::MIN, "DPrecision.hour was not less than DPrecision.min")
21
+ assert(DPrecision::MIN<DPrecision::SEC, "DPrecision.min was not less than DPrecision.sec")
22
+ assert(DPrecision::SEC<DPrecision::MILLI, "DPrecision.sec was not less than DPrecision.millisec")
23
+ end
24
+
25
+ def test_pseudo_singleton_instance
26
+ assert(DPrecision::YEAR.id==DPrecision::YEAR.id, "Object Id's not equal.")
27
+ assert(DPrecision::MONTH.id==DPrecision::MONTH.id, "Object Id's not equal.")
28
+ assert(DPrecision::DAY.id==DPrecision::DAY.id, "Object Id's not equal.")
29
+ assert(DPrecision::HOUR.id==DPrecision::HOUR.id, "Object Id's not equal.")
30
+ assert(DPrecision::MIN.id==DPrecision::MIN.id, "Object Id's not equal.")
31
+ assert(DPrecision::SEC.id==DPrecision::SEC.id, "Object Id's not equal.")
32
+ assert(DPrecision::MILLI.id==DPrecision::MILLI.id, "Object Id's not equal.")
33
+ end
34
+
35
+ def test_to_precision
36
+ #February 29th, 2004
37
+ no_prec_date = PDate.civil(2004,2,29)
38
+ month_prec = PDate.month(2004,2,29)
39
+ assert(month_prec==DPrecision.to_p(no_prec_date,DPrecision::MONTH))
40
+ #11:59:59 am, February 29th, 2004
41
+ no_prec_datetime = PDate.civil(2004,2,29,23,59,59)
42
+ #puts "-->#{no_prec_datetime.date_precision}<--"
43
+ assert(month_prec==DPrecision.to_p(no_prec_datetime,DPrecision::MONTH))
44
+ end
45
+
46
+ end
data/test/pdatetest.rb ADDED
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:<<'../lib'
4
+
5
+ require 'test/unit'
6
+ require 'date'
7
+ require 'runt'
8
+
9
+ # Unit tests for PDate class
10
+ # Author:: Matthew Lipper
11
+ class PDateTest < Test::Unit::TestCase
12
+
13
+ include Runt
14
+
15
+ def setup
16
+ # 2010 (August - ignored)
17
+ @year_prec = PDate.year(2010,8)
18
+ #August, 2004
19
+ @month_prec = PDate.month(2004,8)
20
+ #January 25th, 2004 (11:39 am - ignored)
21
+ @day_prec = PDate.day(2004,1,25,11,39)
22
+ #11:59(:04 - ignored), December 31st, 1999
23
+ @minute_prec = PDate.min(1999,12,31,23,59,4)
24
+ #12:00:10 am, March 1st, 2004
25
+ @second_prec = PDate.sec(2004,3,1,0,0,10)
26
+ end
27
+
28
+ def test_new
29
+ date = PDate.new(2004,2,29)
30
+ assert(!date.date_precision.nil?)
31
+ date_time = PDate.new(2004,2,29,22,13,2)
32
+ assert(!date_time.date_precision.nil?)
33
+
34
+ date2 = PDate.day(2004,2,29)
35
+ assert(date==date2)
36
+
37
+ date_time2 = PDate.sec(2004,2,29,22,13,2)
38
+ assert(date_time==date_time2)
39
+
40
+ end
41
+
42
+ def test_plus
43
+ assert(PDate.year(2022,12)==(@year_prec+12))
44
+ assert(PDate.month(2005,2)==(@month_prec+6))
45
+ assert(PDate.day(2004,2,1)==(@day_prec+7))
46
+ assert(PDate.min(2000,1,1,0,0)==(@minute_prec+1))
47
+ assert(PDate.sec(2004,3,1,0,0,21)==(@second_prec+11))
48
+ end
49
+
50
+ def test_minus
51
+ assert(PDate.year(1998,12)==(@year_prec-12))
52
+ assert(PDate.month(2002,6)==(@month_prec-26))
53
+ #Hmmm...FIXME? @day_prec-26 == 12/31??
54
+ assert(PDate.day(2003,12,30)==(@day_prec-26))
55
+ assert(PDate.min(1999,12,31,21,57)==(@minute_prec-122))
56
+ assert(PDate.sec(2004,2,29,23,59,59)==(@second_prec-11))
57
+ end
58
+ def test_spaceship_comparison_operator
59
+ sec_prec = PDate.sec(2002,8,28,6,04,02)
60
+ assert(PDate.year(1998,12)<sec_prec)
61
+ assert(PDate.month(2002,9)>sec_prec)
62
+ assert(PDate.day(2002,8,28)==sec_prec)
63
+ assert(PDate.min(1999,12,31,21,57)<sec_prec)
64
+ assert(DateTime.new(2002,8,28,6,04,02)==sec_prec)
65
+ assert(Date.new(2004,8,28)>sec_prec)
66
+ end
67
+ def test_succ
68
+ #~ fail("FIXME! Implement succ")
69
+ end
70
+ def test_range
71
+ #11:50 pm (:22 seconds ignored), February 2nd, 2004
72
+ min1 = PDate.min(2004,2,29,23,50,22)
73
+ #12:02 am , March 1st, 2004
74
+ min2 = PDate.min(2004,3,1,0,2)
75
+ #Inclusive Range w/minute precision
76
+ r_min = min1..min2
77
+ assert( r_min.include?(PDate.min(2004,2,29,23,50,22)) )
78
+ assert( r_min.include?(PDate.min(2004,3,1,0,2)) )
79
+ assert( r_min.include?(PDate.min(2004,3,1,0,0)) )
80
+ assert( ! r_min.include?(PDate.min(2004,3,1,0,3)) )
81
+ #Exclusive Range w/minute precision
82
+ r_min = min1...min2
83
+ assert( r_min.include?(PDate.min(2004,2,29,23,50,22)) )
84
+ assert( !r_min.include?(PDate.min(2004,3,1,0,2)) )
85
+ end
86
+
87
+ def test_create_with_class_methods
88
+ #December 12th, 1968
89
+ no_prec = PDate.civil(1968,12,12)
90
+ #December 12th, 1968 (at 11:15 am - ignored)
91
+ day_prec = PDate.day(1968,12,12,11,15)
92
+ assert(no_prec==day_prec, "PDate instance does not equal precisioned instance.")
93
+ #December 2004 (24th - ignored)
94
+ month_prec1 = PDate.month(2004,12,24)
95
+ #December 31st, 2004 (31st - ignored)
96
+ month_prec2 = PDate.month(2004,12,31)
97
+ assert(month_prec1==month_prec2, "PDate.month instances not equal.")
98
+ #December 2004
99
+ month_prec3 = PDate.month(2004,12)
100
+ assert(month_prec1==month_prec3, "PDate.month instances not equal.")
101
+ assert(month_prec2==month_prec3, "PDate.month instances not equal.")
102
+ #December 2003
103
+ month_prec4 = PDate.month(2003,12)
104
+ assert(month_prec4!=month_prec1, "PDate.month instances not equal.")
105
+ end
106
+ end