overtrue / chinese-calendar Goto Github PK
View Code? Open in Web Editor NEW:date: **农历(阴历)与阳历(公历)转换与查询工具
License: MIT License
:date: **农历(阴历)与阳历(公历)转换与查询工具
License: MIT License
之前发 PR #12 的时候没考虑到早子时和晚子时对日柱的影响(怪百度百科里没说,哼都是百度的错)
今天在用别人的软件时发现
2018-03-31 23点 和 2018-03-31 00点 的农历是不一样的
23点的农历是 二月廿五子时
00点的农历是 二月廿四子时
google 了下,大部分的结论都是古时与子时为一天的开始,23点后就算新一天的开始,所以日柱应该加一天
所以当 $hour
参数为 23 时,是否有必要将日柱加一天?如果需要的话,我再提个 PR,顺便把 $hour
参数的说明在 README 更新下
参考:
早子與晚子都是子時
飄風點萃....有關.早子.與.晚子..乃至於..日柱的界定與關照..之ㄧ..
子时,分早子时、晚子时?命理学上最画蛇添足的说法。
solarMonths 应该改成 solarMonth
Could not find package overtrue/chinese-calendar at any version for your minimum-stability (stable). Check the package spelling or your minimum-stability
30.12.2018 Gregorian results in 24.12.2018 Chinese
but
24.12.2018 Chinese results in 29.12.2018 Gregorian
我用 sql:DATE_FORMAT(birthday, '%m-%d') 来查今天过生日的会员。
本轮子转换出的农历月日 是没有补0的,刚才提取出来的月何日 6-7 这样,直接插发现不行要06-07这样。
下个版本 神超是否考虑这个农历的月和日也以06-07这样呢,因为有中文的六月初七,感觉这里补0
如果感觉此建议实在可笑请忽略。
以上这段代码,在windows平台的xampp的apache正常运行没有问题, 可是放到centos上,输入地址,页面直接就找不到了,请问,你们有人遇到过吗?
Parse error: syntax error, unexpected '[' in /chinese-calendar-master/src/Calendar.php on line 28
这是啥意思啊?所有的日期好像都少了一天?#13的issues也没有啊。
输入农历1996-5-6,排出的农历是初五。
输入公历,得出的农历也是比实际的少一天。
PS:
退回到一个很老的版本,居然就对了。
$result = $calendar->lunlar(2017, 4, 10); // 阴历
应该是
$result = $calendar->lunar(2017, 4, 10); // 阴历
// 1900 年农历正月一日的公历时间为 1900 年 1 月 30 日 0 时 0 分 0 秒 (该时间也是本农历的最开始起始点)
$startTimestamp = mktime(0, 0, 0, 1, 30, 1900);
$date = date('Y-m-d', ($offset + $day) * 86400 + $startTimestamp);
mktime
在32位系统下超出了2^31返回false,取值范围1901-12-14到2038-01-19
* 农历年份转换为干支纪年.
*
* @param int $lunarYear
* @param null|int $termIndex
*
* @return string
*/
public function ganZhiYear($lunarYear, $termIndex = null)
{
/**
* 据维基百科干支词条:『在西历新年后,华夏新年或干支历新年之前,则续用上一年之干支』
* 所以干支年份应该不需要根据节气校正,为免影响现有系统,此处暂时保留原有逻辑
* https://zh.wikipedia.org/wiki/%E5%B9%B2%E6%94%AF.
*
* 即使考虑节气,有的年份没有立春,有的年份有两个立春,此处逻辑仍不能处理该特殊情况
*/
$adjust = (null !== $termIndex && 3 > $termIndex) ? 1 : 0;
$ganKey = ($lunarYear + $adjust - 4) % 10;
$zhiKey = ($lunarYear + $adjust - 4) % 12;
return $this->gan[$ganKey].$this->zhi[$zhiKey];
}```
这里 3 > $termIndex 应该是 3 <= $termIndex
我没有仔细研究农历,你看看这里是不是写错了。
1986-05-04和1986-05-05相对1900-01-31都是31504天
转换出来的农历都是 1986年3月26日
应该是跟夏令时有关
使用UTC可以解决
chinese-calendar/src/Calendar.php
Line 232 in ba1458f
这个逻辑应该是 #5 时修改的,目前该 issue 涉及的 mktime 和 strtotime 被改成硬编码了,此逻辑是否可以一并删除?
另外因为看黄历的华人在不同时区均有分布,所以感觉一般还是使用 UTC 比较好
1933年0x06e95改为0x16a95;
I found some php version get your dateDiff not same value. I change from makeDate to date_create will work well.
public function dateDiff($date1, $date2)
{
$date1 = date_create($date1);
$date2 = date_create($date2);
$diff = date_diff($date1,$date2);
return $diff;
/* Original
if (!($date1 instanceof DateTime)) {
$date1 = $this->makeDate($date1);
}
if (!($date2 instanceof DateTime)) {
$date2 = $this->makeDate($date2);
}
return $date1->diff($date2);
*/
}
阳历日期:1939-01-06
阴历日期:1938冬月十六
生肖:虎
计算结果生肖为:兔
以上仅仅是我提供的一个日期,还有后续好多日期都有问题
问题2:
string(10) "2001-02-02"
string(16) "2001正月初十"
string(16) "2001正月初十"
string(3) "蛇"
string(3) "蛇"
string(10) "2001-02-03"
string(16) "2001正月十一"
string(16) "2001正月十一"
string(3) "蛇"
string(3) "蛇"
string(10) "2001-02-04"
string(16) "2001正月十二"
string(16) "2001正月十二"
string(3) "蛇"
string(3) "马" //此处生肖突然变化。。。
string(10) "2001-02-05"
string(16) "2001正月十三"
string(16) "2001正月十三"
string(3) "蛇"
string(3) "蛇"
23时,对day+1
如果是5月31日,那么这里就变成 5月32日了,直接出错
498行
if (23 == $hour) {
// 23点过后算子时,农历以子时为一天的起始
$day += 1;
}
$date = $this->makeDate("{$year}-{$month}-{$day}");
改为
if (23 == $hour) {
// 23点过后算子时,农历以子时为一天的起始
$date = $this->makeDate("{$year}-{$month}-{$day} +1day");
} else {
$date = $this->makeDate("{$year}-{$month}-{$day}");
}
I want to use your script in my TYPO3 Extension timer (https://extensions.typo3.org/extension/timer)
But I am afraid about it, because of the missing MIT-Licence in your code.
Can you add the MIT-licence to your code?
$calendar = new Calendar();
$result = $calendar->lunar2solar(2017, 04, 02);
返回:
array(3) {
["solar_year"] => string(4) "1951"
["solar_month"] => string(2) "03"
["solar_day"] => string(2) "01"
}
为什么是 1951年3月1日,农历 2017 四月初二 应该是今天 2017年4月27啊
This date 20.01.1981 (d-m-Y) year of the Monkey, but recognize as Rooster. Can you check please?
// 这里输出 26
echo (new Overtrue\ChineseCalendar\Calendar())->solar2lunar(1986, 5, 4)['lunar_day'];
// 这里还是输出 26
echo (new Overtrue\ChineseCalendar\Calendar())->solar2lunar(1986, 5, 5)['lunar_day'];
大佬能不能处理一下,很急,不弄好老板要开除我
阳历时间:2019-4-30
InvalidArgumentException : 传入的参数不合法
at /home/hr/jz-yibashou/vendor/overtrue/chinese-calendar/src/Calendar.php:750
746| }
747|
748| // 参数合法性效验
749| if ($year < 1900 || $year > 2100 || $day > $maxDays) {
> 750| throw new InvalidArgumentException('传入的参数不合法');
751| }
752|
753| // 计算农历的时间差
754| $offset = 0;
Exception trace:
1 Overtrue\ChineseCalendar\Calendar::lunar2solar()
/home/hr/jz-yibashou/vendor/overtrue/chinese-calendar/src/Calendar.php:250
2 Overtrue\ChineseCalendar\Calendar::lunar()
/home/hr/jz-yibashou/app/Transformers/EmployeesBaseTransformer.php:77
Please use the argument -v to see more details.
阳历日期:1996-07-15
正确阴历日期:1996五月三十(百度万年历)
阳历转阴历日期:1996六月初一
以上仅我提供的一个日期,还有后续好多日期不对
1、时辰
2、地支
3、是否闰年
4、是否闰月
5、农历月总天数
6、农历年总天数
7、期距离本年的正月初一有多少天
8、农历每月最后一天是哪天
9、每月最后一天是该农历总天数的第几天
10、计算农历第一天到指定时间相隔多少天
等等。。。
哈哈
https://www.mediawiki.org/wiki/Extension:LunarFunctions
除了動到 namespace
//namespace Overtrue\ChineseCalendar;
namespace MediaWiki\Extensions\LunarFunctions;
本來是想把字串的簡体字都改成繁體字的
但是想以後配合MediaWiki的i18n的做法
所以只動了一行,其他的就先沒改了
//$constellations = '魔羯水瓶双鱼白羊金牛双子巨蟹狮子处女天秤天蝎射手魔羯';
$constellations = '魔羯水瓶双魚白羊金牛双子巨蟹獅子處女天秤天蝎射手魔羯';
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.