public void CSOMDateConverter_Test_FromConstructor()
        {
            CSOMDateConverter converter   = new CSOMDateConverter();
            string            inputString = "/Date(2019,11,5,17,7,26,0)/";

            DateTime expectedDate = new DateTime(2019, 11, 5, 17, 7, 26, 0);
            DateTime?actualDate   = converter.ConverDate(inputString);

            Assert.AreEqual(expectedDate, actualDate);
        }
        public void CSOMDateConverter_Test_FromMiliseconds()
        {
            CSOMDateConverter converter   = new CSOMDateConverter();
            string            inputString = "/Date(1612534319000)/";

            DateTime expectedDate = new DateTime(2021, 2, 5, 14, 11, 59, 0);
            DateTime?actualDate   = converter.ConverDate(inputString);

            Assert.AreEqual(expectedDate, actualDate);
        }
Esempio n. 3
0
        public override DateTime Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
        {
            string value = reader.GetString();
            //ok, so far I found two different date formats returned from the endpoint
            //You can check out both in \PnP.Core.Test\Services\Core\CSOM\Utils\CSOMResponseHelperTests.cs
            //Hence we need two strategies
            DateTime?result = DateConverter.ConverDate(value);

            return(result.HasValue ? result.Value : DateTime.MinValue);
        }