Ejemplo n.º 1
0
        private static TimestampParseResult TryParseExactCore(string input, string[] formats, IFormatProvider formatProvider, DateTimeStyles styles, out Timestamp result)
        {
            ValidateParseInput(input);

            if (formats == null)
            {
                throw new ArgumentNullException("formats");
            }

            if (formats.Length == 0)
            {
                throw new ArgumentException("The 'formats' must not be empty.", "formats");
            }

            ValidateParseStyles(styles);

            if (input.Length == 0)
            {
                result = default(Timestamp);
                return(TimestampParseResult.EmptyInput);
            }

            foreach (var format in formats)
            {
                if (TimestampStringConverter.TryParseExact(input, format, formatProvider, styles, out result) == TimestampParseResult.Success)
                {
                    return(TimestampParseResult.Success);
                }
            }

            result = default(Timestamp);
            return(TimestampParseResult.NoMatchedFormats);
        }
Ejemplo n.º 2
0
        private static TimestampParseResult TryParseExactCore(string input, string format, IFormatProvider formatProvider, DateTimeStyles styles, out Timestamp result)
        {
            ValidateParseInput(input);

            if (input.Length == 0)
            {
                result = default(Timestamp);
                return(TimestampParseResult.EmptyInput);
            }

            if (format == null)
            {
                throw new ArgumentNullException("format");
            }

            if (format.Length == 0)
            {
                throw new ArgumentException("The 'format' must not be empty.", "format");
            }

            ValidateParseStyles(styles);

            var error = TimestampStringConverter.TryParseExact(input, format, formatProvider, styles, out result);

            if (error == TimestampParseResult.UnsupportedFormat)
            {
                // UnsupportedFormat should throw Exception instead of returning false.
                HandleParseResult(error, "Cannot parse specified input with specified format.");
            }

            return(error);
        }
Ejemplo n.º 3
0
        public void TestToStringCore_Zero_LowerS()
        {
            var value =
                new Timestamp.Value(
                    0,
                    1,
                    1,
                    0,
                    0,
                    0,
                    0
                    );

            Assert.That(
                TimestampStringConverter.ToString(
                    "s",
                    CultureInfo.InvariantCulture,
                    ref value
                    ),
                Is.EqualTo("0000-01-01T00:00:00Z")
                );
        }
Ejemplo n.º 4
0
        public void TestToStringCore_TimestampMax_LowerS()
        {
            var value =
                new Timestamp.Value(
                    292277026596,
                    12,
                    4,
                    15,
                    30,
                    7,
                    999999999
                    );

            Assert.That(
                TimestampStringConverter.ToString(
                    "s",
                    CultureInfo.InvariantCulture,
                    ref value
                    ),
                Is.EqualTo("292277026596-12-04T15:30:07Z")
                );
        }
Ejemplo n.º 5
0
        public void TestToStringCore_TimestampMin_LowerS()
        {
            var value =
                new Timestamp.Value(
                    -292277022657,
                    1,
                    27,
                    8,
                    29,
                    52,
                    0
                    );

            Assert.That(
                TimestampStringConverter.ToString(
                    "s",
                    CultureInfo.InvariantCulture,
                    ref value
                    ),
                Is.EqualTo("-292277022657-01-27T08:29:52Z")
                );
        }
Ejemplo n.º 6
0
        public void TestToStringCore_YearMinus10000_LowerS()
        {
            var value =
                new Timestamp.Value(
                    -10000,
                    10,
                    10,
                    10,
                    10,
                    10,
                    123456789
                    );

            Assert.That(
                TimestampStringConverter.ToString(
                    "s",
                    CultureInfo.InvariantCulture,
                    ref value
                    ),
                Is.EqualTo("-10000-10-10T10:10:10Z")
                );
        }
Ejemplo n.º 7
0
        public void TestToStringCore_Year10000_UpperO()
        {
            var value =
                new Timestamp.Value(
                    10000,
                    10,
                    10,
                    10,
                    10,
                    10,
                    123456789
                    );

            Assert.That(
                TimestampStringConverter.ToString(
                    "O",
                    CultureInfo.InvariantCulture,
                    ref value
                    ),
                Is.EqualTo("10000-10-10T10:10:10.123456789Z")
                );
        }
Ejemplo n.º 8
0
        public void TestToStringCore_YearMinus1000_UpperO()
        {
            var value =
                new Timestamp.Value(
                    -1000,
                    1,
                    1,
                    0,
                    0,
                    0,
                    0
                    );

            Assert.That(
                TimestampStringConverter.ToString(
                    "O",
                    CultureInfo.InvariantCulture,
                    ref value
                    ),
                Is.EqualTo("-1000-01-01T00:00:00.000000000Z")
                );
        }
Ejemplo n.º 9
0
        /// <summary>
        ///		Returns a <see cref="String"/> representation of this instance with the default format and the specified format provider.
        /// </summary>
        /// <param name="format">
        ///		A format string to specify output format. You can specify <c>null</c> for default behavior, which is interpreted as <c>"o"</c>.
        /// </param>
        /// <param name="formatProvider">
        ///		An <see cref="IFormatProvider"/> to provide culture specific format information.
        ///		You can specify <c>null</c> for default behavior, which uses <see cref="CultureInfo.CurrentCulture"/>.
        ///	</param>
        /// <returns>
        ///		A <see cref="String"/> representation of this instance.
        /// </returns>
        /// <exception cref="ArgumentException">
        ///		<paramref name="format"/> is not valid.
        /// </exception>
        /// <remarks>
        ///		<para>
        ///			Currently, only <c>"o"</c> and <c>"O"</c> (ISO 8601 like round trip format) and <c>"s"</c> (ISO 8601 format) are supported.
        ///			Other standard date time format and any custom date time format are not supported.
        ///		</para>
        ///		<para>
        ///			The round trip format is <c>yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fffffffff'Z'</c> which 'fffffffff' nanoseconds.
        ///		</para>
        ///		<para>
        ///			As of recommendation of the msgpack specification and consistency with <see cref="DateTime"/> and <see cref="DateTimeOffset"/>,
        ///			the default value of the <paramref name="format"/> is <c>"o"</c> (ISO 8601 like round-trip format)
        ///			and the default value of the <paramref name="formatProvider"/> is <c>null</c> (<see cref="CultureInfo.CurrentCulture"/>.
        ///			If you want to ensure interoperability for other implementation, specify <c>"s"</c> and <see cref="CultureInfo.InvariantCulture"/> resepectively.
        ///		</para>
        /// </remarks>
        public string ToString(string format, IFormatProvider formatProvider)
        {
            var value = new Value(this);

            return(TimestampStringConverter.ToString(format, formatProvider, ref value));
        }