public static EcmaValue NumberFormat([This] EcmaValue thisValue, EcmaValue locales, EcmaValue options) { RelativeTimeFormat formatter = thisValue.GetUnderlyingObject <RelativeTimeFormat>(); ICollection <string> requestedLocales = IntlUtility.CanonicalizeLocaleList(locales); formatter.Init(requestedLocales, new RelativeTimeFormatOptions(options)); return(thisValue); }
public static EcmaValue ResolvedOptions([This] EcmaValue thisValue) { RelativeTimeFormat formatter = thisValue.GetUnderlyingObject <RelativeTimeFormat>(); EcmaObject obj = new EcmaObject(); obj.CreateDataPropertyOrThrow(PropertyKey.Locale, formatter.Locale); obj.CreateDataPropertyOrThrow(PropertyKey.Style, IntlProviderOptions.ToStringValue(formatter.Style)); obj.CreateDataPropertyOrThrow(PropertyKey.Numeric, IntlProviderOptions.ToStringValue(formatter.Numeric)); obj.CreateDataPropertyOrThrow(PropertyKey.NumberingSystem, formatter.NumberingSystem); return(obj); }
/// <summary> /// Responsible for converting a relative time format and value into a delegate /// </summary> /// <param name="number">The amount of units</param> /// <param name="format">The time unit</param> /// <returns>A delegate that will be used to construct the final result</returns> /// <exception cref="ArgumentOutOfRangeException"></exception> protected virtual Func <DateTime, DateTime> ParseRelativeTime(double number, RelativeTimeFormat format) { const int daysPerWeek = 7; return(format switch { RelativeTimeFormat.Tomorrow => time => time.AddDays(1), RelativeTimeFormat.Seconds => time => time.AddSeconds(number), RelativeTimeFormat.Minutes => time => time.AddMinutes(number), RelativeTimeFormat.Hours => time => time.AddHours(number), RelativeTimeFormat.Days => time => time.AddDays(number), RelativeTimeFormat.Weeks => time => time.AddDays(number * daysPerWeek), RelativeTimeFormat.Months => time => time.AddMonths((int)number), //LOSSY CONVERSION RelativeTimeFormat.Years => time => time.AddYears((int)number), //LOSSY CONVERSION _ => throw new ArgumentOutOfRangeException(nameof(format), format, null) });
public static EcmaValue FormatToParts([This] EcmaValue thisValue, EcmaValue value, EcmaValue unit) { RelativeTimeFormat formatter = thisValue.GetUnderlyingObject <RelativeTimeFormat>(); return(formatter.Format(value, unit, out string[] units).ToPartArray(PropertyKey.Unit, units)); }
public static EcmaValue Format([This] EcmaValue thisValue) { RelativeTimeFormat formatter = thisValue.GetUnderlyingObject <RelativeTimeFormat>(); return(formatter.BoundFormat); }
/// <summary> /// Initializes a new instance of the <see cref="RelativeTime"/> class. /// </summary> /// <param name="amount">The amount of time</param> /// <param name="format">The time unit to use</param> public RelativeTime(double amount, RelativeTimeFormat format) { Amount = amount; Format = format; }