Skip to content

Commit

Permalink
Merge pull request #52 from JetBrains/develop
Browse files Browse the repository at this point in the history
Wrong Json Conversion in UnixDateTimeOffsetConverter #51
  • Loading branch information
maartenba authored Aug 31, 2017
2 parents 69e9b95 + 777e22e commit 338860d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -203,3 +203,5 @@ fabric.properties

# Our own folders
artifacts/
.vs/YouTrackSharp/v15/sqlite3/storage.ide
.idea/.idea.YouTrackSharp/.idea/inspectionProfiles/profiles_settings.xml
6 changes: 3 additions & 3 deletions src/YouTrackSharp/Json/UnixDateTimeOffsetConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
namespace YouTrackSharp.Json
{
/// <summary>
/// A JSON convertor that can convert a unix timestamp into a <see cref="DateTimeOffset" /> value and vice-versa.
/// A JSON convertor that can convert a unix timestamp (in milliseconds) into a <see cref="DateTimeOffset" /> value and vice-versa.
/// </summary>
public class UnixDateTimeOffsetConverter
: DateTimeConverterBase
Expand All @@ -15,11 +15,11 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
{
if (value is DateTimeOffset)
{
writer.WriteValue(((DateTimeOffset)value).ToUnixTimeSeconds());
writer.WriteValue(((DateTimeOffset)value).ToUnixTimeMilliseconds());
}
else if (value is DateTime)
{
writer.WriteValue(new DateTimeOffset((DateTime)value).ToUnixTimeSeconds());
writer.WriteValue(new DateTimeOffset((DateTime)value).ToUnixTimeMilliseconds());
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public class WriteJson
{
public static IEnumerable<object[]> GetData()
{
yield return new object[] { new DateTimeOffset(2001, 01, 01, 10, 11, 0, TimeSpan.Zero), new DateTimeOffset(2001, 01, 01, 10, 11, 0, TimeSpan.Zero).ToUnixTimeSeconds() };
yield return new object[] { new DateTimeOffset(2001, 01, 01, 10, 11, 0, TimeSpan.Zero).DateTime, new DateTimeOffset(new DateTimeOffset(2001, 01, 01, 10, 11, 0, TimeSpan.Zero).DateTime).ToUnixTimeSeconds() };
yield return new object[] { new DateTimeOffset(2001, 01, 01, 10, 11, 0, TimeSpan.Zero), new DateTimeOffset(2001, 01, 01, 10, 11, 0, TimeSpan.Zero).ToUnixTimeMilliseconds() };
yield return new object[] { new DateTimeOffset(2001, 01, 01, 10, 11, 0, TimeSpan.Zero).DateTime, new DateTimeOffset(new DateTimeOffset(2001, 01, 01, 10, 11, 0, TimeSpan.Zero).DateTime).ToUnixTimeMilliseconds() };
}

[Theory]
Expand Down

0 comments on commit 338860d

Please sign in to comment.