Пример #1
0
        public void GetChineseDateString_ReturnChineseDateString()
        {
            var    cc     = new ChineseCalendar(DateTime.Parse("2018-11-27"));
            string actual = cc.ChineseDateString;

            Assert.Equal("二零一八年十月二十", actual);
        }
Пример #2
0
        public ErrorInfo GetChineseCalendar(ref ErrorInfo err, ApiRequesEntityBean <ErrorInfo> inEnt)
        {
            DateTime dateTime = new DateTime();

            if (!DateTime.TryParse(inEnt.data.ToString(), out dateTime))
            {
                err.IsError = true;
                err.Message = "参数有误";
                return(err);
            }
            var tempPar = inEnt.para.FirstOrDefault(x => x.K == "inType");

            try
            {
                if (tempPar == null || tempPar.V == "china")
                {
                    ChineseCalendar cc = new ChineseCalendar(dateTime.Year, dateTime.Month, dateTime.Day, false);
                    err.Message = cc.Date.ToString("yyyy-MM-dd");
                }
                else
                {
                    ChineseCalendar cc = new ChineseCalendar(dateTime);
                    err.Message = cc.ChineseDateString;
                }
            }
            catch {
                err.Message = dateTime.ToString("yyyy-MM-dd");
            }

            return(err);
        }
Пример #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="公历时间"></param>
        /// <returns></returns>
        public static HuangLiModel 获取黄历(DateTime 公历时间)
        {
            var nongli = ChineseCalendar.计算农历(公历时间);
            var result = new HuangLiModel()
            {
                TianGanDiZhi     = TianGanDiZhiHelper.获取天干地支(公历时间),
                NongLiYearDescn  = nongli.YearDescn,
                NongLiYear       = nongli.Year,
                NongLiMonthDescn = nongli.MonthDescn,
                NongLiMonth      = nongli.Month,
                NongLiDayDescn   = nongli.DayDescn,
                NongLiDay        = nongli.Day,

                GongLiYear       = 公历时间.Year,
                GongLiYearDescn  = 公历时间.Year.ToString(),
                GongLiMonth      = 公历时间.Month,
                GongLiMonthDescn = 公历时间.Month.ToString(),
                GongLiDay        = 公历时间.Day,
                GongLiDayDescn   = 公历时间.Day.ToString(),

                ShengXiao = ChineseCalendar.计算生肖(公历时间),

                IsLeapYear  = nongli.IsLeapYear,
                IsLeapMonth = nongli.IsLeapMonth,
                LeapMonth   = nongli.LeapMonth
            };

            return(result);
        }
Пример #4
0
        static void Main(string[] args)
        {
            var canlender = new ChineseCalendar(DateTime.Now);

            Console.WriteLine(canlender.WeekDayStr);
            ChineseCalendar c       = new ChineseCalendar(DateTime.Now);
            StringBuilder   dayInfo = new StringBuilder();

            dayInfo.Append("阳历:" + c.DateString + "\r\n");
            dayInfo.Append("农历:" + c.ChineseDateString + "\r\n");
            dayInfo.Append("星期:" + c.WeekDayStr);
            dayInfo.Append("时辰:" + c.ChineseHour + "\r\n");
            dayInfo.Append("属相:" + c.AnimalString + "\r\n");
            dayInfo.Append("节气:" + c.ChineseTwentyFourDay + "\r\n");
            dayInfo.Append("前一个节气:" + c.ChineseTwentyFourPrevDay + "\r\n");
            dayInfo.Append("下一个节气:" + c.ChineseTwentyFourNextDay + "\r\n");
            dayInfo.Append("节日:" + c.DateHoliday + "\r\n");
            dayInfo.Append("干支:" + c.GanZhiDateString + "\r\n");
            dayInfo.Append("星宿:" + c.ChineseConstellation + "\r\n");
            dayInfo.Append("星座:" + c.Constellation + "\r\n");
            Console.WriteLine(dayInfo.ToString());
            Console.WriteLine(RegexUtil.IsEmail("*****@*****.**"));
            Console.WriteLine(RmbUtil.CmycurD("123.45"));
            Console.ReadLine();
        }
Пример #5
0
        public void TestInitWithCurrentTime()
        {
            // jb4555
            // if the chinese calendar current millis isn't called, the default year
            // is wrong.
            // this test is assuming the 'year' is the current cycle
            // so when we cross a cycle boundary, the target will need to change
            // that shouldn't be for awhile yet...

            ChineseCalendar cc = new ChineseCalendar();

            cc.Set(IBM.ICU.Util.Calendar.YEAR, 22);
            cc.Set(IBM.ICU.Util.Calendar.MONTH, 0);
            // need to set leap month flag off, otherwise, the test case always
            // fails when
            // current time is in a leap month
            cc.Set(IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH, 0);
            cc.Set(IBM.ICU.Util.Calendar.DATE, 19);
            cc.Set(IBM.ICU.Util.Calendar.HOUR_OF_DAY, 0);
            cc.Set(IBM.ICU.Util.Calendar.MINUTE, 0);
            cc.Set(IBM.ICU.Util.Calendar.SECOND, 0);
            cc.Set(IBM.ICU.Util.Calendar.MILLISECOND, 0);

            cc.Add(IBM.ICU.Util.Calendar.DATE, 1);

            DateTime target = new DateTime(105, IBM.ICU.Util.Calendar.FEBRUARY, 28);
            DateTime result = cc.GetTime();

            AssertEquals("chinese and gregorian date should match", target, result);
        }
Пример #6
0
        public void TestZeroDOM()
        {
            ChineseCalendar cal = new ChineseCalendar();

            IBM.ICU.Util.GregorianCalendar greg = new IBM.ICU.Util.GregorianCalendar(1989,
                                                                                     IBM.ICU.Util.Calendar.SEPTEMBER, 1);
            Logln("Start: " + greg.GetTime());
            for (int i = 0; i < 1000; ++i)
            {
                cal.SetTimeInMillis(greg.GetTimeInMillis());
                if (cal.Get(IBM.ICU.Util.Calendar.DAY_OF_MONTH) == 0)
                {
                    Errln("Fail: "
                          + greg.GetTime()
                          + " -> "
                          + cal.Get(IBM.ICU.Util.Calendar.EXTENDED_YEAR)
                          + "/"
                          + cal.Get(IBM.ICU.Util.Calendar.MONTH)
                          + ((cal.Get(IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH) == 1) ? "(leap)"
                                    : "") + "/" + cal.Get(IBM.ICU.Util.Calendar.DAY_OF_MONTH));
                }
                greg.Add(IBM.ICU.Util.Calendar.DAY_OF_YEAR, 1);
            }
            Logln("End: " + greg.GetTime());
        }
Пример #7
0
        public void JudgeWorkDay_ReturnTrue(string date)
        {
            ChineseCalendar.CustomWorkDays.Add(DateTime.Parse("2019-02-02"));
            var cc     = new ChineseCalendar(DateTime.Parse(date));
            var actual = cc.IsWorkDay;

            Assert.True(actual);
        }
Пример #8
0
        public void JudgeHoliday_ReturnTrue()
        {
            ChineseCalendar.CustomHolidays.Add(DateTime.Parse("2019-2-6"), "春节");
            var cc     = new ChineseCalendar(DateTime.Parse("2019-2-6"));
            var actual = cc.IsHoliday;

            Assert.True(actual);
        }
Пример #9
0
        private void btnGeJu_Click(object sender, EventArgs e)
        {
            DateTime        dateTime = this.dpBirthDate.Value;
            ChineseCalendar cc       = new ChineseCalendar(dateTime);
            PaiPan          pan      = new PaiPan(cc, this.ckMan.Checked);
            var             eg       = new Engine(@".\Data\");

            this.txtBrithday.Text = eg.GeJuAnalyzer.GetResult(pan).ToString();
        }
Пример #10
0
        public void TestRoll()
        {
            int[][] tests = new int[][] {
                new int[] { 4642, 3, 0, 15,
                            IBM.ICU.Charset.CalendarTest.MONTH, 3,
                            4642, 6, 0, 15 },
                new int[] { 4642, 3, 0, 15,
                            IBM.ICU.Charset.CalendarTest.MONTH, 11,
                            4642, 2, 0, 15 },
                new int[] { 4639, 12, 0, 15,
                            IBM.ICU.Charset.CalendarTest.MONTH, 1,
                            4639, 1, 0, 15 },
                new int[] { 4640, 1, 0, 15,
                            IBM.ICU.Charset.CalendarTest.MONTH, -1,
                            4640, 12, 0, 15 },
                new int[] { 4638, 3, 0, 15,
                            IBM.ICU.Charset.CalendarTest.MONTH, 3,
                            4638, 5, 0, 15 },
                new int[] { 4638, 3, 0, 15,
                            IBM.ICU.Charset.CalendarTest.MONTH, 16,
                            4638, 5, 0, 15 },
                new int[] { 4638, 3, 0, 15,
                            IBM.ICU.Charset.CalendarTest.MONTH, 2,
                            4638, 4, 1, 15 },
                new int[] { 4638, 3, 0, 15,
                            IBM.ICU.Charset.CalendarTest.MONTH, 28,
                            4638, 4, 1, 15 },
                new int[] { 4638, 4, 0, 15,
                            IBM.ICU.Charset.CalendarTest.MONTH, 1,
                            4638, 4, 1, 15 },
                new int[] { 4638, 4, 0, 15,
                            IBM.ICU.Charset.CalendarTest.MONTH, -12,
                            4638, 4, 1, 15 },
                new int[] { 4638, 4, 1, 15,
                            IBM.ICU.Charset.CalendarTest.MONTH, 1,
                            4638, 5, 0, 15 },
                new int[] { 4638, 4, 1, 15,
                            IBM.ICU.Charset.CalendarTest.MONTH, -25,
                            4638, 5, 0, 15 },
                new int[] { 4638, 4, 0, 30,
                            IBM.ICU.Charset.CalendarTest.MONTH, 1,
                            4638, 4, 1, 29 },
                new int[] { 4638, 4, 0, 30,
                            IBM.ICU.Charset.CalendarTest.MONTH, 14,
                            4638, 4, 1, 29 },
                new int[] { 4638, 4, 0, 30,
                            IBM.ICU.Charset.CalendarTest.MONTH, 15,
                            4638, 5, 0, 30 },
                new int[] { 4638, 4, 0, 30,
                            IBM.ICU.Charset.CalendarTest.MONTH, -10,
                            4638, 6, 0, 29 }
            };

            ChineseCalendar cal = new ChineseCalendar();

            DoRollAdd(IBM.ICU.Charset.CalendarTest.ROLL, cal, tests);
        }
Пример #11
0
        public object GetCalendar(string date = "2021-01-01")
        {
            ChineseCalendar today = new ChineseCalendar(DateTime.Parse(date));

            return(new
            {
                ChineseDateString = today.ChineseDateString,
                AnimalString = today.AnimalString,
                GanZhiDateString = today.GanZhiDateString,
                DateHoliday = today.DateHoliday,
            });
        }
Пример #12
0
    // Use this for initialization
    void Start()
    {
        //ChineseCalendar cc = new ChineseCalendar(System.DateTime.Now);

        ChineseCalendar cc = new ChineseCalendar(Convert.ToDateTime("2018/12/5"));

        Debug.Log(cc.ChineseDateString);
        Debug.Log(cc.ChineseTwentyFourDay);
        Debug.Log(cc.AnimalString);
        Debug.Log(cc.Constellation);
        Debug.Log(cc.WeekDayStr);
        Debug.Log(cc.GanZhiDateString);
    }
Пример #13
0
        private void button2_Click(object sender, EventArgs e)
        {
            DateTime        dateTime = this.dpBirthDate.Value;
            ChineseCalendar cc       = new ChineseCalendar(dateTime);
            PaiPan          pan      = new PaiPan(cc, this.ckMan.Checked);

            ChineseCalendar cliu = new ChineseCalendar(this.dpLiuDate.Value);


            pan.Liu(cliu);


            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + pan.TestLiu;
        }
Пример #14
0
        void TestAiqingScore()
        {
            var asa = new AiqingScoreAnalyzer();
            var dt1 = new DateTime(1980, 1, 1, 0, 0, 0);
            var dt2 = new DateTime(1980, 2, 1, 0, 0, 0);
            var sb  = new StringBuilder();

            for (var dt = dt1; dt < dt2; dt = dt.AddHours(2))
            {
                var dtc   = new ChineseCalendar(dt);
                var pan   = new PaiPan(dtc, true);
                var score = asa.GetScore(pan);
                sb.AppendLine(score.ToString());
            }
            this.txtBrithday.Text = sb.ToString();
        }
Пример #15
0
        private void button5_Click(object sender, EventArgs e)
        {
            //解流年盘

            DateTime        dateTime = this.dpBirthDate.Value;
            ChineseCalendar cc       = new ChineseCalendar(dateTime);
            var             pan      = new PaiPan(cc, this.ckMan.Checked);

            eg = new Engine(@".\Data\");

            pan.Liu(new ChineseCalendar(this.dpLiuDate.Value));


            StringBuilder sb = new StringBuilder();

            foreach (GongIndex g_index in (GongIndex[])System.Enum.GetValues(typeof(GongIndex)))
            {
                var gong = pan.Gongs.First(g => g.LiuName == g_index.ToString());

                var stars = gong.Stars.Where(s => s.Type == Star.StarType.主星).ToList();
                if (stars.Count == 0)
                {
                    var sfsz = SanFangSiZheng(pan, gong.Name);
                    stars = sfsz.DuiZhaoGong.Stars.Where(s => s.Type == Star.StarType.主星).ToList();
                }

                var infos = eg.LiuNianAnalyzer.GetLiuNianInfo(stars.Select(s => s.Name).ToArray(), g_index);


                sb.AppendLine(string.Format("【{0}】", g_index.ToString()));
                sb.AppendLine("");
                foreach (var info in infos)
                {
                    sb.AppendLine(info.title);
                    sb.AppendLine(info.text);
                    sb.AppendLine("");
                }
                sb.AppendLine("");
                sb.AppendLine("");
            }



            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + sb.ToString();
        }
Пример #16
0
        public void TestCoverage()
        {
            ChineseCalendar cal    = new ChineseCalendar();
            DateFormat      format = IBM.ICU.Text.DateFormat.GetInstance(cal);

            if (!(format is ChineseDateFormat))
            {
                Errln("DateFormat.getInstance(" + cal
                      + ") did not return a ChineseDateFormat");
            }
            ChineseDateFormat fmt = (ChineseDateFormat)format;

            fmt.ApplyPattern("llyyll");
            DateTime time = IBM.ICU.Charset.TestFmwk.GetDate(2100, IBM.ICU.Util.Calendar.JANUARY, 1);
            String   str  = fmt.Format(time);

            try
            {
                DateTime e = fmt.Parse(str);
                Logln("chinese calendar time: " + time + " result: " + str
                      + " --> " + e);
            }
            catch (ILOG.J2CsMapping.Util.ParseException ex)
            {
                Logln(ex.Message); // chinese calendar can't parse this, no
                // error for now
            }

            // new ChineseCalendar(TimeZone,ULocale)
            ChineseCalendar ccal2 = new ChineseCalendar(IBM.ICU.Util.TimeZone.GetDefault(),
                                                        IBM.ICU.Util.ULocale.CHINA);

            if (ccal2 == null)
            {
                Errln("could not create ChineseCalendar with TimeZone ULocale");
            }
            else
            {
                fmt = (ChineseDateFormat)IBM.ICU.Text.DateFormat.GetDateInstance(ccal2,
                                                                                 IBM.ICU.Text.DateFormat.DEFAULT, IBM.ICU.Util.ULocale.CHINA);
                time = IBM.ICU.Charset.TestFmwk.GetDate(2001, IBM.ICU.Util.Calendar.MAY, 23);
                str  = fmt.Format(time);
                Logln("Chinese calendar time: " + time + " result: " + str);
            }
        }
Пример #17
0
        static void Main(string[] args)
        {
            DateTime        dt = DateTime.Now;
            ChineseCalendar cc = new ChineseCalendar(dt);

            Console.WriteLine("阳历:" + cc.DateString);
            Console.WriteLine("属相:" + cc.AnimalString);
            Console.WriteLine("农历:" + cc.ChineseDateString);
            Console.WriteLine("时辰:" + cc.ChineseHour);
            Console.WriteLine("节气:" + cc.ChineseTwentyFourDay);
            Console.WriteLine("节日:" + cc.DateHoliday);
            Console.WriteLine("前一个节气:" + cc.ChineseTwentyFourPrevDay);
            Console.WriteLine("后一个节气:" + cc.ChineseTwentyFourNextDay);
            Console.WriteLine("干支:" + cc.GanZhiDateString);
            Console.WriteLine("星期:" + cc.WeekDayStr);
            Console.WriteLine("星宿:" + cc.ChineseConstellation);
            Console.WriteLine("星座:" + cc.Constellation);
        }
Пример #18
0
        public void Liu(ChineseCalendar liu_cal)
        {
            liu_calendar = liu_cal;

            int old = this.liu_calendar.ChineseYear - this.calendar.ChineseYear;


            //大限
            var gong = _xingGong.FirstOrDefault(g => g.DaXian_From <= old && g.DaXian_To > old);

            if (gong == null)
            {
                gong = _xingGong.First(g => g.Is_Ming);
            }

            gong.XianName = "命宫";

            for (int i = 1; i < _gongName.Length; i++)
            {
                gong          = gong.Next;
                gong.XianName = _gongName[i];
            }


            //流年
            int zhi = this.liu_calendar.BaziIndex[1];

            gong = _xingGong.First(g => g.Zhi == zhi + 1);

            gong.LiuName = "命宫";

            for (int i = 1; i < _gongName.Length; i++)
            {
                gong         = gong.Next;
                gong.LiuName = _gongName[i];
            }

            //流年四化
            foreach (var star in _sihuaxing)
            {
                var xg = _xingGong.First(g => g.Stars.Exists(s => s.Name == star.Value[this.liu_calendar.BaziIndex[0]].ToString()));
                xg.Stars.Find(s => s.Name == star.Value[this.liu_calendar.BaziIndex[0]].ToString()).LiuHua = star.Key;
            }
        }
Пример #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="公历时间"></param>
        /// <returns></returns>
        public static TianGanDiZhiModel 获取天干地支(DateTime 公历时间)
        {
            var 纪月 = ChineseCalendar.计算纪月(公历时间);
            var 纪时 = ChineseCalendar.计算纪时(公历时间);

            var result = new TianGanDiZhiModel()
            {
                TianGanYear = new TianGanModel()
                {
                    Name = ChineseCalendar.计算纪年天干(公历时间)
                },
                TianGanMonth = new TianGanModel()
                {
                    Name = 纪月.ToString().Substring(0, 1).To天干()
                },
                TianGanDay = new TianGanModel()
                {
                    Name = ChineseCalendar.计算纪日天干(公历时间)
                },
                TianGanHour = new TianGanModel()
                {
                    Name = 纪时.ToString().Substring(0, 1).To天干()
                },

                DiZhiYear = new DiZhiModel()
                {
                    Name = ChineseCalendar.计算纪年地支(公历时间)
                },
                DiZhiMonth = new DiZhiModel()
                {
                    Name = 纪月.ToString().Substring(1, 1).To地支()
                },
                DiZhiDay = new DiZhiModel()
                {
                    Name = ChineseCalendar.计算纪日地支(公历时间)
                },
                DiZhiHour = new DiZhiModel()
                {
                    Name = 纪时.ToString().Substring(1, 1).To地支()
                },
            };

            return(result);
        }
        public void NongLi()
        {
            //调用:
            ChineseCalendar nc      = new ChineseCalendar(1990, 1, 15, false);
            StringBuilder   dayInfo = new StringBuilder();

            dayInfo.Append("阳历:" + nc.DateString + "\r\n");
            dayInfo.Append("农历:" + nc.ChineseDateString + "\r\n");
            dayInfo.Append("星期:" + nc.WeekDayStr);
            dayInfo.Append("时辰:" + nc.ChineseHour + "\r\n");
            dayInfo.Append("属相:" + nc.AnimalString + "\r\n");
            dayInfo.Append("节气:" + nc.ChineseTwentyFourDay + "\r\n");
            dayInfo.Append("前一个节气:" + nc.ChineseTwentyFourPrevDay + "\r\n");
            dayInfo.Append("下一个节气:" + nc.ChineseTwentyFourNextDay + "\r\n");
            dayInfo.Append("节日:" + nc.DateHoliday + "\r\n");
            dayInfo.Append("干支:" + nc.GanZhiDateString + "\r\n");
            dayInfo.Append("星宿:" + nc.ChineseConstellation + "\r\n");
            dayInfo.Append("星座:" + nc.Constellation + "\r\n");
        }
Пример #21
0
        internal void DoRollAdd(bool roll, ChineseCalendar cal, int[][] tests)
        {
            String name = (roll) ? "rolling" : "adding";

            for (int i = 0; i < tests.Length; i++)
            {
                int[] test = tests[i];

                cal.Clear();
                cal.Set(IBM.ICU.Util.Calendar.EXTENDED_YEAR, test[0]);
                cal.Set(IBM.ICU.Util.Calendar.MONTH, test[1] - 1);
                cal.Set(IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH, test[2]);
                cal.Set(IBM.ICU.Util.Calendar.DAY_OF_MONTH, test[3]);
                if (roll)
                {
                    cal.Roll(test[4], test[5]);
                }
                else
                {
                    cal.Add(test[4], test[5]);
                }
                if (cal.Get(IBM.ICU.Util.Calendar.EXTENDED_YEAR) != test[6] ||
                    cal.Get(IBM.ICU.Charset.CalendarTest.MONTH) != (test[7] - 1) ||
                    cal.Get(IBM.ICU.Util.ChineseCalendar.IS_LEAP_MONTH) != test[8] ||
                    cal.Get(IBM.ICU.Charset.CalendarTest.DATE) != test[9])
                {
                    Errln("Fail: " + name + " "
                          + YmdToString(test[0], test[1] - 1, test[2], test[3])
                          + " " + IBM.ICU.Charset.CalendarTest.FieldName(test[4]) + " by " + test[5]
                          + ": expected "
                          + YmdToString(test[6], test[7] - 1, test[8], test[9])
                          + ", got " + IBM.ICU.Charset.CalendarTest.YmdToString(cal));
                }
                else if (IsVerbose())
                {
                    Logln("OK: " + name + " "
                          + YmdToString(test[0], test[1] - 1, test[2], test[3])
                          + " " + IBM.ICU.Charset.CalendarTest.FieldName(test[4]) + " by " + test[5]
                          + ": got " + IBM.ICU.Charset.CalendarTest.YmdToString(cal));
                }
            }
        }
Пример #22
0
        public void TestChineseCalendar()
        {
            ChineseCalendar c       = new ChineseCalendar(new DateTime(1990, 01, 15));
            StringBuilder   dayInfo = new StringBuilder();

            dayInfo.Append("阳历:" + c.DateString + "\r\n");
            dayInfo.Append("农历:" + c.ChineseDateString + "\r\n");
            dayInfo.Append("星期:" + c.WeekDayStr);
            dayInfo.Append("时辰:" + c.ChineseHour + "\r\n");
            dayInfo.Append("属相:" + c.AnimalString + "\r\n");
            dayInfo.Append("节气:" + c.ChineseTwentyFourDay + "\r\n");
            dayInfo.Append("前一个节气:" + c.ChineseTwentyFourPrevDay + "\r\n");
            dayInfo.Append("下一个节气:" + c.ChineseTwentyFourNextDay + "\r\n");
            dayInfo.Append("节日:" + c.DateHoliday + "\r\n");
            dayInfo.Append("干支:" + c.GanZhiDateString + "\r\n");
            dayInfo.Append("星宿:" + c.ChineseConstellation + "\r\n");
            dayInfo.Append("星座:" + c.Constellation + "\r\n");
            Console.Write(dayInfo.ToString());
            Assert.IsTrue(true);
        }
Пример #23
0
        public void TestLimits()
        {
            // The number of days and the start date can be adjusted
            // arbitrarily to either speed up the test or make it more
            // thorough, but try to test at least a full year, preferably a
            // full non-leap and a full leap year.

            // Final parameter is either number of days, if > 0, or test
            // duration in seconds, if < 0.
            IBM.ICU.Util.Calendar tempcal = IBM.ICU.Util.Calendar.GetInstance();
            tempcal.Clear();
            tempcal.Set(1989, IBM.ICU.Util.Calendar.NOVEMBER, 1);
            ChineseCalendar chinese = new ChineseCalendar();

            if (!SkipIfBeforeICU(3, 9, 0))
            {
                DoLimitsTest(chinese, null, tempcal.GetTime());
            }
            DoTheoreticalLimitsTest(chinese, true);
        }
Пример #24
0
        public void TestOutOfRange()
        {
            int[] DATA = new int[] {
                // Input Output
                4638, 13, 1, 4639, 1, 1, 4638, 18, 1, 4639, 6, 1, 4639, 0, 1,
                4638, 12, 1, 4639, -6, 1, 4638, 6, 1, 4638, 1, 32, 4638, 2, 2,         // 1-4638
                                                                                       // has
                                                                                       // 30
                                                                                       // days
                4638, 2, -1, 4638, 1, 29,
            };
            ChineseCalendar cal = new ChineseCalendar();

            for (int i = 0; i < DATA.Length;)
            {
                int y1 = DATA[i++];
                int m1 = DATA[i++] - 1;
                int d1 = DATA[i++];
                int y2 = DATA[i++];
                int m2 = DATA[i++] - 1;
                int d2 = DATA[i++];
                cal.Clear();
                cal.Set(IBM.ICU.Util.Calendar.EXTENDED_YEAR, y1);
                cal.Set(IBM.ICU.Charset.CalendarTest.MONTH, m1);
                cal.Set(IBM.ICU.Charset.CalendarTest.DATE, d1);
                int y = cal.Get(IBM.ICU.Util.Calendar.EXTENDED_YEAR);
                int m = cal.Get(IBM.ICU.Charset.CalendarTest.MONTH);
                int d = cal.Get(IBM.ICU.Charset.CalendarTest.DATE);
                if (y != y2 || m != m2 || d != d2)
                {
                    Errln("Fail: " + y1 + "/" + (m1 + 1) + "/" + d1
                          + " resolves to " + y + "/" + (m + 1) + "/" + d
                          + ", expected " + y2 + "/" + (m2 + 1) + "/" + d2);
                }
                else if (IsVerbose())
                {
                    Logln("OK: " + y1 + "/" + (m1 + 1) + "/" + d1 + " resolves to "
                          + y + "/" + (m + 1) + "/" + d);
                }
            }
        }
Пример #25
0
        public void TestFormat()
        {
            ChineseCalendar cal = new ChineseCalendar();
            DateFormat      fmt = IBM.ICU.Text.DateFormat.GetDateTimeInstance(cal,
                                                                              IBM.ICU.Text.DateFormat.DEFAULT, IBM.ICU.Text.DateFormat.DEFAULT);

            IBM.ICU.Util.Calendar tempcal = IBM.ICU.Util.Calendar.GetInstance();
            tempcal.Clear();

            DateTime[] DATA = new DateTime[2];
            tempcal.Set(2001, IBM.ICU.Util.Calendar.MAY, 22);
            DATA[0] = tempcal.GetTime();
            tempcal.Set(2001, IBM.ICU.Util.Calendar.MAY, 23);
            DATA[1] = tempcal.GetTime();
            // Wed May 23 2001 = Month 4(leap), Day 1, Year 18, Cycle 78

            for (int i = 0; i < DATA.Length; ++i)
            {
                String s = fmt.Format(DATA[i]);
                try
                {
                    DateTime e = fmt.Parse(s);
                    if (e.Equals(DATA[i]))
                    {
                        Logln("Ok: " + DATA[i] + " -> " + s + " -> " + e);
                    }
                    else
                    {
                        Errln("FAIL: " + DATA[i] + " -> " + s + " -> " + e);
                    }
                }
                catch (ILOG.J2CsMapping.Util.ParseException e_0)
                {
                    Errln("Fail: " + s + " -> parse failure at "
                          + e_0.GetErrorOffset());
                    Errln(e_0.ToString());
                }
            }
        }
Пример #26
0
 private string LunarShow(DateTime dt)
 {
     ChineseCalendar chineseCalendar = new ChineseCalendar(dt);
     string res = "";
     if (chineseCalendar.ChineseTwentyFourDay != "")
     {
         res = chineseCalendar.ChineseTwentyFourDay;
     }
     else if (chineseCalendar.ChineseCalendarHoliday != "")
     {
         res = chineseCalendar.ChineseCalendarHoliday;
     }
     else if (chineseCalendar.DateHoliday != "")
     {
         res = chineseCalendar.DateHoliday;
     }
     else
     {
         res = chineseCalendar.ChineseShortDateString;
     }
     return res;
 }
Пример #27
0
        private void button6_Click(object sender, EventArgs e)
        {
            var birth = this.dpBirthDate.Value;
            var cc    = new ChineseCalendar(birth);

            this.txtBrithday.Text = cc.LiChunBaZi();

            /*
             * List<string> rets = new List<string>();
             * var cc = new ChineseCalendar2(birth);
             * var nianzhu = cc.GanZhiYearStringFromLichun;
             * var yuezhu = cc.GanZhiMonthStringFromLichun;
             * if (!string.IsNullOrEmpty(cc.ChineseTwentyFourDay))
             * {
             *  rets.Add(cc.ChineseTwentyFourDay);
             * }
             * else
             * {
             *  rets.Add(cc.ChineseTwentyFourPrevDay);
             *  rets.Add(cc.ChineseTwentyFourNextDay);
             * }*/
        }
Пример #28
0
        public void TestCNDate()
        {
            //CNDate date = ChinaDate.GetChinaDate();
            //Console.WriteLine("农历信息:"+ date.ToString()+"\r\n");

            ChineseCalendar c       = new ChineseCalendar();
            StringBuilder   dayInfo = new StringBuilder();

            dayInfo.Append("阳历:" + c.DateString + "\r\n");
            dayInfo.Append("农历:" + c.ChineseDateString + "\r\n");
            dayInfo.Append("星期:" + c.WeekDayStr);
            dayInfo.Append("时辰:" + c.ChineseHour + "\r\n");
            dayInfo.Append("属相:" + c.AnimalString + "\r\n");
            dayInfo.Append("节气:" + c.ChineseTwentyFourDay + "\r\n");
            dayInfo.Append("前一个节气:" + c.ChineseTwentyFourPrevDay + "\r\n");
            dayInfo.Append("下一个节气:" + c.ChineseTwentyFourNextDay + "\r\n");
            dayInfo.Append("节日:" + c.DateHoliday + "\r\n");
            dayInfo.Append("干支:" + c.GanZhiDateString + "\r\n");
            dayInfo.Append("星宿:" + c.ChineseConstellation + "\r\n");
            dayInfo.Append("星座:" + c.Constellation + "\r\n");
            Console.WriteLine("中国日历信息:" + dayInfo.ToString());
        }
Пример #29
0
        private void button3_Click(object sender, EventArgs e)
        {
            DateTime        dateTime = this.dpBirthDate.Value;
            ChineseCalendar cc       = new ChineseCalendar(dateTime);

            var pan = new PaiPan(cc, this.ckMan.Checked);

            eg = new Engine(@".\Data\");

            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + eg.MingAnalyzer.GetResult(pan).ToString();
            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + eg.GeJuAnalyzer.GetResult(pan).ToString();
            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + eg.FuMuAnalyzer.GetResult(pan).ToString();
            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + eg.FuQiAnalyzer.GetResult(pan).ToString();
            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + eg.JiaoYouAnalyzer.GetResult(pan).ToString();
            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + eg.JiEAnalyzer.GetResult(pan).ToString();
            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + eg.QianYiAnalyzer.GetResult(pan).ToString();
            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + eg.ShiYeAnalyzer.GetResult(pan).ToString();
            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + eg.TianZhaiAnalyzer.GetResult(pan).ToString();
            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + eg.XiongDiAnalyzer.GetResult(pan).ToString();
            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + eg.ZiNvAnalyzer.GetResult(pan).ToString();
            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + eg.CaiBoAnalyzer.GetResult(pan).ToString();
            this.txtBrithday.Text = this.txtBrithday.Text + "\n\n" + eg.FudeAnalyzer.GetResult(pan).ToString();
        }
Пример #30
0
        static void Main(string[] args)
        {
            //Console.WriteLine("Hello World!");

            ChineseCalendar c       = new ChineseCalendar(new DateTime(1996, 04, 28));
            StringBuilder   dayInfo = new StringBuilder();

            dayInfo.Append("阳历:" + c.DateString + "\r\n");
            dayInfo.Append("农历:" + c.ChineseDateString + "\r\n");
            dayInfo.Append("星期:" + c.WeekDayStr);
            dayInfo.Append("时辰:" + c.ChineseHour + "\r\n");
            dayInfo.Append("属相:" + c.AnimalString + "\r\n");
            dayInfo.Append("节气:" + c.ChineseTwentyFourDay + "\r\n");
            dayInfo.Append("前一个节气:" + c.ChineseTwentyFourPrevDay + "\r\n");
            dayInfo.Append("下一个节气:" + c.ChineseTwentyFourNextDay + "\r\n");
            dayInfo.Append("节日:" + c.DateHoliday + "\r\n");
            dayInfo.Append("干支:" + c.GanZhiDateString + "\r\n");
            dayInfo.Append("星宿:" + c.ChineseConstellation + "\r\n");
            dayInfo.Append("星座:" + c.Constellation + "\r\n");

            Console.WriteLine(dayInfo.ToString());
            Console.ReadLine();
        }