Esempio n. 1
0
        public static string Convert(TLInt date, string TodayFormat, string WeekFormat, string RegularFormat, string LongRegularFormat)
        {
            var clientDelta = IoC.Get <IMTProtoService>().ClientTicksDelta;
            //var utc0SecsLong = date.Value * 4294967296 - clientDelta;
            var utc0SecsInt = date.Value - clientDelta / 4294967296.0;
            var dateTime    = Telegram.Api.Helpers.Utils.UnixTimestampToDateTime(utc0SecsInt);

            var cultureInfo      = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
            var shortTimePattern = UserStatusToStringConverter.GetShortTimePattern(ref cultureInfo);

            //Today
            if ((dateTime.Date == DateTime.Now.Date) && !string.IsNullOrEmpty(TodayFormat))
            {
                return(dateTime.ToString(string.Format(TodayFormat, shortTimePattern), cultureInfo));
            }

            //Week
            if (dateTime.Date.AddDays(7) >= DateTime.Now.Date && !string.IsNullOrEmpty(WeekFormat))
            {
                return(dateTime.ToString(string.Format(WeekFormat, shortTimePattern), cultureInfo));
            }

            //Long time ago (no more than one year ago)
            if (dateTime.Date.AddDays(365) >= DateTime.Now.Date && !string.IsNullOrEmpty(RegularFormat))
            {
                return(dateTime.ToString(string.Format(RegularFormat, shortTimePattern), cultureInfo));
            }

            //Long long time ago
            return(dateTime.ToString(string.Format(LongRegularFormat, shortTimePattern), cultureInfo));
        }
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
#if DEBUG
            return(value);
#endif

            if (!(value is TLInt))
            {
                return(value);
            }

            var clientDelta  = IoC.Get <IMTProtoService>().ClientTicksDelta;
            var utc0SecsLong = ((TLInt)value).Value * 4294967296 - clientDelta;
            var utc0SecsInt  = utc0SecsLong / 4294967296.0;

            var dateTime = Telegram.Api.Helpers.Utils.UnixTimestampToDateTime(utc0SecsInt);

            //var tzi = TimeZoneInfo.Local;
            //Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;


            var cultureInfo      = (CultureInfo)Thread.CurrentThread.CurrentCulture.Clone();
            var shortTimePattern = UserStatusToStringConverter.GetShortTimePattern(ref cultureInfo);


            //Today
            if ((dateTime.Date == DateTime.Now.Date) && !string.IsNullOrEmpty(TodayFormat))
            {
                return(dateTime.ToString(string.Format(TodayFormat, shortTimePattern), cultureInfo));
            }

            //Yesterday
            if ((dateTime.Date.AddDays(1) == DateTime.Now.Date) && !string.IsNullOrEmpty(YesterdayString))
            {
                return(YesterdayString);
            }

            if ((dateTime.Date.AddDays(1) == DateTime.Now.Date) && !string.IsNullOrEmpty(YesterdayFormat))
            {
                return(dateTime.ToString(string.Format(YesterdayFormat, shortTimePattern), cultureInfo));
            }

            //Long time ago (no more than one year ago)
            if (dateTime.Date.AddDays(365) >= DateTime.Now.Date && !string.IsNullOrEmpty(RegularFormat))
            {
                return(dateTime.ToString(string.Format(RegularFormat, shortTimePattern), cultureInfo));
            }

            //Long long time ago
            return(dateTime.ToString(string.Format(LongRegularFormat, shortTimePattern), cultureInfo));
        }