diff --git a/SETUP.md b/SETUP.md
new file mode 100644
index 0000000..e53b365
--- /dev/null
+++ b/SETUP.md
@@ -0,0 +1,179 @@
+# 사주보기 설정 가이드
+
+## 카카오 앱 키 설정
+
+카카오톡 공유 기능을 사용하려면 카카오 개발자 앱 키가 필요합니다.
+
+### 1. 카카오 개발자 계정 생성
+
+1. [카카오 개발자 센터](https://developers.kakao.com/) 접속
+2. 카카오 계정으로 로그인
+3. 개발자 등록 (처음 사용 시)
+
+### 2. 애플리케이션 생성
+
+1. **내 애플리케이션** 메뉴 클릭
+2. **애플리케이션 추가하기** 클릭
+3. 앱 정보 입력:
+ - 앱 이름: `사주보기` (또는 원하는 이름)
+ - 사업자명: `개인` 또는 사업자명
+4. **저장** 클릭
+
+### 3. JavaScript 키 발급
+
+1. 생성한 앱 선택
+2. **앱 키** 메뉴에서 **JavaScript 키** 복사
+ - 예: `a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6`
+
+### 4. 플랫폼 설정
+
+1. **플랫폼** 메뉴 선택
+2. **Web 플랫폼 추가** 클릭
+3. 사이트 도메인 등록:
+ - 개발 환경: `http://localhost:3003`
+ - 배포 환경: `https://your-domain.com`
+4. **저장** 클릭
+
+### 5. 환경 변수 설정
+
+1. 프로젝트 루트의 `.env.local` 파일 열기
+2. `NEXT_PUBLIC_KAKAO_APP_KEY=` 뒤에 복사한 JavaScript 키 붙여넣기
+
+```bash
+NEXT_PUBLIC_KAKAO_APP_KEY=a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6
+```
+
+3. 개발 서버 재시작
+
+```bash
+npm run dev
+```
+
+### 6. 동작 확인
+
+1. 사주 결과 페이지에서 **공유하기** 버튼 클릭
+2. 카카오톡 아이콘 클릭
+3. 카카오톡 로그인 후 친구 선택하여 공유 테스트
+
+---
+
+## 절기 기준 사주 계산
+
+이 프로젝트는 정확한 사주 계산을 위해 **24절기**를 기준으로 월주를 계산합니다.
+
+### 절기란?
+
+- 1년을 24개로 나눈 계절의 구분점
+- 사주에서 월주는 양력 월이 아닌 절기를 기준으로 계산
+- 예: 입춘(立春) 이후가 인월(寅月)
+
+### 주요 절기
+
+| 절기 | 시기 | 월주 |
+|------|------|------|
+| 입춘 | 2월 4일경 | 인월 (寅月) |
+| 경칩 | 3월 5일경 | 묘월 (卯月) |
+| 청명 | 4월 4일경 | 진월 (辰月) |
+| 입하 | 5월 5일경 | 사월 (巳月) |
+| 망종 | 6월 6일경 | 오월 (午月) |
+| 소서 | 7월 7일경 | 미월 (未月) |
+| 입추 | 8월 7일경 | 신월 (申月) |
+| 백로 | 9월 8일경 | 유월 (酉月) |
+| 한로 | 10월 8일경 | 술월 (戌月) |
+| 입동 | 11월 7일경 | 해월 (亥月) |
+| 대설 | 12월 7일경 | 자월 (子月) |
+| 소한 | 1월 5일경 | 축월 (丑月) |
+
+---
+
+## 대운 계산
+
+### 대운이란?
+
+- 10년 단위로 변화하는 큰 운의 흐름
+- 각 사람마다 대운이 시작되는 나이가 다름
+
+### 대운 시작 나이 계산
+
+1. **양남음녀** (양년생 남자, 음년생 여자)
+ - 순행: 생일부터 **다음 절기**까지의 일수 계산
+
+2. **음남양녀** (음년생 남자, 양년생 여자)
+ - 역행: **이전 절기**부터 생일까지의 일수 계산
+
+3. **대운수 공식**
+ - 일수 ÷ 3 = 대운 시작 나이
+ - 예: 24일 → 8세부터 대운 시작
+
+### 양년/음년 구분
+
+- 년간(天干)이 **양**(甲, 丙, 戊, 庚, 壬): 양년
+- 년간(天干)이 **음**(乙, 丁, 己, 辛, 癸): 음년
+
+---
+
+## 음력 변환
+
+### 음력 생일 입력
+
+1. 생년월일 입력 시 **음력** 버튼 선택
+2. 윤달인 경우 **윤달** 체크박스 선택
+3. 자동으로 양력 날짜로 변환되어 사주 계산
+
+### 지원 범위
+
+- 1900년 ~ 2100년
+- 윤달 지원
+
+### 주의사항
+
+- 음력 1월 1일 = 양력 1월 말 ~ 2월 초
+- 매년 음력과 양력의 대응 날짜가 다름
+- 정확한 변환을 위해 `lunar-calendar` 라이브러리 사용
+
+---
+
+## 개발 환경
+
+### 필수 요구사항
+
+- Node.js 18+
+- npm 또는 yarn
+
+### 설치
+
+```bash
+npm install
+```
+
+### 개발 서버 실행
+
+```bash
+npm run dev
+```
+
+http://localhost:3003 에서 확인
+
+### 빌드
+
+```bash
+npm run build
+npm start
+```
+
+---
+
+## 기술 스택
+
+- **Next.js 14** - React 프레임워크
+- **TypeScript** - 타입 안정성
+- **Tailwind CSS** - 스타일링
+- **jsPDF + html2canvas** - PDF 생성
+- **lunar-calendar** - 음력 변환
+- **Kakao SDK** - 카카오톡 공유
+
+---
+
+## 라이선스
+
+© 2025 쟁승메이드. All rights reserved.
diff --git a/app/layout.tsx b/app/layout.tsx
index 0d0a747..7b1524d 100644
--- a/app/layout.tsx
+++ b/app/layout.tsx
@@ -22,6 +22,8 @@ export default function RootLayout({
}: Readonly<{
children: React.ReactNode;
}>) {
+ const kakaoAppKey = process.env.NEXT_PUBLIC_KAKAO_APP_KEY;
+
return (
@@ -31,15 +33,17 @@ export default function RootLayout({
crossOrigin="anonymous"
async
>
-
+ {kakaoAppKey && (
+
+ )}
-
-
- 일간 (日干): {sajuData.day.stem}({sajuData.day.stemKr}) - 나 자신을 나타내는 중심 기둥입니다.
-
+
+
+
+ 일간 (日干): {sajuData.day.stem}({sajuData.day.stemKr}) - 나 자신을 나타내는 중심 기둥입니다.
+
+
+
+
+ 절기 (節氣): {solarTermName} 이후 -
+ 월주는 절기를 기준으로 {monthBranchName}월입니다.
+
+
+ * 사주 월주는 양력 월이 아닌 24절기를 기준으로 계산됩니다.
+
+
@@ -297,10 +316,15 @@ export default async function ResultPage({ searchParams }: PageProps) {
-
+
대운(大運): 10년 단위로 변화하는 큰 운의 흐름입니다.
각 대운마다 삶의 방향과 환경이 달라질 수 있으므로, 현재 대운의 특성을 이해하고 활용하는 것이 중요합니다.
+ {daeunList.length > 0 && (
+
+ * 대운은 생일부터 다음 절기까지의 일수를 기준으로 {daeunList[0].age}세부터 시작됩니다. (3일 = 1세)
+
+ )}
diff --git a/lib/daeun-calculator.ts b/lib/daeun-calculator.ts
index be49e45..8a6d94d 100644
--- a/lib/daeun-calculator.ts
+++ b/lib/daeun-calculator.ts
@@ -13,6 +13,60 @@ export interface DaeunPillar {
branchKr: string; // 지지 한글
}
+/**
+ * 대운 시작 나이 정밀 계산
+ * @param birthYear 생년
+ * @param birthMonth 생월
+ * @param birthDay 생일
+ * @param gender 성별
+ * @param isYangYear 양년 여부
+ * @returns 대운 시작 나이
+ */
+function calculateDaeunStartAge(
+ birthYear: number,
+ birthMonth: number,
+ birthDay: number,
+ gender: 'male' | 'female',
+ isYangYear: boolean
+): number {
+ const { getDaysToNextSolarTerm, getCurrentSolarTerm, getSolarTermDate } = require('./solar-terms');
+
+ // 양남음녀는 순행 (다음 절기까지), 음남양녀는 역행 (이전 절기부터)
+ let days: number;
+
+ if ((gender === 'male' && isYangYear) || (gender === 'female' && !isYangYear)) {
+ // 순행: 생일부터 다음 절기까지의 일수
+ days = getDaysToNextSolarTerm(birthYear, birthMonth, birthDay);
+ } else {
+ // 역행: 이전 절기부터 생일까지의 일수
+ const currentTerm = getCurrentSolarTerm(birthYear, birthMonth, birthDay);
+ const termDate = getSolarTermDate(birthYear, currentTerm);
+
+ let termYear = termDate.year;
+ let termMonth = termDate.month;
+
+ // 대한, 소한 처리
+ if (currentTerm >= 22 && birthMonth >= 2) {
+ termYear = birthYear;
+ } else if (currentTerm >= 22) {
+ termYear = birthYear - 1;
+ }
+
+ const termDateObj = new Date(termYear, termMonth - 1, termDate.day);
+ const birthDateObj = new Date(birthYear, birthMonth - 1, birthDay);
+
+ const diffTime = birthDateObj.getTime() - termDateObj.getTime();
+ days = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
+ }
+
+ // 3일 = 1세 (대운수)
+ // 정확히는 3일당 1세이지만, 일수를 3으로 나눈 몫
+ const startAge = Math.floor(days / 3);
+
+ // 최소 1세, 최대 10세로 제한
+ return Math.max(1, Math.min(10, startAge));
+}
+
/**
* 대운 계산
* @param birthYear 생년
@@ -49,9 +103,8 @@ export function calculateDaeun(
isForward = !isYangYear; // 양녀: 역행, 음녀: 순행
}
- // 대운 시작 나이 계산 (간단화: 평균 8세로 설정)
- // 실제로는 절입일부터 생일까지의 일수를 계산해야 하지만 복잡하므로 단순화
- const startAge = 8;
+ // 대운 시작 나이 정밀 계산 (절기 기준)
+ const startAge = calculateDaeunStartAge(birthYear, birthMonth, birthDay, gender, isYangYear);
const daeunList: DaeunPillar[] = [];
diff --git a/lib/saju-calculator.ts b/lib/saju-calculator.ts
index 322bbe5..a309e54 100644
--- a/lib/saju-calculator.ts
+++ b/lib/saju-calculator.ts
@@ -60,19 +60,19 @@ export function getYearGanzi(year: number): { stem: string; branch: string; stem
}
/**
- * 월의 간지를 계산
+ * 월의 간지를 계산 (절기 기준)
*/
-export function getMonthGanzi(year: number, month: number): { stem: string; branch: string; stemKr: string; branchKr: string } {
- // 월 지지는 고정: 1월=인, 2월=묘, 3월=진, 4월=사, 5월=오, 6월=미...
- // 단, 절기 기준이지만 간단히 월로 계산
- const branchIndex = (month + 1) % 12; // 1월=인(2), 2월=묘(3)...
+export function getMonthGanzi(year: number, month: number, day: number): { stem: string; branch: string; stemKr: string; branchKr: string } {
+ // 절기 기준으로 월 지지 계산
+ const { getSolarTermMonthBranch } = require('./solar-terms');
+ const branchIndex = getSolarTermMonthBranch(year, month, day);
// 월 천간 계산 (년간에 따라 달라짐)
const yearStem = getYearGanzi(year).stem;
const yearStemIndex = HEAVENLY_STEMS.indexOf(yearStem as any);
- // 월 천간 공식: (년간 * 2 + 월) % 10
- const stemIndex = (yearStemIndex * 2 + month) % 10;
+ // 월 천간 공식: (년간 * 2 + 월지지) % 10
+ const stemIndex = (yearStemIndex * 2 + branchIndex) % 10;
return {
stem: HEAVENLY_STEMS[stemIndex],
@@ -224,7 +224,7 @@ export function calculateSaju(
gender: 'male' | 'female'
): SajuData {
const yearGanzi = getYearGanzi(year);
- const monthGanzi = getMonthGanzi(year, month);
+ const monthGanzi = getMonthGanzi(year, month, day);
const dayGanzi = getDayGanzi(year, month, day);
const hourGanzi = hour !== null ? getHourGanzi(dayGanzi, hour) : null;
diff --git a/lib/solar-terms.ts b/lib/solar-terms.ts
new file mode 100644
index 0000000..85ad5c4
--- /dev/null
+++ b/lib/solar-terms.ts
@@ -0,0 +1,187 @@
+/**
+ * 24절기 계산
+ * 사주 계산에서 월주는 절기를 기준으로 합니다.
+ */
+
+// 24절기 (입춘부터 시작)
+export const SOLAR_TERMS = [
+ '입춘', '우수', '경칩', '춘분', '청명', '곡우',
+ '입하', '소만', '망종', '하지', '소서', '대서',
+ '입추', '처서', '백로', '추분', '한로', '상강',
+ '입동', '소설', '대설', '동지', '소한', '대한'
+] as const;
+
+// 월 절기 (홀수 인덱스: 입X, 짝수 인덱스: X분/X지)
+export const MONTH_SOLAR_TERMS = [
+ '입춘', // 1월 (인월)
+ '경칩', // 2월 (묘월)
+ '청명', // 3월 (진월)
+ '입하', // 4월 (사월)
+ '망종', // 5월 (오월)
+ '소서', // 6월 (미월)
+ '입추', // 7월 (신월)
+ '백로', // 8월 (유월)
+ '한로', // 9월 (술월)
+ '입동', // 10월 (해월)
+ '대설', // 11월 (자월)
+ '소한', // 12월 (축월)
+] as const;
+
+interface SolarTermDate {
+ year: number;
+ month: number;
+ day: number;
+ hour: number;
+ minute: number;
+}
+
+/**
+ * 간단한 절기 계산 (근사치)
+ * 실제로는 천문 계산이 필요하지만, 여기서는 근사값 사용
+ *
+ * 절기는 매년 비슷한 시기에 오지만 정확한 시간은 천문학적 계산 필요
+ */
+export function getSolarTermDate(year: number, termIndex: number): SolarTermDate {
+ // 절기 기준일 (대략적인 날짜)
+ // 입춘은 대략 2월 4일경, 각 절기는 약 15일 간격
+
+ const baseMonth = [
+ 2, 2, 3, 3, 4, 4, // 입춘~곡우
+ 5, 5, 6, 6, 7, 7, // 입하~대서
+ 8, 8, 9, 9, 10, 10, // 입추~상강
+ 11, 11, 12, 12, 1, 1 // 입동~대한
+ ];
+
+ const baseDay = [
+ 4, 19, 5, 20, 4, 20, // 입춘~곡우 (2월 4일, 2월 19일...)
+ 5, 21, 6, 21, 7, 23, // 입하~대서
+ 7, 23, 8, 23, 8, 23, // 입추~상강
+ 7, 22, 7, 22, 5, 20 // 입동~대한
+ ];
+
+ let month = baseMonth[termIndex];
+ let day = baseDay[termIndex];
+
+ // 대한과 소한은 다음 해 1월이므로 조정
+ if (termIndex >= 22) {
+ // 이미 1월로 설정되어 있음
+ }
+
+ return {
+ year,
+ month,
+ day,
+ hour: 0,
+ minute: 0
+ };
+}
+
+/**
+ * 주어진 날짜가 어느 절기 이후인지 확인
+ * @param year 년
+ * @param month 월
+ * @param day 일
+ * @returns 절기 인덱스 (0~23)
+ */
+export function getCurrentSolarTerm(year: number, month: number, day: number): number {
+ const date = new Date(year, month - 1, day);
+ const dateValue = date.getTime();
+
+ // 각 절기 날짜 확인
+ for (let i = 23; i >= 0; i--) {
+ const termDate = getSolarTermDate(year, i);
+ let termYear = termDate.year;
+ let termMonth = termDate.month;
+
+ // 대한, 소한은 이전 해 처리
+ if (i >= 22 && month >= 2) {
+ termYear = year;
+ } else if (i >= 22) {
+ termYear = year - 1;
+ }
+
+ const term = new Date(termYear, termMonth - 1, termDate.day);
+
+ if (dateValue >= term.getTime()) {
+ return i;
+ }
+ }
+
+ // 입춘 이전이면 전년도 대한 이후
+ return 23;
+}
+
+/**
+ * 절기 기준 월주 지지 인덱스 계산
+ * @param year 년
+ * @param month 월
+ * @param day 일
+ * @returns 지지 인덱스 (0: 자, 1: 축, 2: 인, ...)
+ */
+export function getSolarTermMonthBranch(year: number, month: number, day: number): number {
+ const termIndex = getCurrentSolarTerm(year, month, day);
+
+ // 절기 인덱스를 월로 변환
+ // 입춘(0) -> 인월(2)
+ // 경칩(2) -> 묘월(3)
+ // 청명(4) -> 진월(4)
+ // ...
+
+ const monthBranches = [
+ 2, // 입춘 -> 인월
+ 2, // 우수 -> 인월
+ 3, // 경칩 -> 묘월
+ 3, // 춘분 -> 묘월
+ 4, // 청명 -> 진월
+ 4, // 곡우 -> 진월
+ 5, // 입하 -> 사월
+ 5, // 소만 -> 사월
+ 6, // 망종 -> 오월
+ 6, // 하지 -> 오월
+ 7, // 소서 -> 미월
+ 7, // 대서 -> 미월
+ 8, // 입추 -> 신월
+ 8, // 처서 -> 신월
+ 9, // 백로 -> 유월
+ 9, // 추분 -> 유월
+ 10, // 한로 -> 술월
+ 10, // 상강 -> 술월
+ 11, // 입동 -> 해월
+ 11, // 소설 -> 해월
+ 0, // 대설 -> 자월
+ 0, // 동지 -> 자월
+ 1, // 소한 -> 축월
+ 1, // 대한 -> 축월
+ ];
+
+ return monthBranches[termIndex];
+}
+
+/**
+ * 절기명 가져오기
+ */
+export function getSolarTermName(termIndex: number): string {
+ return SOLAR_TERMS[termIndex];
+}
+
+/**
+ * 다음 절기까지 남은 일수 계산
+ */
+export function getDaysToNextSolarTerm(year: number, month: number, day: number): number {
+ const currentDate = new Date(year, month - 1, day);
+ const currentTerm = getCurrentSolarTerm(year, month, day);
+ const nextTermIndex = (currentTerm + 1) % 24;
+
+ let nextYear = year;
+ if (currentTerm === 23) {
+ nextYear = year + 1;
+ }
+
+ const nextTerm = getSolarTermDate(nextYear, nextTermIndex);
+ const nextDate = new Date(nextTerm.year, nextTerm.month - 1, nextTerm.day);
+
+ const diffTime = nextDate.getTime() - currentDate.getTime();
+ const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
+
+ return diffDays;
+}