diff --git a/AutoRest/Generators/Ruby/Azure.Ruby/AzureClientModelExtensions.cs b/AutoRest/Generators/Ruby/Azure.Ruby/AzureClientModelExtensions.cs index 13a93416ce55d..61699fbef07be 100644 --- a/AutoRest/Generators/Ruby/Azure.Ruby/AzureClientModelExtensions.cs +++ b/AutoRest/Generators/Ruby/Azure.Ruby/AzureClientModelExtensions.cs @@ -68,6 +68,11 @@ public static string AzureDeserializeType( { return builder.AppendLine("{0} = DateTime.parse({0}) unless {0}.to_s.empty?", valueReference).ToString(); } + + if (primary.Type == KnownPrimaryType.UnixTime) + { + return builder.AppendLine("{0} = DateTime.strptime({0}.to_s, '%s') unless {0}.to_s.empty?", valueReference).ToString(); + } } else if (enumType != null && !string.IsNullOrEmpty(enumType.Name)) { @@ -175,6 +180,11 @@ public static string AzureSerializeType( { return builder.AppendLine("{0} = {0}.new_offset(0).strftime('%a, %d %b %Y %H:%M:%S GMT')", valueReference).ToString(); } + + if (primary.Type == KnownPrimaryType.UnixTime) + { + return builder.AppendLine("{0} = {0}.new_offset(0).strftime('%s')", valueReference).ToString(); + } } else if (sequence != null) { diff --git a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/integer_spec.rb b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/integer_spec.rb index 2d118b8531760..f7556f6741a20 100644 --- a/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/integer_spec.rb +++ b/AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/integer_spec.rb @@ -67,11 +67,33 @@ it 'should get null' do result = @int_client.get_null_async().value! - expect(result.response.status).to eq(200) - expect(result.body).to eq(nil) + expect(result.response.status).to eq(200) + expect(result.body).to eq(nil) end it 'should get invalid' do expect{ @int_client.get_invalid_async().value! }.to raise_error(MsRest::DeserializationError) end + + it 'should put unix time' do + result = @int_client.put_unix_time_date_async(DateTime.new(2016, 4, 13, 0, 0, 0, 'Z')).value! + expect(result.response.status).to eq(200) + expect(result.body).to eq(nil) + end + + it 'should get unix time' do + result = @int_client.get_unix_time_async().value! + expect(result.response.status).to eq(200) + expect(result.body).to eq(DateTime.new(2016, 4, 13, 0, 0, 0, 'Z')) + end + + it 'should get null unix time' do + result = @int_client.get_null_unix_time_async().value! + expect(result.response.status).to eq(200) + expect(result.body).to eq(nil) + end + + it 'should get invalid unix time' do + expect{ @int_client.get_invalid_unix_time_async().value! }.to raise_error(MsRest::DeserializationError) + end end \ No newline at end of file diff --git a/AutoRest/Generators/Ruby/Ruby/ClientModelExtensions.cs b/AutoRest/Generators/Ruby/Ruby/ClientModelExtensions.cs index 8a055ed3fe45a..853c37f8ea7e7 100644 --- a/AutoRest/Generators/Ruby/Ruby/ClientModelExtensions.cs +++ b/AutoRest/Generators/Ruby/Ruby/ClientModelExtensions.cs @@ -313,6 +313,11 @@ public static string DeserializeType( { return builder.AppendLine("{0} = DateTime.parse({0}) unless {0}.to_s.empty?", valueReference).ToString(); } + + if (primary.Type == KnownPrimaryType.UnixTime) + { + return builder.AppendLine("{0} = DateTime.strptime({0}.to_s, '%s') unless {0}.to_s.empty?", valueReference).ToString(); + } } else if (enumType != null && !string.IsNullOrEmpty(enumType.Name)) { @@ -415,6 +420,11 @@ public static string SerializeType( { return builder.AppendLine("{0} = {0}.new_offset(0).strftime('%a, %d %b %Y %H:%M:%S GMT')", valueReference).ToString(); } + + if (primary.Type == KnownPrimaryType.UnixTime) + { + return builder.AppendLine("{0} = {0}.new_offset(0).strftime('%s')", valueReference).ToString(); + } } else if (sequence != null) { diff --git a/AutoRest/Generators/Ruby/Ruby/RubyCodeNamer.cs b/AutoRest/Generators/Ruby/Ruby/RubyCodeNamer.cs index c40423ee1b4ae..3709e888fdb8c 100644 --- a/AutoRest/Generators/Ruby/Ruby/RubyCodeNamer.cs +++ b/AutoRest/Generators/Ruby/Ruby/RubyCodeNamer.cs @@ -374,7 +374,7 @@ private IType NormalizePrimaryType(PrimaryType primaryType) } else if (primaryType.Type == KnownPrimaryType.UnixTime) { - primaryType.Name = "Bignum"; + primaryType.Name = "DateTime"; } else if (primaryType.Type == KnownPrimaryType.Object) {