public string Format(string format, object arg, IFormatProvider formatProvider)
        {
            if (arg == null)
            {
                return(string.Empty);
            }
            else if (arg is TimeRange)
            {
                var timeRange = (TimeRange)arg;
                return(TimestampFormatter.ToString(timeRange.Duration.ToNanoseconds, format, formatProvider));
            }
            else if (arg is TimestampDelta)
            {
                var timestampDelta = (TimestampDelta)arg;
                return(TimestampFormatter.ToString(timestampDelta.ToNanoseconds, format, formatProvider));
            }
            else if (arg is Timestamp)
            {
                var timestamp = (Timestamp)arg;
                return(TimestampFormatter.ToString(timestamp.ToNanoseconds, format, formatProvider));
            }
            else if (arg is double)
            {
                var timestamp = Timestamp.FromNanoseconds((double)arg);
                return(TimestampFormatter.ToString(timestamp.ToNanoseconds, format, formatProvider));
            }

            return(arg.ToString());
        }
        /// <summary>
        ///     Attempts to parse the given string into a <see cref="TimestampDelta"/>,
        ///     assuming the given units if none are specified in the string.
        /// </summary>
        /// <param name="s">
        ///     The string to parse.
        /// </param>
        /// <param name="defaultUnits">
        ///     The units to assume if none are specified in <paramref name="s"/>.
        /// </param>
        /// <param name="result">
        ///     The result of parsing, if successful.
        /// </param>
        /// <param name="parsedUnits">
        ///     The units parsed.
        /// </param>
        /// <returns>
        ///     <c>true</c> if <paramref name="s"/> can be parsed into a <see cref="TimestampDelta"/>
        ///     instance; <c>false</c> otherwise.
        /// </returns>
        public static bool TryParse(string s, TimeUnit defaultUnits, out TimestampDelta result, out TimeUnit parsedUnits)
        {
            long resultNS;
            bool success = TimestampFormatter.TryParse(s, defaultUnits, out resultNS, out parsedUnits);

            result = TimestampDelta.FromNanoseconds(resultNS);
            return(success);
        }
        /// <summary>
        ///     Attempts to parse the given string into a <see cref="TimestampDelta"/>.
        /// </summary>
        /// <param name="s">
        ///     The string to parse.
        /// </param>
        /// <param name="result">
        ///     The result of parsing, if successful.
        /// </param>
        /// <returns>
        ///     <c>true</c> if <paramref name="s"/> can be parsed into a <see cref="TimestampDelta"/>
        ///     instance; <c>false</c> otherwise.
        /// </returns>
        public static bool TryParse(string s, out TimestampDelta result)
        {
            long resultNS;
            bool success = TimestampFormatter.TryParse(s, out resultNS);

            result = TimestampDelta.FromNanoseconds(resultNS);
            return(success);
        }
 /// <summary>
 ///     Parses the given string into a <see cref="TimestampDelta" />,
 ///     assuming the given units if no units are specified in the string.
 /// </summary>
 /// <param name="s">
 ///     The string to parse.
 /// </param>
 /// <param name="defaultUnits">
 ///     The units to assume if no units are present in <paramref name="s"/>.
 /// </param>
 /// <returns>
 ///     The parsed <see cref="TimestampDelta"/>
 /// </returns>
 /// <exception cref="System.FormatException">
 ///     The given string is not parseable into a <see cref="TimestampDelta"/>.
 /// </exception>
 /// <exception cref="System.OverflowException">
 ///     The string represents a value not representable by a
 ///     <see cref="TimestampDelta"/>.
 /// </exception>
 public static TimestampDelta Parse(string s, TimeUnit defaultUnits)
 {
     return(TimestampDelta.FromNanoseconds(TimestampFormatter.ParseToNanoseconds(s, defaultUnits)));
 }
 /// <inheritdoc />
 public string ToClipboardString(string format, bool includeUnits)
 {
     return(TimestampFormatter.ToClipboardString(this.nanoseconds, format, null, includeUnits));
 }
 /// <inheritdoc />
 public string ToString(string format, IFormatProvider formatProvider)
 {
     return(TimestampFormatter.ToString(this.nanoseconds, format, formatProvider));
 }
Ejemplo n.º 7
0
 /// <summary>
 ///     Gets the string representation of this
 ///     instance using the specified units.
 /// </summary>
 /// <param name="units">
 ///     The units.
 /// </param>
 /// <returns>
 ///     The string representation.
 /// </returns>
 public string ToString2(TimeUnit units)
 {
     return(TimestampFormatter.ToString(this.nanoseconds, null, units, true, false));
 }
Ejemplo n.º 8
0
 /// <inheritdoc />
 string IFormatForClipboard.ToClipboardString(string format, bool includeUnits)
 {
     return(TimestampFormatter.ToClipboardString(this.Duration.ToNanoseconds, format, null, includeUnits));
 }