Permalink
Browse files

Changes to picker_mode

  • Loading branch information...
1 parent 8e8260c commit 41b5f5c13c3742100d4698bc89f48bd3a1252c68 @clayallsopp committed Nov 19, 2012
View
@@ -13,9 +13,9 @@ class Row < Formotion::Base
# either Formotion::RowType or a string/symbol representation of one
# see row_type.rb
:type,
- # Stores possible date pickers mode
- # Available modes [UIDatePickerModeTime, UIDatePickerModeDate, UIDatePickerModeDateAndTime, UIDatePickerModeCountDownTimer]
- # http://developer.apple.com/library/ios/#documentation/uikit/reference/UIDatePicker_Class/Reference/UIDatePicker.html
+ # Stores possible date pickers mode; corresponds to UIDatePickerMode______
+ # OPTIONS: :time, :date, :date_time, :countdown
+ # DEFAULT is :date
:picker_mode,
# Stores possible formatting information (used by date pickers, etc)
# if :type == :date, accepts values in [:short, :medium, :long, :full]
@@ -28,15 +28,11 @@ def formatter
end
formatter.dateStyle = self.row.send(:const_int_get, "NSDateFormatter", date_style || NSDateFormatterShortStyle)
+ formatter.timeStyle = NSDateFormatterNoStyle
formatter
end
end
- def formatted_value
- return formatter.stringFromDate(self.date_value) if self.date_value
- self.row.value
- end
-
def after_build(cell)
self.row.text_field.inputView = self.picker
update
@@ -50,7 +46,11 @@ def picker
picker.date = self.date_value || NSDate.date
picker.when(UIControlEventValueChanged) do
- self.row.value = format_picker_value(@picker)
+ if self.row.picker_mode == :countdown
+ self.row.value = @picker.countDownDuration
+ else
+ self.row.value = @picker.date.timeIntervalSince1970.to_i
+ end
update
end
@@ -60,20 +60,55 @@ def picker
def picker_mode
case self.row.picker_mode
- when :time then UIDatePickerModeTime
- when :date then UIDatePickerModeDate
- when :datetime then UIDatePickerModeDateAndTime
- when :countdown then UIDatePickerModeCountDownTimer
- else UIDatePickerModeDate
+ when :time
+ UIDatePickerModeTime
+ when :date_time
+ UIDatePickerModeDateAndTime
+ when :countdown
+ UIDatePickerModeCountDownTimer
+ else
+ UIDatePickerModeDate
end
end
- def format_picker_value(picker)
- case self.row.picker_mode
- when :time then picker.date.strftime("%I:%M %p")
- when :countdown then picker.date.strftime("%R")
- else picker.date.timeIntervalSince1970.to_i
+ def formatted_value
+ if self.date_value
+ return case self.row.picker_mode
+ when :time
+ old_date_style = formatter.dateStyle
+ formatter.dateStyle = NSDateFormatterNoStyle
+ formatter.timeStyle = NSDateFormatterShortStyle
+ formatted = formatter.stringFromDate(self.date_value)
+ formatter.dateStyle = old_date_style
+ formatter.timeStyle = NSDateFormatterNoStyle
+ formatted
+ when :date_time
+ old_date_style = formatter.dateStyle
+ formatter.dateStyle = NSDateFormatterShortStyle
+ formatter.timeStyle = NSDateFormatterShortStyle
+ formatted = formatter.stringFromDate(self.date_value)
+ formatter.dateStyle = old_date_style
+ formatter.timeStyle = NSDateFormatterNoStyle
+ formatted
+ when :countdown
+ time = self.row.value
+ date = NSDate.dateWithTimeIntervalSinceReferenceDate(time)
+ old_date_style = formatter.dateStyle
+ old_time_zone = formatter.timeZone
+
+ formatter.dateFormat = "HH:mm"
+ formatter.timeZone = NSTimeZone.timeZoneForSecondsFromGMT(0)
+ formatted = formatter.stringFromDate(date)
+
+ formatter.dateStyle = old_date_style
+ formatter.timeZone = old_time_zone
+ formatter.dateFormat = nil
+ formatted
+ else
+ formatter.stringFromDate(self.date_value)
+ end
end
+ self.row.value
end
# Used when row.value changes
@@ -64,11 +64,11 @@
{
:date => '1/1/00',
:time => '12:57 AM',
- :datetime => '1/1/00',
+ :date_time => '1/1/00, 12:57 AM',
:countdown => '00:57'
}.each do |mode, expected_output|
- it "should display chosen mode date/time format" do
+ it "should display chosen mode #{mode} date/time format #{expected_output}" do
@row.format = :short
@row.picker_mode = mode
cell = @row.make_cell
@@ -3,7 +3,6 @@ module UIControlWrap
# that was previously defined by #when
def trigger(events)
@callback ||= {}
- p "Callback #{@callback}"
@callback[events].map(&:call) if @callback.has_key? events
end
end

0 comments on commit 41b5f5c

Please sign in to comment.