public void Should_format_string(string format, string mask)
        {
            var expected = string.Format(Consts.CultureEnUS, mask, 1.757899e2);

            var instance = new Millisecond(1.757899e2);
            var actual   = instance.ToString(format, Consts.CultureEnUS);

            Assert.AreEqual(expected, actual);
        }
        public void Should_convert_to_string(double value)
        {
            var expected = $"{value:e} milliseconds";

            var instance = new Millisecond(value);
            var actual   = instance.ToString();

            Assert.AreEqual(expected, actual);
        }
Beispiel #3
0
        public override string ToString()
        {
            string overall = "";

            overall += Hour.ToString().PadLeft(2, '0') + ':';
            overall += Minute.ToString().PadLeft(2, '0') + ':';
            overall += Second.ToString().PadLeft(2, '0') + ',';
            overall += Millisecond.ToString().PadLeft(3, '0');
            return(overall);
        }
        public AlaskaDateTime(TimeSpan timeOfDay)
        {
            var alaskaNow = DateTime.UtcNow.ToAlaska();

            Year  = alaskaNow.Year;
            Month = alaskaNow.Month;
            Day   = alaskaNow.Day;

            Hour        = timeOfDay.Hours;
            Minute      = timeOfDay.Minutes;
            Second      = timeOfDay.Seconds;
            Millisecond = timeOfDay.Milliseconds;

            var dateTimeParse =
                DateTime.Parse(string.Concat(Year, "-", Month.ToString("00"), "-", Day.ToString("00"), "T", Hour.ToString("00"), ":", Minute.ToString("00"), ":", Second.ToString("00"), ".", Millisecond.ToString("00"), "Z"))
                .ToUniversalTime()
                .ToAlaska();

            Offset = dateTimeParse.IsInDaylightSavingsTime() ? DaylightOffset : StandardOffset;

            Date      = new AlaskaDateTime(Year, Month, Day);
            DayOfYear = Date.DayOfYear;
            DayOfWeek = Date.DayOfWeek;
        }
Beispiel #5
0
 public override string ToString()
 {
     return(Year + "/" + Month.ToString().PadLeft(2, '0') + "/" + Day.ToString().PadLeft(2, '0') +
            " " + Hour.ToString().PadLeft(2, '0') + ":" + Minute.ToString().PadLeft(2, '0') + ":" + Second.ToString().PadLeft(2, '0') + "." + Millisecond.ToString().PadLeft(3, '0'));
 }
Beispiel #6
0
        public string ToString(string format)
        {
            var formattedText = "";

            if (format != null)
            {
                for (int i = 0, len = format.Length; i < len; i++)
                {
                    var wildcard = format[i];
                    var part     = wildcard.ToString();
                    i++;
                    while (i < len && format[i] == wildcard)
                    {
                        part += format[i];
                        i++;
                    }
                    i--;
                    switch (part)
                    {
                    case "y":
                    case "yy":
                    case "yyy":
                    case "yyyy":
                        formattedText += Year.ToString().PadLeft(part.Length, '0');
                        break;

                    case "MMMM":
                        formattedText += GetMonthName(Month);
                        break;

                    case "MMM":
                        formattedText += GetShortMonthName(Month);
                        break;

                    case "MM":
                    case "M":
                        formattedText += Month.ToString().PadLeft(part.Length, '0');
                        break;

                    case "dddd":
                        formattedText += DayName;
                        break;

                    case "ddd":
                        formattedText += ShortDayName;
                        break;

                    case "dd":
                    case "d":
                        formattedText += Day.ToString().PadLeft(part.Length, '0');
                        break;

                    case "HH":
                    case "H":
                        formattedText += Hour.ToString().PadLeft(part.Length, '0');
                        break;

                    case "hh":
                    case "h":
                        formattedText += (Hour % 12 == 0 ? 12 : Hour % 12).ToString().PadLeft(part.Length, '0');
                        break;

                    case "mm":
                    case "m":
                        formattedText += Minute.ToString().PadLeft(part.Length, '0');
                        break;

                    case "ss":
                    case "s":
                        formattedText += Second.ToString().PadLeft(part.Length, '0');
                        break;

                    case "fffffff":
                    case "ffffff":
                    case "fffff":
                    case "ffff":
                    case "fff":
                    case "ff":
                    case "f":
                        formattedText += Millisecond.ToString().PadLeft(part.Length, '0');
                        break;

                    case "tt":
                    case "t":
                        formattedText += (Hour < 12 ? "صبح" : "عصر").Substring(0, part.Length == 1 ? 1 : 3);
                        break;

                    default:
                        formattedText += part;
                        break;
                    }
                }
            }

            return(formattedText);
        }
Beispiel #7
0
        } // Equals

        // ----------------------------------------------------------------------
        public override string ToString()
        {
            return(((int)TotalHours).ToString("00") + ":" + Minute.ToString("00") +
                   ":" + Second.ToString("00") + "." + Millisecond.ToString("000"));
        } // ToString