Skip to content

Commit

Permalink
Merge pull request #219 from simplificator/feature/date_row_formatting
Browse files Browse the repository at this point in the history
Add option to set date format with a style submitted by string
  • Loading branch information
clayallsopp committed Jun 9, 2014
2 parents 852c900 + 63e92bf commit d329231
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
5 changes: 4 additions & 1 deletion lib/formotion/row/row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@ class Row < Formotion::Base
# DEFAULT is :date
:picker_mode,
# Stores possible formatting information (used by date pickers, etc)
# if :type == :date, accepts values in [:short, :medium, :long, :full]
# if :type == :date, accepts values in [:short, :medium, :long, :full, :string]
# if string is specified it uses format string passed in date_format property
:format,
# Defines detailed formatting for date (only used in DateRow)
:date_format,
# alternative title for row (only used in EditRow for now)
:alt_title,
# determines if the user can edit the row
Expand Down
14 changes: 10 additions & 4 deletions lib/formotion/row_type/date_row.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,18 @@ def formatter
formatter = NSDateFormatter.new

date_style = self.row.format
if date_style && date_style.to_s[-5..-1] != "style"
date_style = (date_style.to_s + "_style").to_sym

if date_style == :string
formatter.dateFormat = self.row.date_format
else
if date_style && date_style.to_s[-5..-1] != "style"
date_style = (date_style.to_s + "_style").to_sym
end

formatter.dateStyle = self.row.send(:const_int_get, "NSDateFormatter", date_style || NSDateFormatterShortStyle)
formatter.timeStyle = NSDateFormatterNoStyle
end

formatter.dateStyle = self.row.send(:const_int_get, "NSDateFormatter", date_style || NSDateFormatterShortStyle)
formatter.timeStyle = NSDateFormatterNoStyle
formatter
end
end
Expand Down

0 comments on commit d329231

Please sign in to comment.