sugarcube 0.20.23 → 0.20.24

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -161,8 +161,18 @@ class NSDate
161
161
  # (main)> t.start_of_day
162
162
  # => 2012-09-27 00:00:00 +0900
163
163
  def start_of_day
164
- time_interval = self.hour.hours + self.min.minutes + self.sec
165
- return self - time_interval
164
+ date_components = NSDateComponents.new
165
+ date_components.hour = 0
166
+ date_components.minute = 0
167
+ date_components.second = 0
168
+ date_components.day = self.day
169
+ date_components.month = self.month
170
+ date_components.year = self.year
171
+
172
+ calendar = NSCalendar.alloc.initWithCalendarIdentifier(NSGregorianCalendar)
173
+ return calendar.dateFromComponents(date_components)
174
+
175
+ return date
166
176
  end
167
177
 
168
178
  # (main)> t = Time.new
@@ -170,8 +180,7 @@ class NSDate
170
180
  # (main)> t.end_of_day
171
181
  # => 2012-09-28 00:00:00 +0900
172
182
  def end_of_day
173
- time_interval = (23 - self.hour).hours + (59 - self.min).minutes - self.sec + 60
174
- return self + time_interval
183
+ return self.delta(days: 1).start_of_day
175
184
  end
176
185
 
177
186
  # (main)> t = Time.new
@@ -1,3 +1,3 @@
1
1
  module SugarCube
2
- Version = '0.20.23'
2
+ Version = '0.20.24'
3
3
  end
data/spec/nsdate_spec.rb CHANGED
@@ -18,6 +18,12 @@ describe "NSDate" do
18
18
  date.sec.should == 0
19
19
  end
20
20
 
21
+ it "NSDate##today method should be equal to itself" do
22
+ date1 = NSDate.today
23
+ date2 = NSDate.today
24
+ date1.should == date2
25
+ end
26
+
21
27
  it "Should have an NSDate##yesterday method" do
22
28
  now = NSDate.today
23
29
  date = NSDate.yesterday
@@ -28,6 +34,12 @@ describe "NSDate" do
28
34
  (now - date).in_hours.should <= 25 # savings time.
29
35
  end
30
36
 
37
+ it "NSDate##yesterday method should be equal to itself" do
38
+ date1 = NSDate.yesterday
39
+ date2 = NSDate.yesterday
40
+ date1.should == date2
41
+ end
42
+
31
43
  it "Should have an NSDate##tomorrow method" do
32
44
  now = NSDate.today
33
45
  date = NSDate.tomorrow
@@ -38,6 +50,12 @@ describe "NSDate" do
38
50
  (date - now).in_hours.should <= 25 # savings time.
39
51
  end
40
52
 
53
+ it "NSDate##tomorrow method should be equal to itself" do
54
+ date1 = NSDate.tomorrow
55
+ date2 = NSDate.tomorrow
56
+ date1.should == date2
57
+ end
58
+
41
59
  before do
42
60
  @date = NSDate.from_components(year: 2013, month: 1, day: 2, hour:12, minute: 15, second: 30)
43
61
  end
@@ -114,10 +132,18 @@ describe "NSDate" do
114
132
  @date.start_of_day.datetime_array.should == [2013, 1, 2, 0, 0, 0]
115
133
  end
116
134
 
135
+ it "NSDate#start_of_day should be equal to itself" do
136
+ @date.start_of_day.should == @date.start_of_day
137
+ end
138
+
117
139
  it "should have an NSDate#end_of_day method" do
118
140
  @date.end_of_day.datetime_array.should == [2013, 1, 3, 0, 0, 0]
119
141
  end
120
142
 
143
+ it "NSDate#end_of_day should be equal to itself" do
144
+ @date.end_of_day.should == @date.end_of_day
145
+ end
146
+
121
147
  it "should have an NSDate#start_of_week method" do
122
148
  @date.start_of_week(:sunday).datetime_array.should == [2012, 12, 30, 0, 0, 0]
123
149
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sugarcube
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.20.23
4
+ version: 0.20.24
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ authors:
13
13
  autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
- date: 2013-06-14 00:00:00.000000000 Z
16
+ date: 2013-06-21 00:00:00.000000000 Z
17
17
  dependencies: []
18
18
  description: ! '== Description
19
19