Example #1
0
        public static string DateForChatHeader(DateTime date)
        {
            var    ts    = new TimeSpan(DateTime.Now.Ticks - date.Ticks);
            double delta = Math.Abs(ts.TotalSeconds);

            if (date.Date == DateTime.Now.Date)
            {
                return(L10N.Localize("date_Today"));
            }

            if (date.Date.AddDays(1) == DateTime.Now.Date)
            {
                return(L10N.Localize("date_Yesterday"));
            }

            if (date.Date.AddDays(2) == DateTime.Now.Date || delta < 144 * HOUR)
            {
                return(L10N.Localize($"date_{date.DayOfWeek.ToString()}"));
            }

            if (date.Date.Year == DateTime.Now.Year)
            {
                return(L10N.Locale() == "en-US" ? date.ToString("MMM dd") : date.ToString("dd MMM"));
            }

            return(date.Date.ToShortDateString());
        }
Example #2
0
        public static string GetCallerName(int callerId)
        {
            #if DEBUG
            var realm = Realm.GetInstance(new RealmConfiguration {
                ShouldDeleteIfMigrationNeeded = true
            });
            #else
            var realm = Realm.GetInstance();
            #endif

            var members = realm.All <GetUsersInDivisionModel>();
            var caller  = members.Where(x => x.UserId == callerId)?.FirstOrDefault();

            string fullname = string.Empty;

            if (caller != null)
            {
                fullname = $"{caller?.FirstName} {caller?.LastName} - {caller?.Position}";
            }
            else
            {
                fullname = L10N.Localize("Call_Anonym");
            }

            return(fullname);
        }
Example #3
0
 public static void Handle(NoInternetException e)
 {
     if (!AppSettings.UserNoInternetNotified)
     {
         DialogService.ShowAlert(L10N.Localize("Dialogs_InternetException"), AlertType.Error);
         AppSettings.UserNoInternetNotified = true;
     }
 }
Example #4
0
        //https://stackoverflow.com/questions/11/calculate-relative-time-in-c-sharp
        public static string TimePassed(DateTime date)
        {
            var    ts    = new TimeSpan(DateTime.Now.Ticks - date.Ticks);
            double delta = Math.Abs(ts.TotalSeconds);

            if (delta < 1 * MINUTE)
            {
                return(ts.Seconds + L10N.Localize("date_Seconds"));
            }

            if (delta < 2 * MINUTE)
            {
                return(L10N.Localize("date_Minute"));
            }

            if (delta < 45 * MINUTE)
            {
                return(ts.Minutes + L10N.Localize("date_Minutes"));
            }

            if (delta < 90 * MINUTE)
            {
                return(L10N.Localize("date_Hour"));
            }

            if (delta <= 9 * HOUR)
            {
                return(ts.Hours + L10N.Localize("date_Hours"));
            }

            if (delta > 9 * HOUR && date.Date == DateTime.Now.Date)
            {
                return(L10N.Localize("date_Today"));
            }

            if (date.Date.AddDays(1) == DateTime.Now.Date)
            {
                return(L10N.Localize("date_Yesterday"));
            }

            if (delta > 48 * HOUR && delta < 144 * HOUR || date.Date.AddDays(2) == DateTime.Now.Date)
            {
                return(L10N.Localize($"date_{date.DayOfWeek.ToString()}"));
            }

            return(date.Date.ToShortDateString());
        }