Skip to content

Commit

Permalink
重构,将LunarDate与SolarDate统一为CalendarDate.
Browse files Browse the repository at this point in the history
  • Loading branch information
Birdy authored and Birdy committed Mar 21, 2020
1 parent 59ccace commit 5e71b55
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.jstarcraft.core.common.instant;

/**
* 历法日期
*
* @author Birdy
*
*/
public interface CalendarDate {

/**
* 获取历法年
*
* @return
*/
int getYear();

/***
* 获取历法月
*
* @return
*/
int getMonth();

/**
* 获取历法日
*
* @return
*/
int getDay();

/**
* 是否闰
*
* @return
*/
boolean isLeap();

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author Birdy
*
*/
public class LunarDate {
public class LunarDate implements CalendarDate {

/**
* 支持的最小年份
Expand Down Expand Up @@ -415,6 +415,7 @@ public LunarDate(int year, boolean leap, int month, int day) {
*
* @return
*/
@Override
public int getYear() {
return year;
}
Expand All @@ -424,6 +425,7 @@ public int getYear() {
*
* @return
*/
@Override
public int getMonth() {
return month;
}
Expand All @@ -433,6 +435,7 @@ public int getMonth() {
*
* @return
*/
@Override
public int getDay() {
return day;
}
Expand All @@ -442,6 +445,7 @@ public int getDay() {
*
* @return
*/
@Override
public boolean isLeap() {
return leap;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* @author Birdy
*
*/
public class SolarDate {
public class SolarDate implements CalendarDate {

private LocalDate date;

Expand All @@ -33,6 +33,7 @@ public SolarDate(int year, int month, int day) {
*
* @return
*/
@Override
public int getYear() {
return date.getYear();
}
Expand All @@ -42,6 +43,7 @@ public int getYear() {
*
* @return
*/
@Override
public int getMonth() {
return date.getMonthValue();
}
Expand All @@ -51,6 +53,7 @@ public int getMonth() {
*
* @return
*/
@Override
public int getDay() {
return date.getDayOfMonth();
}
Expand All @@ -60,6 +63,7 @@ public int getDay() {
*
* @return
*/
@Override
public boolean isLeap() {
return date.isLeapYear();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package com.jstarcraft.core.common.instant;

import java.time.LocalDate;

import org.hamcrest.CoreMatchers;
import org.junit.Assert;
import org.junit.Test;

import com.jstarcraft.core.common.instant.LunarDate;
import com.jstarcraft.core.common.instant.SolarDate;

public class Lunar2SolarTestCase {

@Test
Expand Down

0 comments on commit 5e71b55

Please sign in to comment.