Example #1
0
        public void BuildInstantByIntAndReturnToIntTests(
            int value,
            Type type,
            InstantType instType,
            InstantTypeGroup instTypeGroup,
            int[] segments
            )
        {
            var inst = Instant.FromInt(value);

            Assert.Equal(type, inst.GetType());
            Assert.Equal(inst.InstantType, instType);
            Assert.Equal(inst.InstantTypeGroup, instTypeGroup);
            if (inst.GetType() == typeof(YearInstant))
            {
                var y = inst as YearInstant;
                Assert.Equal(segments[0], y.Year);
                Assert.Equal(value, y.ToInt());
            }
            else if (inst.GetType() == typeof(YearHalfYearInstant))
            {
                var yh = inst as YearHalfYearInstant;
                Assert.Equal(segments[0], yh.Year);
                Assert.Equal(segments[1], yh.HalfYear);
                Assert.Equal(value, yh.ToInt());
            }
            else if (inst.GetType() == typeof(YearQuarterInstant))
            {
                var yq = inst as YearQuarterInstant;
                Assert.Equal(segments[0], yq.Year);
                Assert.Equal(segments[1], yq.Quarter);
                Assert.Equal(value, yq.ToInt());
            }
            else if (inst.GetType() == typeof(YearMonthInstant))
            {
                var ym = inst as YearMonthInstant;
                Assert.Equal(segments[0], ym.Year);
                Assert.Equal(segments[1], ym.Month);
                Assert.Equal(value, ym.ToInt());
            }
            else if (inst.GetType() == typeof(YearMonthDayInstant))
            {
                var ymd = inst as YearMonthDayInstant;
                Assert.Equal(segments[0], ymd.Year);
                Assert.Equal(segments[1], ymd.Month);
                Assert.Equal(segments[2], ymd.Day);
                Assert.Equal(value, ymd.ToInt());
            }
            else
            {
                Assert.False(true);
            }
        }
Example #2
0
 /// <summary>
 /// 构造函数
 /// </summary>
 /// <param name="type">类型</param>
 /// <param name="typeGroup">类型所在组</param>
 protected Instant(InstantType type, InstantTypeGroup typeGroup)
 {
     InstantType      = type;
     InstantTypeGroup = typeGroup;
 }