-
Notifications
You must be signed in to change notification settings - Fork 26
/
demo.php
322 lines (255 loc) · 8.82 KB
/
demo.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
<?php
require 'Lunar.php';
use com\nlf\calendar\Foto;
use com\nlf\calendar\LunarYear;
use com\nlf\calendar\util\HolidayUtil;
use com\nlf\calendar\Lunar;
use com\nlf\calendar\Solar;
$lunar = Lunar::fromYmd(1986, 4, 21);
echo $lunar->toFullString() . "\n";
echo $lunar->getSolar()->toFullString() . "\n";
// 节假日
echo HolidayUtil::getHoliday('2020-05-02') . "\n";
// 儒略日
$solar = Solar::fromYmd(2020, 7, 15);
echo $solar->getJulianDay() . "\n";
$solar = Solar::fromJulianDay(2459045.5);
echo $solar->toFullString() . "\n";
// 遍历节气表
$lunar = Lunar::fromDate(new DateTime());
$jieQi = $lunar->getJieQiTable();
foreach ($jieQi as $key => $value) {
echo $key . ' = ' . $value->toYmdHms() . "\n";
}
// 遍历日吉神(宜趋)
foreach ($lunar->getDayJiShen() as $js) {
echo $js . ' ';
}
echo "\n";
// 遍历时辰宜
foreach ($lunar->getTimeYi() as $yi) {
echo $yi . ' ';
}
echo "\n";
// 八字
$baZi = $lunar->getEightChar();
echo $baZi . ' ';
echo "\n";
// 八字五行
echo $baZi->getYearWuXing() . ' ' . $baZi->getMonthWuXing() . ' ' . $baZi->getDayWuXing() . ' ' . $baZi->getTimeWuXing();
echo "\n";
// 八字纳音
echo $baZi->getYearNaYin() . ' ' . $baZi->getMonthNaYin() . ' ' . $baZi->getDayNaYin() . ' ' . $baZi->getTimeNaYin();
echo "\n";
// 八字天干十神
echo $baZi->getYearShiShenGan() . ' ' . $baZi->getMonthShiShenGan() . ' ' . $baZi->getDayShiShenGan() . ' ' . $baZi->getTimeShiShenGan();
echo "\n";
// 遍历八字年支十神
foreach ($baZi->getYearShiShenZhi() as $shen) {
echo $shen . ' ';
}
echo "\n";
// 遍历八字月支十神
foreach ($baZi->getMonthShiShenZhi() as $shen) {
echo $shen . ' ';
}
echo "\n";
// 遍历八字日支十神
foreach ($baZi->getDayShiShenZhi() as $shen) {
echo $shen . ' ';
}
echo "\n";
// 遍历八字时支十神
foreach ($baZi->getTimeShiShenZhi() as $shen) {
echo $shen . ' ';
}
echo "\n";
// 八字胎元
echo $baZi->getTaiYuan();
echo "\n";
// 八字命宫
echo $baZi->getMingGong();
echo "\n";
// 八字身宫
echo $baZi->getShenGong();
echo "\n";
// 时辰吉神方位
echo $lunar->getTimePositionFu() . "\n";
echo $lunar->getTimePositionXi() . "\n";
echo $lunar->getTimePositionCai() . "\n";
echo $lunar->getTimePositionYinGui() . "\n";
echo $lunar->getTimePositionYangGui() . "\n";
echo $lunar->getTimePositionFuDesc() . "\n";
echo $lunar->getTimePositionXiDesc() . "\n";
echo $lunar->getTimePositionCaiDesc() . "\n";
echo $lunar->getTimePositionYinGuiDesc() . "\n";
echo $lunar->getTimePositionYangGuiDesc() . "\n";
// 指定阳历时间得到八字信息
$solar = Solar::fromYmdHms(1988, 2, 15, 23, 0, 0);
$lunar = $solar->getLunar();
$baZi = $lunar->getEightChar();
echo $baZi->getYear() . ' ' . $baZi->getMonth() . ' ' . $baZi->getDay() . ' ' . $baZi->getTime() . "\n";
$solar = Solar::fromYmdHms(1988, 3, 20, 18, 0, 0);
$lunar = $solar->getLunar();
$baZi = $lunar->getEightChar();
// 男运
$yun = $baZi->getYun(1);
echo "\n";
echo '阳历' . $solar->toYmdHms() . '出生\n';
echo '出生' . $yun->getStartYear() . '年' . $yun->getStartMonth() . '个月' . $yun->getStartDay() . '天后起运' . "\n";
echo '阳历' . $yun->getStartSolar()->toYmd() . '后起运' . "\n";
echo "\n";
// 大运
$daYunArr = $yun->getDaYun();
for ($i = 0; $i < count($daYunArr); $i++) {
$daYun = $daYunArr[$i];
echo '大运[' . $daYun->getIndex() . '] = ' . $daYun->getStartYear() . '年 ' . $daYun->getStartAge() . '岁 ' . $daYun->getGanZhi() . "\n";
}
echo "\n";
// 第1次大运流年
$liuNianArr = $daYunArr[1]->getLiuNian();
for ($i = 0; $i < count($liuNianArr); $i++) {
$liuNian = $liuNianArr[$i];
echo '流年[' . $liuNian->getIndex() . '] = ' . $liuNian->getYear() . '年 ' . $liuNian->getAge() . '岁 ' . $liuNian->getGanZhi() . "\n";
}
echo "\n";
// 第1次大运小运
$xiaoYunArr = $daYunArr[1]->getXiaoYun();
for ($i = 0; $i < count($xiaoYunArr); $i++) {
$xiaoYun = $xiaoYunArr[$i];
echo '小运[' . $xiaoYun->getIndex() . '] = ' . $xiaoYun->getYear() . '年 ' . $xiaoYun->getAge() . '岁 ' . $xiaoYun->getGanZhi() . "\n";
}
echo "\n";
// 第1次大运首个流年的流月
$liuYueArr = $liuNianArr[0]->getLiuYue();
for ($i = 0; $i < count($liuYueArr); $i++) {
$liuYue = $liuYueArr[$i];
echo '流月[' . $liuYue->getIndex() . '] = ' . $liuYue->getMonthInChinese() . '月 ' . $liuYue->getGanZhi() . "\n";
}
echo "\n";
// 八字转阳历
try {
$l = Solar::fromBaZi('庚子', '癸未', '乙丑', '丁亥');
foreach ($l as $d) {
echo $d->toFullString() . "\n";
}
} catch (Exception $e) {
echo $e->getMessage();
}
// 阳历日期推移
$date = Solar::fromYmd(2020, 1, 23);
echo strcmp('2020-01-24', $date->next(1)->toYmd());
// 仅工作日,跨越春节假期
echo strcmp('2020-02-03', $date->nextWorkday(1)->toYmd());
$date = Solar::fromYmd(2020, 2, 3);
echo strcmp('2020-01-31', $date->next(-3)->toYmd());
// 仅工作日,跨越春节假期
echo strcmp('2020-01-21', $date->nextWorkday(-3)->toYmd());
$date = Solar::fromYmd(2020, 2, 9);
echo strcmp('2020-02-15', $date->next(6)->toYmd());
// 仅工作日,跨越周末
echo strcmp('2020-02-17', $date->nextWorkday(6)->toYmd());
$date = Solar::fromYmd(2020, 1, 17);
echo strcmp('2020-01-18', $date->next(1)->toYmd());
// 仅工作日,周日调休按上班算
echo strcmp('2020-01-19', $date->nextWorkday(1)->toYmd()) . "\n";
// 节假日数据修改
echo strcmp('2020-01-01 元旦节 2020-01-01', HolidayUtil::getHoliday('2020-01-01') . '');
// 将2020-01-01修改为春节
HolidayUtil::fix(null, '202001011120200101');
echo strcmp('2020-01-01 春节 2020-01-01', HolidayUtil::getHoliday('2020-01-01') . '');
// 追加2099-01-01为元旦节
HolidayUtil::fix(null, '209901010120990101');
echo strcmp('2099-01-01 元旦节 2099-01-01', HolidayUtil::getHoliday('2099-01-01') . '');
// 将2020-01-01修改为春节,并追加2099-01-01为元旦节
HolidayUtil::fix(null, '202001011120200101209901010120990101');
echo strcmp('2020-01-01 春节 2020-01-01', HolidayUtil::getHoliday('2020-01-01') . '');
echo strcmp('2099-01-01 元旦节 2099-01-01', HolidayUtil::getHoliday('2099-01-01') . '');
// 更改节假日名称
$names = HolidayUtil::$NAMES;
$names[0] = '元旦';
$names[1] = '大年初一';
HolidayUtil::fix($names, null);
echo strcmp('2020-01-01 大年初一 2020-01-01', HolidayUtil::getHoliday('2020-01-01') . '');
echo strcmp('2099-01-01 元旦 2099-01-01', HolidayUtil::getHoliday('2099-01-01') . '');
// 追加节假日名称和数据
$names = array();
for ($i = 0, $j = count(HolidayUtil::$NAMES); $i < $j; $i++) {
$names[$i] = HolidayUtil::$NAMES[$i];
}
$names[9] = '我的生日';
$names[10] = '结婚纪念日';
$names[11] = '她的生日';
HolidayUtil::fix($names, '20210529912021052920211111:12021111120211201;120211201');
echo strcmp('2021-05-29 我的生日 2021-05-29', HolidayUtil::getHoliday('2021-05-29') . '');
echo strcmp('2021-11-11 结婚纪念日 2021-11-11', HolidayUtil::getHoliday('2021-11-11') . '');
echo strcmp('2021-12-01 她的生日 2021-12-01', HolidayUtil::getHoliday('2021-12-01') . '') . "\n";
// 节日
$solar = Solar::fromYmd(2020, 11, 26);
foreach ($solar->getFestivals() as $f) {
echo $f . "\n";
}
$solar = Solar::fromYmd(2020, 6, 21);
foreach ($solar->getFestivals() as $f) {
echo $f . "\n";
}
$solar = Solar::fromYmd(2021, 5, 9);
foreach ($solar->getFestivals() as $f) {
echo $f . "\n";
}
$solar = Solar::fromYmd(1986, 11, 27);
foreach ($solar->getFestivals() as $f) {
echo $f . "\n";
}
$solar = Solar::fromYmd(1985, 6, 16);
foreach ($solar->getFestivals() as $f) {
echo $f . "\n";
}
$solar = Solar::fromYmd(1984, 5, 13);
foreach ($solar->getFestivals() as $f) {
echo $f . "\n";
}
// 旬
$solar = Solar::fromYmdHms(2020, 11, 19, 0, 0, 0);
$lunar = $solar->getLunar();
// 甲午
echo $lunar->getYearXun() . "\n";
// 旬空(空亡)
// 辰巳
echo $lunar->getYearXunKong() . "\n";
// 午未
echo $lunar->getMonthXunKong() . "\n";
// 戌亥
echo $lunar->getDayXunKong() . "\n";
// 八字日柱旬空(空亡)
$solar = Solar::fromYmdHms(1990, 12, 23, 8, 37, 0);
$lunar = $solar->getLunar();
$eightChar = $lunar->getEightChar();
// 子丑
echo $eightChar->getDayXunKong() . "\n";
// 数九
$lunar = Lunar::fromDate(new DateTime());
echo $lunar->getShuJiu() . "\n";
// 三伏
$solar = Solar::fromYmd(2020, 7, 26);
$lunar = $solar->getLunar();
echo $lunar->getFu()->toFullString() . "\n";
// 六曜
$lunar = Lunar::fromDate(new DateTime());
echo $lunar->getLiuYao() . "\n";
// 物候
echo $lunar->getWuHou() . "\n";
// 三日得金
$year = LunarYear::fromYear(2018);
echo $year->getDeJin() . "\n";
$solar = Solar::fromYmd(2021, 11, 5);
echo $solar->getLunar()->toString() . "\n";
$solar = Solar::fromDate(new DateTime());
echo $solar->getLunar()->toString() . "\n";
$lunar = Lunar::fromDate(new DateTime());
echo $lunar->toString() . "\n";
$solar = Solar::fromDate(new DateTime('2021-11-05'));
echo $solar->getLunar()->toString() . "\n";
// 佛历
$foto = Foto::fromLunar(Lunar::fromYmd(2021, 10, 14));
echo $foto->toFullString() . "\n";