lib/cocoa/sugarcube-nsdate/nsdate_delta.rb in sugarcube-3.3.1 vs lib/cocoa/sugarcube-nsdate/nsdate_delta.rb in sugarcube-3.3.2

- old
+ new

@@ -17,12 +17,12 @@ is_dst = self.dst? delta = s # todo: leap second adjustment? can leap seconds be detected? - delta += mi.minutes - delta += h.hours + delta += mi * 60 + delta += h * 3600 return_date = self + delta # using days_in_month, this is pretty easy. 12 mos per year IS a constant, # and then we just keep adding the number of days in the month (or last month @@ -40,49 +40,49 @@ end if mo > 0 mo.times do delta = return_date.days_in_month - return_date += delta.days + return_date += delta * 3600 * 24 # if the day_of_month is wrong, it must be because we either added PAST # the correct month (so roll back), or because we WERE rolled back and # when we moved forward a month, we were left back at the smaller day. if correct_day_of_month if return_date.day < 28 - return_date -= return_date.day.days + return_date -= return_date.day * 3600 * 24 elsif return_date.day < correct_day_of_month fix = correct_day_of_month > return_date.days_in_month ? return_date.days_in_month : correct_day_of_month - return_date += (fix - return_date.day).days + return_date += (fix - return_date.day) * 3600 * 24 end end end else # mo < 0 (-mo).times do # subtract *last* months number of days. # there is a REALLY rare case where subtracting return_date.day is one # hour short of "last month" and so you end up with THIS month. there # is NEVER a case when subtracting return_date.day+1 days is NOT # "previous month". dates. :-| f-em. - delta = (return_date - (return_date.day+1).days).days_in_month - return_date -= delta.days + delta = (return_date - (return_date.day+1) * 3600 * 24).days_in_month + return_date -= delta * 3600 * 24 # same correction as above if correct_day_of_month if return_date.day < 28 - return_date -= return_date.day.days + return_date -= return_date.day * 3600 * 24 elsif return_date.day < correct_day_of_month fix = correct_day_of_month > return_date.days_in_month ? return_date.days_in_month : correct_day_of_month - return_date += (fix - return_date.day).days + return_date += (fix - return_date.day) * 3600 * 24 end end end end end delta = 0 - delta += d.days - delta += w.weeks + delta += d * 3600 * 24 + delta += w * 3600 * 24 * 7 return_date += delta # DST adjustment, unless minutes, hours, or seconds were specified. # # the thinking here is that if they WERE specified, the delta should be @@ -96,12 +96,12 @@ # notice the time is the SAME, even though the time zone is different. BUT: # Time.at(3/10/2012).delta(hours:24) # => 2012-03-11 17:00:00 -0600 # Time.at(3/10/2012).delta(hours:25) # => 2012-03-11 18:00:00 -0600 unless return_date.dst? == is_dst or is_very_specific if is_dst - return_date += 1.hour + return_date += 3600 else - return_date -= 1.hour + return_date -= 3600 end end return return_date end