isee15 / Lunar-Solar-Calendar-Converter

公历(阳历) 农历(阴历)转换,支持时间段从1900-2100 如果需要更长的时间段,利用generate.htm生成的数据即可。 支持各种编程语言 C#,java,Objective-C,php,Python,javascript(nodejs),C/C++,ruby,swift,golang等 支持Mac,Windows,Android,WP多种平台
MIT License
638 stars 240 forks source link

java 测试转化后 出现很多转化错误 #24

Closed LuckyJayce closed 3 years ago

LuckyJayce commented 3 years ago

java 测试出现通过,测试代码如下 (Solar类 加了equals,hashCode和toString)

public static void main(String[] args) {
    int dayCount = 365 * 1;
    Calendar calendar = Calendar.getInstance();
    calendar.set(2001, Calendar.JANUARY, 1);
    for (int i = 0; i < dayCount; i++) {
        calendar.add(Calendar.DAY_OF_YEAR, 1);
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH);
        int day = calendar.get(Calendar.DATE);

        Solar solar = new Solar();
        solar.solarYear = year;
        solar.solarMonth = month+1;
        solar.solarDay = day;

        Lunar lunar = LunarSolarConverter.SolarToLunar(solar);
        Solar solar2 = LunarSolarConverter.LunarToSolar(lunar);

        if (solar.equals(solar2)) {
            System.out.println("ok solar:" + solar + " lunar:" + lunar + " solar2:" + solar2);
        } else {
            System.out.println("---error solar:" + solar + " lunar:" + lunar + " solar2:" + solar2);
        }
    }
}

打印结果

LuckyJayce commented 3 years ago

dart 测试完美通过,测试代码如下,(Solar类 加了equals,hashCode和toString)

main(List<String> arguments) {
  DateTime dateTime = DateTime(1900, 1, 1);
  int dayCount = 365 * 1;
  for (int i = 0; i < dayCount; i++) {
    dateTime = dateTime.add(Duration(days: 1));

    Solar solar = Solar(
        solarYear: dateTime.year,
        solarMonth: dateTime.month,
        solarDay: dateTime.day);
    Lunar lunar = LunarSolarConverter.solarToLunar(solar);
    Solar solar2 = LunarSolarConverter.lunarToSolar(lunar);
    if (solar == solar2) {
      // print('ok solar:$solar lunar:$lunar solar2:$solar2');
    } else {
      print('---error solar:$solar lunar:$lunar solar2:$solar2');
    }
  }
  print('finished');
}

打印结果 finished

随机抽样了几个和日历上的一致。