6tail / lunar-java

日历、公历(阳历)、农历(阴历、老黄历)、佛历、道历,支持节假日、星座、儒略日、干支、生肖、节气、节日、彭祖百忌、每日宜忌、吉神宜趋凶煞宜忌、吉神(喜神/福神/财神/阳贵神/阴贵神)方位、胎神方位、冲煞、纳音、星宿、八字、五行、十神、建除十二值星、青龙名堂等十二神、黄道日及吉凶等。lunar is a calendar library for Solar and Chinese Lunar.
http://6tail.cn/calendar/api.html
MIT License
691 stars 161 forks source link

Lunar.fromDate得出的农历是错误的 #11

Closed BadReese closed 2 years ago

BadReese commented 2 years ago

取了我现在的时间戳: 681231600000 初始化后打印出农历: 二〇二一年冬月十一 ,这个是正确的 时间戳替换成: 681231600000 初始化后打印出农历: 一九九一年六月廿三, 这个是错误的,正确的应该一九九一年六月廿四

ps: dart版本是正确的

6tail commented 2 years ago

java: @Test public void test11(){ Date date = new Date(681231600000L); Solar solar = Solar.fromDate(date); Assert.assertEquals("1991-08-03",solar.toYmd()); Assert.assertEquals("一九九一年六月廿三",solar.getLunar().toString()); Assert.assertEquals("一九九一年六月廿三",Lunar.fromDate(date).toString()); } dart: test('11', () { DateTime date = DateTime.fromMillisecondsSinceEpoch(681231600000); Solar solar = Solar.fromDate(date); expect(solar.toYmd(), '1991-08-03'); expect(solar.getLunar().toString(), '一九九一年六月廿三'); expect(Lunar.fromDate(date).toString(), '一九九一年六月廿三'); }); 我测试都通过,681231600000 对应阳历1991-08-03,阴历一九九一年六月廿三。

------------------ 原始邮件 ------------------ 发件人: "6tail/lunar-java" @.>; 发送时间: 2021年12月14日(星期二) 下午5:17 @.>; @.***>; 主题: [6tail/lunar-java] Lunar.fromDate得出的农历是错误的 (Issue #11)

取了我现在的时间戳: 681231600000 初始化后打印出农历: 二〇二一年冬月十一 ,这个是正确的 时间戳替换成: 681231600000 初始化后打印出农历: 一九九一年六月廿三, 这个是错误的,正确的应该一九九一年六月廿四

ps: dart版本是正确的

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

BadReese commented 2 years ago

image 难道是站长工具的问题 - -

BadReese commented 2 years ago

我的提问里时间戳粘贴错了..稍等 我修改下

BadReese commented 2 years ago

取了我现在的时间戳: 1639473146000 初始化后打印出农历: 二〇二一年冬月十一 ,这个是正确的 时间戳替换成: 681231600000 初始化后打印出农历: 一九九一年六月廿三, 这个是错误的,正确的应该一九九一年六月廿四

BadReese commented 2 years ago

所以这个时间戳681231600000 应该是8月4号

BadReese commented 2 years ago

应该是夏令时的问题?

6tail commented 2 years ago

我转出来是1991-08-03 23:00:00,这个看怎么考证一下。

------------------ 原始邮件 ------------------ 发件人: "6tail/lunar-java" @.>; 发送时间: 2021年12月15日(星期三) 上午9:45 @.>; @.**@.>; 主题: Re: [6tail/lunar-java] Lunar.fromDate得出的农历是错误的 (Issue #11)

所以这个时间戳681231600000 应该是8月4号

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

BadReese commented 2 years ago

应该是夏令时的问题,不过我感觉有点晕.在苹果上用苹果自带的库转过,是8.4号

BadReese commented 2 years ago

你好,dart 我使用的是1.2.12版本,java是1.2.13的jar文件版本,我复制了你的dart test来执行,得到的结果跟你的不同. image

image

很奇怪..

BadReese commented 2 years ago

Dart SDK version: 2.14.4 (stable) (Wed Oct 13 11:11:32 2021 +0200) on "macos_x64"

caoyanglee commented 2 years ago

这个问题又出现了! @6tail 1946年9月30号 => 九月初五,实际上是九月初六才对。往前的日子都一样,按农历来算都是少一天! 版本:[v1.2.14] 然后老版本[v1.2.0]是没有这个问题的!

dart版本完全没问题,版本:1.2.12

6tail commented 2 years ago

@Test public void test45() { Solar solar = Solar.fromYmd(1946, 9, 30); Lunar lunar = solar.getLunar(); Assert.assertEquals("一九四六年九月初六", lunar.toString()); }

@Test public void test46() { Solar solar = Solar.fromYmd(1946, 9, 29); Lunar lunar = solar.getLunar(); Assert.assertEquals("一九四六年九月初五", lunar.toString()); }

你把单元测试跑一遍看看,我这之前已经加了这个用例,测试全通过的。

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2021年12月16日(星期四) 下午4:40 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [6tail/lunar-java] Lunar.fromDate得出的农历是错误的 (Issue #11)

1946年9月30号 => 九月初五,实际上是九月初六才对。往前的日子都一样,按农历来算都是少一天! 版本:[v1.2.14] 这个问题又出现了! @6tail

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android.

caoyanglee commented 2 years ago

@6tail fromYmd确实没问题,但是fromCalendar和fromDate就有问题了

下面是单元测试

//1946年9月30号
@Test
fun test1() {
    val calendar = Calendar.getInstance().apply {
        this.set(Calendar.YEAR,1946)
        this.set(Calendar.MONTH,8)//9月
        this.set(Calendar.DAY_OF_MONTH,30)
        this.set(Calendar.HOUR_OF_DAY, 0)
        this.set(Calendar.MINUTE, 0)
        this.set(Calendar.SECOND, 0)
        this.set(Calendar.MILLISECOND, 0)
    }
    val solar = Solar.fromCalendar(calendar)
    val lunar = solar.lunar
    Assert.assertEquals("一九四六年九月初六", lunar.toString())
}

//1946年9月29号
@Test
fun test2() {
    val calendar = Calendar.getInstance().apply {
        this.set(Calendar.YEAR,1946)
        this.set(Calendar.MONTH,8)//9月
        this.set(Calendar.DAY_OF_MONTH,29)
        this.set(Calendar.HOUR_OF_DAY, 0)
        this.set(Calendar.MINUTE, 0)
        this.set(Calendar.SECOND, 0)
        this.set(Calendar.MILLISECOND, 0)
    }
    val solar = Solar.fromCalendar(calendar)
    val lunar = solar.lunar
    Assert.assertEquals("一九四六年九月初五", lunar.toString())
}
6tail commented 2 years ago

@Test public void test54() { Calendar c = Calendar.getInstance(); c.set(1946, Calendar.SEPTEMBER, 30, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); Solar solar = Solar.fromCalendar(c); Lunar lunar = solar.getLunar(); Assert.assertEquals("一九四六年九月初六", lunar.toString()); @.*** public void test55() { Calendar c = Calendar.getInstance(); c.set(1946, Calendar.SEPTEMBER, 29, 0, 0, 0); c.set(Calendar.MILLISECOND, 0); Solar solar = Solar.fromCalendar(c); Lunar lunar = solar.getLunar(); Assert.assertEquals("一九四六年九月初五", lunar.toString()); }

Calendar和Date带了默认时区的,我没做处理,你设置一下时区看看呢。

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2021年12月25日(星期六) 下午5:04 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [6tail/lunar-java] Lunar.fromDate得出的农历是错误的 (Issue #11)

@6tail fromYmd确实没问题,但是fromCalendar和fromDate就有问题了

下面是单元测试 //1946年9月30号 @Test fun test1() { val calendar = Calendar.getInstance().apply { this.set(Calendar.YEAR,1946) this.set(Calendar.MONTH,8)//9月 this.set(Calendar.DAY_OF_MONTH,30) this.set(Calendar.HOUR_OF_DAY, 0) this.set(Calendar.MINUTE, 0) this.set(Calendar.SECOND, 0) this.set(Calendar.MILLISECOND, 0) } val solar = Solar.fromCalendar(calendar) val lunar = solar.lunar Assert.assertEquals("一九四六年九月初六", lunar.toString()) } //1946年9月29号 @Test fun test2() { val calendar = Calendar.getInstance().apply { this.set(Calendar.YEAR,1946) this.set(Calendar.MONTH,8)//9月 this.set(Calendar.DAY_OF_MONTH,29) this.set(Calendar.HOUR_OF_DAY, 0) this.set(Calendar.MINUTE, 0) this.set(Calendar.SECOND, 0) this.set(Calendar.MILLISECOND, 0) } val solar = Solar.fromCalendar(calendar) val lunar = solar.lunar Assert.assertEquals("一九四六年九月初五", lunar.toString()) }

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.Message ID: @.***>

caoyanglee commented 2 years ago

@6tail 你说的设置时区是App里还是手机里的,我刚试了一下你的单元测试,依然是有问题的

caoyanglee commented 2 years ago

@6tail 我现在先把Calendar和Date转Solar然后在转Lunar就没问题了。但是这样子,Lunar.fromDate和Lunar.fromCalendar就不能用了~

6tail commented 2 years ago

Calendar和Date先设置一下时区,再传入Lunar试下呢。

------------------ 原始邮件 ------------------ 发件人: @.>; 发送时间: 2021年12月27日(星期一) 上午9:52 收件人: @.>; 抄送: @.>; @.>; 主题: Re: [6tail/lunar-java] Lunar.fromDate得出的农历是错误的 (Issue #11)

@6tail 我现在先把Calendar和Date转Solar然后在转Lunar就没问题了。但是这样子,Lunar.fromDate和Lunar.fromCalendar就不能用了~

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.Message ID: @.***>