ServiceStack TypeSerializer: ISO8601 and dot culture as TimeSeparator

This is my first question, please be careful.
In .Net 4.5.2 using C #, I found strange behavior on ServiceStack.Text 4.5.6 serializing DateTime: if the current culture time is a delimiter - period (.), And serialized DateTime- either local or rounded to seconds, the result of serialization will also have dot as a time separator, even when used DateHandler.ISO8601. I made a simple test program:

static void Main(string[] args)
{
    JsConfig.DateHandler = DateHandler.ISO8601;
    Thread.CurrentThread.CurrentCulture = CultureInfo.GetCultureInfo("bn-IN");

    var utcNow = DateTime.UtcNow;
    var utcRoundedToSecond = new DateTime(utcNow.Year, utcNow.Month, utcNow.Day, 
        utcNow.Hour, utcNow.Minute, utcNow.Second, DateTimeKind.Utc);
    var localNow = DateTime.Now;

    var utcNowSerialized = SerializeDateTime(utcNow);
    var utcRoundedToSecondSerialized = SerializeDateTime(utcRoundedToSecond);
    var localNowSerialized = SerializeDateTime(localNow);

    Console.WriteLine("Serialization tests:");
    Console.WriteLine("UTC \t\t\t{0}", utcNowSerialized);
    Console.WriteLine("UTC rounded to seconds \t{0}", utcRoundedToSecondSerialized);
    Console.WriteLine("Local \t\t\t{0}", localNowSerialized);
    Console.WriteLine();

    Console.WriteLine("Deserialization tests:");
    Console.WriteLine("UTC \t\t\t{0}", DeserializeDateTime(utcNowSerialized).ToString("o"));
    Console.WriteLine("UTC rounded to seconds \t{0}", DeserializeDateTime(utcRoundedToSecondSerialized).ToString("o"));
    Console.WriteLine("Local \t\t\t{0}", DeserializeDateTime(localNowSerialized).ToString("o"));

    Console.ReadKey();
}

private static string SerializeDateTime(DateTime dateTime)
{
    return TypeSerializer.SerializeToString(dateTime);
}
private static DateTime DeserializeDateTime(string str)
{
    return (DateTime)TypeSerializer.DeserializeFromString(str,typeof(DateTime));
}

It outputs:

Serialization tests:
UTC                     2017-03-21T21:24:41.1494902Z
UTC rounded to seconds  2017-03-21T21.24.41Z
Local                   2017-03-21T22.24.41.1494902+01:00

Deserialization tests:
UTC                     2017-03-21T22:24:41.1494902+01:00
UTC rounded to seconds  2017-03-21T22:24:41.0000000+01:00
Local                   2017-03-20T23:00:00.0000000+01:00

, DateTime . Windows , HH.mm.ss HH.mm .
? - ? , : , , , . , JsConfig.DateHandler = DateHandler.ISO8601 TypeSerializer ISO8601 ISO8601 .

+4
1

InvariantCulture, DateTimeSerializer.ToShortestXsdDateTimeString(), InvariantCulture , ( @JeroenMostert ) this commit.

v4.5.7 +, MyGet.

+2

Source: https://habr.com/ru/post/1672872/


All Articles