Giter Site home page Giter Site logo

calendar.js's People

Contributors

consatan avatar jjonline avatar panjp-git avatar shixianqin avatar sunzongming avatar yukiniro avatar zhangyuhan2016 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

calendar.js's Issues

发现两个问题,已经提交pr

初次使用这个插件,没有作任何修改,发现有以下两个问题:image1、每月最后一天和下个月的第一天,比如31号跟1号,显示出的农历信息重复
2、获取到的节气是错误的
如图:

我以为是我传参问题,但是不论我怎么修改,都无法正确的显示相应信息。后查看源码,发现部分逻辑存在错误之处,已经在pr中做修改#25

以上修改都经过验证,已经能拿到正确信息。第一次提pr,不太懂操作,如果pr代码中或者提交操作上有不妥之处,望指出,我会及时更改。

发现一个bug

哈喽,作者大佬你好。
我在使用您的插件中发现阳历1996-10-1对应的农历应该是八月十九,但是插件的计算结果是八月二十
1996这年的0x055c0应该是0x05ac0

修改了节气显示的方式

本来节气 只有在节气当天显示, 不在当天的时候,节气是null。
按照历法,节气,只是这一段时间的天气,所以讲节气显示出来。
并且取出了下一个节气及其日期。
修改1:
image
修改2:
image

最终的数据如下:
image

`

    //传入的日期的节气与否
    let isTerm = false;
    let Term = null;
    let nextTerm = null;
    let nextTermDate = null;
    if (d ==  firstNode || d == secondNode) {
        isTerm = true
    }
    if (d < firstNode){
        Term = this.solarTerm[(m*2-3)>=0?m*2-3:23];


        nextTerm = this.solarTerm[m*2-2];
        nextTermDate = y + '-' + m + '-' + firstNode
    }
    if (d >= firstNode  && d < secondNode) {
        Term = this.solarTerm[m*2 - 2];
        nextTerm = this.solarTerm[m*2 - 1];
        nextTermDate = y + '-' + m + '-' + secondNode
    }
    if (d >= secondNode) {
        Term = this.solarTerm[m*2 - 1];
        if (m == 12) {
            nextTerm = this.solarTerm[0];
            nextTermDate = (y+1) + '-' + 1 + '-' + this.getTerm(y+1, 1)
        } else {
            nextTerm = this.solarTerm[m*2];
            nextTermDate = y + '-' + (m+1) + '-' + this.getTerm(y, ((m+1) * 2 - 1))
        }


    }
    //日柱 当月一日与 1900/1/1 相差天数
    const dayCyclical = Date.UTC(y, sm, 1, 0, 0, 0, 0) / 86400000 + 25567 + 10;
    const gzD = this.toGanZhi(dayCyclical + d - 1);
    //该日期所属的星座
    const astro = this.toAstro(m, d);

    const solarDate = y + '-' + m + '-' + d;
    const lunarDate = year + '-' + month + '-' + day;

    const festival = this.festival;
    const lFestival = this.lFestival;

    const festivalDate = m + '-' + d;
    let lunarFestivalDate = month + '-' + day;

    // bugfix https://github.com/jjonline/calendar.js/issues/29
    // 农历节日修正:农历12月小月则29号除夕,大月则30号除夕
    // 此处取巧修正:当前为农历12月29号时增加一次判断并且把lunarFestivalDate设置为12-30以正确取得除夕
    // 天朝农历节日遇闰月过前不过后的原则,此处取农历12月天数不考虑闰月
    // 农历润12月在本工具支持的200年区间内仅1574年出现
    if (month === 12 && day === 29 && this.monthDays(year, month) === 29) {
        lunarFestivalDate = '12-30';
    }
    return {
        date: solarDate,
        lunarDate: lunarDate,
        festival: festival[festivalDate] ? festival[festivalDate].title : null,
        lunarFestival: lFestival[lunarFestivalDate] ? lFestival[lunarFestivalDate].title : null,
        'lYear': year,
        'lMonth': month,
        'lDay': day,
        'Animal': this.getAnimal(year),
        'IMonthCn': (isLeap ? "\u95f0" : '') + this.toChinaMonth(month),
        'IDayCn': this.toChinaDay(day),
        'cYear': y,
        'cMonth': m,
        'cDay': d,
        'gzYear': gzY,
        'gzMonth': gzM,
        'gzDay': gzD,
        'isToday': isToday,
        'isLeap': isLeap,
        'nWeek': nWeek,
        'ncWeek': "\u661f\u671f" + cWeek,
        'isTerm': isTerm,
        'Term': Term,
        'nextTerm':nextTerm,
        'nextTermDate':nextTermDate,
        'astro': astro
    };`

关于 getTerm

var _24 = calendar.getTerm(1987,3) ; // _24=4;意即1987年2月4日立春

想问下 2 月是怎么得到的

加个黄历的宜忌吧!

本来想自己加的,结果看了网上的推算方法,一头雾水!!实在看不懂历法!
有当天的宜忌就可以,时辰的太细,没必要!看了一些源码,固定的数据很少,只是搞不懂规则怎么取到对的。。。。。

农历计算错误

今天阳历是2021年12月14日,计算的结果是农历IDayCn: "初十" IMonthCn: "十月" 今天农历是 十一月十一

import 报错改怎么改

C:\Users\25166\Desktop\vue\fullcalendar-example-projects\vue-vuex\src\assets\calendar.js
417:13 error Unreachable code no-unreachable
420:13 error Unreachable code no-unreachable
462:17 error 'objDate' is already defined no-redeclare
466:13 error 'y' is already defined no-redeclare
467:13 error 'm' is already defined no-redeclare
468:13 error 'd' is already defined no-redeclare
493:13 error 'leap' is already defined no-redeclare
608:13 error 'isLeapMonth' is already defined no-redeclare
609:13 error 'leapOffset' is assigned a value but never used no-unused-vars
611:13 error 'leapDay' is assigned a value but never used no-unused-vars
629:17 error 'i' is already defined no-redeclare

转换存在错误

阳历1995-06-17转换到阴历变成1995-06-20,实际应该是1995-05-20,月份多了1
还有为什么有时候转换,时辰也会变化?

求大佬支援

路過的

剛找到這,看著有點感概。
2014年尾的時候,我在網上找新舊歷轉換,找到一些網頁有你2014年中的舊版本,我放到在我的project裡面來用。
之後的日子也遇到過一些人跟我說我的project日期轉換有bug之類的,我也在我copy的版本裡fix過。

最近我剛想著把那project重構,又在看看calendar轉換,就找到你這裡了。
這樣子就8年光陰了。人生匆匆,沒有幾多個8年,藉著代碼在人海裡遇上過又再遇上,也是緣份吧。

有看到你blog最近的一篇,疫情年不好過吧。默默的想跟你說句加油吧。

传参问题

看了源码才发现传入的月份为1-12(含12),即自然月表示法.
然而,js原生的Date()对象的月份是0-11(含11)即自然月-1.既然js标准我们改变不了,那为什么不去适应它呢.这边调用函数month+1,传入参数再month-1图个啥呢.很多时候就直接传参了,导致非常复杂的bug改起来那叫一个酸爽.

这里可以优化一下吧,写的有点乱,一个for就能解决的事

calendar.js/calendar.js

Lines 505 to 530 in 0c968ed

for(i=1; i<13 && offset>0; i++) {
//闰月
if(leap>0 && i==(leap+1) && isLeap==false){
--i;
isLeap = true; temp = this.leapDays(year); //计算农历闰月天数
}
else{
temp = this.monthDays(year, i);//计算农历普通月天数
}
//解除闰月
if(isLeap==true && i==(leap+1)) { isLeap = false; }
offset -= temp;
}
// 闰月导致数组下标重叠取反
if(offset==0 && leap>0 && i==leap+1)
{
if(isLeap){
isLeap = false;
}else{
isLeap = true; --i;
}
}
if(offset<0)
{
offset += temp; --i;
}

建议拆分一下结构

1、阴历农历的转换为基础库js
2、节气与星座等,分别独立成js文件
3、通过简单脚本可以合并所有的,也可以按需索取

好处:减少文本容量

不对啊

大佬!现在的时间转农历不对啊

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.