wvv8oo / lunar Goto Github PK
View Code? Open in Web Editor NEW农历与公历相互转换的模块,支持农历之间的加减运算,并提供生肖、干支等,支持1900-2100年。
Home Page: https://github.com/wvv8oo/lunar
农历与公历相互转换的模块,支持农历之间的加减运算,并提供生肖、干支等,支持1900-2100年。
Home Page: https://github.com/wvv8oo/lunar
首先,这是个很好的库,准确率也非常好!
关于API设计方面,提供一个小建议:
目前公农历互转的函数solarToLunar
和lunarToSolar
所需要的参数都是一样的,一个需要Date
对象,返回一个自定义的农历对象,一个需要年、月、日,返回一个Date
对象(猜测是这样,文档没有说明白)。
这里建议将二者的API从形式上做些统一,比如都支持传入年、月、日,都返回一个包含公历和农历的对象。我设想使用方式的大致如下:
var lunar = new ChineseLunar('lunar',1988,8,13); //农历1988年8月13日
lunar.lunarDate; //自定义的农历日期对象
lunar.solarDate; //公历日期对象
//取农历日期操作
lunar.lunarDate.format('YMD'); //格式化农历日期
lunar.lunarDate.getDate(); //获取农历日期
//取公历日期操作
lunar.solarDate.format('YMD'); //格式化公历日期
lunar.solarDate.getDate(); //获取公历日期
//或者API也可以这样设计
lunar.format('lunar','YMD'); //格式化农历日期
lunar.getDate('lunar'); //获取农历日期
lunar.format('lunar','YMD'); //格式化农历日期
lunar.getDate('lunar'); //获取农历日期
望考虑。
另外希望文档可以再详细一些,将参数和返回值说明白,比如看测试用例中可以在农历转公历时使用自定义的农历日期对象,但文档中没有说明。还有之前提到的农历转公历的返回值类型也没有说明。
如题,不知道作者还管不管这个项目了
输入 new date(2016,12,29) -->返回二O一七年正月初二。 但是正确的值应该是二O一七年正月初一。也有其他数据测试出错,暂未记录
Line 540 in 34940a8
Line 244 in 34940a8
Line 248 in 34940a8
例子:
var a = new Date(2017, 7, 22) // 农历七月初一
var b = new Date('2017-9-1 16:20:20') // 农历七月十一
var c = new Date('2017-9-1')
var span1 = b.getTime() - a.getTime() // 922820000
var diff1 = Math.ceil(span1/ 1000 / 60 / 60 /24) // 结果为11,算上后面再加上的一天,那么农历则为七月十二,错误
var span2 = c.getTime() - a.getTime() // 864000000
var diff2 = Math.ceil(span2/ 1000 / 60 / 60 /24) // 结果为10,算上后面再加上的一天,那么农历则为七月十一,正确
最后在 switch-case
也不需要 Math.ceil
看了下原码,这个也太硬编码了,太容易错,且对于不在范围内的日期不能用。
Line 627 in 5dfe9f1
感觉像是这行代码是优先考虑了AMD模式,但是在小程序的框架中的define函数和AMD中define函数不一样,所以会导致里面的回调不执行,也就引入不了。我提了个PR增加了更严格的AMD模式检查,规避了这种情况。
你好,经过对比发现2070年以后的农历MAPPING信息不准确,建议检查。
在计算农历节日时,计算正月初一时,发现转换成了正月正月,所以去查看源码,发现这段注释
不太明白
//如果是初一,则显示月,而不是显示
case "D":
if(lunar.day == 1){
return _chineseLunar.monthName(lunar.month, false, lunar.leap);
}else{
return _chineseLunar.dayName(lunar.day);
};
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.