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

음력변환

조회 수 17852 추천 수 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"));

}





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

?

List of Articles
번호 분류 제목 날짜 조회 수
677 Server 아파치 ab 로 성능테스트 하기 2016.02.22 12357
676 Server 8기가 램에 맞는 Mysql config 셋팅 값 1 2016.02.22 3857
675 컴퓨터잡담 LG G5 기능 어디한번 보자 file 2016.02.21 8993
674 Server 오토셋과 apmsetup file 2016.02.17 2026
673 컴퓨터잡담 Sitemap.xml 만들어 주는 사이트 file 2016.01.23 689
672 컴퓨터잡담 ES 파일 탐색기로 FTP 동영상 재생하기 2016.01.22 2363
671 WindowsTip Diskless Boot Software for Windows(윈도우용 노하드 시스템) 2 file 2016.01.11 8581
670 컴퓨터잡담 ACTIVE-X 의 무서움 file 2015.12.26 669
669 컴퓨터잡담 서버 다운 원인 2015.12.10 556
668 Excel 엑셀 지정행 반복인쇄 하는 방법[지정행/지정열] file 2015.12.04 6105
667 컴퓨터잡담 [안드로이드] 키캣 4.4 버전 플래시 동영상 안될때 해결방법 file 2015.12.04 1147
666 컴퓨터잡담 PC에 안드로이드 설치하기 2015.12.01 989
665 컴퓨터잡담 안드로이드 플래시 동영상이 안될때 해결방법 [200, Stream not found, NetStream.Play.StreamNotFound, clip: '[Clip] ...Progress] file 2015.12.01 3902
664 컴퓨터잡담 [오류해결방법] 200, Stream not found, NetStream.Play.StreamNotFound, clip: '[Clip] ... 2015.11.30 1355
663 Server Windows APM Install(Apache 2.4, PHP 6.0, Mysql) 최신버전 설치해보기 2015.11.27 1246
662 [Docs]스프레드시트 Google 문서도구를 컴퓨터에 동기화 2015.11.18 4377
661 컴퓨터잡담 박지성 맨유시절 호날두와의 호흡경기 모음(유니세프 친선경기) 2015.11.13 827
660 컴퓨터잡담 도스 배치파일로 원격지 컴퓨터 모니터링 2015.11.13 833
659 WindowsTip DOS Batch - FTP Scripts 배치파일 2015.11.12 5702
658 Excel 엑셀 깨진파일 복구하기 file 2015.11.11 7673
Board Pagination Prev 1 ... 11 12 13 14 15 ... 46 Next
/ 46

http://urin79.com

우린친구블로그

sketchbook5, 스케치북5

sketchbook5, 스케치북5

나눔글꼴 설치 안내


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

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

설치 취소