public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var d = value as DateTimeOffset?;

            if (value is DateTime)
            {
                d = (DateTime)value;
            }

            ILocalizedResourceProvider res = null;

            try
            {
                res = DependencyService.Get <IDependencyGetter>().Get <ILocalizedResourceProvider>();
            }
            catch
            {
                res = null;
            }

            if (!d.HasValue)
            {
                return(res?.GetText("TimeAgo_NA") ?? "N/A");
            }

            DateTimeOffset now      = DateTime.Now;
            var            timespan = now.Subtract(d.Value);

            if (timespan < TimeSpan.FromSeconds(60))
            {
                return(res?.GetText("TimeAgo_LessThan1Minute") ?? "Just now");
            }
            if (timespan < TimeSpan.FromMinutes(5))
            {
                return(res?.GetText("TimeAgo_LessThan5Minutes") ?? "Few minutes ago");
            }

            if (timespan < TimeSpan.FromMinutes(60))
            {
                return(res?.GetText("TimeAgo_LessThan1Hour", timespan.Minutes) ?? $"{timespan.Minutes} minutes ago");
            }

            if (timespan < TimeSpan.FromHours(24))
            {
                return(res?.GetText("TimeAgo_LessThan1Day", timespan.Hours) ?? $"{timespan.Hours} hours ago");
            }

            if (timespan < TimeSpan.FromDays(2))
            {
                return(res?.GetText("TimeAgo_Yesterday") ?? $"Yesterday");
            }

            if (timespan < TimeSpan.FromDays(7))
            {
                return(res?.GetText("TimeAgo_LessThan1Week", timespan.Days) ?? $"{timespan.Days} days ago");
            }

            return(res?.GetText("TimeAgo_Past", d.Value) ?? d.Value.ToString("MMM dd, YYYY"));
        }
Ejemplo n.º 2
0
        public SimpleFormsViewModel()
        {
            Rates = new ObservableDictionary <string, object>
            {
                { "0", "none" },
                { "1", "Less than 1 year" },
                { "2", "Between 1 and 2 years" },
                { "3", "More than 2 years" }
            };

            Genders = new ObservableDictionary <string, object>
            {
                { "1", _i18N.GetText("Form.Man") },
                { "2", _i18N.GetText("Form.Woman") }
            };

            Languages = new ObservableCollection <string>
            {
                _i18N.GetText("Form.English"),
                _i18N.GetText("Form.Spanish"),
                _i18N.GetText("Form.Russian")
            };

            Time         = new TimeSpan(DateTime.Now.Ticks);
            Date         = DateTime.Today.AddYears(1);
            SelectedItem = _i18N.GetText("Form.Russian");
        }
Ejemplo n.º 3
0
        public SimpleFormsViewModel()
        {
            Rates = new ObservableDictionary <string, object>
            {
                { "0", "none" },
                { "1", "Less than 1 year" },
                { "2", "Between 1 and 2 years" },
                { "3", "More than 2 years" }
            };

            Genders = new ObservableDictionary <string, object>
            {
                { "1", _i18N.GetText("Form.Man") },
                { "2", _i18N.GetText("Form.Woman") }
            };


            Languages = new ObservableDictionary <string, object>
            {
                { "English", _i18N.GetText("Form.English") },
                { "Spanish", _i18N.GetText("Form.Spanish") },
                { "Russian", _i18N.GetText("Form.Russian") }
            };
        }
Ejemplo n.º 4
0
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            ILocalizedResourceProvider res = null;

            try
            {
                res = DependencyService.Get <IDependencyGetter>().Get <ILocalizedResourceProvider>();
            }
            catch
            {
                res = null;
            }

            return(res?.GetText(value as string) ?? value);
        }
Ejemplo n.º 5
0
 public object ProvideValue(IServiceProvider serviceProvider)
 {
     return(resProvider?.GetText(Text));
 }