public static CurrencyNumberFormatter GetCurrencyFormatter(string currency) { if (_currencyCache.TryGetValue(currency, out CurrencyNumberFormatter formatter) == false) { var culture = NativeUtils.GetCurrentCulture(); var languages = new[] { culture }.Union(GlobalizationPreferences.Languages); var region = GlobalizationPreferences.HomeGeographicRegion; formatter = new CurrencyNumberFormatter(currency, languages, region); _currencyCache[currency] = formatter; } return(formatter); }
public static string Grams(long value, bool gem) { if (gem) { var culture = NativeUtils.GetCurrentCulture(); var info = new CultureInfo(culture); if (info.NumberFormat.CurrencyPositivePattern == 0 || info.NumberFormat.CurrencyPositivePattern == 2) { return(string.Format("\uD83D\uDC8E {0:0.000000000}", value / 1000000000d)); } return(string.Format("{0:0.000000000} \uD83D\uDC8E", value / 1000000000d)); } return(string.Format("{0:0.000000000}", value / 1000000000d)); }
private BindConvert() { //var region = new GeographicRegion(); //var code = region.CodeTwoLetter; var culture = NativeUtils.GetCurrentCulture(); var languages = new[] { culture }.Union(GlobalizationPreferences.Languages); ShortDate = new DateTimeFormatter("shortdate", languages, GlobalizationPreferences.HomeGeographicRegion, GlobalizationPreferences.Calendars.FirstOrDefault(), GlobalizationPreferences.Clocks.FirstOrDefault()); ShortTime = new DateTimeFormatter("shorttime", languages, GlobalizationPreferences.HomeGeographicRegion, GlobalizationPreferences.Calendars.FirstOrDefault(), GlobalizationPreferences.Clocks.FirstOrDefault()); LongDate = new DateTimeFormatter("longdate", languages, GlobalizationPreferences.HomeGeographicRegion, GlobalizationPreferences.Calendars.FirstOrDefault(), GlobalizationPreferences.Clocks.FirstOrDefault()); LongTime = new DateTimeFormatter("longtime", languages, GlobalizationPreferences.HomeGeographicRegion, GlobalizationPreferences.Calendars.FirstOrDefault(), GlobalizationPreferences.Clocks.FirstOrDefault()); MonthFull = new DateTimeFormatter("month.full", languages, GlobalizationPreferences.HomeGeographicRegion, GlobalizationPreferences.Calendars.FirstOrDefault(), GlobalizationPreferences.Clocks.FirstOrDefault()); MonthFullYear = new DateTimeFormatter("month.full year", languages, GlobalizationPreferences.HomeGeographicRegion, GlobalizationPreferences.Calendars.FirstOrDefault(), GlobalizationPreferences.Clocks.FirstOrDefault()); DayMonthFull = new DateTimeFormatter("day month.full", languages, GlobalizationPreferences.HomeGeographicRegion, GlobalizationPreferences.Calendars.FirstOrDefault(), GlobalizationPreferences.Clocks.FirstOrDefault()); DayMonthFullYear = new DateTimeFormatter("day month.full year", languages, GlobalizationPreferences.HomeGeographicRegion, GlobalizationPreferences.Calendars.FirstOrDefault(), GlobalizationPreferences.Clocks.FirstOrDefault()); }
static Converter() { var culture = NativeUtils.GetCurrentCulture(); var languages = new[] { culture }.Union(GlobalizationPreferences.Languages); var region = GlobalizationPreferences.HomeGeographicRegion; var calendar = GlobalizationPreferences.Calendars.FirstOrDefault(); var clock = GlobalizationPreferences.Clocks.FirstOrDefault(); ShortDate = new DateTimeFormatter("shortdate", languages, region, calendar, clock); ShortTime = new DateTimeFormatter("shorttime", languages, region, calendar, clock); LongDate = new DateTimeFormatter("longdate", languages, region, calendar, clock); LongTime = new DateTimeFormatter("longtime", languages, region, calendar, clock); MonthFull = new DateTimeFormatter("month.full", languages, region, calendar, clock); MonthAbbreviatedDay = new DateTimeFormatter("month.abbreviated day", languages, region, calendar, clock); MonthFullYear = new DateTimeFormatter("month.full year", languages, region, calendar, clock); DayMonthFull = new DateTimeFormatter("day month.full", languages, region, calendar, clock); DayMonthFullYear = new DateTimeFormatter("day month.full year", languages, region, calendar, clock); MonthAbbreviatedYear = new DateTimeFormatter("month.abbreviated year", languages, region, calendar, clock); DayMonthAbbreviatedYear = new DateTimeFormatter("day month.abbreviated year", languages, region, calendar, clock); DayOfWeekAbbreviated = new DateTimeFormatter("dayofweek.abbreviated", languages, region, calendar, clock); }
public static string Grams(long value, bool gem) { var sign = value < 0 ? "-" : string.Empty; var builder = new StringBuilder(string.Format("{0}{1}.{2:000000000}", sign, Math.Abs(value / 1000000000L), Math.Abs(value % 1000000000))); while (builder.Length > 1 && builder[builder.Length - 1] == '0' && builder[builder.Length - 2] != '.') { builder.Remove(builder.Length - 1, 1); } if (gem) { var culture = NativeUtils.GetCurrentCulture(); var info = new CultureInfo(culture); if (info.NumberFormat.CurrencyPositivePattern == 0 || info.NumberFormat.CurrencyPositivePattern == 2) { return(string.Format("\uD83D\uDC8E {0}", builder)); } return(string.Format("{0} \uD83D\uDC8E", builder)); } return(builder.ToString()); }
public static string Distance(float distance) { var useImperialSystemType = false; switch (SettingsService.Current.DistanceUnits) { case DistanceUnits.Automatic: var culture = NativeUtils.GetCurrentCulture(); var info = new RegionInfo(culture); useImperialSystemType = !info.IsMetric; break; case DistanceUnits.Kilometers: useImperialSystemType = false; break; case DistanceUnits.Miles: useImperialSystemType = true; break; } if (useImperialSystemType) { distance *= 3.28084f; if (distance < 1000) { return(string.Format(Strings.Resources.FootsAway, string.Format("{0}", (int)Math.Max(1, distance)))); } else { String arg; if (distance % 5280 == 0) { arg = string.Format("{0}", (int)(distance / 5280)); } else { arg = string.Format("{0:0.00}", distance / 5280.0f); } return(string.Format(Strings.Resources.MilesAway, arg)); } } else { if (distance < 1000) { return(string.Format(Strings.Resources.MetersAway2, string.Format("{0}", (int)Math.Max(1, distance)))); } else { String arg; if (distance % 1000 == 0) { arg = string.Format("{0}", (int)(distance / 1000)); } else { arg = string.Format("{0:0.00}", distance / 1000.0f); } return(string.Format(Strings.Resources.KMetersAway2, arg)); } } }
public static IList <DateRange> Parse(string query) { var monthEngl = new string[12]; var monthInLocal = new string[12]; var cultureEngl = new CultureInfo("en"); var cultureInLocal = new CultureInfo(NativeUtils.GetCurrentCulture()); for (int i = 1; i <= 12; i++) { monthEngl[i - 1] = cultureEngl.DateTimeFormat.GetMonthName(i).ToLower(); monthInLocal[i - 1] = cultureInLocal.DateTimeFormat.GetMonthName(i).ToLower(); } var split = query.ToLower().Trim().Split(' ', StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < split.Length; i++) { if (split[i].Length > 3) { for (int j = 0; j < 12; j++) { if (monthEngl[j].StartsWith(split[i]) || monthInLocal[j].StartsWith(split[i])) { split[i] = split[i].Substring(0, 3); break; } } } } var text = string.Join(' ', split); var results = new List <DateRange>(); foreach (var format in _formats) { if (TryParseExact(text, format.Key, cultureEngl, cultureInLocal, out DateTime result)) { DateTime start = result.Date; DateTime end = result.Date; switch (format.Value) { case DateRangeFormat.Day: end = result.Date.AddDays(1); break; case DateRangeFormat.Month: end = result.Date.AddMonths(1); break; case DateRangeFormat.Year: end = result.Date.AddYears(1); break; } for (int i = start.Year; i >= 2010; i--) { results.Add(new DateRange { StartDate = start.AddYears(-(start.Year - i)).ToTimestamp(), EndDate = end.AddYears(-(start.Year - i)).ToTimestamp() - 1 }); } break; } } return(results); }