Beispiel #1
0
 public void UnsupportedDateTimeFields_AreBuiltFromDurationFields()
 {
     FieldSet fieldSet = new FieldSet.Builder { Seconds = PreciseDurationField.Seconds }.Build();
     DateTimeField field = fieldSet.SecondOfMinute;
     Assert.IsFalse(field.IsSupported);
     Assert.AreSame(fieldSet.Seconds, field.DurationField);
 }
 private static FieldSet CreatePreciseFields()
 {
     // First create the simple durations, then fill in date/time fields,
     // which rely on the other properties
     FieldSet.Builder builder = new FieldSet.Builder
                                {
                                    Ticks = TicksDurationField.Instance,
                                    Milliseconds = PreciseDurationField.Milliseconds,
                                    Seconds = PreciseDurationField.Seconds,
                                    Minutes = PreciseDurationField.Minutes,
                                    Hours = PreciseDurationField.Hours,
                                    HalfDays = PreciseDurationField.HalfDays,
                                    Days = PreciseDurationField.Days,
                                    Weeks = PreciseDurationField.Weeks
                                };
     builder.TickOfSecond = new PreciseDateTimeField(DateTimeFieldType.TickOfSecond, builder.Ticks, builder.Seconds);
     builder.TickOfMillisecond = new PreciseDateTimeField(DateTimeFieldType.TickOfMillisecond, builder.Ticks, builder.Milliseconds);
     builder.TickOfDay = new PreciseDateTimeField(DateTimeFieldType.TickOfDay, builder.Ticks, builder.Days);
     builder.MillisecondOfSecond = new PreciseDateTimeField(DateTimeFieldType.MillisecondOfSecond, builder.Milliseconds, builder.Seconds);
     builder.MillisecondOfDay = new PreciseDateTimeField(DateTimeFieldType.MillisecondOfDay, builder.Milliseconds, builder.Days);
     builder.SecondOfMinute = new PreciseDateTimeField(DateTimeFieldType.SecondOfMinute, builder.Seconds, builder.Minutes);
     builder.SecondOfDay = new PreciseDateTimeField(DateTimeFieldType.SecondOfDay, builder.Seconds, builder.Days);
     builder.MinuteOfHour = new PreciseDateTimeField(DateTimeFieldType.MinuteOfHour, builder.Minutes, builder.Hours);
     builder.MinuteOfDay = new PreciseDateTimeField(DateTimeFieldType.MinuteOfDay, builder.Minutes, builder.Days);
     builder.HourOfDay = new PreciseDateTimeField(DateTimeFieldType.HourOfDay, builder.Hours, builder.Days);
     builder.HourOfHalfDay = new PreciseDateTimeField(DateTimeFieldType.HourOfHalfDay, builder.Hours, builder.HalfDays);
     builder.ClockHourOfDay = new ZeroIsMaxDateTimeField(builder.HourOfDay, DateTimeFieldType.ClockHourOfDay);
     builder.ClockHourOfHalfDay = new ZeroIsMaxDateTimeField(builder.HourOfHalfDay, DateTimeFieldType.ClockHourOfHalfDay);
     // TODO: This was a separate subclass in Joda, for i18n purposes
     builder.HalfDayOfDay = new PreciseDateTimeField(DateTimeFieldType.HalfDayOfDay, builder.HalfDays, builder.Days);
     return builder.Build();
 }
Beispiel #3
0
        public void Builder_WithFieldSet_CopiesFields()
        {
            FieldSet originalFieldSet = new FieldSet.Builder { SecondOfMinute = sampleField, Seconds = sampleField.DurationField }.Build();

            FieldSet newFieldSet = new FieldSet.Builder(originalFieldSet).Build();
            Assert.AreSame(sampleField, newFieldSet.SecondOfMinute);
            Assert.AreSame(sampleField.DurationField, newFieldSet.Seconds);
        }
Beispiel #4
0
 public void UnspecifiedDateTimeFields_DefaultToUnsupported()
 {
     FieldSet fieldSet = new FieldSet.Builder().Build();
     foreach (var prop in typeof(FieldSet).GetProperties().Where(p => p.PropertyType == typeof(DateTimeField)))
     {
         DateTimeField field = (DateTimeField)prop.GetValue(fieldSet, null);
         Assert.IsNotNull(field);
         Assert.IsFalse(field.IsSupported);
     }
 }
Beispiel #5
0
        public void WithSupportedFieldsFrom_CopiedSupportedFields()
        {
            FieldSet originalFieldSet = new FieldSet.Builder { SecondOfMinute = sampleField }.Build();
            DateTimeField newField = new PreciseDateTimeField(DateTimeFieldType.SecondOfMinute, PreciseDurationField.Seconds, PreciseDurationField.Minutes);

            FieldSet newFieldSet = new FieldSet.Builder { SecondOfMinute = newField }.WithSupportedFieldsFrom(originalFieldSet).Build();
            // SecondOfMinute is supported in originalFieldSet, so the field is copied over
            Assert.AreSame(originalFieldSet.SecondOfMinute, newFieldSet.SecondOfMinute);
        }
Beispiel #6
0
 public void FieldsAreCopiedFromBuilderToSet()
 {
     FieldSet fieldSet = new FieldSet.Builder { SecondOfMinute = sampleField, Seconds = sampleField.DurationField }.Build();
     Assert.AreSame(sampleField, fieldSet.SecondOfMinute);
     Assert.AreSame(sampleField.DurationField, fieldSet.Seconds);
 }
Beispiel #7
0
 public void WithSupportedFieldsFrom_ReturnsSameBuilderReference()
 {
     FieldSet originalSet = new FieldSet.Builder().Build();
     FieldSet.Builder builder = new FieldSet.Builder();
     Assert.AreSame(builder, builder.WithSupportedFieldsFrom(originalSet));
 }
Beispiel #8
0
        public void WithSupportedFieldsFrom_DoesNotCopyUnsupportedFields()
        {
            FieldSet originalFieldSet = new FieldSet.Builder { SecondOfMinute = sampleField }.Build();
            Assert.IsFalse(originalFieldSet.SecondOfDay.IsSupported);

            DateTimeField newField = new PreciseDateTimeField(DateTimeFieldType.SecondOfMinute, PreciseDurationField.Seconds, PreciseDurationField.Minutes);

            FieldSet newFieldSet = new FieldSet.Builder { SecondOfDay = newField }.WithSupportedFieldsFrom(originalFieldSet).Build();
            // SecondOfDay isn't supported in originalFieldSet, so the property we set is kept
            Assert.AreSame(newField, newFieldSet.SecondOfDay);
        }
Beispiel #9
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();
 }