Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
jlucansky committed Apr 29, 2019
2 parents 11ee765 + 07c3c36 commit 1cd96ae
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 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);
}
}
}
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 1cd96ae

Please sign in to comment.