/// <summary> /// Creates a character handler for the calendar specifier (c). /// </summary> internal static CharacterHandler <TResult, TBucket> CreateCalendarHandler <TResult, TBucket> (Func <TResult, CalendarSystem> getter, Action <TBucket, CalendarSystem> setter) where TBucket : ParseBucket <TResult> { return((pattern, builder) => { builder.AddField(PatternFields.Calendar, pattern.Current); builder.AddParseAction((cursor, bucket) => { // TODO(V2.0): (Breaking change, although undocumented.) Potentially make this case-sensitive // as we're parsing IDs. foreach (var id in CalendarSystem.Ids) { if (cursor.MatchCaseInsensitive(id, NodaFormatInfo.InvariantInfo.CompareInfo, true)) { setter(bucket, CalendarSystem.ForId(id)); return null; } } return ParseResult <TResult> .NoMatchingCalendarSystem(cursor); }); builder.AddFormatAction((value, sb) => sb.Append(getter(value).Id)); }); }
/// <summary> /// Converts the given object to the type of this converter, using the specified context and culture information. /// </summary> /// <returns> /// An <see cref="T:System.Object"/> that represents the converted value. /// </returns> /// <param name="context">An <see cref="T:System.ComponentModel.ITypeDescriptorContext"/> that provides a format context. </param> /// <param name="culture">The <see cref="T:System.Globalization.CultureInfo"/> to use as the current culture. </param> /// <param name="value">The <see cref="T:System.Object"/> to convert. </param> /// <exception cref="T:System.NotSupportedException">The conversion cannot be performed. </exception> public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value) { if (value is string @string) { CalendarSystem calendarSystem = CalendarSystem.ForId(@string); return(calendarSystem); } return(base.ConvertFrom(context, culture, value)); }
public void FromDateTimeWithCalendarSystem() { DateTime earlyJune = new DateTime(2010, 6, 5); CalendarSystem calendar = CalendarSystem.ForId("Julian"); LocalDate date = Snippet.For(LocalDate.FromDateTime(earlyJune, calendar)); // Between the years 2000 and 2099, the Julian calendar is 13 days behind the Gregorian calendar. Assert.AreEqual(2010, date.Year); Assert.AreEqual(5, date.Month); Assert.AreEqual(23, date.Day); }
public object NullSafeGet(DbDataReader dr, string[] names, ISessionImplementor session, object owner) { var ticks = (long?)NHibernateUtil.Int64.NullSafeGet(dr, names[0], session, owner); var calendarId = (string)NHibernateUtil.String.NullSafeGet(dr, names[1], session, owner); if (ticks == null || string.IsNullOrEmpty(calendarId)) { return(null); } return(Instant.FromUnixTimeTicks(ticks.Value).InUtc().Date.WithCalendar(CalendarSystem.ForId(calendarId))); }
/// <summary> /// Checks for what has changed and invokes the respective events /// </summary> private void ProcessChanges() { // Process image style ImageLayout newStyle = (ImageLayout)this.comboBoxOverlayImageStyle.SelectedIndex; _settings.ImageStyle.Value = newStyle; // Process time formats _settings.DateFormat.Value = textBoxTimeFormat.Text; // Process time interval _settings.RealTimeInterval.Value = (int)numericUpDownTimeInterval.Value; // Process calendars _settings.Calendar.Value = CalendarSystem.ForId(comboBoxCalendar.SelectedItem.ToString()); }
public object NullSafeGet(DbDataReader dr, string[] names, ISessionImplementor session, object owner) { var localDateTimeTicks = (long?)NHibernateUtil.Int64.NullSafeGet(dr, names[0], session); var zoneId = (string)NHibernateUtil.String.NullSafeGet(dr, names[1], session); var calendarId = (string)NHibernateUtil.String.NullSafeGet(dr, names[2], session); if (localDateTimeTicks == null || string.IsNullOrEmpty(zoneId) || string.IsNullOrEmpty(calendarId)) { return(null); } else { var instant = Instant.FromUnixTimeTicks(localDateTimeTicks.Value); var zone = DateTimeZoneProviders.Tzdb[zoneId]; var calendar = CalendarSystem.ForId(calendarId); return(new ZonedDateTime(instant, zone, calendar)); } }
public object NullSafeGet(DbDataReader dr, string[] names, ISessionImplementor session, object owner) { var localDateTicks = (long?)NHibernateUtil.Int64.NullSafeGet(dr, names[0], session); var offsetNanoseconds = (long?)NHibernateUtil.Int64.NullSafeGet(dr, names[1], session); var calendarId = (string)NHibernateUtil.String.NullSafeGet(dr, names[2], session); if (localDateTicks == null || offsetNanoseconds == null || string.IsNullOrEmpty(calendarId)) { return(null); } var localDate = Instant.FromUnixTimeTicks(localDateTicks.Value).InUtc().Date; localDate = localDate.WithCalendar(CalendarSystem.ForId(calendarId)); var offset = Offset.FromNanoseconds(offsetNanoseconds.Value); return(new OffsetDate(localDate, offset)); }
/// <summary> /// Creates a character handler for the calendar specifier (c). /// </summary> internal static CharacterHandler <TResult, TBucket> CreateCalendarHandler <TResult, TBucket> (Func <TResult, CalendarSystem> getter, Action <TBucket, CalendarSystem> setter) where TBucket : ParseBucket <TResult> { return((pattern, builder) => { builder.AddField(PatternFields.Calendar, pattern.Current); builder.AddParseAction((cursor, bucket) => { foreach (var id in CalendarSystem.Ids) { if (cursor.Match(id)) { setter(bucket, CalendarSystem.ForId(id)); return null; } } return ParseResult <TResult> .NoMatchingCalendarSystem(cursor); }); builder.AddFormatAction((value, sb) => sb.Append(getter(value).Id)); }); }
public void BadId() { Assert.Throws <KeyNotFoundException>(() => CalendarSystem.ForId("bad")); }
public void AllIdsGiveDifferentCalendars() { var allCalendars = CalendarSystem.Ids.Select(id => CalendarSystem.ForId(id)); Assert.AreEqual(CalendarSystem.Ids.Count(), allCalendars.Distinct().Count()); }
public void IdsAreCaseSensitive(string id) { Assert.Throws <KeyNotFoundException>(() => CalendarSystem.ForId(id.ToLowerInvariant())); }
public void ValidId(string id) { Assert.IsInstanceOf <CalendarSystem>(CalendarSystem.ForId(id)); }