Permalink
Browse files

Update DateRow to use ruby Time rather than broken NSDate.dateWithTim…

…eIntervalSince1970
  • Loading branch information...
1 parent c4e42df commit ad4441be02766ab647c41fcd2a8d7de323068239 @dlongmuir dlongmuir committed Jan 16, 2013
Showing with 16 additions and 9 deletions.
  1. +7 −0 examples/KitchenSink/app/app_delegate.rb
  2. +3 −3 lib/formotion/row_type/date_row.rb
  3. +6 −6 spec/row_type/date_spec.rb
@@ -93,6 +93,13 @@ def application(application, didFinishLaunchingWithOptions:launchOptions)
type: :date,
format: :short
}, {
+ title: "Date (Time)",
+ subtitle: "w/picker_mode => :time",
+ key: :date_time_short,
+ type: :date,
+ picker_mode: :time,
+ format: :short
+ }, {
title: "Slider",
key: :slider,
type: :slider,
@@ -12,7 +12,7 @@ def update
def date_value
value = self.row.value
if value.is_a? Numeric
- NSDate.dateWithTimeIntervalSince1970(value.to_i)
+ Time.at value
else
nil
end
@@ -43,13 +43,13 @@ def picker
picker = UIDatePicker.alloc.initWithFrame(CGRectZero)
picker.datePickerMode = self.picker_mode
picker.hidden = false
- picker.date = self.date_value || NSDate.date
+ picker.date = self.date_value || Time.now
picker.when(UIControlEventValueChanged) do
if self.row.picker_mode == :countdown
self.row.value = @picker.countDownDuration
else
- self.row.value = @picker.date.timeIntervalSince1970.to_i
+ self.row.value = @picker.date.to_i #timeIntervalSince1970.to_i
end
update
end
@@ -1,4 +1,4 @@
-MILLENIUM = 946684672
+MILLENIUM = 946684772 # Time.at(MILLENIUM) => 1999-12-31 18:59:32 -0500
TIME_ZONE = NSTimeZone.timeZoneWithName "Europe/Paris"
describe "Date Row" do
@@ -34,7 +34,7 @@
it "should update value when date is picked" do
cell = @row.make_cell
- @row.object.picker.date = NSDate.dateWithTimeIntervalSince1970(MILLENIUM)
+ @row.object.picker.date = Time.at MILLENIUM
@row.object.picker.trigger UIControlEventValueChanged
@row.value.should == MILLENIUM
@@ -63,16 +63,16 @@
# Modes
{
:date => '1/1/00',
- :time => '12:57 AM',
- :date_time => '1/1/00, 12:57 AM',
- :countdown => '00:57'
+ :time => '12:59 AM',
+ :date_time => '1/1/00, 12:59 AM',
+ :countdown => '00:59'
}.each do |mode, expected_output|
it "should display chosen mode #{mode} date/time format #{expected_output}" do
@row.format = :short
@row.picker_mode = mode
cell = @row.make_cell
- @row.object.picker.date = NSDate.dateWithTimeIntervalSince1970(MILLENIUM)
+ @row.object.picker.date = Time.at MILLENIUM
@row.object.picker.trigger UIControlEventValueChanged
@row.text_field.text.should == expected_output

0 comments on commit ad4441b

Please sign in to comment.