示例#1
0
        /// <summary>
        ///     Decrease the time and date of a <see cref="EorzeaDateTime" /> by a <see cref="TimeSpan" />.
        /// </summary>
        /// <param name="lh"><see cref="EorzeaDateTime" /> to use as base.</param>
        /// <param name="rh"><see cref="TimeSpan" /> to subtract to the <see cref="EorzeaDateTime" />.</param>
        /// <returns>Returns a new <see cref="EorzeaDateTime" /> object with the resulting time and date.</returns>
        public static EorzeaDateTime operator-(EorzeaDateTime lh, TimeSpan rh)
        {
            EorzeaDateTime copy = lh.Clone();

            copy.Minute -= (int)rh.TotalMinutes;
            return(copy);
        }
示例#2
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="EorzeaDateTime" /> class that represents the same time and date as
 ///     another <see cref="EorzeaDateTime" />.
 /// </summary>
 /// <param name="source"><see cref="EorzeaDateTime" /> whose values to copy.</param>
 public EorzeaDateTime(EorzeaDateTime source)
 {
     Minute = source.Minute;
     Bell   = source.Bell;
     Sun    = source.Sun;
     Moon   = source.Moon;
     Year   = source.Year;
 }
 /// <summary>
 ///     Initializes a new instance of the <see cref="EorzeaDateTime" /> class that represents the same time and date as
 ///     another <see cref="EorzeaDateTime" />.
 /// </summary>
 /// <param name="source"><see cref="EorzeaDateTime" /> whose values to copy.</param>
 public EorzeaDateTime(EorzeaDateTime source)
 {
     Minute = source.Minute;
     Bell = source.Bell;
     Sun = source.Sun;
     Moon = source.Moon;
     Year = source.Year;
 }
示例#4
0
            /// <summary>
            ///     Append the format for a specifier to the output, if applicable.
            /// </summary>
            /// <param name="dateTime">The Source <see cref="EorzeaDateTime"/>.</param>
            /// <param name="stringBuilder"><see cref="StringBuilder"/> to write to.</param>
            /// <param name="specifier">Specifier to use for formatting, or \0 should nothing be appended. When this method returns this value will always be \0.</param>
            /// <param name="count">Subsequent occurences of <c>specifier</c>.</param>
            /// <param name="formatProvider">The provider to use to format the value.</param>
            private static void TryFinishSequence(EorzeaDateTime dateTime, StringBuilder stringBuilder, ref char specifier, int count, IFormatProvider formatProvider)
            {
                if (specifier == '\0')
                {
                    return;
                }

                stringBuilder.Append(KnownSpecifiers[specifier].FormatFunction(dateTime, count, formatProvider));
                specifier = '\0';
            }
示例#5
0
            /// <summary>
            ///     Formats the value of the current instance using the specified format and format provider..
            /// </summary>
            /// <param name="dateTime"><see cref="EorzeaDateTime"/> to format.</param>
            /// <param name="format">Format string to use, or <c>null</c> to use the default format.</param>
            /// <param name="formatProvider">The provider to use to format the value, or <c>null</c> if the current culture's provider should be used.</param>
            /// <returns>The value of <c>dateTime</c> formatted as a string according to <c>format</c>.</returns>
            public static string Format(EorzeaDateTime dateTime, string format, IFormatProvider formatProvider)
            {
                if (dateTime == null)
                {
                    throw new ArgumentNullException("dateTime");
                }
                if (format == null)
                {
                    format = DefaultFormat;
                }
                if (formatProvider == null)
                {
                    formatProvider = System.Globalization.CultureInfo.CurrentCulture;
                }

                if (string.IsNullOrWhiteSpace(format))
                {
                    throw new ArgumentException();
                }

                if (format.Length == 1)
                {
                    char standardKey = format[0];
                    if (StandardFormats.ContainsKey(standardKey))
                    {
                        format = StandardFormats[standardKey];
                    }
                }

                StringBuilder sb = new StringBuilder();

                char isInString       = '\0';
                char currentSpecifier = '\0';
                int  specifierCount   = 0;

                foreach (char c in format)
                {
                    if (isInString != '\0')
                    {
                        if (c == isInString)
                        {
                            isInString = '\0';
                        }
                        else
                        {
                            sb.Append(c);
                        }
                    }
                    else
                    {
                        if (c == currentSpecifier)
                        {
                            ++specifierCount;
                        }
                        else
                        {
                            TryFinishSequence(dateTime, sb, ref currentSpecifier, specifierCount, formatProvider);

                            if (StringSpecifiers.Contains(c))
                            {
                                isInString = c;
                            }
                            else if (KnownSpecifiers.ContainsKey(c))
                            {
                                currentSpecifier = c;
                                specifierCount   = 1;
                            }
                            else
                            {
                                sb.Append(c);
                            }
                        }

                        if (currentSpecifier != '\0')
                        {
                            if (specifierCount == KnownSpecifiers[currentSpecifier].MaximumCount)
                            {
                                TryFinishSequence(dateTime, sb, ref currentSpecifier, specifierCount, formatProvider);
                            }
                        }
                    }
                }
                TryFinishSequence(dateTime, sb, ref currentSpecifier, specifierCount, formatProvider);

                return(sb.ToString());
            }