date-performance 0.4.6 → 0.4.7

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -11,9 +11,9 @@ Project.new "Date::Performance" do |p|
11
11
  p.author = 'Ryan Tomayko <r@tomayko.com>'
12
12
  p.rubyforge_project = 'wink'
13
13
 
14
- p.remote_dist_location = "tomayko.com:/dist/#{p.package_name}"
15
- p.remote_branch_location = "tomayko.com:/src/#{p.package_name}.git"
16
- p.remote_doc_location = "tomayko.com:/src/#{p.package_name}"
14
+ p.remote_dist_location = "gus@tomayko.com:/dist/#{p.package_name}"
15
+ p.remote_branch_location = "gus@tomayko.com:/src/#{p.package_name}.git"
16
+ p.remote_doc_location = "gus@tomayko.com:/src/#{p.package_name}"
17
17
  end
18
18
 
19
19
  task :default => [ :compile, :test ]
@@ -22,6 +22,7 @@ static ID id_new; /* :new */
22
22
  static ID id_new_bang; /* :new! */
23
23
  static ID id_ivar_civil; /* :@__civil__ */
24
24
  static ID id_jd; /* :jd */
25
+ static ID id_ivar_ajd; /* :@ajd */
25
26
  static ID id_jd_to_civil; /* :jd_to_civil */
26
27
  static ID id_ivar_sg; /* :@sg */
27
28
  static ID id_numerator; /* :numerator */
@@ -338,6 +339,42 @@ rb_date_strptime(int argc, VALUE * argv, VALUE self)
338
339
  return rb_funcall2(self, id_strptime_without_performance, argc, argv);
339
340
  }
340
341
 
342
+ /*
343
+ * Date::<=>(other)
344
+ */
345
+ static VALUE
346
+ rb_date_compare(int argc, VALUE * argv, VALUE self)
347
+ {
348
+ if (NIL_P(argv[0]))
349
+ return Qnil;
350
+ long other_den = -1;
351
+ long other_num = -1;
352
+ if (FIXNUM_P(argv[0])) {
353
+ //compare with argument as with astronomical julian day number
354
+ other_den = 1;
355
+ other_num = FIX2LONG(argv[0]);
356
+ } else if (rb_obj_is_kind_of(argv[0], rb_cDate)) {
357
+ VALUE other_date = argv[0];
358
+ VALUE other_ajd = rb_ivar_get(other_date, id_ivar_ajd);
359
+ other_den = FIX2LONG(rb_funcall(other_ajd, id_denominator, 0));
360
+ other_num = FIX2LONG(rb_funcall(other_ajd, id_numerator, 0));
361
+ } else {
362
+ return Qnil;
363
+ }
364
+
365
+ VALUE ajd = rb_ivar_get(self, id_ivar_ajd);
366
+ long den = FIX2LONG(rb_funcall(ajd, id_denominator, 0));
367
+ long num = FIX2LONG(rb_funcall(ajd, id_numerator, 0));
368
+
369
+ long v = (num * other_den) - (other_num * den);
370
+ if (v > 0)
371
+ return INT2FIX(1);
372
+ else if (v < 0)
373
+ return INT2FIX(-1);
374
+ else
375
+ return INT2FIX(0);
376
+ }
377
+
341
378
 
342
379
  VALUE
343
380
  Init_date_performance() {
@@ -358,6 +395,7 @@ Init_date_performance() {
358
395
  rb_define_method(rb_cDate, "civil", rb_date_civil, 0);
359
396
  rb_define_method(rb_cDate, "sys_strftime", rb_date_strftime, -1);
360
397
  rb_define_method(rb_cDate, "strftime", rb_date_strftime, -1);
398
+ rb_define_method(rb_cDate, "<=>", rb_date_compare, -1);
361
399
 
362
400
  /* Date Singleton Methods */
363
401
  rb_define_singleton_method(rb_cDate, "civil_to_jd", rb_date_civil_to_jd, -1);
@@ -383,6 +421,7 @@ Init_date_performance() {
383
421
  id_divmod = rb_intern("divmod");
384
422
  id_new = rb_intern("new");
385
423
  id_jd = rb_intern("jd");
424
+ id_ivar_ajd = rb_intern("@ajd");
386
425
  id_jd_to_civil = rb_intern("jd_to_civil");
387
426
  id_ivar_civil = rb_intern("@__civil__");
388
427
  id_ivar_sg = rb_intern("@sg");
@@ -9,7 +9,7 @@ class Date
9
9
  # The Date::Performance module is present when the performance enhacing extension
10
10
  # has been loaded. It serves no other purpose.
11
11
  module Performance
12
- VERSION = "0.4.6"
12
+ VERSION = "0.4.7"
13
13
  end
14
14
 
15
15
  # The extension replaces Date#strftime but falls back on the stock version when
@@ -117,4 +117,29 @@ class ExtensionTest < Test::Unit::TestCase
117
117
  end
118
118
  end
119
119
 
120
+ def test_date_comparisons
121
+ #regular Date class comparison
122
+ d = Date.new(2008, 1, 1)
123
+ 366.times do |i|
124
+ assert_equal( 0, d+i <=> d+i )
125
+ assert_equal(-1, d+i <=> d+i+1 )
126
+ assert_equal( 1, d+i+1 <=> d+i )
127
+ end
128
+
129
+ #DateTime comparison
130
+ dt1 = DateTime.new(2006,1,1,12,15,30)
131
+ dt2 = DateTime.new(2006,1,1,12,15,31)
132
+ dt3 = DateTime.new(2006,1,1,12,15,29)
133
+
134
+ assert_equal( 0, DateTime.new(2006,1,1,12,15,30) <=> dt1 )
135
+ assert_equal( 1, dt1 <=> dt3 )
136
+ assert_equal( -1, dt1 <=> dt2 )
137
+
138
+ #comparison with some random type
139
+ assert_equal nil, dt1 <=> "foo"
140
+
141
+ #comparison with Fixnum that represents ajd
142
+ assert_equal(-1, d <=> d.ajd.numerator )
143
+ end
144
+
120
145
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: date-performance
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.6
4
+ version: 0.4.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Tomayko
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir:
10
10
  cert_chain: []
11
11
 
12
- date: 2008-07-12 00:00:00 -07:00
12
+ date: 2008-07-17 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -30,7 +30,6 @@ files:
30
30
  - test/date_memoize_test.rb
31
31
  - test/extension_test.rb
32
32
  - doc/asciidoc.conf
33
- - doc/changes.html
34
33
  - doc/changes.txt
35
34
  - doc/images
36
35
  - doc/images/icons
@@ -60,7 +59,6 @@ files:
60
59
  - doc/images/icons/tip.png
61
60
  - doc/images/icons/up.png
62
61
  - doc/images/icons/warning.png
63
- - doc/license.html
64
62
  - doc/license.txt
65
63
  - doc/stylesheets
66
64
  - doc/stylesheets/handbookish-manpage.css
@@ -1,32 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2
- "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4
- <head>
5
- <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
6
- <meta name="generator" content="AsciiDoc 8.2.5" />
7
- <link rel="stylesheet" href="stylesheets/handbookish.css" type="text/css" />
8
- <title>Date::Performance ChangeLog</title>
9
- </head>
10
- <body>
11
- <div id="header">
12
- <h1>Date::Performance ChangeLog</h1>
13
- <span id="author">Ryan Tomayko</span><br />
14
- <span id="email"><tt>&lt;<a href="mailto:r@tomayko.com">r@tomayko.com</a>&gt;</tt></span><br />
15
- </div>
16
- <div id="preamble">
17
- <div class="sectionbody">
18
- <div class="listingblock">
19
- <div class="content"><!-- Generator: GNU source-highlight 2.9
20
- by Lorenzo Bettini
21
- http://www.lorenzobettini.it
22
- http://www.gnu.org/software/src-highlite -->
23
- <pre><tt></tt></pre></div></div>
24
- </div>
25
- </div>
26
- <div id="footer">
27
- <div id="footer-text">
28
- Last updated 2008-07-12 08:15:20 PDT
29
- </div>
30
- </div>
31
- </body>
32
- </html>
@@ -1,42 +0,0 @@
1
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
2
- "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
3
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
4
- <head>
5
- <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=UTF-8" />
6
- <meta name="generator" content="AsciiDoc 8.2.5" />
7
- <link rel="stylesheet" href="stylesheets/handbookish.css" type="text/css" />
8
- <title>The MIT License</title>
9
- </head>
10
- <body>
11
- <div id="header">
12
- <h1>The MIT License</h1>
13
- <span id="author">Ryan Tomayko</span><br />
14
- <span id="email"><tt>&lt;<a href="mailto:r@tomayko.com">r@tomayko.com</a>&gt;</tt></span><br />
15
- </div>
16
- <div id="preamble">
17
- <div class="sectionbody">
18
- <div class="para"><p>Date::Performance is Copyright (c) 2007-08, Ryan Tomayko</p></div>
19
- <div class="para"><p>Permission is hereby granted, free of charge, to any person obtaining a copy
20
- of this software and associated documentation files (the "Software"), to deal
21
- in the Software without restriction, including without limitation the rights
22
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
23
- copies of the Software, and to permit persons to whom the Software is
24
- furnished to do so, subject to the following conditions:</p></div>
25
- <div class="para"><p>The above copyright notice and this permission notice shall be included in all
26
- copies or substantial portions of the Software.</p></div>
27
- <div class="para"><p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
30
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
31
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
32
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
33
- SOFTWARE.</p></div>
34
- </div>
35
- </div>
36
- <div id="footer">
37
- <div id="footer-text">
38
- Last updated 2008-07-12 08:15:21 PDT
39
- </div>
40
- </div>
41
- </body>
42
- </html>