named datetime formats

This commit is contained in:
Ken Miller
2015-01-30 10:52:07 -08:00
parent a9331f76e8
commit 8a8f4f7c7a
2 changed files with 19 additions and 1 deletions

View File

@@ -24,7 +24,7 @@ module RubyMotionQuery
#
# See <http://www.unicode.org/reports/tr35/tr35-19.html#Date_Format_Patterns>
# for more information about date format strings.
def date(date, *format_or_styles)
def date(date = nil, *format_or_styles)
RubyMotionQuery::Format::Date.formatter(*format_or_styles).stringFromDate(date)
end
@@ -35,6 +35,10 @@ module RubyMotionQuery
def date_formatter(*format_or_styles)
RubyMotionQuery::Format::Date.formatter(*format_or_styles)
end
def add_datetime_style(style, format)
RubyMotionQuery::Format::Date.add_datetime_style(style, format)
end
end
end
@@ -120,6 +124,11 @@ module RubyMotionQuery
end
end
def add_datetime_style(style_name, format)
@_date_formatters ||= {}
@_date_formatters[[style_name].to_s] ||= formatter_from_format(format)
end
end
end
end

View File

@@ -73,4 +73,13 @@ describe 'format' do
rmq.format.date(date, :medium_time, :short_date).should == '1/2/13, 12:15:30 PM'
end
it "should associate formats with custom styles" do
date = Time.new(2013,1,2,12,15,30)
rmq.format.add_datetime_style(:mon_year, "MMM yyyy")
rmq.format.date_formatter(:mon_year).class.should == NSDateFormatter
rmq.format.date_formatter(:mon_year).stringFromDate(date).should == 'Jan 2013'
rmq.format.date(date, :mon_year).should == 'Jan 2013'
end
end