示例#1
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(年, 月, 日, 时));
        }
示例#2
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流年);
        }
示例#3
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());
        }
示例#4
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, "时令出错");
            }
        }
示例#5
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.性别);
        }
示例#6
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));
            }
        }
示例#7
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());
        }
示例#8
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());
        }
示例#9
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);
        }
示例#10
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());
        }