Skip to content

Commit

Permalink
Merge pull request jlucansky#32 from darrenhull/bug/master-fix-java-d…
Browse files Browse the repository at this point in the history
…atetime-serialization

Fix java date time serialization
  • Loading branch information
jlucansky authored Apr 29, 2019
2 parents cc2ee36 + eb91ab4 commit 07c3c36
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
25 changes: 25 additions & 0 deletions Camunda.Api.Client.Tests/DateTimeTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using System;
using System.Globalization;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Camunda.Api.Client.ProcessInstance;
using Refit;
using RichardSzalay.MockHttp;
using Xunit;

namespace Camunda.Api.Client.Tests
{
public class DateTimeTests
{
[Theory]
[InlineData("2010-01-01T01:01:01", "2010-01-01T01:01:01.000+0000")]
[InlineData("2010-05-01T01:01:01", "2010-05-01T01:01:01.000+0100")]
public void GetDateTime(string testDateTimeString,string expectedDatetimeString)
{
var actualIso8601DateString = DateTime.Parse(testDateTimeString).ToJavaISO8601();
Assert.Equal(expectedDatetimeString, actualIso8601DateString);
}
}
}
2 changes: 1 addition & 1 deletion Camunda.Api.Client/Camunda.Api.Client.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFrameworks>netstandard2.0;net461</TargetFrameworks>
<GenerateDocumentationFile Condition=" '$(Configuration)' == 'Release' ">true</GenerateDocumentationFile>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>2.4.1</Version>
<Version>2.4.2</Version>
<Product>Camunda REST API Client</Product>
<Title>Camunda REST API Client</Title>
<Authors>Jan Lucansky</Authors>
Expand Down
8 changes: 6 additions & 2 deletions Camunda.Api.Client/DateTimeExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
using System;
using System.Globalization;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Camunda.Api.Client.Tests")]
namespace Camunda.Api.Client
{
internal static class DateTimeExtensions
{
const string _dateTimeFormat = "yyyy'-'MM'-'dd'T'HH':'mm':'ss.FFF";
const string _dateTimeFormat = "yyyy-MM-ddTHH':'mm':'ss.fff";

public static string ToJavaISO8601(this DateTime dateTime)
{
if (dateTime.Kind == DateTimeKind.Unspecified) // treat unspecified time as local time
dateTime = new DateTime(dateTime.Ticks, DateTimeKind.Local);
return dateTime.ToString(_dateTimeFormat, CultureInfo.InvariantCulture)
+ dateTime.ToString("%K").Replace(":", "").Replace("Z", "UTC");
+ dateTime.ToString("%K").Replace(":", "").Replace("Z", "+0000");
}
}
}

0 comments on commit 07c3c36

Please sign in to comment.