mirror of
https://github.com/zhigang1992/rmq.git
synced 2026-01-12 22:51:53 +08:00
named datetime formats
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user