npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

chinese-lunar

v0.1.4

Published

农历与公历相互转换的类库,支持农历的之间的加减运算,并提供生肖、干支等,支持1900-2100年

Downloads

751

Readme

chinese-lunar

农历与公历相互转换的模块,支持农历之间的加减运算,并提供生肖、干支等,支持1900-2100年。

Install

  1. 在node.js中用npm安装 npm install chinese-lunar
  2. 在浏览器中加载方式,<script src="../lib/chinese-lunar.js></script>
  3. chinese-lunar支持require

Usage

Node.js

var chineseLunar = require("chinese-lunar");

浏览器

window.chineseLunar是一个全局函数,直接调用就可以,例如chineseLunar.solarToLunar(new Date());

对于require,可以用如下方式使用:

    require(["chinese-lunar"], function(chineseLunar){
      console.log(chineseLunar.solarToLunar(new Date());
      //more...
    });

Methods

solarToLunar

solarToLunar(solar[,format]); //=> lunar or string 将公历转换为农历,如果设置了format,则返回字符形式,反之返回农历对象。 示例代码如下:

var lunar = chineseLunar.solarToLunar(new Date(1982, 0, 29));
console.log(lunar.format('YMD'));     //一九八二年腊月十六

lunarToSolar

lunarToSolar(lunar); // => solar lunarToSolar(year, month, day[,leap]); //=> solar

将农历转换为公历,leap为可选参数

format

chineseLunar.format(lunar, format); //=> 一九八二年腊月十六 可以通过返回格式化字符,format表示如下:

  • T返回传统的天干地支年份
  • A返回生肖属相
  • Y返回中文的年,如二〇一二
  • y返回英文数字的年,如2012
  • m返回中文的月份,如五
  • M返回传统的月份,如腊月和正月
  • d返回传统的天名称,如初四、十八、卅
  • D返回传统的天名称,但是如果是初一的话,会返回这个月的月份名称,例如四月初一返回的是四月而非初一

monthDiff

monthDiff(lunar1, lunar2); 返回两个农历日期之间相差多少个月

monthAdd

monthAdd(lunar, inc); 返回农历相加N个月后的新日期,与公历不同,农历可能会存在闰月的情况

dateDiff

monthDiff(lunar1, lunar2, expr); 返回两个农历日期的差值,expr可以为yMdhms任意中的一个

dateAdd

dateAdd(lunar, expr);

根据exprlunar进行相加,expr是一个表达式,格式如:/[+-]?\d+((ms)|[yMdhmsw])/,可以多个表达式叠加,其中符号+可以省略。 示例:

  • 1M-5d表示增加1个月然后再减5天
  • +5d6M-4h表示增加5天,再增加6个月,然后减去4小时

leapMonthOfYear

leapMonthOfYear(year); 判断指定年year的闰月是几月,返回0表示这一年没有闰月

monthsOfYear

monthsOfYear(year); 返回指定年的闰月是几月。

daysOfMonth

daysOfMonth(year, month, leap); 返回某年某月共有多少天,农历中每个月有多少天是不固定的。

dayName

dayName(lunar); 返回农历天的名称,例如初一。

monthName

monthName(month, traditional, leap); 返回农历月份的名称,参数traditional表示是否返回传统的月份名称,如正月和腊月。

animalName

animalName(year); 返回某年的生肖属相

yearName

yearName(year); 返回年的中文名称。

traditionalYearName

traditionalYearName(year); 返回传统天干地支名称。

Test

make test

Credits

License

The MIT License

Copyright (c) 2012-2013 Conis Yi <http://iove.net/>