public
Fork of halorgium/mephisto
Description: A mirror of the mephisto code-base
Homepage: http://mephistoblog.com/
Clone URL: git://github.com/technoweenie/mephisto.git
Click here to lend your support to: mephisto and make a donation at www.pledgie.com !
shit, grow up and use precise time methods when calculating time deltas 
[Jon Leighton]

git-svn-id: http://svn.techno-weenie.net/projects/mephisto/trunk@2370 
567b1171-46fb-0310-a4c9-b4bef9110e78
technoweenie (author)
Sun Oct 15 12:15:11 -0700 2006
commit  ba574f63e7f06f0b90440359ba78e6ff3cecc6db
tree    df83339c85915215d610069150e383d55f280170
parent  0d87471da14fdd0ed19c5b4c56c59f6858d91b2b
...
98
99
100
101
102
103
104
105
106
107
108
109
 
 
 
 
 
 
 
 
 
 
110
111
112
...
98
99
100
 
101
 
 
 
 
 
 
 
102
103
104
105
106
107
108
109
110
111
112
113
114
0
@@ -98,15 +98,17 @@ class Time
0
     end
0
   end
0
       
0
- # Borrowed from Typo
0
   def self.delta(year, month = nil, day = nil)
0
- # XXX what to do here? should we use UTC?
0
- from = Time.mktime(year, month || 1, day || 1)
0
-
0
- to = from + 1.year
0
- to = from + 1.month unless month.blank?
0
- to = from + 1.day unless day.blank?
0
- to = to.tomorrow unless month.blank? or day
0
+ from = Time.local(year, month || 1, day || 1)
0
+
0
+ to =
0
+ if !day.blank?
0
+ from.advance :days => 1
0
+ elsif !month.blank?
0
+ from.advance :months => 1
0
+ else
0
+ from.advance :years => 1
0
+ end
0
     return [from.midnight, to.midnight]
0
   end
0
 end
...
6
7
8
9
 
 
 
10
11
12
...
6
7
8
 
9
10
11
12
13
14
0
@@ -6,7 +6,9 @@ class TimeTest < Test::Unit::TestCase
0
   end
0
 
0
   def test_should_show_month_delta
0
- assert_equal [Time.local(2006, 7, 1), Time.local(2006,8,1)], Time.local(2006,7,15).to_delta(:month)
0
+ assert_equal [Time.local(2006, 7, 1), Time.local(2006, 8, 1)], Time.local(2006, 7, 15).to_delta(:month)
0
+ assert_equal [Time.local(2006, 11, 1), Time.local(2006, 12, 1)], Time.local(2006, 11, 1).to_delta(:month)
0
+ assert_equal [Time.local(2006, 12, 1), Time.local(2007, 1, 1)], Time.local(2006, 12, 1).to_delta(:month)
0
   end
0
 
0
   def test_should_show_daily_delta

Comments

    No one has commented yet.