Skip to content

Commit

Permalink
Adding support for Unix date-time in ruby (Azure#1014)
Browse files Browse the repository at this point in the history
  • Loading branch information
vishrutshah committed May 13, 2016
1 parent 3285bee commit 6de0b6d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 3 deletions.
10 changes: 10 additions & 0 deletions AutoRest/Generators/Ruby/Azure.Ruby/AzureClientModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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)
{
Expand Down
26 changes: 24 additions & 2 deletions AutoRest/Generators/Ruby/Ruby.Tests/RspecTests/integer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 10 additions & 0 deletions AutoRest/Generators/Ruby/Ruby/ClientModelExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
{
Expand Down Expand Up @@ -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)
{
Expand Down
2 changes: 1 addition & 1 deletion AutoRest/Generators/Ruby/Ruby/RubyCodeNamer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down

0 comments on commit 6de0b6d

Please sign in to comment.