Example #1
0
        /// <summary>
        /// 计算八字
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="ob">日对象</param>
        /// <param name="type">八字类型</param>
        /// <param name="curTZ">时区</param>
        /// <param name="year">年</param>
        /// <param name="month">月</param>
        /// <param name="day">日</param>
        /// <param name="time">时间串</param>
        /// <param name="longitudeStr">经度(度分秒格式)</param>
        /// <returns>八字字符串</returns>
        public static string ML_calc <T>(OB ob, BaZiType type, double curTZ, T year, T month, T day, string time, string longitudeStr, BaZiTypeS baziTypes)
        {
            double y = LunarHelper.year2Ayear(year);

            if (y == -10000)
            {
                return(String.Empty);
            }

            string timeName = (type == BaZiType.ZtyBaZi ? "真太阳 " :
                               (type == BaZiType.PtyBaZi ? "平太阳 " : "北京时间 "));

            double t = LunarHelper.timeStr2hour(time);

            double longitude;

            if (type == BaZiType.EL120BaZi)
            {
                longitude = LunarHelper.str2rad("-120°");    // 解析东经120°经度为弧度
            }
            else
            {
                longitude = LunarHelper.str2rad(longitudeStr);    // 解析经度为弧度
            }
            double jd = JD.JD__(y, LunarHelper.VAL(month.ToString()),
                                LunarHelper.VAL(day.ToString()) + t / 24);

            if (type == BaZiType.ZtyBaZi)
            {
                obb.mingLiBaZi(jd + curTZ / 24 - LunarHelper.J2000, longitude, ob, baziTypes);    // 八字计算, 独立于 Lunar 类
                timeName += ob.bz_zty;
            }
            else
            {
                obb.mingLiBaZiNormal(jd + curTZ / 24 - LunarHelper.J2000, longitude, ob, baziTypes);    // 八字计算, 独立于 Lunar 类
                timeName += ob.bz_pty;
            }

            // C#: 新增的代码段
            JD.setFromJD(jd);
            double yearAjusted  = JD.Y;
            double monthAjusted = JD.M;
            double dayAjusted   = JD.D;

            return("[日标]:" + "公历 " + yearAjusted + "-" + monthAjusted + "-" + dayAjusted + " 儒略日数 " + LunarHelper.int2(jd + 0.5) +
                   " 距2000年首" + LunarHelper.int2(jd + 0.5 - LunarHelper.J2000) + "日"
                   + "\r\n[八字]:" + ob.bz_jn + "年 " + ob.bz_jy + "月 " + ob.bz_jr + "日 " + ob.bz_js + "时 " + timeName
                   + "\r\n[纪时]:" + ob.bz_JS
                   + "\r\n[时标]:" + "23  01  03  05  07  09  11  13  15  17  19  21  23");
        }
Example #2
0
        /// <summary>
        /// 求y年m月的第n个星期w的儒略日数
        /// </summary>
        /// <param name="y">年</param>
        /// <param name="m">月</param>
        /// <param name="n"></param>
        /// <param name="w">星期w</param>
        /// <returns></returns>
        public static double nnweek(double y, double m, double n, double w)
        {
            double jd = JD.JD__(y, m, 1.5);  //月首儒略日
            double w0 = (jd + 1) % 7;        //月首的星期
            double r  = jd - w0 + 7 * n + w; //jd-w0+7*n是和n个星期0,起算下本月第一行的星期日(可能落在上一月)。加w后为第n个星期w

            if (w >= w0)
            {
                r -= 7;          //第1个星期w可能落在上个月,造成多算1周,所以考虑减1周
            }
            if (n == 5)
            {
                m++; if (m > 12)
                {
                    m = 1; y++;
                }                                 //下个月
                if (r >= JD.JD__(y, m, 1.5))
                {
                    r -= 7;                          //r跑到下个月则减1周
                }
            }
            return(r);
        }
Example #3
0
 /// <summary>
 /// 公历转儒略日
 /// </summary>
 /// <returns></returns>
 public static double toJD()
 {
     return(JD.JD__(JD.Y, JD.M, JD.D + ((JD.s / 60 + JD.m) / 60 + JD.h) / 24));
 }