Esempio n. 1
0
        public override object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (!(value is TimeSpan))
            {
                return(DependencyProperty.UnsetValue);
            }

            // префикс, если в конце пробел: 'через '
            var isPrefix = false;
            var label    = parameter as string;

            if (label != null && label.Length > 0)
            {
                isPrefix = label.Last() == ' ';
                label    = label.Trim();
            }

            TimeSpan ts       = (TimeSpan)value;
            var      sameTime = "в то же время";
            var      str      = TimeSpanFormatter.GetTimeSpanString(ts, 3, sameTime);

            if (label == null || str == sameTime)
            {
                return(str);
            }
            else
            if (isPrefix)
            {
                return(string.Format("{0} {1}", label, str));
            }
            else
            {
                return(string.Format("{0} {1}", str, label));
            }
        }
Esempio n. 2
0
        public void Negative()
        {
            DateTime one = new DateTime(2014, 1, 2, 15, 6, 0);
            DateTime two = new DateTime(2014, 1, 1, 19, 5, 0);
            var      ts  = two - one;
            var      str = TimeSpanFormatter.GetTimeSpanString(ts, 3, "equal");

            Assert.AreEqual("equal", str);
        }
Esempio n. 3
0
        public void LessThanDaySameHours()
        {
            DateTime one = new DateTime(2014, 1, 1, 20, 5, 0);
            DateTime two = new DateTime(2014, 1, 1, 20, 6, 0);
            var      ts  = two - one;
            var      str = TimeSpanFormatter.GetTimeSpanString(ts, 3);

            Assert.AreEqual("0 ч 1 м", str);
        }
Esempio n. 4
0
        public void SameTime()
        {
            DateTime one = new DateTime(2014, 1, 1, 15, 5, 0);
            DateTime two = new DateTime(2014, 1, 3, 15, 5, 0);
            var      ts  = two - one;
            var      str = TimeSpanFormatter.GetTimeSpanString(ts, 3);

            Assert.AreEqual("2 дня 0 ч", str);
        }
Esempio n. 5
0
        public void ManyDays()
        {
            DateTime one = new DateTime(2014, 1, 1);
            DateTime two = new DateTime(2014, 1, 5);
            var      ts  = two - one;
            var      str = TimeSpanFormatter.GetTimeSpanString(ts, 3);

            Assert.AreEqual("4 дня", str);
        }
Esempio n. 6
0
        public void Common()
        {
            DateTime one = new DateTime(2014, 1, 1, 0, 0, 0);
            DateTime two = new DateTime(2014, 1, 3, 6, 5, 0);
            var      ts  = two - one;
            var      str = TimeSpanFormatter.GetTimeSpanString(ts, 3);

            Assert.AreEqual("2 дня 6 ч 5 м", str);
        }