Пример #1
0
    /// <summary>
    /// The format date time topic.
    /// </summary>
    /// <param name="dateTimeInstance">
    /// The yaf date time.
    /// </param>
    /// <param name="objectDateTime">
    /// The object date time.
    /// </param>
    /// <returns>
    /// The format date time topic.
    /// </returns>
    public static string FormatDateTimeTopic([NotNull] this IDateTime dateTimeInstance, [NotNull] object objectDateTime)
    {
      CodeContracts.VerifyNotNull(dateTimeInstance, "dateTimeInstance");
      CodeContracts.VerifyNotNull(objectDateTime, "objectDateTime");

      try
      {
        DateTime dateTime = Convert.ToDateTime(objectDateTime);
        return dateTimeInstance.FormatDateTimeTopic(dateTime);
      }
      catch
      {
        // failed convert...
        return "[error]";
      }
    }
Пример #2
0
        /// <summary>
        /// Format objectDateTime according to the format enum. "[error]" if the value is invalid.
        /// </summary>
        /// <param name="dateTimeInstance">
        /// The datetime.
        /// </param>
        /// <param name="format">
        /// The format.
        /// </param>
        /// <param name="objectDateTime">
        /// The object date time.
        /// </param>
        /// <returns>
        /// Formatted datetime or "[error]" if invalid.
        /// </returns>
        public static string Format([NotNull] this IDateTime dateTimeInstance, DateTimeFormat format, [NotNull] object objectDateTime)
        {
            CodeContracts.VerifyNotNull(dateTimeInstance, "dateTimeInstance");
            CodeContracts.VerifyNotNull(objectDateTime, "objectDateTime");

            try
            {
                var dateTime = Convert.ToDateTime(objectDateTime);

                return(format switch
                {
                    DateTimeFormat.BothDateShort => dateTimeInstance.FormatDateTimeShort(dateTime),
                    DateTimeFormat.BothTopic => dateTimeInstance.FormatDateTimeTopic(dateTime),
                    DateTimeFormat.DateLong => dateTimeInstance.FormatDateLong(dateTime),
                    DateTimeFormat.DateShort => dateTimeInstance.FormatDateShort(dateTime),
                    DateTimeFormat.Time => dateTimeInstance.FormatTime(dateTime),
                    DateTimeFormat.Both => dateTimeInstance.FormatDateTime(dateTime),
                    _ => dateTimeInstance.FormatDateTime(dateTime)
                });
            }
Пример #3
0
    /// <summary>
    /// Format objectDateTime according to the format enum. "[error]" if the value is invalid.
    /// </summary>
    /// <param name="dateTimeInstance">
    /// The yaf date time.
    /// </param>
    /// <param name="format">
    /// The format.
    /// </param>
    /// <param name="objectDateTime">
    /// The object date time.
    /// </param>
    /// <returns>
    /// Formatted datetime or "[error]" if invalid.
    /// </returns>
    public static string Format([NotNull] this IDateTime dateTimeInstance, DateTimeFormat format, [NotNull] object objectDateTime)
    {
      CodeContracts.VerifyNotNull(dateTimeInstance, "dateTimeInstance");
      CodeContracts.VerifyNotNull(objectDateTime, "objectDateTime");

      try
      {
        DateTime dateTime = Convert.ToDateTime(objectDateTime);

        switch (format)
        {
          case DateTimeFormat.BothDateShort:
            return dateTimeInstance.FormatDateTimeShort(dateTime);

          case DateTimeFormat.BothTopic:
            return dateTimeInstance.FormatDateTimeTopic(dateTime);

          case DateTimeFormat.DateLong:
            return dateTimeInstance.FormatDateLong(dateTime);

          case DateTimeFormat.DateShort:
            return dateTimeInstance.FormatDateShort(dateTime);

          case DateTimeFormat.Time:
            return dateTimeInstance.FormatTime(dateTime);
          
          case DateTimeFormat.Both:
          default:
            return dateTimeInstance.FormatDateTime(dateTime);

        }
      }
      catch
      {
      }

      // failed convert...
      return "[error]";
    }