Skip to content

Unix Time Stamp to .NET DateTime converter for Json.NET

License

Notifications You must be signed in to change notification settings

egorikas/UnixTimeConverter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UnixTimeConverter

Build status NuGet License

Unix Time Stamp to .NET DateTime converter for Json.NET

Installation

Install-Package UnixTimeConverter

Usage

namespace UsageExample
{
    public class ApiData
    {
        [JsonConverter(typeof(UnixTimeConverter))]
        public DateTime Date { get; set; }
    }

    public class ConverterTest
    {
        [Fact]
        public void HappyPath()
        {
            //Arrange
            var apiJson = "{ Date : 1321009871 }";

            //Act
            var result = JsonConvert.DeserializeObject<ApiData>(apiJson);

            //Assert
            Assert.Equal(new DateTime(2011, 11, 11, 11, 11, 11, DateTimeKind.Utc), result.Date);
        }
    }
}

Build

Install .NET Core SDK

Open src folder in the command prompt. Then

    dotnet restore
    dotnet build

Tests

Open src\JsonNetConverters.Test folder in the command prompt. Then

    dotnet test

.NET Standart compatibility

Library was created with supporting for .NET Standart 1.0

Contributing

Don't be shy to ask a question or offer something :)