Esempio n. 1
0
        public void 大运Test()
        {
            DateTime day  = new DateTime(1978, 7, 1, 6, 45, 0);
            Ming     ming = new Ming(new HHTime(day), 性别.男);

            Assert.AreEqual(11, ming.大运.Count());

            Assert.AreEqual("戊午", ming.大运.ElementAt(0).Name);
            Assert.AreEqual("己未", ming.大运.ElementAt(1).Name);
            Assert.AreEqual("庚申", ming.大运.ElementAt(2).Name);
            Assert.AreEqual("辛酉", ming.大运.ElementAt(3).Name);
            Assert.AreEqual("壬戌", ming.大运.ElementAt(4).Name);


            Assert.AreEqual(1980, ((DateTime)ming.大运.ElementAt(1).Start).Year);
            Assert.AreEqual("偏财", ming.大运.ElementAt(1).干十神);
            Assert.AreEqual("七杀", ming.大运.ElementAt(2).支十神);
            Assert.AreEqual("枭神", ming.大运.ElementAt(4).干十神);

            BaZiList <GanZhi> gzlist = BaZiList.Create(new GanZhi("戊午"), new GanZhi("戊午"), new GanZhi("甲子"), new GanZhi("丁卯"));
            Ming bazi = new Ming(new HHTime(gzlist), 性别.男);

            Assert.IsNotNull(bazi.大运);
            Assert.AreEqual(ming.大运.ElementAt(1).Name, bazi.大运.ElementAt(1).Name);
            Assert.AreEqual(ming.大运.ElementAt(2).Name, bazi.大运.ElementAt(2).Name);
            Assert.AreEqual(ming.大运.ElementAt(3).Name, bazi.大运.ElementAt(3).Name);

            Assert.IsNull(bazi.大运.ElementAt(0).流年);
            Assert.IsNull(bazi.大运.ElementAt(1).小运);
            Assert.IsFalse(bazi.Has流年);
        }
Esempio n. 2
0
        private BaZiList <GanZhi> InitBaZiFromDateTime(DateTime date, bool 确定时辰)
        {
            this.datetime = new LnDate(date);
            this.time     = 确定时辰 ? date.TimeOfDay : TimeSpan.Zero;

            GanZhi 年 = new GanZhi(this.datetime.YearGZ);
            GanZhi 月 = new GanZhi(this.datetime.MonthGZ);
            GanZhi 日 = new GanZhi(this.datetime.DayGZ);

            LnDate 明天 = this.datetime.Add(1);

            if (date.Hour >= 23)
            {
                日 = 日.Add(1);
                年 = new GanZhi(明天.YearGZ);
                月 = new GanZhi(明天.MonthGZ);
            }

            GanZhi 时 = GanZhi.Zero;

            if (确定时辰)
            {
                Zhi 时支 = Zhi.Get((int)((date.Hour + 1) / 2) % 12);
                时 = 日.Gan.起月时(时支, 柱位.时);
            }

            return(BaZiList.Create(年, 月, 日, 时));
        }
Esempio n. 3
0
        private static IEnumerable <ShenSha> InitShenSha(BaZiList <GanZhi> bazi, 性别 gender)
        {
            List <ShenSha> shenshas = new List <ShenSha>();

            shenshas.Add(new ShenSha("将星", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("羊刃", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("禄神", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("华盖", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("文昌", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("学堂", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("天喜", new GanZhi[] { bazi.月 }));
            shenshas.Add(new ShenSha("天医", new GanZhi[] { bazi.月 }));

            shenshas.Add(new ShenSha("贵人", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("驿马", new GanZhi[] { bazi.年, bazi.日 }));
            shenshas.Add(new ShenSha("桃花", new GanZhi[] { bazi.年, bazi.日 }));
            shenshas.Add(new ShenSha("灾煞", new GanZhi[] { bazi.年, bazi.日 }));
            shenshas.Add(new ShenSha("劫煞", new GanZhi[] { bazi.年, bazi.日 }));
            shenshas.Add(new ShenSha("旬空", new GanZhi[] { bazi.日 }));

            shenshas.Add(new ShenSha("魁罡", new GanZhi[] { bazi.年, bazi.月, bazi.日, bazi.时 }));
            shenshas.Add(new ShenSha("四废", new GanZhi[] { bazi.年, bazi.月, bazi.日, bazi.时 }));
            shenshas.Last().Bazi = bazi;
            shenshas.Add(new ShenSha("孤辰寡宿", new GanZhi[] { bazi.年, bazi.月, bazi.日, bazi.时 }));
            shenshas.Last().Bazi = bazi;
            shenshas.Add(new ShenSha("阴差阳错", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("天罗地网", new GanZhi[] { bazi.年, bazi.月, bazi.日, bazi.时 }));
            shenshas.Last().性别 = gender;

            return(shenshas);
        }
Esempio n. 4
0
        /// <summary>
        /// 计算胎元干支
        /// </summary>
        /// <returns></returns>
        private static GanZhi CalcTaiYuan(BaZiList <ShiYun> bazi)
        {
            var gan = (bazi.月.Gan.Index + 1) % 10;
            var zhi = (bazi.月.Zhi.Index + 3) % 12;
            var gz  = new GanZhi(gan, zhi);

            return(gz);
        }
Esempio n. 5
0
        public void 八字调整Test()
        {
            DateTime day  = new DateTime(1978, 7, 1, 6, 45, 0);
            HHTime   ming = new HHTime(day);

            Assert.IsNotNull(ming);

            Assert.AreEqual("戊午", ming.年.Name);
            Assert.AreEqual("戊午", ming.月.Name);
            Assert.AreEqual("甲子", ming.日.Name);
            Assert.AreEqual("丁卯", ming.时.Name);

            HHTime ming1 = new HHTime(day, 确定时辰: false);

            Assert.IsNotNull(ming1);
            Assert.AreEqual("戊午", ming1.年.Name);
            Assert.AreEqual("戊午", ming1.月.Name);
            Assert.AreEqual("甲子", ming1.日.Name);
            Assert.AreEqual("口口", ming1.时.Name);

            // 2017.2.3 晚 23后换月令 所以当天还是
            DateTime old     = new DateTime(2017, 2, 3, 22, 45, 0);
            HHTime   mingOld = new HHTime(old);

            Assert.AreEqual("丙申", mingOld.年.Name);
            Assert.AreEqual("辛丑", mingOld.月.Name);
            Assert.AreEqual("辛酉", mingOld.日.Name);
            Assert.AreEqual("己亥", mingOld.时.Name);

            DateTime lichun     = new DateTime(2017, 2, 3, 23, 45, 0);
            HHTime   mingLiChun = new HHTime(lichun);

            Assert.AreEqual("丁酉", mingLiChun.年.Name);
            Assert.AreEqual("壬寅", mingLiChun.月.Name);
            Assert.AreEqual("壬戌", mingLiChun.日.Name);
            Assert.AreEqual("庚子", mingLiChun.时.Name);

            day  = new DateTime(2017, 2, 2, 7, 45, 0);
            ming = new HHTime(day);
            Assert.AreEqual("丙申", ming.年.Name);
            Assert.AreEqual("辛丑", ming.月.Name);
            Assert.AreEqual("庚申", ming.日.Name);
            Assert.AreEqual("庚辰", ming.时.Name);


            BaZiList <GanZhi> bazi = BaZiList.Create(new GanZhi(""), new GanZhi("卯"), new GanZhi("甲子"), new GanZhi(""));

            ming = new HHTime(bazi);
            Assert.IsNotNull(ming);
            Assert.AreEqual(-1, ming.年.Index);
            Assert.AreEqual(-1, ming.月.Index);
            Assert.AreEqual(0, ming.日.Index);
            Assert.AreEqual("口卯", ming.月.Name);
            Assert.AreEqual("口卯月 甲子日 ", ming.TimeText);
            Assert.AreEqual("/卯/甲子/", ming.ToString());
        }
Esempio n. 6
0
        public void BaziListTest()
        {
            BaZiList <GanZhi> bazi = BaZiList.Create(new GanZhi("戊午"), new GanZhi("戊午"), new GanZhi("甲子"), new GanZhi("丁卯"));

            Assert.IsNotNull(bazi);

            bazi = BaZiList.Create(new GanZhi(""), new GanZhi("戊午"), new GanZhi("甲子"), new GanZhi(null));
            Assert.IsNotNull(bazi);
            Assert.AreEqual(GanZhi.Zero, bazi.年);
            Assert.AreEqual(GanZhi.Zero, bazi.时);

            bazi = BaZiList.Create(new GanZhi(""), new GanZhi(""), new GanZhi("甲子"), new GanZhi(null));
            Assert.IsNotNull(bazi);
            Assert.AreEqual(GanZhi.Zero, bazi.月);

            bazi = BaZiList.Create(new GanZhi(""), new GanZhi(""), new GanZhi(""), new GanZhi(null));
            Assert.IsNotNull(bazi);
            Assert.AreEqual(GanZhi.Zero, bazi.日);

            bazi = BaZiList.Create(new GanZhi(""), new GanZhi(""), new GanZhi(""), new GanZhi("甲子"));
            Assert.IsNotNull(bazi);

            bazi = BaZiList.Create(new GanZhi(""), new GanZhi("卯"), new GanZhi("甲子"), new GanZhi(""));
            Assert.IsNotNull(bazi);
            Assert.AreEqual(-1, bazi.年.Index);
            Assert.AreEqual(-1, bazi.月.Index);
            Assert.AreEqual(0, bazi.日.Index);
            Assert.AreEqual("口卯", bazi.月.Name);


            try
            {
                bazi = BaZiList.Create(new GanZhi("戊午"), new GanZhi("庚午"), new GanZhi("甲子"), new GanZhi("丁卯"));
            }
            catch (ArgumentException)
            {
            }
            catch (Exception)
            {
                Assert.IsTrue(false, "月令出错");
            }

            try
            {
                bazi = BaZiList.Create(new GanZhi("戊午"), new GanZhi("戊午"), new GanZhi("甲子"), new GanZhi("乙卯"));
            }
            catch (ArgumentException)
            {
            }
            catch (Exception)
            {
                Assert.IsTrue(false, "时令出错");
            }
        }
Esempio n. 7
0
        private void InitData()
        {
            List <ShiYun> tmp = new List <ShiYun>();

            this.time.Bazi.Items.ForEach(gz => tmp.Add(new ShiYun(gz, ShiYun.YunType.命局, this.time.Bazi)));
            this.四柱 = BaZiList.Create(tmp[0], tmp[1], tmp[2], tmp[3]);

            this.命宫   = CalcMingGong(this.四柱);
            this.胎元   = CalcTaiYuan(this.四柱);
            this.统计五行 = CalcWuXingInfos(this.四柱);

            this.神煞 = InitShenSha(this.time.Bazi, this.性别);
        }
Esempio n. 8
0
        /// <summary>
        /// 统计五行数目
        /// </summary>
        /// <param name="bazi"></param>
        /// <returns></returns>
        private static IEnumerable <Tuple <string, int> > CalcWuXingInfos(BaZiList <ShiYun> bazi)
        {
            // "金", "水", "木", "火", "土"
            int[] sum = new int[BaseDef.WuXings.Count()];
            bazi.Items.ForEach(gz =>
            {
                if (gz != GanZhi.Zero)
                {
                    sum[gz.Gan.五行.Index] += 1;
                    sum[gz.Zhi.五行.Index] += 1;
                }
            });

            return(sum.Select((num, idx) => new Tuple <string, int>(BaseDef.WuXings[idx], num)));
        }
Esempio n. 9
0
        public static HHTime Parse(string text, bool 确定时辰 = true)
        {
            DateTime date;
            bool     isdatetime = DateTime.TryParse(text, out date);

            if (isdatetime)
            {
                return(new HHTime(date, 确定时辰));
            }
            else
            {
                string[]          items = text.Split(new char[] { '/' }, StringSplitOptions.None);
                BaZiList <GanZhi> bazi  = BaZiList.Create(new GanZhi(items[0]), new GanZhi(items[1]), new GanZhi(items[2]), new GanZhi(items[3]));
                return(new HHTime(bazi));
            }
        }
Esempio n. 10
0
        public void 四废Test()
        {
            string name = "四废";

            // 寅卯月见庚申、辛酉
            // 春庚申,辛酉,夏壬子,癸亥,秋甲寅,乙卯,冬丙午,丁巳
            BaZiList <GanZhi> bazi1 = BaZiList.Create(new GanZhi("甲辰"), new GanZhi("丙寅"), new GanZhi("甲辰"), new GanZhi("戊辰"));
            BaZiList <GanZhi> bazi2 = BaZiList.Create(new GanZhi("甲辰"), new GanZhi("庚午"), new GanZhi("甲辰"), new GanZhi("戊辰"));
            BaZiList <GanZhi> bazi3 = BaZiList.Create(new GanZhi("甲辰"), new GanZhi("壬申"), new GanZhi("甲辰"), new GanZhi("戊辰"));
            BaZiList <GanZhi> bazi4 = BaZiList.Create(new GanZhi("甲辰"), new GanZhi("丙子"), new GanZhi("甲辰"), new GanZhi("戊辰"));

            ShenSha ss庚申 = new ShenSha(name, new GanZhi[] { new GanZhi("庚申") });

            ss庚申.Bazi = bazi1;
            Assert.AreEqual(string.Empty, string.Join("", ss庚申.Calc()));

            ShenSha ss壬子 = new ShenSha(name, new GanZhi[] { new GanZhi("壬子") });

            ss壬子.Bazi = bazi2;
            Assert.AreEqual(string.Empty, string.Join("", ss壬子.Calc()));

            ShenSha ss乙卯 = new ShenSha(name, new GanZhi[] { new GanZhi("乙卯") });

            ss乙卯.Bazi = bazi3;
            Assert.AreEqual(string.Empty, string.Join("", ss乙卯.Calc()));

            ShenSha ss丁巳 = new ShenSha(name, new GanZhi[] { new GanZhi("丁巳"), new GanZhi("甲子"), new GanZhi("丁酉") });

            ss丁巳.Bazi = bazi4;
            Assert.AreEqual(string.Empty, string.Join("", ss丁巳.Calc()));

            ShenSha ss甲子 = new ShenSha(name, new GanZhi[] { new GanZhi("甲子"), new GanZhi("丁酉") });

            ss甲子.Bazi = bazi4;
            Assert.IsNull(ss甲子.Calc());

            BaZiList <GanZhi> bazi5 = BaZiList.Create(new GanZhi("甲辰"), new GanZhi("戊辰"), new GanZhi("甲辰"), new GanZhi("戊辰"));
            ShenSha           ss    = new ShenSha(name, new GanZhi[] { new GanZhi("庚申"), new GanZhi("壬子"), new GanZhi("乙卯") });

            ss.Bazi = bazi5;
            Assert.IsNull(ss.Calc());
        }
Esempio n. 11
0
        /// <summary>
        /// 计算命宫干支
        /// </summary>
        /// <returns></returns>
        private static GanZhi CalcMingGong(BaZiList <ShiYun> bazi)
        {
            if (bazi.时 == GanZhi.Zero)
            {
                return(GanZhi.Zero);
            }

            var sum = bazi.月.Zhi.Index + 1 + bazi.时.Zhi.Index + 1;
            var zhi = sum < 14 ? 14 - sum : 26 - sum;

            zhi = zhi - 1;
            var startGan = bazi.年.Gan.起月干.Index;

            var diff = ((zhi - 2) + 12) % 12;
            var gan  = (startGan + diff) % 10;

            var ganzhi = new GanZhi(gan, zhi);

            return(ganzhi);
        }
Esempio n. 12
0
        private static IEnumerable <ShenSha> InitShenSha(BaZiList <GanZhi> bazi)
        {
            List <ShenSha> shenshas = new List <ShenSha>();

            shenshas.Add(new ShenSha("将星", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("华盖", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("驿马", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("谋星", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("桃花", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("灾煞", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("劫煞", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("禄神", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("羊刃", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("文昌", new GanZhi[] { bazi.日 }));

            shenshas.Add(new ShenSha("天喜", new GanZhi[] { bazi.月 }));
            shenshas.Add(new ShenSha("天医", new GanZhi[] { bazi.月 }));

            shenshas.Add(new ShenSha("贵人", new GanZhi[] { bazi.日 }));
            shenshas.Add(new ShenSha("旬空", new GanZhi[] { bazi.日 }));
            return(shenshas);
        }
Esempio n. 13
0
        public void 孤辰寡宿Test()
        {
            string name = "孤辰寡宿";

            // 亥子丑年生人,柱中见寅为孤见戌为寡
            // 寅卯辰年生人,柱中见巳为孤见丑为寡
            // 巳午未年生人,柱中见申为孤见辰为寡
            // 申酉戌年生人,柱中见亥为孤见未为寡
            BaZiList <GanZhi> bazi1 = BaZiList.Create(new GanZhi("甲子"), new GanZhi("丙寅"), new GanZhi("甲辰"), new GanZhi("戊辰"));
            BaZiList <GanZhi> bazi2 = BaZiList.Create(new GanZhi("甲辰"), new GanZhi("庚午"), new GanZhi("甲辰"), new GanZhi("戊辰"));
            BaZiList <GanZhi> bazi3 = BaZiList.Create(new GanZhi("甲午"), new GanZhi("壬申"), new GanZhi("甲辰"), new GanZhi("戊辰"));
            BaZiList <GanZhi> bazi4 = BaZiList.Create(new GanZhi("甲戌"), new GanZhi("丙子"), new GanZhi("甲辰"), new GanZhi("戊辰"));

            ShenSha ss庚寅 = new ShenSha(name, new GanZhi[] { new GanZhi("庚寅") });

            ss庚寅.Bazi = bazi1;
            Assert.AreEqual(string.Empty, string.Join("", ss庚寅.Calc()));

            ShenSha ss丁巳 = new ShenSha(name, new GanZhi[] { new GanZhi("丁巳") });

            ss丁巳.Bazi = bazi2;
            Assert.AreEqual(string.Empty, string.Join("", ss丁巳.Calc()));

            ShenSha ss庚辰 = new ShenSha(name, new GanZhi[] { new GanZhi("庚辰") });

            ss庚辰.Bazi = bazi3;
            Assert.AreEqual(string.Empty, string.Join("", ss庚辰.Calc()));

            ShenSha ss丁亥 = new ShenSha(name, new GanZhi[] { new GanZhi("丁亥") });

            ss丁亥.Bazi = bazi4;
            Assert.AreEqual(string.Empty, string.Join("", ss丁亥.Calc()));

            ShenSha ss = new ShenSha(name, new GanZhi[] { new GanZhi("庚申"), new GanZhi("壬子"), new GanZhi("乙卯") });

            ss.Bazi = bazi1;
            Assert.IsNull(ss.Calc());
        }
Esempio n. 14
0
        public void ParseMethodeTest()
        {
            DateTime day  = new DateTime(1978, 7, 1, 6, 45, 0);
            string   text = day.ToString();

            HHTime time = HHTime.Parse(text);

            Assert.IsNotNull(time);
            Assert.AreEqual(text, time.ToString());

            time = HHTime.Parse(text, 确定时辰: false);
            Assert.IsNotNull(time);
            Assert.AreEqual(day.ToShortDateString(), time.ToString());

            BaZiList <GanZhi> bazi = BaZiList.Create(new GanZhi(""), new GanZhi("卯"), new GanZhi("甲子"), new GanZhi(""));

            Assert.AreEqual("/卯/甲子/", bazi.ToString());
            time = HHTime.Parse(bazi.ToString());
            Assert.AreEqual(bazi.ToString(), time.ToString());

            time = HHTime.Parse("//丁卯/");
            Assert.AreEqual("//丁卯/", time.ToString());
        }
Esempio n. 15
0
        public void 构造函数Test()
        {
            HHTime time = new HHTime(new DateTime(1978, 7, 1, 6, 45, 0));

            Assert.IsNotNull(time);
            Assert.AreEqual(HHTime.TimeType.时间, time.Type);
            Assert.AreEqual("戊午", time.年.Name);
            Assert.AreEqual("戊午", time.月.Name);
            Assert.AreEqual("甲子", time.日.Name);
            Assert.AreEqual("丁卯", time.时.Name);
            Assert.AreEqual("五月廿六", time.农历);

            Assert.AreEqual("1978年7月1日 6时45分", time.TimeText);
            Assert.AreNotEqual(new DateTime(), time.DateTime);

            BaZiList <GanZhi> bazi = BaZiList.Create(new GanZhi("戊午"), new GanZhi("戊午"), new GanZhi("甲子"), new GanZhi("丁卯"));

            time = new HHTime(bazi);
            Assert.AreEqual(HHTime.TimeType.干支, time.Type);
            Assert.AreEqual("戊午年 戊午月 甲子日 丁卯时", time.TimeText);

            Assert.AreEqual(new DateTime(), time.DateTime);
        }
Esempio n. 16
0
 public HHTime(BaZiList <GanZhi> ganzhi)
 {
     this.Type     = TimeType.干支;
     this.bazi     = ganzhi;
     this.sureTime = this.bazi.时 != GanZhi.Zero;
 }
Esempio n. 17
0
 public HHTime(DateTime date, bool 确定时辰 = true)
 {
     this.sureTime = 确定时辰;
     this.Type     = TimeType.时间;
     this.bazi     = this.InitBaZiFromDateTime(date, 确定时辰);
 }
Esempio n. 18
0
 public ShiYun(GanZhi gz, YunType type, BaZiList <GanZhi> bz) : this(gz.Index, type, bz)
 {
 }
Esempio n. 19
0
 public ShiYun(int gzIndex, YunType type, BaZiList <GanZhi> bz) : base(gzIndex)
 {
     this.Type = type;
     this.Base = bz;
 }