관련 사이트 :
- Joda Time : http://joda-time.sourceforge.net/quickstart.html
- ICU4j calendar : http://userguide.icu-project.org/datetime/calendar#TOC-Calendar
쪼다타임(Joda time)은 자바의 Date, Time class를 대신할 수 있는 DateTime 클래스를 제공한다. 날짜, 시간 정보를 손쉽게 접근하고 가공할 수 있는 오픈소스다. 퀵스타트만 봐도 손쉽게 사용할 수 있다. ^^;
쪼다타임이 편리하기는 한데, 음력 처리를 해주지 못하는 걸 알고는 인터넷을 뒤져보다가 IBM에서 ICU(International Componenets for Unicode)라는 이름으로 제공하는 컴포넌트다. 그 중에 달력처리 부분에서 ChineseCalendar를 이용해서 음력처리가 가능한 것을 발견하고는 간단하게 테스트 코드를 작성해본다.
/**
* Create Date : 2011. 10. 11.
*/
package honeymon.study.test;
import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;
import org.joda.time.DateTime;
import org.junit.Before;
import org.junit.Test;
import com.ibm.icu.util.ChineseCalendar;
/**
* @author 허니몬
*/
public class LunarCalendarTest {
private ChineseCalendar chineseCal;
private DateTime dateTime;
@Before
public void setUp() {
chineseCal = new ChineseCalendar();
dateTime = new DateTime();
}
/**
* 왜 중국음력에서 달에 +1을 하는 걸까?
* +1은 회합주기?
* 2011/10/11 음력은 2011/09/15일
*/
@Test
public void 음력테스트() {
chineseCal.setTimeInMillis(dateTime.getMillis());
assertThat(chineseCal.get(ChineseCalendar.MONTH) + 1, is(9));
assertThat(chineseCal.get(ChineseCalendar.DAY_OF_MONTH), is(15));
}
}
'Java > Language' 카테고리의 다른 글
| 문자열 IP주소 목록 정렬하기 (0) | 2012.03.29 |
|---|---|
| [Java Object] java.lang.Class (0) | 2011.11.11 |
| 자바언어의 패키지 코딩 관례 (0) | 2011.08.07 |
| Java Method Chaining : '자바에서 메소드 이어서 쓰기' 랄까? (2) | 2011.07.17 |
| The server was expecting token 32 but got the token 33. This is an internal error. (0) | 2011.06.24 |