-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/jlucansky/Camunda.Api.Client
- Loading branch information
Showing
2 changed files
with
31 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} | ||
} |