protected override void InitInternal(ICollection <string> locales, DateTimeFormatOptions options) { Hashtable ht = new Hashtable(); LocaleMatcher matcher = options.LocaleMatcher; ht["ca"] = options.Calendar; ht["nu"] = options.NumberingSystem; bool? hour12 = options.Hour12; HourCycle hourCycle = options.HourCycle; if (hour12 != default) { hourCycle = HourCycle.Unspecified; } ht["hc"] = IntlProviderOptions.ToStringValue(hourCycle); this.Locale = ResolveLocale(locales, matcher, relevantExtensionKeys, ht, out ht); this.Calendar = (string)ht["ca"]; this.NumberingSystem = (string)ht["nu"]; string tz = options.TimeZone; if (tz != null) { if (!IntlUtility.IsValidTimeZoneName(tz)) { throw new EcmaRangeErrorException("Invalid time zone specified: {0}", tz); } this.TimeZone = IntlUtility.CanonicalizeTimeZoneName(tz); } else { this.TimeZone = IntlContext.DefaultTimeZone; } this.FormatMatcher = options.FormatMatcher; DateTimePartStyles styles = new DateTimePartStyles(options); HourCycle finalHourCycle = IntlProviderOptions.ParseEnum <HourCycle>((string)ht["hc"]); this.HourCycle = hour12 == default ? finalHourCycle : NormalizeHourCycle(finalHourCycle, hour12.Value); this.Hour12 = this.HourCycle == HourCycle.Hour11 || this.HourCycle == HourCycle.Hour12; this.format = GetBestFormat(styles); this.calendar = IntlUtility.SupportedCalendars[this.Calendar]; this.DateTimePartStyles = format.Styles; this.BoundFormat = Literal.FunctionLiteral(this.FormatInternal); }
private static int GetHourInHourCycle(int value, HourCycle hc) { if (hc == HourCycle.Hour11 || hc == HourCycle.Hour12) { value = value % 12; } if (value == 0) { if (hc == HourCycle.Hour12) { value = 12; } else if (hc == HourCycle.Hour24) { value = 24; } } return(value); }
private static HourCycle NormalizeHourCycle(HourCycle hc, bool hour12) { return(hour12 ? hc == HourCycle.Hour11 || hc == HourCycle.Hour23 ? HourCycle.Hour11 : HourCycle.Hour12 : hc == HourCycle.Hour11 || hc == HourCycle.Hour23 ? HourCycle.Hour23 : HourCycle.Hour24); }