当前位置: 首页>>代码示例>>C#>>正文


C# SwissEph.swe_utc_to_jd方法代码示例

本文整理汇总了C#中SwissEph.swe_utc_to_jd方法的典型用法代码示例。如果您正苦于以下问题:C# SwissEph.swe_utc_to_jd方法的具体用法?C# SwissEph.swe_utc_to_jd怎么用?C# SwissEph.swe_utc_to_jd使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SwissEph的用法示例。


在下文中一共展示了SwissEph.swe_utc_to_jd方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Test_LoadingLeapSeconds

        public void Test_LoadingLeapSeconds()
        {
            int year = 2019, month = 12, day = 31, hour = 23, min = 59; double sec = 60;
            string serr = null; double[] dret = new double[2]; int res;

            // The date is not a standard leap second
            using (var swe = new SwissEph()) {
                res = swe.swe_utc_to_jd(year, month, day, hour, min, sec, SwissEph.SE_GREG_CAL, dret, ref serr);
                Assert.AreEqual(SwissEph.OK, res);
                Assert.AreEqual(2458849.50082255, dret[0], 0.0000001);
                Assert.AreEqual(2458849.5, dret[1], 0.00000001);
                Assert.AreEqual(null, serr);
            }

            // We include the date as leap second in fake loading
            String content = @"
            # comments
            19720630
            19721231
            19731231
            19741231
            19751231
            19761231
            19771231
            19781231
            19791231
            19810630
            19820630
            19830630
            19850630
            19871231
            19891231
            19901231
            19920630
            19930630
            19940630
            19951231
            19970630
            19981231
            20051231
            20081231

            #
            20101231
            20111231
            20121231
            20131231
            20141231
            20141231
            20161231
            20171231
            20181231
            20191231
            20201231
            20211231
            20221231
            20231231
            20241231
            20251231
            20261231
            20271231
            20281231
            20291231
            20301231
            20311231
            20321231
            20331231
            20341231
            20351231
            20361231
            20371231

            ";
            using (var swe = new SwissEph()) {
                swe.OnLoadFile += (s, e) => {
                    if (e.FileName == @"[ephe]\seleapsec.txt") {
                        e.File = new System.IO.MemoryStream(Encoding.ASCII.GetBytes(content));
                    }
                };

                res = swe.swe_utc_to_jd(year, month, day, hour, min, sec, SwissEph.SE_GREG_CAL, dret, ref serr);
                Assert.AreEqual(SwissEph.OK, res);
                Assert.AreEqual(2458849.50082389, dret[0], 0.0000001);
                Assert.AreEqual(2458849.50000134, dret[1], 0.00000001);
                Assert.AreEqual(null, serr);
            }

            // We adding a lot of lines in 'file' for code coverage purpose
            StringBuilder sb = new StringBuilder(content);
            for (int i = 0; i < 100; i++) {
                sb.AppendFormat("{0}1231", 2038 + i).AppendLine();
            }
            content = sb.ToString();
            using (var swe = new SwissEph()) {
                swe.OnLoadFile += (s, e) => {
                    if (e.FileName == @"[ephe]\seleapsec.txt") {
                        e.File = new System.IO.MemoryStream(Encoding.ASCII.GetBytes(content));
                    }
                };

//.........这里部分代码省略.........
开发者ID:thenuts,项目名称:SwissEphNet,代码行数:101,代码来源:SwissEphTest.Date.cs

示例2: Test_swe_utc_to_jd

        public void Test_swe_utc_to_jd()
        {
            using (var swe = new SwissEph()) {
                int year = 1974, month = 8, day = 16, hour = 0, min = 30; double sec = 0;
                string serr = null; double[] dret = new double[2];

                var res = swe.swe_utc_to_jd(year, month, day, hour, min, sec, SwissEph.SE_GREG_CAL, dret, ref serr);
                Assert.AreEqual(SwissEph.OK, res);
                Assert.AreEqual(2442275.5213563, dret[0], 0.0000001);
                Assert.AreEqual(2442275.52083414, dret[1], 0.00000001);
                Assert.AreEqual(null, serr);

                res = swe.swe_utc_to_jd(year, month, day, hour, min, sec, SwissEph.SE_JUL_CAL, dret, ref serr);
                Assert.AreEqual(SwissEph.OK, res);
                Assert.AreEqual(2442288.5213563, dret[0], 0.0000001);
                Assert.AreEqual(2442288.52083373, dret[1], 0.00000001);
                Assert.AreEqual(null, serr);

                // leap second
                res = swe.swe_utc_to_jd(year, 12, 31, 23, 59, 60, SwissEph.SE_GREG_CAL, dret, ref serr);
                Assert.AreEqual(SwissEph.OK, res);
                Assert.AreEqual(2442413.50052296, dret[0], 0.0000001);
                Assert.AreEqual(2442413.49999659, dret[1], 0.00000001);
                Assert.AreEqual(null, serr);

                res = swe.swe_utc_to_jd(year, 12, 31, 23, 59, 60, SwissEph.SE_JUL_CAL, dret, ref serr);
                Assert.AreEqual(SwissEph.ERR, res);
                Assert.AreEqual("invalid time (no leap second!): 23:59:60.00", serr);
                serr = null;

                // Before 1972
                year = 1960;
                res = swe.swe_utc_to_jd(year, month, day, hour, min, sec, SwissEph.SE_GREG_CAL, dret, ref serr);
                Assert.AreEqual(SwissEph.OK, res);
                Assert.AreEqual(2437162.52122023, dret[0], 0.0000001);
                Assert.AreEqual(2437162.52083333, dret[1], 0.00000001);
                Assert.AreEqual(null, serr);

                res = swe.swe_utc_to_jd(year, month, day, hour, min, sec, SwissEph.SE_JUL_CAL, dret, ref serr);
                Assert.AreEqual(SwissEph.OK, res);
                Assert.AreEqual(2437175.52122041, dret[0], 0.0000001);
                Assert.AreEqual(2437175.52083333, dret[1], 0.00000001);
                Assert.AreEqual(null, serr);

                // Date > today (after last leap date)
                year = 2030;
                res = swe.swe_utc_to_jd(year, month, day, hour, min, sec, SwissEph.SE_GREG_CAL, dret, ref serr);
                Assert.AreEqual(SwissEph.OK, res);
                Assert.AreEqual(2462729.52185329, dret[0], 0.0000001);
                Assert.AreEqual(2462729.52083333, dret[1], 0.00000001);
                Assert.AreEqual(null, serr);

                res = swe.swe_utc_to_jd(year, month, day, hour, min, sec, SwissEph.SE_JUL_CAL, dret, ref serr);
                Assert.AreEqual(SwissEph.OK, res);
                Assert.AreEqual(2462742.52185396, dret[0], 0.0000001);
                Assert.AreEqual(2462742.52083333, dret[1], 0.00000001);
                Assert.AreEqual(null, serr);

                // Errors
                year = 1974;
                res = swe.swe_utc_to_jd(year, 2, 31, hour, min, sec, SwissEph.SE_GREG_CAL, dret, ref serr);
                Assert.AreEqual(SwissEph.ERR, res);
                Assert.AreEqual("invalid date: year = 1974, month = 2, day = 31", serr);

                res = swe.swe_utc_to_jd(year, month, day, hour, 62, sec, SwissEph.SE_GREG_CAL, dret, ref serr);
                Assert.AreEqual(SwissEph.ERR, res);
                Assert.AreEqual("invalid time: 0:62:0.00", serr);

            }
        }
开发者ID:thenuts,项目名称:SwissEphNet,代码行数:70,代码来源:SwissEphTest.Date.cs


注:本文中的SwissEph.swe_utc_to_jd方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。