1
0
mirror of synced 2026-02-21 04:18:00 +08:00

Initial commit

This commit is contained in:
6tail
2018-06-23 16:41:40 +08:00
commit 6db19410ea
21 changed files with 2151 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
package sample;
import com.nlf.calendar.*;
import org.junit.Test;
/**
* 半年示例
*/
public class HalfYearTest {
@Test
public void test(){
SolarHalfYear halfYear = new SolarHalfYear();
System.out.println(halfYear);
System.out.println(halfYear.toFullString());
for(SolarMonth month:halfYear.getMonths()){
System.out.println(month.toFullString());
}
}
}

View File

@@ -0,0 +1,26 @@
package sample;
import com.nlf.calendar.Lunar;
import org.junit.Test;
/**
* 农历示例
*/
public class LunarTest {
@Test
public void test(){
//今天
Lunar date = new Lunar();
//输出阴历信息
System.out.println(date.toFullString());
//输出阳历信息
System.out.println(date.getSolar().toFullString());
System.out.println();
//指定阴历的某一天
date = new Lunar(1986,4,21);
System.out.println(date.toFullString());
System.out.println(date.getSolar().toFullString());
}
}

View File

@@ -0,0 +1,26 @@
package sample;
import com.nlf.calendar.Solar;
import com.nlf.calendar.SolarMonth;
import org.junit.Test;
/**
* 月份示例
*/
public class MonthTest {
@Test
public void test(){
//下个月
SolarMonth month = new SolarMonth().next(1);
//遍历每一天
for(Solar d:month.getDays()){
//输出阳历信息
System.out.println(d.toFullString());
//输出阴历信息
System.out.println(d.getLunar().toFullString());
System.out.println();
}
}
}

View File

@@ -0,0 +1,23 @@
package sample;
import com.nlf.calendar.SolarMonth;
import com.nlf.calendar.SolarSeason;
import org.junit.Test;
/**
* 季度示例
*/
public class SeasonTest {
@Test
public void test(){
SolarSeason season = new SolarSeason();
System.out.println(season);
System.out.println(season.toFullString());
for(SolarMonth month:season.getMonths()){
System.out.println(month.toFullString());
}
}
}

View File

@@ -0,0 +1,26 @@
package sample;
import com.nlf.calendar.Solar;
import org.junit.Test;
/**
* 阳历示例
*/
public class SolarTest {
@Test
public void test(){
//阳历今天
Solar date = new Solar();
//输出阳历信息
System.out.println(date.toFullString());
//输出阴历信息
System.out.println(date.getLunar().toFullString());
System.out.println();
//指定某个阳历日期
date = new Solar(1986,5,29);
System.out.println(date.toFullString());
System.out.println(date.getLunar().toFullString());
}
}

View File

@@ -0,0 +1,28 @@
package sample;
import com.nlf.calendar.Solar;
import com.nlf.calendar.SolarWeek;
import com.nlf.calendar.util.SolarUtil;
import org.junit.Test;
/**
* 周示例
*/
public class WeekTest {
@Test
public void test(){
//一周的开始从星期一开始计
SolarWeek week = new SolarWeek(1);
System.out.println(week);
System.out.println(week.toFullString());
System.out.println("本月共几周:"+ SolarUtil.getWeeksOfMonth(week.getYear(),week.getMonth(),1));
System.out.println("本周第一天:"+week.getFirstDay());
//遍历本周的每一天
for(Solar day:week.getDays()){
System.out.println(day);
}
}
}

View File

@@ -0,0 +1,46 @@
package sample;
import com.nlf.calendar.Lunar;
import com.nlf.calendar.Solar;
import com.nlf.calendar.SolarMonth;
import com.nlf.calendar.SolarYear;
import org.junit.Test;
/**
* 年份示例,我们来做一个日历吧
*/
public class YearTest {
@Test
public void test(){
//明年
SolarYear year = new SolarYear().next(1);
System.out.println("==="+year.getYear()+"年===");
//遍历明年的每个月
for(SolarMonth m:year.getMonths()){
System.out.println("---"+m.getMonth()+"月---");
//遍历当月的每一天
for(Solar d:m.getDays()){
//获取阴历
Lunar lunar = d.getLunar();
StringBuilder s = new StringBuilder();
s.append(d.getDay()<10?"0":"");
s.append(d.getDay());
s.append(" ");
s.append(lunar.getMonthInChinese());
s.append("");
s.append(lunar.getDayInChinese());
s.append(" ");
s.append("星期");
s.append(d.getWeekInChinese());
s.append(" ");
s.append(d.getFestivals());
s.append(lunar.getFestivals());
s.append(lunar.getJie());
s.append(lunar.getQi());
System.out.println(s.toString());
}
}
}
}