コード例 #1
0
 private static void AssembleFields(FieldSet.Builder builder, CalendarSystem @this)
 {
     builder.Era = EraField;
     builder.MonthOfYear = new BasicMonthOfYearDateTimeField((BasicCalendarSystem) @this, 12);
     builder.Months = builder.MonthOfYear.DurationField;
 }
コード例 #2
0
        private static void AssembleFields(FieldSet.Builder builder, CalendarSystem @this)
        {
            // None of the fields will call anything on the calendar system *yet*, so this is safe enough.
            BasicCalendarSystem thisCalendar = (BasicCalendarSystem) @this;
            // First copy the fields that are the same for all basic
            // calendars
            builder.WithSupportedFieldsFrom(preciseFields);

            // Now create fields that have unique behavior for Gregorian and Julian
            // calendars.

            builder.Year = new BasicYearDateTimeField(thisCalendar);
            builder.YearOfEra = new GJYearOfEraDateTimeField(builder.Year, thisCalendar);

            // Define one-based centuryOfEra and yearOfCentury.
            DateTimeField field = new OffsetDateTimeField(builder.YearOfEra, 99);
            builder.CenturyOfEra = new DividedDateTimeField(field, DateTimeFieldType.CenturyOfEra, 100);

            field = new RemainderDateTimeField((DividedDateTimeField)builder.CenturyOfEra);
            builder.YearOfCentury = new OffsetDateTimeField(field, DateTimeFieldType.YearOfCentury, 1);

            builder.Era = new GJEraDateTimeField(thisCalendar);
            builder.DayOfWeek = new GJDayOfWeekDateTimeField(thisCalendar, builder.Days);
            builder.DayOfMonth = new BasicDayOfMonthDateTimeField(thisCalendar, builder.Days);
            builder.DayOfYear = new BasicDayOfYearDateTimeField(thisCalendar, builder.Days);
            builder.MonthOfYear = new BasicMonthOfYearDateTimeField(thisCalendar, 2); // February is the leap month
            builder.WeekYear = new BasicWeekYearDateTimeField(thisCalendar);
            builder.WeekOfWeekYear = new BasicWeekOfWeekYearDateTimeField(thisCalendar, builder.Weeks);

            field = new RemainderDateTimeField(builder.WeekYear, DateTimeFieldType.WeekYearOfCentury, 100);
            builder.WeekYearOfCentury = new OffsetDateTimeField(field, DateTimeFieldType.WeekYearOfCentury, 1);
            // The remaining (imprecise) durations are available from the newly
            // created datetime fields.

            builder.Years = builder.Year.DurationField;
            builder.Centuries = builder.CenturyOfEra.DurationField;
            builder.Months = builder.MonthOfYear.DurationField;
            builder.WeekYears = builder.WeekYear.DurationField;
        }
コード例 #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="CalendarSystem"/> class.
 /// </summary>
 /// <param name="name">The name of the calendar</param>
 /// <param name="fieldAssembler">Delegate to invoke in order to assemble fields for this calendar.</param>
 /// <param name="eras">The eras within this calendar, which need not be unique to the calendar.</param>
 internal CalendarSystem(string name, FieldAssembler fieldAssembler, IEnumerable<Era> eras)
 {
     this.name = name;
     this.eras = new List<Era>(eras).AsReadOnly();
     FieldSet.Builder builder = new FieldSet.Builder();
     fieldAssembler(builder, this);
     this.fields = builder.Build();
 }
コード例 #4
0
 /// <summary>
 /// Field assembly used solely for the ISO calendar variation.
 /// </summary>
 private static void AssembleIsoFields(FieldSet.Builder builder, CalendarSystem @this)
 {
     // Use zero based century and year of century.
     DividedDateTimeField centuryOfEra = new DividedDateTimeField(IsoYearOfEraDateTimeField.Instance, DateTimeFieldType.CenturyOfEra, 100);
     builder.CenturyOfEra = centuryOfEra;
     builder.YearOfCentury = new RemainderDateTimeField(centuryOfEra, DateTimeFieldType.YearOfCentury);
     builder.WeekYearOfCentury = new RemainderDateTimeField(centuryOfEra, DateTimeFieldType.WeekYearOfCentury);
     builder.Centuries = centuryOfEra.DurationField;
 }
コード例 #5
0
ファイル: FieldSet.cs プロジェクト: manirana007/NodaTime
            /// <summary>
            /// Copies just the supported fields from the specified set into this builder,
            /// and returns this builder again (for fluent building).
            /// </summary>
            /// <param name="other">The set of fields to copy.</param>
            internal Builder WithSupportedFieldsFrom(FieldSet other)
            {
                if (other == null)
                {
                    throw new ArgumentNullException("other");
                }
                Ticks = other.Ticks.IsSupported ? other.Ticks : Ticks;
                Milliseconds = other.Milliseconds.IsSupported ? other.Milliseconds : Milliseconds;
                Seconds = other.Seconds.IsSupported ? other.Seconds : Seconds;
                Minutes = other.Minutes.IsSupported ? other.Minutes : Minutes;
                Hours = other.Hours.IsSupported ? other.Hours : Hours;
                HalfDays = other.HalfDays.IsSupported ? other.HalfDays : HalfDays;
                Days = other.Days.IsSupported ? other.Days : Days;
                Weeks = other.Weeks.IsSupported ? other.Weeks : Weeks;
                WeekYears = other.WeekYears.IsSupported ? other.WeekYears : WeekYears;
                Months = other.Months.IsSupported ? other.Months : Months;
                Years = other.Years.IsSupported ? other.Years : Years;
                Centuries = other.Centuries.IsSupported ? other.Centuries : Centuries;
                Eras = other.Eras.IsSupported ? other.Eras : Eras;

                TickOfSecond = other.TickOfSecond.IsSupported ? other.TickOfSecond : TickOfSecond;
                TickOfMillisecond = other.TickOfMillisecond.IsSupported ? other.TickOfMillisecond : TickOfMillisecond;
                TickOfDay = other.TickOfDay.IsSupported ? other.TickOfDay : TickOfDay;
                MillisecondOfSecond = other.MillisecondOfSecond.IsSupported ? other.MillisecondOfSecond : MillisecondOfSecond;
                MillisecondOfDay = other.MillisecondOfDay.IsSupported ? other.MillisecondOfDay : MillisecondOfDay;
                SecondOfMinute = other.SecondOfMinute.IsSupported ? other.SecondOfMinute : SecondOfMinute;
                SecondOfDay = other.SecondOfDay.IsSupported ? other.SecondOfDay : SecondOfDay;
                MinuteOfHour = other.MinuteOfHour.IsSupported ? other.MinuteOfHour : MinuteOfHour;
                MinuteOfDay = other.MinuteOfDay.IsSupported ? other.MinuteOfDay : MinuteOfDay;
                HourOfDay = other.HourOfDay.IsSupported ? other.HourOfDay : HourOfDay;
                ClockHourOfDay = other.ClockHourOfDay.IsSupported ? other.ClockHourOfDay : ClockHourOfDay;
                HourOfHalfDay = other.HourOfHalfDay.IsSupported ? other.HourOfHalfDay : HourOfHalfDay;
                ClockHourOfHalfDay = other.ClockHourOfHalfDay.IsSupported ? other.ClockHourOfHalfDay : ClockHourOfHalfDay;
                HalfDayOfDay = other.HalfDayOfDay.IsSupported ? other.HalfDayOfDay : HalfDayOfDay;
                DayOfWeek = other.DayOfWeek.IsSupported ? other.DayOfWeek : DayOfWeek;
                DayOfMonth = other.DayOfMonth.IsSupported ? other.DayOfMonth : DayOfMonth;
                DayOfYear = other.DayOfYear.IsSupported ? other.DayOfYear : DayOfYear;
                WeekOfWeekYear = other.WeekOfWeekYear.IsSupported ? other.WeekOfWeekYear : WeekOfWeekYear;
                WeekYear = other.WeekYear.IsSupported ? other.WeekYear : WeekYear;
                WeekYearOfCentury = other.WeekYearOfCentury.IsSupported ? other.WeekYearOfCentury : WeekYearOfCentury;
                MonthOfYear = other.MonthOfYear.IsSupported ? other.MonthOfYear : MonthOfYear;
                Year = other.Year.IsSupported ? other.Year : Year;
                YearOfCentury = other.YearOfCentury.IsSupported ? other.YearOfCentury : YearOfCentury;
                YearOfEra = other.YearOfEra.IsSupported ? other.YearOfEra : YearOfEra;
                CenturyOfEra = other.CenturyOfEra.IsSupported ? other.CenturyOfEra : CenturyOfEra;
                Era = other.Era.IsSupported ? other.Era : Era;
                return this;
            }
コード例 #6
0
ファイル: FieldSet.cs プロジェクト: manirana007/NodaTime
            internal Builder(FieldSet baseSet)
            {
                if (baseSet == null)
                {
                    throw new ArgumentNullException("baseSet");
                }
                Ticks = baseSet.Ticks;
                Milliseconds = baseSet.Milliseconds;
                Seconds = baseSet.Seconds;
                Minutes = baseSet.Minutes;
                Hours = baseSet.Hours;
                HalfDays = baseSet.HalfDays;
                Days = baseSet.Days;
                Weeks = baseSet.Weeks;
                WeekYears = baseSet.WeekYears;
                Months = baseSet.Months;
                Years = baseSet.Years;
                Centuries = baseSet.Centuries;
                Eras = baseSet.Eras;

                TickOfSecond = baseSet.TickOfSecond;
                TickOfMillisecond = baseSet.TickOfMillisecond;
                TickOfDay = baseSet.TickOfDay;
                MillisecondOfSecond = baseSet.MillisecondOfSecond;
                MillisecondOfDay = baseSet.MillisecondOfDay;
                SecondOfMinute = baseSet.SecondOfMinute;
                SecondOfDay = baseSet.SecondOfDay;
                MinuteOfHour = baseSet.MinuteOfHour;
                MinuteOfDay = baseSet.MinuteOfDay;
                HourOfDay = baseSet.HourOfDay;
                ClockHourOfDay = baseSet.ClockHourOfDay;
                HourOfHalfDay = baseSet.HourOfHalfDay;
                ClockHourOfHalfDay = baseSet.ClockHourOfHalfDay;
                HalfDayOfDay = baseSet.HalfDayOfDay;
                DayOfWeek = baseSet.DayOfWeek;
                DayOfMonth = baseSet.DayOfMonth;
                DayOfYear = baseSet.DayOfYear;
                WeekOfWeekYear = baseSet.WeekOfWeekYear;
                WeekYear = baseSet.WeekYear;
                WeekYearOfCentury = baseSet.WeekYearOfCentury;
                MonthOfYear = baseSet.MonthOfYear;
                Year = baseSet.Year;
                YearOfCentury = baseSet.YearOfCentury;
                YearOfEra = baseSet.YearOfEra;
                CenturyOfEra = baseSet.CenturyOfEra;
                Era = baseSet.Era;
            }
コード例 #7
0
ファイル: FieldSet.cs プロジェクト: manirana007/NodaTime
 /// <summary>
 /// Convenience method to create a new field set with
 /// the current field set as a "base" overridden with
 /// supported fields from the given set.
 /// </summary>
 internal FieldSet WithSupportedFieldsFrom(FieldSet fields)
 {
     return new Builder(this).WithSupportedFieldsFrom(fields).Build();
 }
コード例 #8
0
 private static void AssembleFields(FieldSet.Builder builder, CalendarSystem @this, CalendarSystem baseCalendar, FieldAssembler assembler)
 {
     builder.WithSupportedFieldsFrom(baseCalendar.Fields);
     assembler(builder, @this);
 }