Пример #1
0
        internal static void WriteValue(TextWriter writer, DateTimeOffset value, ODataJsonDateTimeFormat dateTimeFormat)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(writer != null, "writer != null");

            Int32 offsetMinutes = (Int32)value.Offset.TotalMinutes;

            switch (dateTimeFormat)
            {
            case ODataJsonDateTimeFormat.ISO8601DateTime:
            {
                // Uses the same format as DateTime but with offset:
                // jsonDateTime= quotation-mark
                //  YYYY-MM-DDThh:mm:ss.sTZD
                //  [("+" / "-") offset]
                //  quotation-mark
                //
                // offset = 4DIGIT
                string textValue = XmlConvert.ToString(value);
                WriteQuoted(writer, textValue);
            }

            break;

            case ODataJsonDateTimeFormat.ODataDateTime:
            {
                // Uses the same format as DateTime but with offset:
                // jsonDateTime= quotation-mark
                //  "\/Date("
                //  ticks
                //  [("+" / "-") offset]
                //  ")\/"
                //  quotation-mark
                //
                // ticks = *DIGIT
                // offset = 4DIGIT
                string textValue = String.Format(
                    CultureInfo.InvariantCulture,
                    JsonConstants.ODataDateTimeOffsetFormat,
                    DateTimeTicksToJsonTicks(value.Ticks),
                    offsetMinutes >= 0 ? JsonConstants.ODataDateTimeOffsetPlusSign : string.Empty,
                    offsetMinutes);
                WriteQuoted(writer, textValue);
            }

            break;
            }
        }
Пример #2
0
        internal static void WriteValue(TextWriter writer, DateTime value, ODataJsonDateTimeFormat dateTimeFormat)
        {
            switch (dateTimeFormat)
            {
            case ODataJsonDateTimeFormat.ODataDateTime:
            {
                value = GetUniversalDate(value);
                string text = string.Format(CultureInfo.InvariantCulture, @"\/Date({0})\/", new object[] { DateTimeTicksToJsonTicks(value.Ticks) });
                WriteQuoted(writer, text);
                return;
            }

            case ODataJsonDateTimeFormat.ISO8601DateTime:
            {
                string str = PlatformHelper.ConvertDateTimeToString(value);
                WriteQuoted(writer, str);
                return;
            }
            }
        }
Пример #3
0
        internal static void WriteValue(TextWriter writer, DateTimeOffset value, ODataJsonDateTimeFormat dateTimeFormat)
        {
            int totalMinutes = (int)value.Offset.TotalMinutes;

            switch (dateTimeFormat)
            {
            case ODataJsonDateTimeFormat.ODataDateTime:
            {
                string text = string.Format(CultureInfo.InvariantCulture, @"\/Date({0}{1}{2:D4})\/", new object[] { DateTimeTicksToJsonTicks(value.Ticks), (totalMinutes >= 0) ? "+" : string.Empty, totalMinutes });
                WriteQuoted(writer, text);
                return;
            }

            case ODataJsonDateTimeFormat.ISO8601DateTime:
            {
                string str = XmlConvert.ToString(value);
                WriteQuoted(writer, str);
                return;
            }
            }
        }
Пример #4
0
        internal static void WriteValue(TextWriter writer, DateTime value, ODataJsonDateTimeFormat dateTimeFormat)
        {
            DebugUtils.CheckNoExternalCallers();
            Debug.Assert(writer != null, "writer != null");

            switch (dateTimeFormat)
            {
            case ODataJsonDateTimeFormat.ISO8601DateTime:
            {
                // jsonDateTime= quotation-mark
                //  YYYY-MM-DDThh:mm:ss.sTZD
                //  [("+" / "-") offset]
                //  quotation-mark
                string textValue = PlatformHelper.ConvertDateTimeToString(value);
                WriteQuoted(writer, textValue);
            }

            break;

            case ODataJsonDateTimeFormat.ODataDateTime:
            {
                // taken from the Atlas serializer
                // DevDiv 41127: Never confuse atlas serialized strings with dates
                // Serialized date: "\/Date(123)\/"
                // sb.Append(@"""\/Date(");
                // sb.Append((datetime.ToUniversalTime().Ticks - DatetimeMinTimeTicks) / 10000);
                // sb.Append(@")\/""");
                value = GetUniversalDate(value);
                System.Diagnostics.Debug.Assert(value.Kind == DateTimeKind.Utc, "dateTime.Kind == DateTimeKind.Utc");

                string textValue = String.Format(
                    CultureInfo.InvariantCulture,
                    JsonConstants.ODataDateTimeFormat,
                    DateTimeTicksToJsonTicks(value.Ticks));
                WriteQuoted(writer, textValue);
            }

            break;
            }
        }
Пример #5
0
        internal static void WriteValue(TextWriter writer, DateTimeOffset value, ODataJsonDateTimeFormat dateTimeFormat)
        {
            Debug.Assert(writer != null, "writer != null");

            switch (dateTimeFormat)
            {
            case ODataJsonDateTimeFormat.ISO8601DateTime:
            {
                // Uses the same format as DateTime but with offset:
                // jsonDateTime= quotation-mark
                //  YYYY-MM-DDThh:mm:ss.sTZD
                //  [("+" / "-") offset]
                //  quotation-mark
                //
                // offset = 4DIGIT
                string textValue = XmlConvert.ToString(value);
                JsonValueUtils.WriteQuoted(writer, textValue);
            }

            break;

            case ODataJsonDateTimeFormat.ODataDateTime:
            {
                // Uses the same format as DateTime but with offset:
                // jsonDateTime= quotation-mark
                //  "\/Date("
                //  ticks
                //  [("+" / "-") offset]
                //  ")\/"
                //  quotation-mark
                //
                // ticks = *DIGIT
                // offset = 4DIGIT
                string textValue = FormatDateTimeAsJsonTicksString(value);
                JsonValueUtils.WriteQuoted(writer, textValue);
            }

            break;
            }
        }
 public static void WriteValue(TextWriter writer, DateTimeOffset value, ODataJsonDateTimeFormat dateTimeFormat)
 {
     ReflectionUtils.InvokeMethod(classType, "WriteValue", writer, value, ReflectionUtils.GetEnumerationValue(formatEnumType, dateTimeFormat.ToString()));
 }
Пример #7
0
        internal static Task WriteValueAsync(this TextWriter writer, DateTimeOffset value, ODataJsonDateTimeFormat dateTimeFormat)
        {
            Debug.Assert(writer != null, "writer != null");

            switch (dateTimeFormat)
            {
            case ODataJsonDateTimeFormat.ISO8601DateTime:
            {
                // Uses the same format as DateTime but with offset:
                // jsonDateTime= quotation-mark
                //  YYYY-MM-DDThh:mm:ss.sTZD
                //  [("+" / "-") offset]
                //  quotation-mark
                //
                // offset = 4DIGIT
                string textValue = XmlConvert.ToString(value);
                return(writer.WriteQuotedAsync(textValue));
            }

            case ODataJsonDateTimeFormat.ODataDateTime:
            {
                // Uses the same format as DateTime but with offset:
                // jsonDateTime= quotation-mark
                //  "\/Date("
                //  ticks
                //  [("+" / "-") offset]
                //  ")\/"
                //  quotation-mark
                //
                // ticks = *DIGIT
                // offset = 4DIGIT
                string textValue = FormatDateTimeAsJsonTicksString(value);
                return(writer.WriteQuotedAsync(textValue));
            }
            }

            return(TaskUtils.CompletedTask);
        }
Пример #8
0
 public static void WriteValue(TextWriter writer, DateTimeOffset value, ODataJsonDateTimeFormat dateTimeFormat) { ReflectionUtils.InvokeMethod(classType, "WriteValue", writer, value, ReflectionUtils.GetEnumerationValue(formatEnumType, dateTimeFormat.ToString())); }
Пример #9
0
        internal static void WriteValue(TextWriter writer, DateTimeOffset value, ODataJsonDateTimeFormat dateTimeFormat)
        {
            Debug.Assert(writer != null, "writer != null");

            Int32 offsetMinutes = (Int32)value.Offset.TotalMinutes;

            switch (dateTimeFormat)
            {
                case ODataJsonDateTimeFormat.ISO8601DateTime:
                    {
                        // Uses the same format as DateTime but with offset:
                        // jsonDateTime= quotation-mark   
                        //  YYYY-MM-DDThh:mm:ss.sTZD 
                        //  [("+" / "-") offset] 
                        //  quotation-mark  
                        //
                        // offset = 4DIGIT
                        string textValue = XmlConvert.ToString(value);
                        WriteQuoted(writer, textValue);
                    }

                    break;

                case ODataJsonDateTimeFormat.ODataDateTime:
                    {
                        // Uses the same format as DateTime but with offset:
                        // jsonDateTime= quotation-mark   
                        //  "\/Date("  
                        //  ticks 
                        //  [("+" / "-") offset] 
                        //  ")\/"  
                        //  quotation-mark  
                        //
                        // ticks = *DIGIT
                        // offset = 4DIGIT
                        string textValue = String.Format(
                            CultureInfo.InvariantCulture,
                            JsonConstants.ODataDateTimeOffsetFormat,
                            DateTimeTicksToJsonTicks(value.Ticks),
                            offsetMinutes >= 0 ? JsonConstants.ODataDateTimeOffsetPlusSign : string.Empty,
                            offsetMinutes);
                        WriteQuoted(writer, textValue);
                    }

                    break;
            }
        }
Пример #10
0
 internal static void WriteValue(TextWriter writer, DateTimeOffset value, ODataJsonDateTimeFormat dateTimeFormat)
 {
     int totalMinutes = (int) value.Offset.TotalMinutes;
     switch (dateTimeFormat)
     {
         case ODataJsonDateTimeFormat.ODataDateTime:
         {
             string text = string.Format(CultureInfo.InvariantCulture, @"\/Date({0}{1}{2:D4})\/", new object[] { DateTimeTicksToJsonTicks(value.Ticks), (totalMinutes >= 0) ? "+" : string.Empty, totalMinutes });
             WriteQuoted(writer, text);
             return;
         }
         case ODataJsonDateTimeFormat.ISO8601DateTime:
         {
             string str = XmlConvert.ToString(value);
             WriteQuoted(writer, str);
             return;
         }
     }
 }
Пример #11
0
 internal static void WriteValue(TextWriter writer, DateTime value, ODataJsonDateTimeFormat dateTimeFormat)
 {
     switch (dateTimeFormat)
     {
         case ODataJsonDateTimeFormat.ODataDateTime:
         {
             value = GetUniversalDate(value);
             string text = string.Format(CultureInfo.InvariantCulture, @"\/Date({0})\/", new object[] { DateTimeTicksToJsonTicks(value.Ticks) });
             WriteQuoted(writer, text);
             return;
         }
         case ODataJsonDateTimeFormat.ISO8601DateTime:
         {
             string str = PlatformHelper.ConvertDateTimeToString(value);
             WriteQuoted(writer, str);
             return;
         }
     }
 }