Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return object data instead of string #49

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/i18n_alchemy/date_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def parse(value)
return value unless valid_for_parsing?(value)

if parsed_date = Date._strptime(value, i18n_format)
build_object(parsed_date).to_s
build_object(parsed_date)
else
value
end
Expand Down
10 changes: 3 additions & 7 deletions test/i18n_alchemy/date_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,19 @@ def setup
@date = Date.new(2011, 12, 31)
end

def test_does_not_convert_non_string_objects
assert_equal @date, @parser.parse(@date)
end

def test_parses_valid_string_dates_with_default_i18n_locale
assert_equal "2011-12-31", @parser.parse("12/31/2011")
assert_equal @date, @parser.parse("12/31/2011")
end

def test_parsers_string_dates_on_current_i18n_locale
I18n.with_locale :pt do
assert_equal "2011-12-31", @parser.parse("31/12/2011")
assert_equal @date, @parser.parse("31/12/2011")
end
end

def test_parsers_string_dates_with_implicit_day
I18n.with_locale :jp do
assert_equal "2011-12-01", @parser.parse("12/2011")
assert_equal @date.at_beginning_of_month, @parser.parse("12/2011")
end
end

Expand Down
6 changes: 3 additions & 3 deletions test/i18n_alchemy/time_parser_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ def test_does_not_convert_non_string_objects

# TODO: why so many time differences on the output?
def test_parses_valid_string_times_with_default_i18n_locale
assert_equal "2011-12-31 12:15:45 UTC", @parser.parse("12/31/2011 12:15:45")
assert_equal @time, @parser.parse("12/31/2011 12:15:45")
end

def test_parsers_string_times_on_current_i18n_locale
I18n.with_locale :pt do
assert_equal "2011-12-31 12:15:45 UTC", @parser.parse("31/12/2011 12:15:45")
assert_equal @time, @parser.parse("31/12/2011 12:15:45")
end
end

Expand All @@ -38,7 +38,7 @@ def test_localizes_time_values_based_on_current_i18n_locale
class TimeParserTest < I18n::Alchemy::TestCase
def setup
@parser = I18n::Alchemy::TimeParser
@time = Time.mktime(2011, 12, 31, 12, 15, 45)
@time = Time.utc(2011, 12, 31, 12, 15, 45)
end

include BaseTimeParserTest
Expand Down