using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Data;

namespace TwitterClient.Converters
{
    class DateTimeToPeriodConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            String ret = null;
            try
            {
                DateTime dt1 = DateTime.Now;
                DateTime dt2 = (DateTime)value;
                TimeSpan ts = dt1.Subtract(dt2);
                if (ts.Days > 0) ret = ts.Days + " dni temu";
                else if (ts.Hours > 0) ret = ts.Hours + " godzin temu";
                else if (ts.Minutes > 0) ret = ts.Minutes + " minut temu";
                else if (ts.Seconds>0) ret = ts.Seconds + " sekund temu";
                return ret;
            }
            catch (Exception ex)
            {
                return value.ToString();
            } 
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
}
