Skip to content

Latest commit

 

History

History
62 lines (49 loc) · 1.47 KB

README.md

File metadata and controls

62 lines (49 loc) · 1.47 KB

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 :)