Skip to content

Informatievlaanderen/timestamp-jsonconverter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

86 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Be.Vlaanderen.Basisregisters.Converters.Timestamp Build Status

Goal

JSON.NET converter for parsing timestamps in Zulu time.

Usage

Apply the [JsonConverter(typeof(TimestampConverter))] attribute on the date property you want to have serialized in UTC (Zulu) time.

For example:

namespace Example
{
    using System;
    using Be.Vlaanderen.Basisregisters.Converters.Timestamp;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Converters;

    public class Test
    {
        [JsonConverter(typeof(IsoDateTimeConverter))]
        public DateTimeOffset IsoTimestamp { get; set; }

        [JsonConverter(typeof(TimestampConverter))]
        public DateTimeOffset ZuluTimestamp { get; set; }

        public DateTimeOffset RegularTimestamp { get; set; }
    }

    public class Program
    {
        public static void Main(string[] _)
        {
            var d = new DateTimeOffset(2020, 1, 1, 1, 1, 1, TimeSpan.FromHours(2));

            var test = new Test
            {
                IsoTimestamp = d,
                ZuluTimestamp = d,
                RegularTimestamp = d
            };

            Console.WriteLine(JsonConvert.SerializeObject(test, Formatting.Indented));
        }
    }
}

When you run this, this is the output:

$ dotnet run
{
  "IsoTimestamp": "2020-01-01T01:01:01+02:00",
  "ZuluTimestamp": "2019-12-31T23:01:01Z",
  "RegularTimestamp": "2020-01-01T01:01:01+02:00"
}

License

MIT License

Credits

Languages & Frameworks

  • .NET Core - MIT
  • .NET Core Runtime - CoreCLR is the runtime for .NET Core. It includes the garbage collector, JIT compiler, primitive data types and low-level classes. - MIT
  • .NET Core APIs - CoreFX is the foundational class libraries for .NET Core. It includes types for collections, file systems, console, JSON, XML, async and many others. - MIT
  • .NET Core SDK - Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI. - MIT
  • Roslyn and C# - The Roslyn .NET compiler provides C# and Visual Basic languages with rich code analysis APIs. - Apache License 2.0
  • F# - The F# Compiler, Core Library & Tools - MIT
  • F# and .NET Core - F# and .NET Core SDK working together. - MIT

Libraries

Tooling

Flemish Government Libraries