Example #1
0
        public static void WriteDateTime(DateTime value, ProtoWriter dest)
        {
            if (dest == null)
            {
                throw new ArgumentNullException("dest");
            }
            WireType wireType = dest.WireType;
            TimeSpan timeSpan;

            if (wireType != WireType.String && wireType != WireType.StartGroup)
            {
                timeSpan = value - BclHelpers.EpochOrigin;
            }
            else if (value == DateTime.MaxValue)
            {
                timeSpan = TimeSpan.MaxValue;
            }
            else if (value == DateTime.MinValue)
            {
                timeSpan = TimeSpan.MinValue;
            }
            else
            {
                timeSpan = value - BclHelpers.EpochOrigin;
            }
            BclHelpers.WriteTimeSpan(timeSpan, dest);
        }
Example #2
0
        public static void WriteDateTime(DateTime value, ProtoWriter dest)
        {
            TimeSpan maxValue;

            if (dest == null)
            {
                throw new ArgumentNullException("dest");
            }
            switch (dest.WireType)
            {
            case WireType.String:
            case WireType.StartGroup:
            {
                if (value == DateTime.MaxValue)
                {
                    maxValue = TimeSpan.MaxValue;
                    break;
                }
                else if (value != DateTime.MinValue)
                {
                    maxValue = value - BclHelpers.EpochOrigin;
                    break;
                }
                else
                {
                    maxValue = TimeSpan.MinValue;
                    break;
                }
            }

            default:
            {
                maxValue = value - BclHelpers.EpochOrigin;
                break;
            }
            }
            BclHelpers.WriteTimeSpan(maxValue, dest);
        }