ConvertDateTimeToJavaScriptTicks() static private method

static private ConvertDateTimeToJavaScriptTicks ( System.DateTime dateTime ) : long
dateTime System.DateTime
return long
        internal static int WriteDateTimeString(
            char[] chars,
            int start,
            DateTime value,
            TimeSpan?offset,
            DateTimeKind kind,
            DateFormatHandling format)
        {
            int num1 = start;
            int start1;

            if (format == DateFormatHandling.MicrosoftDateFormat)
            {
                TimeSpan offset1         = offset ?? value.GetUtcOffset();
                long     javaScriptTicks = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(value, offset1);
                "\\/Date(".CopyTo(0, chars, num1, 7);
                int    destinationIndex = num1 + 7;
                string str = javaScriptTicks.ToString((IFormatProvider)CultureInfo.InvariantCulture);
                str.CopyTo(0, chars, destinationIndex, str.Length);
                int num2 = destinationIndex + str.Length;
                switch (kind)
                {
                case DateTimeKind.Unspecified:
                    if (value != DateTime.MaxValue && value != DateTime.MinValue)
                    {
                        num2 = DateTimeUtils.WriteDateTimeOffset(chars, num2, offset1, format);
                        break;
                    }
                    break;

                case DateTimeKind.Local:
                    num2 = DateTimeUtils.WriteDateTimeOffset(chars, num2, offset1, format);
                    break;
                }
                ")\\/".CopyTo(0, chars, num2, 3);
                start1 = num2 + 3;
            }
            else
            {
                start1 = DateTimeUtils.WriteDefaultIsoDate(chars, num1, value);
                switch (kind)
                {
                case DateTimeKind.Utc:
                    chars[start1++] = 'Z';
                    break;

                case DateTimeKind.Local:
                    start1 = DateTimeUtils.WriteDateTimeOffset(chars, start1, offset ?? value.GetUtcOffset(), format);
                    break;
                }
            }
            return(start1);
        }
Example #2
0
        internal static int WriteDateTimeString(char[] chars, int start, DateTime value, TimeSpan?offset, DateTimeKind kind, DateFormatHandling format)
        {
            TimeSpan?nullable;
            int      length = start;

            if (format != DateFormatHandling.MicrosoftDateFormat)
            {
                length = DateTimeUtils.WriteDefaultIsoDate(chars, length, value);
                if (kind == DateTimeKind.Utc)
                {
                    int num = length;
                    length     = num + 1;
                    chars[num] = 'Z';
                }
                else if (kind == DateTimeKind.Local)
                {
                    char[] chrArray = chars;
                    int    num1     = length;
                    nullable = offset;
                    length   = DateTimeUtils.WriteDateTimeOffset(chrArray, num1, (nullable.HasValue ? nullable.GetValueOrDefault() : value.GetUtcOffset()), format);
                }
            }
            else
            {
                nullable = offset;
                TimeSpan timeSpan        = (nullable.HasValue ? nullable.GetValueOrDefault() : value.GetUtcOffset());
                long     javaScriptTicks = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(value, timeSpan);
                "\\/Date(".CopyTo(0, chars, length, 7);
                length += 7;
                string str = javaScriptTicks.ToString(CultureInfo.InvariantCulture);
                str.CopyTo(0, chars, length, str.Length);
                length += str.Length;
                if (kind != DateTimeKind.Unspecified)
                {
                    if (kind == DateTimeKind.Local)
                    {
                        length = DateTimeUtils.WriteDateTimeOffset(chars, length, timeSpan, format);
                    }
                }
                else if (value != DateTime.MaxValue && value != DateTime.MinValue)
                {
                    length = DateTimeUtils.WriteDateTimeOffset(chars, length, timeSpan, format);
                }
                ")\\/".CopyTo(0, chars, length, 3);
                length += 3;
            }
            return(length);
        }
        internal static int WriteDateTimeString(char[] chars, int start, DateTime value, TimeSpan?offset, DateTimeKind kind, DateFormatHandling format)
        {
            int num2;

            if (format == DateFormatHandling.MicrosoftDateFormat)
            {
                TimeSpan offset2 = offset ?? value.GetUtcOffset();
                long     num     = DateTimeUtils.ConvertDateTimeToJavaScriptTicks(value, offset2);
                "\\/Date(".CopyTo(0, chars, start, 7);
                num2 = start + 7;
                string text = num.ToString(CultureInfo.InvariantCulture);
                text.CopyTo(0, chars, num2, text.Length);
                num2 += text.Length;
                switch (kind)
                {
                case DateTimeKind.Unspecified:
                    if (value != DateTime.MaxValue && value != DateTime.MinValue)
                    {
                        num2 = DateTimeUtils.WriteDateTimeOffset(chars, num2, offset2, format);
                    }
                    break;

                case DateTimeKind.Local:
                    num2 = DateTimeUtils.WriteDateTimeOffset(chars, num2, offset2, format);
                    break;
                }
                ")\\/".CopyTo(0, chars, num2, 3);
                num2 += 3;
            }
            else
            {
                num2 = DateTimeUtils.WriteDefaultIsoDate(chars, start, value);
                switch (kind)
                {
                case DateTimeKind.Utc:
                    chars[num2++] = 'Z';
                    break;

                case DateTimeKind.Local:
                    num2 = DateTimeUtils.WriteDateTimeOffset(chars, num2, offset ?? value.GetUtcOffset(), format);
                    break;
                }
            }
            return(num2);
        }
 internal static long ConvertDateTimeToJavaScriptTicks(DateTime dateTime)
 {
     return(DateTimeUtils.ConvertDateTimeToJavaScriptTicks(dateTime, true));
 }