Skip to content
[Docs]스프레드시트
2014.11.11 08:17

음력변환

조회 수 17854 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄




=sol2lun("2014", "11", "11")



 /**

 * 음력일자를 받아서 양력일자를 리턴하는 함수 (한국천문연구원 사이트를 이용)

 * 음력 10월 3일의 2013년 양력일자를 알고 싶은 경우 lun2sol(2013, 10, 3, 1) 으로 호출

 * 응답으로는 '2013/11/05' 와 같이 스트링을 리턴.

 * yoon (윤달구분) : 1 - 평달, 2 - 윤달

 */

function lun2sol(yyyy, mm, dd, yoon) {

  yyyy = parseInt(yyyy, 10); mm = parseInt(mm, 10); dd = parseInt(dd, 10);

  

  if ((yyyy <= 1391) || (yyyy >= 2050)) {

    return "ERROR";

  }

  if ((mm < 1) || (mm > 12)) {

    return "ERROR";

  }

  if ((dd < 1) || (dd > 31)) {

    return "ERROR";

  }

 

  /* 이미 조회했던 일자이면 ScriptProperties 에서 읽어 온다. -- 네트웍을 통한 조회는 한번만 하도록 */  

  var prop = ScriptProperties.getProperty("lun2sol/" + yyyy + "/" + mm + "/" + dd + "/" + yoon);

  if (prop != null) {

    Logger.log("Read from db: " + prop);

    return prop;

  }

  

  var payload = {

    "lun_year": String(yyyy),

    "lun_month": String(mm),

    "lun_day": String(dd),

    "yoon": String(yoon)

  };

  var params = {

    "method": "post",

    "payload": payload

  };

  var result = UrlFetchApp.fetch("http://astro.kasi.re.kr/Life/Knowledge/solar2lunar/convert_daily_l2s.php", params);

  var htmlstr = result.getContentText();

  //Logger.log(htmlstr);

 

  var pos = htmlstr.indexOf("td width=500");  //-- 천문연구원 사이트 변경되면 수정 필요

  if (pos >= 0) {

    pos = pos + 13;

    var checkChar = htmlstr.substr(pos, 1);

    if ((checkChar >= "0") && (checkChar <= "9")) {

      ;

    }

    else {

      return "ERROR";

    }

    

    var new_prop = htmlstr.substr(pos, 4) + "/" + htmlstr.substr(pos + 7, 2) + "/" + htmlstr.substr(pos + 12, 2)

    ScriptProperties.setProperty("lun2sol/" + yyyy + "/" + mm + "/" + dd + "/" + yoon, new_prop);

    

    return new_prop;

  }

  return "ERROR";

}

 

/**

 * 양력일자를 받아서 음력일자를 리턴하는 함수 (한국천문연구원 사이트를 이용)

 * 양력 2013년 1월 26일의 음력일자를 알고 싶은 경우 sol2lun(2013, 1, 26) 으로 호출

 * 응답으로는 '2012/12/15 평달' 과 같이 스트링을 리턴.

 */

function sol2lun(yyyy, mm, dd) {

  yyyy = parseInt(yyyy, 10); mm = parseInt(mm, 10); dd = parseInt(dd, 10);

 

  if ((yyyy <= 1391) || (yyyy >= 2050)) {

    return "ERROR";

  }

  if ((mm < 1) || (mm > 12)) {

    return "ERROR";

  }

  if ((dd < 1) || (dd > 31)) {

    return "ERROR";

  }

 

  /* 이미 조회했던 일자이면 ScriptProperties 에서 읽어 온다. -- 네트웍을 통한 조회는 한번만 하도록 */  

  var prop = ScriptProperties.getProperty("sol2lun/" + yyyy + "/" + mm + "/" + dd);

  if (prop != null) {

    Logger.log("Read from db: " + prop);

    return prop;

  }

  

  var payload = {

    "sol_year": String(yyyy),

    "sol_month": String(mm),

    "sol_day": String(dd),

  };

  var params = {

    "method": "post",

    "payload": payload

  };

  var result = UrlFetchApp.fetch("http://astro.kasi.re.kr/Life/Knowledge/solar2lunar/convert_daily_s2l.php", params);

  var htmlstr = result.getContentText();

  var yoonstr;

  var pos = htmlstr.indexOf("td width=500");  //-- 천문연구원 사이트 변경되면 수정 필요

  if (pos >= 0) {

    pos = pos + 13;

    var checkChar = htmlstr.substr(pos, 1);

    if ((checkChar >= "0") && (checkChar <= "9")) {

      ;

    }

    else {

      return "ERROR";

    }

 

    if (htmlstr.indexOf("br>(") == -1) {             //-- 천문연구원 사이트 변경되면 수정 필요

      yoonstr = "평달";

    } 

    else {

      yoonstr = "윤달";

    }

 

    var new_prop = htmlstr.substr(pos, 4) + "/" + htmlstr.substr(pos + 7, 2) + "/" + htmlstr.substr(pos + 12, 2) + " " + yoonstr;

    ScriptProperties.setProperty("sol2lun/" + yyyy + "/" + mm + "/" + dd, new_prop);

 

    return new_prop;

  }

  return "ERROR";

}

 

function test_lun2sol() {

  //Logger.log(lun2sol("2013", "10", "3", 1));

  Logger.log(lun2sol(2013, 1, 4, 1));

}

 

function test_sol2lun() {

  Logger.log(sol2lun("2013", "1", "26"));

}





로그인 후 댓글쓰기가 가능합니다.

?

  1. 11
    Jul 2011
    22:42

    [익스플로러 오류] 인터넷 연결중 메시지 이후 반응없음, 다시 시작프로그램 작동중 곧바로 꺼짐현상 해결방법

    Category컴퓨터잡담 Views6980
    Read More
  2. 27
    Jun 2011
    09:42

    윈도우7 공유기 사용시 네트워크 연결 문제

    Category컴퓨터잡담 Views17367
    Read More
  3. 23
    Jun 2011
    12:45

    [TCP/IP] 인터넷 연결 문제 복구 및 확인방법

    Category컴퓨터잡담 Views19826
    Read More
  4. 22
    Jun 2011
    12:21

    DHCP서버 IP시간 만료로 인터넷이 안되는 경우 해결방법

    Category컴퓨터잡담 Views15138
    Read More
  5. 20
    Jun 2011
    17:52

    [WGATRAY.EXE] 정품인증 Windows Genuine Advantage 수동 삭제

    Category컴퓨터잡담 Views5753
    Read More
  6. 20
    Jun 2011
    17:08

    마지막 검색 세션이 예상치 못하게 종료되었습니다

    Category컴퓨터잡담 Views6344
    Read More
  7. 20
    Jun 2011
    17:06

    윈도우 진입후 익스플로러 연결 딜레이 현상

    Category컴퓨터잡담 Views4189
    Read More
  8. 20
    Jun 2011
    17:05

    윈도우7 익스플로러8 연결문제.

    Category컴퓨터잡담 Views4438
    Read More
  9. 20
    Jun 2011
    17:01

    윈도우7 노트북에서 인터넷 끊킴현상 발생시 조치.

    Category컴퓨터잡담 Views4894
    Read More
  10. 20
    Jun 2011
    16:56

    SK브로드밴드 윈도우7 또는 Vista 속도이상시 환경설정방법

    Category컴퓨터잡담 Views8374
    Read More
  11. 17
    Jun 2011
    15:27

    호스트 / 서버운영자가 가볼만한 사이트

    Category컴퓨터잡담 Views5423
    Read More
  12. 17
    Jun 2011
    15:21

    CUBRID 알아보기

    Category컴퓨터잡담 Views6252
    Read More
  13. 16
    Jun 2011
    14:13

    GoogleUpdate.exe 프로세스의 제거와 삭제

    Category컴퓨터잡담 Views9852
    Read More
  14. 11
    Jun 2011
    10:58

    윈도우7 노트북에서 인터넷 끊김현상 발생되는 원인 해결방법

    Category컴퓨터잡담 Views15985
    Read More
  15. 05
    Jun 2011
    13:22

    [hosts 파일 이용] 리얼클릭 광고 무력화 시키기

    Category컴퓨터잡담 Views4091
    Read More
  16. 15
    May 2011
    15:27

    [PHP] 랭킹 순위 구하는 로직

    Category컴퓨터잡담 Views9634
    Read More
  17. 07
    May 2011
    13:08

    익스플로러8 액티브X(Active-X) 오류 / DEP 데이터 실행방지 프로그램 문제[Win XP]

    Category컴퓨터잡담 Views8463
    Read More
  18. 04
    May 2011
    16:09

    [PHP] 오류출력 안하기

    Category컴퓨터잡담 Views8424
    Read More
  19. 12
    Apr 2011
    08:01

    익스플로러9 사용시 화면 멈춤현상 개선방법

    Category컴퓨터잡담 Views14442
    Read More
  20. 10
    Apr 2011
    12:46

    PF사용...페이징 중지를 통한 시스템 성능개선

    Category프로세스 Views30889
    Read More
Board Pagination Prev 1 ... 31 32 33 34 35 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


이 PC에는 나눔글꼴이 설치되어 있지 않습니다.

이 사이트를 나눔글꼴로 보기 위해서는
나눔글꼴을 설치해야 합니다.

설치 취소