lunar_rust/lunar/
lunar_ref_helper_defs.rs

1use super::{
2  helper_traits::__LunarRefHelper, Lunar, LunarRef, LunarRefHelper,
3  JIE_QI,
4};
5use crate::{
6  eight_char::{EightChar, EightCharRef, EightCharRefHelper},
7  foto::{self, FotoRef},
8  fu::{Fu, FuRef},
9  jie_qi::{JieQi, JieQiRef, JieQiRefHelper},
10  lunar::JIE_QI_IN_USE,
11  lunar_time::{LunarTime, LunarTimeRef},
12  nine_star::{NineStar, NineStarRef},
13  shu_jiu::{ShuJiu, ShuJiuRef},
14  solar::{self, SolarRef, SolarRefHelper},
15  tao::{self, TaoRef},
16  util::{
17    lunar_util::{
18      LunarUtil, ANIMAL, CHONG, CHONG_GAN, CHONG_GAN_TIE, DAY,
19      FESTIVAL, GAN, GONG, HOU, LIU_YAO, LU, MONTH, NAYIN, NUMBER,
20      OTHER_FESTIVAL, PENG_ZU_GAN, PENG_ZU_ZHI, POSITION_CAI,
21      POSITION_DESC, POSITION_FU, POSITION_FU_2, POSITION_TAI_DAY,
22      POSITION_TAI_MONTH, POSITION_TAI_SUI_YEAR, POSITION_XI,
23      POSITION_YANG_GUI, POSITION_YIN_GUI, SEASON, SHA, SHENGXIAO,
24      SHOU, TIAN_SHEN, TIAN_SHEN_TYPE, TIAN_SHEN_TYPE_LUCK, WU_HOU,
25      XIU, XIU_LUCK, XIU_SONG, YUE_XIANG, ZHENG, ZHI,
26      ZHI_TIAN_SHEN_OFFSET, ZHI_XING,
27    },
28    solar_util::{self, SolarUtilRefHelper},
29  },
30};
31use std::collections::HashMap;
32
33impl LunarRefHelper for LunarRef {
34  fn get_year(&self) -> i64 {
35    self.lock().unwrap().__year
36  }
37
38  fn get_month(&self) -> i64 {
39    self.lock().unwrap().__month
40  }
41
42  fn get_day(&self) -> i64 {
43    self.lock().unwrap().__day
44  }
45
46  fn get_hour(&self) -> i64 {
47    self.lock().unwrap().__hour
48  }
49
50  fn get_minute(&self) -> i64 {
51    self.lock().unwrap().__minute
52  }
53
54  fn get_second(&self) -> i64 {
55    self.lock().unwrap().__second
56  }
57
58  fn get_solar(&self) -> SolarRef {
59    self.lock().unwrap().__solar.clone()
60  }
61
62  fn get_year_gan(&self) -> String {
63    GAN()[self.lock().unwrap().__year_gan_index as usize + 1]
64      .to_string()
65  }
66
67  fn get_year_gan_by_li_chun(&self) -> String {
68    GAN()[self.lock().unwrap().__year_gan_index_by_li_chun as usize + 1]
69      .to_string()
70  }
71
72  fn get_year_gan_exact(&self) -> String {
73    GAN()[self.lock().unwrap().__year_gan_index_exact as usize + 1]
74      .to_string()
75  }
76
77  fn get_year_zhi(&self) -> String {
78    ZHI()[self.lock().unwrap().__year_zhi_index as usize + 1]
79      .to_string()
80  }
81
82  fn get_year_zhi_by_li_chun(&self) -> String {
83    ZHI()[self.lock().unwrap().__year_zhi_index_by_li_chun as usize + 1]
84      .to_string()
85  }
86
87  fn get_year_zhi_exact(&self) -> String {
88    ZHI()[self.lock().unwrap().__year_zhi_index_exact as usize + 1]
89      .to_string()
90  }
91
92  fn get_year_in_gan_zhi(&self) -> String {
93    format!("{}{}", self.get_year_gan(), self.get_year_zhi())
94  }
95
96  fn get_year_in_gan_zhi_by_li_chun(&self) -> String {
97    format!(
98      "{}{}",
99      self.get_year_gan_by_li_chun(),
100      self.get_year_zhi_by_li_chun()
101    )
102  }
103
104  fn get_year_in_gan_zhi_exact(&self) -> String {
105    format!(
106      "{}{}",
107      self.get_year_gan_exact(),
108      self.get_year_zhi_exact()
109    )
110  }
111
112  fn get_month_gan(&self) -> String {
113    GAN()[self.lock().unwrap().__month_gan_index as usize + 1]
114      .to_string()
115  }
116
117  fn get_month_gan_exact(&self) -> String {
118    GAN()[self.lock().unwrap().__month_gan_index_exact as usize + 1]
119      .to_string()
120  }
121
122  fn get_month_zhi(&self) -> String {
123    ZHI()[self.lock().unwrap().__month_zhi_index as usize + 1]
124      .to_string()
125  }
126
127  fn get_month_zhi_exact(&self) -> String {
128    ZHI()[self.lock().unwrap().__month_zhi_index_exact as usize + 1]
129      .to_string()
130  }
131
132  fn get_month_in_gan_zhi(&self) -> String {
133    format!("{}{}", self.get_month_gan(), self.get_month_zhi())
134  }
135
136  fn get_month_in_gan_zhi_exact(&self) -> String {
137    format!(
138      "{}{}",
139      self.get_month_gan_exact(),
140      self.get_month_zhi_exact()
141    )
142  }
143
144  fn get_day_gan(&self) -> String {
145    GAN()[self.lock().unwrap().__day_gan_index as usize + 1].to_string()
146  }
147
148  fn get_day_gan_exact(&self) -> String {
149    GAN()[self.lock().unwrap().__day_gan_index_exact as usize + 1]
150      .to_string()
151  }
152
153  fn get_day_gan_exact2(&self) -> String {
154    GAN()[self.lock().unwrap().__day_gan_index_exact2 as usize + 1]
155      .to_string()
156  }
157
158  fn get_day_zhi(&self) -> String {
159    ZHI()[self.lock().unwrap().__day_zhi_index as usize + 1].to_string()
160  }
161
162  fn get_day_zhi_exact(&self) -> String {
163    ZHI()[self.lock().unwrap().__day_zhi_index_exact as usize + 1]
164      .to_string()
165  }
166
167  fn get_day_zhi_exact2(&self) -> String {
168    ZHI()[self.lock().unwrap().__day_zhi_index_exact2 as usize + 1]
169      .to_string()
170  }
171
172  fn get_day_in_gan_zhi(&self) -> String {
173    format!("{}{}", self.get_day_gan(), self.get_day_zhi())
174  }
175
176  fn get_day_in_gan_zhi_exact(&self) -> String {
177    format!("{}{}", self.get_day_gan_exact(), self.get_day_zhi_exact())
178  }
179
180  fn get_day_in_gan_zhi_exact2(&self) -> String {
181    format!(
182      "{}{}",
183      self.get_day_gan_exact2(),
184      self.get_day_zhi_exact2()
185    )
186  }
187
188  fn get_time_gan(&self) -> String {
189    GAN()[self.lock().unwrap().__time_gan_index as usize + 1]
190      .to_string()
191  }
192
193  fn get_time_zhi(&self) -> String {
194    ZHI()[self.lock().unwrap().__time_zhi_index as usize + 1]
195      .to_string()
196  }
197
198  fn get_time_in_gan_zhi(&self) -> String {
199    format!("{}{}", self.get_time_gan(), self.get_time_zhi())
200  }
201
202  fn get_year_sheng_xiao(&self) -> String {
203    SHENGXIAO()[self.lock().unwrap().__year_zhi_index as usize + 1]
204      .to_string()
205  }
206
207  fn get_year_sheng_xiao_by_li_chun(&self) -> String {
208    SHENGXIAO()
209      [self.lock().unwrap().__year_zhi_index_by_li_chun as usize + 1]
210      .to_string()
211  }
212
213  fn get_year_sheng_xiao_exact(&self) -> String {
214    SHENGXIAO()
215      [self.lock().unwrap().__year_zhi_index_exact as usize + 1]
216      .to_string()
217  }
218
219  fn get_month_sheng_xiao(&self) -> String {
220    SHENGXIAO()[self.lock().unwrap().__month_zhi_index as usize + 1]
221      .to_string()
222  }
223
224  fn get_month_sheng_xiao_exact(&self) -> String {
225    SHENGXIAO()
226      [self.lock().unwrap().__month_zhi_index_exact as usize + 1]
227      .to_string()
228  }
229
230  fn get_day_sheng_xiao(&self) -> String {
231    SHENGXIAO()[self.lock().unwrap().__day_zhi_index as usize + 1]
232      .to_string()
233  }
234
235  fn get_time_sheng_xiao(&self) -> String {
236    SHENGXIAO()[self.lock().unwrap().__time_zhi_index as usize + 1]
237      .to_string()
238  }
239
240  fn get_year_in_chinese(&self) -> String {
241    let y = format!("{}", self.lock().unwrap().__year);
242    let mut s = "".to_string();
243    for c in y.chars().collect::<Vec<_>>().iter() {
244      s = format!(
245        "{}{}",
246        s,
247        NUMBER()[c.to_string().parse::<usize>().unwrap()]
248      );
249    }
250    s
251  }
252
253  fn get_month_in_chinese(&self) -> String {
254    let month = self.lock().unwrap().__month;
255    format!(
256      "{}{}",
257      {
258        match month < 0 {
259          true => "闰",
260          _ => "",
261        }
262      },
263      MONTH()[month.abs() as usize]
264    )
265  }
266
267  fn get_day_in_chinese(&self) -> String {
268    DAY()[self.lock().unwrap().__day as usize].to_string()
269  }
270
271  fn get_peng_zu_gan(&self) -> String {
272    PENG_ZU_GAN()[self.lock().unwrap().__day_gan_index as usize + 1]
273      .to_string()
274  }
275
276  fn get_peng_zu_zhi(&self) -> String {
277    PENG_ZU_ZHI()[self.lock().unwrap().__day_zhi_index as usize + 1]
278      .to_string()
279  }
280
281  fn get_position_xi(&self) -> String {
282    self.get_day_position_xi()
283  }
284
285  fn get_position_xi_desc(&self) -> String {
286    self.get_day_position_xi_desc()
287  }
288
289  fn get_position_yang_gui(&self) -> String {
290    self.get_day_position_yang_gui()
291  }
292
293  fn get_position_yang_gui_desc(&self) -> String {
294    self.get_day_position_yang_gui_desc()
295  }
296
297  fn get_position_yin_gui(&self) -> String {
298    self.get_day_position_yin_gui()
299  }
300
301  fn get_position_yin_gui_desc(&self) -> String {
302    self.get_day_position_yin_gui_desc()
303  }
304
305  fn get_position_fu(&self) -> String {
306    self.get_day_position_fu(None)
307  }
308
309  fn get_position_fu_desc(&self) -> String {
310    self.get_day_position_fu_desc(None)
311  }
312
313  fn get_position_cai(&self) -> String {
314    self.get_day_position_cai()
315  }
316
317  fn get_position_cai_desc(&self) -> String {
318    self.get_day_position_cai_desc()
319  }
320
321  fn get_day_position_xi(&self) -> String {
322    POSITION_XI()[self.lock().unwrap().__day_gan_index as usize + 1]
323      .to_string()
324  }
325
326  fn get_day_position_xi_desc(&self) -> String {
327    POSITION_DESC()
328      .get(&self.get_day_position_xi())
329      .unwrap()
330      .clone()
331  }
332
333  fn get_day_position_yang_gui(&self) -> String {
334    POSITION_YANG_GUI()
335      [self.lock().unwrap().__day_gan_index as usize + 1]
336      .to_string()
337  }
338
339  fn get_day_position_yang_gui_desc(&self) -> String {
340    POSITION_DESC()
341      .get(&self.get_day_position_yang_gui())
342      .unwrap()
343      .clone()
344  }
345
346  fn get_day_position_yin_gui(&self) -> String {
347    POSITION_YIN_GUI()
348      [self.lock().unwrap().__day_gan_index as usize + 1]
349      .to_string()
350  }
351
352  fn get_day_position_yin_gui_desc(&self) -> String {
353    POSITION_DESC()
354      .get(&self.get_day_position_yin_gui())
355      .unwrap()
356      .clone()
357  }
358
359  fn get_day_position_fu(&self, sect: Option<i64>) -> String {
360    let sect = sect.unwrap_or(2);
361    let position_fu = match sect == 1 {
362      true => POSITION_FU.clone(),
363      _ => POSITION_FU_2.clone(),
364    };
365    position_fu()[self.lock().unwrap().__day_gan_index as usize + 1]
366      .to_string()
367  }
368
369  fn get_day_position_fu_desc(&self, sect: Option<i64>) -> String {
370    POSITION_DESC()
371      .get(&self.get_day_position_fu(sect))
372      .unwrap()
373      .clone()
374  }
375
376  fn get_day_position_cai(&self) -> String {
377    POSITION_CAI()[self.lock().unwrap().__day_gan_index as usize + 1]
378      .to_string()
379  }
380
381  fn get_day_position_cai_desc(&self) -> String {
382    POSITION_DESC()
383      .get(&self.get_day_position_cai())
384      .unwrap()
385      .clone()
386  }
387
388  fn get_year_position_tai_sui(&self, sect: Option<i64>) -> String {
389    let sect = sect.unwrap_or(2);
390    let year_zhi_index = match sect {
391      1 => self.lock().unwrap().__year_zhi_index,
392      3 => self.lock().unwrap().__year_zhi_index_exact,
393      _ => self.lock().unwrap().__year_zhi_index_by_li_chun,
394    };
395    POSITION_TAI_SUI_YEAR()[year_zhi_index as usize].to_string()
396  }
397
398  fn get_year_position_tai_sui_desc(
399    &self,
400    sect: Option<i64>,
401  ) -> String {
402    POSITION_DESC()
403      .get(&self.get_year_position_tai_sui(sect))
404      .unwrap()
405      .clone()
406  }
407
408  fn get_month_position_tai_sui(&self, sect: Option<i64>) -> String {
409    let sect = sect.unwrap_or(2);
410    let s = self.lock().unwrap();
411    let (month_zhi_index, month_gan_index) = match sect {
412      3 => (s.__month_zhi_index_exact, s.__month_gan_index_exact),
413      _ => (s.__month_zhi_index, s.__month_gan_index),
414    };
415    Lunar::__get_month_position_tai_sui(
416      month_zhi_index,
417      month_gan_index,
418    )
419  }
420
421  fn get_month_position_tai_sui_desc(
422    &self,
423    sect: Option<i64>,
424  ) -> String {
425    POSITION_DESC()
426      .get(&self.get_month_position_tai_sui(sect))
427      .unwrap()
428      .clone()
429  }
430
431  fn get_day_position_tai_sui(&self, sect: Option<i64>) -> String {
432    let (
433      __year_zhi_index,
434      __year_zhi_index_exact,
435      __year_zhi_index_by_li_chun,
436    ) = {
437      let s = self.lock().unwrap();
438      (
439        s.__year_zhi_index,
440        s.__year_zhi_index_exact,
441        s.__year_zhi_index_by_li_chun,
442      )
443    };
444    let pair = match sect {
445      Some(1) => (self.get_day_in_gan_zhi(), __year_zhi_index),
446      Some(3) => (self.get_day_in_gan_zhi(), __year_zhi_index_exact),
447      _ => (
448        self.get_day_in_gan_zhi_exact2(),
449        __year_zhi_index_by_li_chun,
450      ),
451    };
452    Lunar::__get_day_position_tai_sui(&pair.0, pair.1)
453  }
454
455  fn get_day_position_tai_sui_desc(&self, sect: Option<i64>) -> String {
456    POSITION_DESC()
457      .get(&self.get_day_position_tai_sui(sect))
458      .unwrap()
459      .clone()
460  }
461
462  fn get_time_position_xi(&self) -> String {
463    POSITION_XI()[self.lock().unwrap().__time_gan_index as usize + 1]
464      .to_string()
465  }
466
467  fn get_time_position_xi_desc(&self) -> String {
468    POSITION_DESC()
469      .get(&self.get_time_position_xi())
470      .unwrap()
471      .clone()
472  }
473
474  fn get_time_position_yang_gui(&self) -> String {
475    POSITION_YANG_GUI()
476      [self.lock().unwrap().__time_gan_index as usize + 1]
477      .to_string()
478  }
479
480  fn get_time_position_yang_gui_desc(&self) -> String {
481    POSITION_DESC()
482      .get(&self.get_time_position_yang_gui())
483      .unwrap()
484      .clone()
485  }
486
487  fn get_time_position_yin_gui(&self) -> String {
488    POSITION_YIN_GUI()
489      [self.lock().unwrap().__time_gan_index as usize + 1]
490      .to_string()
491  }
492
493  fn get_time_position_yin_gui_desc(&self) -> String {
494    POSITION_DESC()
495      .get(&self.get_time_position_yin_gui())
496      .unwrap()
497      .clone()
498  }
499
500  fn get_time_position_fu(&self, sect: Option<i64>) -> String {
501    let position_fu = match sect {
502      Some(1) => POSITION_FU.clone(),
503      _ => POSITION_FU_2.clone(),
504    };
505    position_fu()[self.lock().unwrap().__time_gan_index as usize + 1]
506      .to_string()
507  }
508
509  fn get_time_position_fu_desc(&self, sect: Option<i64>) -> String {
510    POSITION_DESC()
511      .get(&self.get_time_position_fu(sect))
512      .unwrap()
513      .clone()
514  }
515
516  fn get_time_position_cai(&self) -> String {
517    POSITION_CAI()[self.lock().unwrap().__time_gan_index as usize + 1]
518      .to_string()
519  }
520
521  fn get_time_position_cai_desc(&self) -> String {
522    POSITION_DESC()
523      .get(&self.get_time_position_cai())
524      .unwrap()
525      .clone()
526  }
527
528  fn get_chong(&self) -> String {
529    self.get_day_chong()
530  }
531
532  fn get_day_chong(&self) -> String {
533    CHONG()[self.lock().unwrap().__day_zhi_index as usize].to_string()
534  }
535
536  fn get_time_chong(&self) -> String {
537    CHONG()[self.lock().unwrap().__time_zhi_index as usize].to_string()
538  }
539
540  fn get_chong_gan(&self) -> String {
541    self.get_day_chong_gan()
542  }
543
544  fn get_day_chong_gan(&self) -> String {
545    CHONG_GAN()[self.lock().unwrap().__day_gan_index as usize]
546      .to_string()
547  }
548
549  fn get_time_chong_gan(&self) -> String {
550    CHONG_GAN()[self.lock().unwrap().__time_gan_index as usize]
551      .to_string()
552  }
553
554  fn get_chong_gan_tie(&self) -> String {
555    self.get_day_chong_gan_tie()
556  }
557
558  fn get_day_chong_gan_tie(&self) -> String {
559    CHONG_GAN_TIE()[self.lock().unwrap().__day_gan_index as usize]
560      .to_string()
561  }
562
563  fn get_time_chong_gan_tie(&self) -> String {
564    CHONG_GAN_TIE()[self.lock().unwrap().__time_gan_index as usize]
565      .to_string()
566  }
567
568  fn get_chong_sheng_xiao(&self) -> String {
569    self.get_day_chong_sheng_xiao()
570  }
571
572  fn get_day_chong_sheng_xiao(&self) -> String {
573    let chong = self.get_day_chong();
574    for (i, zhi) in ZHI().iter().enumerate() {
575      if *zhi == chong {
576        return SHENGXIAO()[i].to_string();
577      }
578    }
579    format!("")
580  }
581
582  fn get_time_chong_sheng_xiao(&self) -> String {
583    let chong = self.get_time_chong();
584    for (i, zhi) in ZHI().iter().enumerate() {
585      if *zhi == chong {
586        return SHENGXIAO()[i].to_string();
587      }
588    }
589    format!("")
590  }
591
592  fn get_chong_desc(&self) -> String {
593    self.get_day_chong_desc()
594  }
595
596  fn get_day_chong_desc(&self) -> String {
597    format!(
598      "({}{}){}",
599      self.get_day_chong_gan(),
600      self.get_day_chong(),
601      self.get_day_chong_sheng_xiao()
602    )
603  }
604
605  fn get_time_chong_desc(&self) -> String {
606    format!(
607      "({}{}){}",
608      self.get_time_chong_gan(),
609      self.get_time_chong(),
610      self.get_time_chong_sheng_xiao()
611    )
612  }
613
614  fn get_sha(&self) -> String {
615    self.get_day_sha()
616  }
617
618  fn get_day_sha(&self) -> String {
619    SHA().get(&self.get_day_zhi()).unwrap().clone()
620  }
621
622  fn get_time_sha(&self) -> String {
623    SHA().get(&self.get_time_zhi()).unwrap().clone()
624  }
625
626  fn get_year_na_yin(&self) -> String {
627    NAYIN().get(&self.get_year_in_gan_zhi()).unwrap().clone()
628  }
629
630  fn get_month_na_yin(&self) -> String {
631    NAYIN().get(&self.get_month_in_gan_zhi()).unwrap().clone()
632  }
633
634  fn get_day_na_yin(&self) -> String {
635    NAYIN().get(&self.get_day_in_gan_zhi()).unwrap().clone()
636  }
637
638  fn get_time_na_yin(&self) -> String {
639    NAYIN().get(&self.get_time_in_gan_zhi()).unwrap().clone()
640  }
641
642  fn get_season(&self) -> String {
643    SEASON()[self.lock().unwrap().__month as usize].to_string()
644  }
645
646  fn get_jie(&self) -> String {
647    // odd items of JIE_QI_IN_USE
648    for (_, key) in JIE_QI_IN_USE().iter().enumerate().step_by(2) {
649      let (__jie_qi, __solar) = {
650        let s = self.lock().unwrap();
651        (s.__jie_qi.clone(), s.__solar.clone())
652      };
653      let d = __jie_qi.get(key).unwrap();
654      if d.get_year() == __solar.get_year()
655        && d.get_month() == __solar.get_month()
656        && d.get_day() == __solar.get_day()
657      {
658        return Lunar::__convert_jie_qi(key);
659      }
660    }
661    format!("")
662  }
663
664  fn get_qi(&self) -> String {
665    // even items of JIE_QI_IN_USE
666    let (__jie_qi, __solar) = {
667      let s = self.lock().unwrap();
668      (s.__jie_qi.clone(), s.__solar.clone())
669    };
670    for key in JIE_QI_IN_USE().iter().skip(1).step_by(2) {
671      let d = __jie_qi.get(key).unwrap();
672      if d.get_year() == __solar.get_year()
673        && d.get_month() == __solar.get_month()
674        && d.get_day() == __solar.get_day()
675      {
676        return Lunar::__convert_jie_qi(key);
677      }
678    }
679    format!("")
680  }
681
682  fn get_week(&self) -> i64 {
683    self.lock().unwrap().__week_index
684  }
685
686  fn get_week_in_chinese(&self) -> String {
687    solar_util::get().WEEK()[self.get_week() as usize].to_string()
688  }
689
690  fn get_xiu(&self) -> String {
691    XIU()
692      .get(&format!("{}{}", self.get_day_zhi(), self.get_week()))
693      .unwrap()
694      .clone()
695  }
696
697  fn get_xiu_luck(&self) -> String {
698    XIU_LUCK().get(&self.get_xiu()).unwrap().clone()
699  }
700
701  fn get_xiu_song(&self) -> String {
702    XIU_SONG().get(&self.get_xiu()).unwrap().clone()
703  }
704
705  fn get_zheng(&self) -> String {
706    ZHENG().get(&self.get_xiu()).unwrap().clone()
707  }
708
709  fn get_animal(&self) -> String {
710    ANIMAL().get(&self.get_xiu()).unwrap().clone()
711  }
712
713  fn get_gong(&self) -> String {
714    GONG().get(&self.get_xiu()).unwrap().clone()
715  }
716
717  fn get_shou(&self) -> String {
718    SHOU().get(&self.get_gong()).unwrap().clone()
719  }
720
721  fn get_festivals(&self) -> Vec<String> {
722    let (__year, __month, __day) = {
723      let s = self.lock().unwrap();
724      (s.__year, s.__month, s.__day)
725    };
726
727    let mut fs = vec![];
728    let found = FESTIVAL().iter().find_map(|_fs| {
729      let (f_month, f_day) = &_fs.0;
730      if *f_month == __month && *f_day == __day {
731        return Some(_fs.1.clone());
732      }
733      None
734    });
735    let _ = found.map_or((), |f| fs.push(f));
736    if __month.abs() == 12
737      && __day >= 29
738      && __year != self.next(1).get_year()
739    {
740      fs.push(format!("除夕"));
741    }
742    fs
743  }
744
745  fn get_other_festivals(&self) -> Vec<String> {
746    let (__month, __day, __solar, __jie_qi) = {
747      let s = self.lock().unwrap();
748      (s.__month, s.__day, s.__solar.clone(), s.__jie_qi.clone())
749    };
750
751    let mut fs: Vec<String> = vec![];
752    let found = OTHER_FESTIVAL().iter().find_map(|(k, v)| {
753      let (f_month, f_day) = k;
754      if *f_month == __month && *f_day == __day {
755        return Some(v.clone());
756      }
757      None
758    });
759    let _ = found.map_or((), |f| {
760      let mut f = f.clone();
761      fs.append(&mut f);
762    });
763    let solar_ymd = __solar.to_ymd();
764    if __jie_qi.get("清明").unwrap().next(-1, None).to_ymd()
765      == solar_ymd
766    {
767      fs.push(format!("寒食节"));
768    }
769
770    let jq = __jie_qi.get("立春").unwrap().clone();
771    let mut offset = 4 - jq.get_lunar().get_day_gan_index();
772    if offset < 0 {
773      offset = offset + 10;
774    }
775    if solar_ymd == jq.next(offset + 40, None).to_ymd() {
776      fs.push(format!("春社"));
777    }
778
779    let jq = __jie_qi.get("立秋").unwrap().clone();
780    let mut offset = 4 - jq.get_lunar().get_day_gan_index();
781    if offset < 0 {
782      offset = offset + 10;
783    }
784    if solar_ymd == jq.next(offset + 40, None).to_ymd() {
785      fs.push(format!("秋社"));
786    }
787
788    fs
789  }
790
791  fn get_eight_char(&self) -> EightCharRef {
792    let mut s = self.lock().unwrap();
793    if s.__eight_char.is_none() {
794      (*s).__eight_char = Some(EightChar::from_lunar(self.clone()));
795    }
796    s.__eight_char.as_ref().unwrap().clone()
797  }
798
799  fn get_ba_zi(&self) -> Vec<String> {
800    let ba_zi = self.get_eight_char();
801    [
802      ba_zi.get_year(),
803      ba_zi.get_month(),
804      ba_zi.get_day(),
805      ba_zi.get_time(),
806    ]
807    .to_vec()
808  }
809
810  fn get_ba_zi_wu_xing(&self) -> Vec<String> {
811    let ba_zi = self.get_eight_char();
812    [
813      ba_zi.get_year_wu_xing(),
814      ba_zi.get_month_wu_xing(),
815      ba_zi.get_day_wu_xing(),
816      ba_zi.get_time_wu_xing(),
817    ]
818    .to_vec()
819  }
820
821  fn get_ba_zi_na_yin(&self) -> Vec<String> {
822    let ba_zi = self.get_eight_char();
823    [
824      ba_zi.get_year_na_yin(),
825      ba_zi.get_month_na_yin(),
826      ba_zi.get_day_na_yin(),
827      ba_zi.get_time_na_yin(),
828    ]
829    .to_vec()
830  }
831
832  fn get_ba_zi_shi_shen_gan(&self) -> Vec<String> {
833    let ba_zi = self.get_eight_char();
834    [
835      ba_zi.get_year_shi_shen_gan(),
836      ba_zi.get_month_shi_shen_gan(),
837      ba_zi.get_day_shi_shen_gan(),
838      ba_zi.get_time_shi_shen_gan(),
839    ]
840    .to_vec()
841  }
842
843  fn get_ba_zi_shi_shen_zhi(&self) -> Vec<Vec<String>> {
844    let ba_zi = self.get_eight_char();
845    [
846      ba_zi.get_year_shi_shen_zhi(),
847      ba_zi.get_month_shi_shen_zhi(),
848      ba_zi.get_day_shi_shen_zhi(),
849      ba_zi.get_time_shi_shen_zhi(),
850    ]
851    .to_vec()
852  }
853
854  fn get_ba_zi_shi_shen_year_zhi(&self) -> Vec<String> {
855    self.get_eight_char().get_year_shi_shen_zhi()
856  }
857
858  fn get_ba_zi_shi_shen_month_zhi(&self) -> Vec<String> {
859    self.get_eight_char().get_month_shi_shen_zhi()
860  }
861
862  fn get_ba_zi_shi_shen_day_zhi(&self) -> Vec<String> {
863    self.get_eight_char().get_day_shi_shen_zhi()
864  }
865
866  fn get_ba_zi_shi_shen_time_zhi(&self) -> Vec<String> {
867    self.get_eight_char().get_time_shi_shen_zhi()
868  }
869
870  fn get_zhi_xing(&self) -> String {
871    let s = self.lock().unwrap();
872    let mut offset = s.__day_zhi_index - s.__month_zhi_index;
873    if offset < 0 {
874      offset += 12
875    }
876    ZHI_XING()[offset as usize + 1].to_string()
877  }
878
879  fn get_day_tian_shen(&self) -> String {
880    let __day_zhi_index = { self.lock().unwrap().__day_zhi_index };
881    TIAN_SHEN()[(__day_zhi_index
882      + ZHI_TIAN_SHEN_OFFSET().get(&self.get_month_zhi()).unwrap())
883      as usize
884      % 12
885      + 1]
886      .to_string()
887  }
888
889  fn get_time_tian_shen(&self) -> String {
890    let __time_zhi_index = { self.lock().unwrap().__time_zhi_index };
891    TIAN_SHEN()[(__time_zhi_index
892      + ZHI_TIAN_SHEN_OFFSET()
893        .get(&self.get_day_zhi_exact())
894        .unwrap()) as usize
895      % 12
896      + 1]
897      .to_string()
898  }
899
900  fn get_day_tian_shen_type(&self) -> String {
901    TIAN_SHEN_TYPE()
902      .get(&self.get_day_tian_shen())
903      .unwrap()
904      .clone()
905  }
906
907  fn get_time_tian_shen_type(&self) -> String {
908    TIAN_SHEN_TYPE()
909      .get(&self.get_time_tian_shen())
910      .unwrap()
911      .clone()
912  }
913
914  fn get_day_tian_shen_luck(&self) -> String {
915    TIAN_SHEN_TYPE_LUCK()
916      .get(&self.get_day_tian_shen_type())
917      .unwrap()
918      .clone()
919  }
920
921  fn get_time_tian_shen_luck(&self) -> String {
922    TIAN_SHEN_TYPE_LUCK()
923      .get(&self.get_time_tian_shen_type())
924      .unwrap()
925      .clone()
926  }
927
928  fn get_day_position_tai(&self) -> String {
929    POSITION_TAI_DAY()
930      [LunarUtil::get_jia_zi_index(&self.get_day_in_gan_zhi()) as usize]
931      .to_string()
932  }
933
934  fn get_month_position_tai(&self) -> String {
935    let m = self.lock().unwrap().__month;
936    if m < 0 {
937      return format!("");
938    }
939    POSITION_TAI_MONTH()[m as usize - 1].to_string()
940  }
941
942  ///
943  /// 获取每日宜
944  ///
945  /// ## Returns
946  /// 宜: Vec<String>
947  ///
948  fn get_day_yi(&self, sect: Option<i64>) -> Vec<String> {
949    let month_gan_zhi = match sect {
950      Some(2) => self.get_month_in_gan_zhi_exact(),
951      _ => self.get_month_in_gan_zhi(),
952    };
953    LunarUtil::get_day_yi(&month_gan_zhi, &self.get_day_in_gan_zhi())
954  }
955
956  ///
957  /// 获取每日忌
958  ///
959  /// ## Returns
960  /// 忌: Vec<String>
961  ///
962  fn get_day_ji(&self, sect: Option<i64>) -> Vec<String> {
963    let month_gan_zhi = match sect {
964      Some(2) => self.get_month_in_gan_zhi_exact(),
965      _ => self.get_month_in_gan_zhi(),
966    };
967    LunarUtil::get_day_ji(&month_gan_zhi, &self.get_day_in_gan_zhi())
968  }
969
970  ///
971  /// 获取时宜
972  ///
973  /// ## Returns
974  /// 宜: Vec<String>
975  ///
976  fn get_time_yi(&self) -> Vec<String> {
977    LunarUtil::get_time_yi(
978      &self.get_day_in_gan_zhi_exact(),
979      &self.get_time_in_gan_zhi(),
980    )
981  }
982
983  ///
984  /// 获取时忌
985  ///
986  /// ## Returns
987  /// 忌: Vec<String>
988  ///
989  fn get_time_ji(&self) -> Vec<String> {
990    LunarUtil::get_time_ji(
991      &self.get_day_in_gan_zhi_exact(),
992      &self.get_time_in_gan_zhi(),
993    )
994  }
995
996  ///
997  /// 获取日吉神(宜趋)
998  ///
999  /// ## Returns
1000  /// 日吉神: Vec<String>
1001  ///
1002  fn get_day_ji_shen(&self) -> Vec<String> {
1003    LunarUtil::get_day_ji_shen(
1004      self.get_month(),
1005      &self.get_day_in_gan_zhi(),
1006    )
1007  }
1008
1009  ///
1010  /// 获取日凶煞(宜忌)
1011  ///
1012  /// ## Returns
1013  /// 日凶煞: Vec<String>
1014  ///
1015  fn get_day_xiong_sha(&self) -> Vec<String> {
1016    LunarUtil::get_day_xiong_sha(
1017      self.get_month(),
1018      &self.get_day_in_gan_zhi(),
1019    )
1020  }
1021
1022  ///
1023  /// 获取月相
1024  ///
1025  /// ## Returns
1026  /// 月相: String
1027  ///
1028  fn get_yue_xiang(&self) -> String {
1029    YUE_XIANG()[self.lock().unwrap().__day as usize].to_string()
1030  }
1031
1032  fn get_year_nine_star(&self, sect: Option<i64>) -> NineStarRef {
1033    let year_in_gan_zhi = match sect {
1034      Some(1) => self.get_year_in_gan_zhi(),
1035      Some(3) => self.get_year_in_gan_zhi_exact(),
1036      _ => self.get_year_in_gan_zhi_by_li_chun(),
1037    };
1038    self.__get_year_nine_star(&year_in_gan_zhi)
1039  }
1040
1041  fn get_month_nine_star(&self, sect: Option<i64>) -> NineStarRef {
1042    let (
1043      __year_zhi_index,
1044      __month_zhi_index,
1045      __year_zhi_index_exact,
1046      __month_zhi_index_exact,
1047      __year_zhi_index_by_li_chun,
1048    ) = {
1049      let s = self.lock().unwrap();
1050      (
1051        s.__year_zhi_index,
1052        s.__month_zhi_index,
1053        s.__year_zhi_index_exact,
1054        s.__month_zhi_index_exact,
1055        s.__year_zhi_index_by_li_chun,
1056      )
1057    };
1058    let (year_zhi_index, month_zhi_index) = match sect {
1059      Some(1) => (__year_zhi_index, __month_zhi_index),
1060      Some(3) => (__year_zhi_index_exact, __month_zhi_index_exact),
1061      _ => (__year_zhi_index_by_li_chun, __month_zhi_index),
1062    };
1063    Lunar::__get_month_nine_star(year_zhi_index, month_zhi_index)
1064  }
1065
1066  fn get_day_nine_star(&self) -> NineStarRef {
1067    let solar_date = self.get_solar().to_naivedate();
1068    let jie_qi = { self.lock().unwrap().__jie_qi.clone() };
1069    let dong_zhi = jie_qi.get("冬至").unwrap().clone();
1070    let dong_zhi2 = jie_qi.get("DONG_ZHI").unwrap().clone();
1071    let xia_zhi = jie_qi.get("夏至").unwrap().clone();
1072    let dong_zhi_index = LunarUtil::get_jia_zi_index(
1073      &dong_zhi.get_lunar().get_day_in_gan_zhi(),
1074    );
1075    let dong_zhi_index2 = LunarUtil::get_jia_zi_index(
1076      &dong_zhi2.get_lunar().get_day_in_gan_zhi(),
1077    );
1078    let xia_zhi_index = LunarUtil::get_jia_zi_index(
1079      &xia_zhi.get_lunar().get_day_in_gan_zhi(),
1080    );
1081
1082    let solar_shun_bai = match dong_zhi_index > 29 {
1083      true => dong_zhi.next(60 - dong_zhi_index, None),
1084      _ => dong_zhi.next(-dong_zhi_index, None),
1085    };
1086    let solar_shun_bai_date = solar_shun_bai.to_naivedate();
1087
1088    let solar_shun_bai2 = match dong_zhi_index2 > 29 {
1089      true => dong_zhi2.next(60 - dong_zhi_index2, None),
1090      _ => dong_zhi2.next(-dong_zhi_index2, None),
1091    };
1092    let solar_shun_bai_date2 = solar_shun_bai2.to_naivedate();
1093
1094    let solar_ni_zi = match xia_zhi_index > 29 {
1095      true => xia_zhi.next(60 - xia_zhi_index, None),
1096      _ => xia_zhi.next(-xia_zhi_index, None),
1097    };
1098    let solar_ni_zi_date = solar_ni_zi.to_naivedate();
1099
1100    let offset = match solar_date {
1101      d if solar_shun_bai_date <= d && d < solar_ni_zi_date => {
1102        self.get_solar().subtract(solar_shun_bai) % 9
1103      }
1104      d if solar_ni_zi_date <= d && d < solar_shun_bai_date2 => {
1105        8 - (self.get_solar().subtract(solar_ni_zi) % 9)
1106      }
1107      d if d >= solar_shun_bai_date2 => {
1108        self.get_solar().subtract(solar_shun_bai2) % 9
1109      }
1110      d if d < solar_shun_bai_date => {
1111        (8 + solar_shun_bai.subtract(self.get_solar())) % 9
1112      }
1113      _ => 0,
1114    };
1115    NineStar::from_index(offset as usize)
1116  }
1117
1118  fn get_time_nine_star(&self) -> NineStarRef {
1119    let solar_date = self.get_solar().to_naivedate();
1120    let (jie_qi, time_zhi_index) = {
1121      let s = self.lock().unwrap();
1122      (s.__jie_qi.clone(), s.__time_zhi_index)
1123    };
1124
1125    let asc = if jie_qi.get("冬至").unwrap().to_naivedate()
1126      <= solar_date
1127      && solar_date < jie_qi.get("夏至").unwrap().to_naivedate()
1128    {
1129      true
1130    } else if solar_date
1131      >= jie_qi.get("DONG_ZHI").unwrap().to_naivedate()
1132    {
1133      true
1134    } else {
1135      false
1136    };
1137
1138    let day_zhi = self.get_day_zhi().chars().collect::<Vec<_>>();
1139    let start = if "子午卯酉"
1140      .chars()
1141      .collect::<Vec<_>>()
1142      .iter()
1143      .find(|c| day_zhi.iter().find(|z| **z == **c).is_some())
1144      .is_some()
1145    {
1146      match asc {
1147        true => 0,
1148        _ => 8,
1149      }
1150    } else if "辰戌丑未"
1151      .chars()
1152      .collect::<Vec<_>>()
1153      .iter()
1154      .find(|c| day_zhi.iter().find(|z| **z == **c).is_some())
1155      .is_some()
1156    {
1157      match asc {
1158        true => 3,
1159        _ => 5,
1160      }
1161    } else {
1162      match asc {
1163        true => 6,
1164        _ => 2,
1165      }
1166    };
1167
1168    let index = match asc {
1169      true => start + time_zhi_index,
1170      _ => start + 9 - time_zhi_index,
1171    };
1172
1173    return NineStar::from_index(index as usize % 9);
1174  }
1175
1176  fn get_jie_qi_table(&self) -> HashMap<String, SolarRef> {
1177    self.lock().unwrap().__jie_qi.clone()
1178  }
1179
1180  fn get_jie_qi_list(&self) -> Vec<String> {
1181    self.lock().unwrap().__jie_qi_list.clone()
1182  }
1183
1184  fn get_time_gan_index(&self) -> i64 {
1185    self.lock().unwrap().__time_gan_index
1186  }
1187
1188  fn get_time_zhi_index(&self) -> i64 {
1189    self.lock().unwrap().__time_zhi_index
1190  }
1191
1192  fn get_day_gan_index(&self) -> i64 {
1193    self.lock().unwrap().__day_gan_index
1194  }
1195
1196  fn get_day_zhi_index(&self) -> i64 {
1197    self.lock().unwrap().__day_zhi_index
1198  }
1199
1200  fn get_day_gan_index_exact(&self) -> i64 {
1201    self.lock().unwrap().__day_gan_index_exact
1202  }
1203
1204  fn get_day_gan_index_exact2(&self) -> i64 {
1205    self.lock().unwrap().__day_gan_index_exact2
1206  }
1207
1208  fn get_day_zhi_index_exact(&self) -> i64 {
1209    self.lock().unwrap().__day_zhi_index_exact
1210  }
1211
1212  fn get_day_zhi_index_exact2(&self) -> i64 {
1213    self.lock().unwrap().__day_zhi_index_exact2
1214  }
1215
1216  fn get_month_gan_index(&self) -> i64 {
1217    self.lock().unwrap().__month_gan_index
1218  }
1219
1220  fn get_month_zhi_index(&self) -> i64 {
1221    self.lock().unwrap().__month_zhi_index
1222  }
1223
1224  fn get_month_gan_index_exact(&self) -> i64 {
1225    self.lock().unwrap().__month_gan_index_exact
1226  }
1227
1228  fn get_month_zhi_index_exact(&self) -> i64 {
1229    self.lock().unwrap().__month_zhi_index_exact
1230  }
1231
1232  fn get_year_gan_index(&self) -> i64 {
1233    self.lock().unwrap().__year_gan_index
1234  }
1235
1236  fn get_year_zhi_index(&self) -> i64 {
1237    self.lock().unwrap().__year_zhi_index
1238  }
1239
1240  fn get_year_gan_index_by_li_chun(&self) -> i64 {
1241    self.lock().unwrap().__year_gan_index_by_li_chun
1242  }
1243
1244  fn get_year_zhi_index_by_li_chun(&self) -> i64 {
1245    self.lock().unwrap().__year_zhi_index_by_li_chun
1246  }
1247
1248  fn get_year_gan_index_exact(&self) -> i64 {
1249    self.lock().unwrap().__year_gan_index_exact
1250  }
1251
1252  fn get_year_zhi_index_exact(&self) -> i64 {
1253    self.lock().unwrap().__year_zhi_index_exact
1254  }
1255
1256  ///
1257  /// 获取下一节(顺推的第一个节)
1258  ///
1259  /// ## Parameters
1260  /// whole_day: Option<bool> - 是否按天计 **default(false)**
1261  ///
1262  /// ## Returns
1263  /// 节气: String
1264  ///
1265  fn get_next_jie(&self, whole_day: Option<bool>) -> Option<JieQiRef> {
1266    let whole_day = whole_day.unwrap_or(false);
1267    let mut conditions = vec![];
1268
1269    for i in 0..(JIE_QI_IN_USE().len() / 2) {
1270      conditions.push(JIE_QI_IN_USE()[i * 2].to_string())
1271    }
1272
1273    self.__get_near_jie_qi(true, &conditions, whole_day)
1274  }
1275
1276  ///
1277  /// 获取上一节(逆推的第一个节)
1278  ///
1279  /// ## Arguments
1280  /// whole_day: Option<bool> - 是否按天计 **default(false)**
1281  ///
1282  /// ## Returns
1283  /// 节气: String
1284  ///
1285  fn get_prev_jie(&self, whole_day: Option<bool>) -> Option<JieQiRef> {
1286    let whole_day = whole_day.map_or(false, |f| f);
1287    let mut conditions = vec![];
1288
1289    JIE_QI_IN_USE()
1290      .iter()
1291      .enumerate()
1292      .step_by(2)
1293      .for_each(|(_i, jq)| conditions.push(jq.to_string()));
1294
1295    self.__get_near_jie_qi(false, &conditions, whole_day)
1296  }
1297
1298  ///
1299  /// 获取下一气令(顺推的第一个气令)
1300  ///
1301  /// ## Arguments
1302  /// whole_day: **Option\<bool\>** - 是否按天计 **default=false**
1303  ///
1304  /// ## Returns
1305  /// 节气: **String**
1306  ///
1307  fn get_next_qi(&self, whole_day: Option<bool>) -> Option<JieQiRef> {
1308    let whole_day = whole_day.map_or(false, |f| f);
1309    let mut conditions = vec![];
1310
1311    JIE_QI_IN_USE()
1312      .iter()
1313      .enumerate()
1314      .skip(1)
1315      .step_by(2)
1316      .for_each(|(_i, jq)| conditions.push(jq.to_string()));
1317    self.__get_near_jie_qi(true, &conditions, whole_day)
1318  }
1319
1320  ///
1321  /// 获取上一气令(逆推的第一个气令)
1322  ///
1323  /// ## Arguments
1324  /// whole_day: **Option\<bool\>** - 是否按天计 **default(false)**
1325  ///
1326  /// ## Returns
1327  /// 节气: String
1328  ///
1329  fn get_prev_qi(&self, whole_day: Option<bool>) -> Option<JieQiRef> {
1330    let whole_day = whole_day.map_or(false, |f| f);
1331    let mut conditions = vec![];
1332
1333    JIE_QI_IN_USE()
1334      .iter()
1335      .enumerate()
1336      .skip(1)
1337      .step_by(2)
1338      .for_each(|(_i, jq)| conditions.push(jq.to_string()));
1339    self.__get_near_jie_qi(false, &conditions, whole_day)
1340  }
1341
1342  ///
1343  /// 获取下一节气(顺推的第一个节气)
1344  ///
1345  /// ## Arguments
1346  /// whole_day: **Option\<bool\>** - 是否按天计 **default(false)**
1347  ///
1348  /// ## Returns
1349  /// 节气: String
1350  ///
1351  fn get_next_jie_qi(
1352    &self,
1353    whole_day: Option<bool>,
1354  ) -> Option<JieQiRef> {
1355    let whole_day = whole_day.map_or(false, |f| f);
1356    self.__get_near_jie_qi(true, &vec![], whole_day)
1357  }
1358
1359  ///
1360  /// 获取上一节气(逆推的第一个节气)
1361  ///
1362  /// ## Arguments
1363  /// whole_day: **Option\<bool\>** - 是否按天计 **default(false)**
1364  ///
1365  /// ## Returns
1366  /// 节气: String
1367  ///
1368  fn get_prev_jie_qi(
1369    &self,
1370    whole_day: Option<bool>,
1371  ) -> Option<JieQiRef> {
1372    let whole_day = whole_day.unwrap_or(false);
1373    self.__get_near_jie_qi(false, &vec![], whole_day)
1374  }
1375
1376  ///
1377  /// 获取节气名称,如果无节气,返回空字符串
1378  ///
1379  /// ## Returns
1380  /// 节气名称: **String**
1381  ///
1382  fn get_jie_qi(&self) -> String {
1383    let (__jie_qi, year, month, day) = {
1384      let s = self.lock().unwrap();
1385      (
1386        s.__jie_qi.clone(),
1387        s.__solar.get_year(),
1388        s.__solar.get_month(),
1389        s.__solar.get_day(),
1390      )
1391    };
1392
1393    for (name, solar) in __jie_qi.iter() {
1394      if solar.get_year() == year
1395        && solar.get_month() == month
1396        && solar.get_day() == day
1397      {
1398        return Lunar::__convert_jie_qi(name.as_str());
1399      }
1400    }
1401    format!("")
1402  }
1403
1404  ///
1405  /// 获取当天节气对象,如果无节气,返回None
1406  ///
1407  /// ## Returns
1408  /// 节气对象: **Option<JieQiRef>**
1409  ///
1410  fn get_current_jie_qi(&self) -> Option<JieQiRef> {
1411    let (__jie_qi, year, month, day) = {
1412      let s = self.lock().unwrap();
1413      (
1414        s.__jie_qi.clone(),
1415        s.__solar.get_year(),
1416        s.__solar.get_month(),
1417        s.__solar.get_day(),
1418      )
1419    };
1420
1421    for (name, solar) in __jie_qi.iter() {
1422      if solar.get_year() == year
1423        && solar.get_month() == month
1424        && solar.get_day() == day
1425      {
1426        return Some(JieQi::new(
1427          &Lunar::__convert_jie_qi(name.as_str()),
1428          solar,
1429        ));
1430      }
1431    }
1432    None
1433  }
1434
1435  ///
1436  /// 获取当天节令对象,如果无节令,返回None
1437  ///
1438  /// ## Return
1439  /// 节气对象: **Option<JieQiRef>**
1440  ///
1441  fn get_current_jie(&self) -> Option<JieQiRef> {
1442    let (__jie_qi, year, month, day) = {
1443      let s = self.lock().unwrap();
1444      (
1445        s.__jie_qi.clone(),
1446        s.__solar.get_year(),
1447        s.__solar.get_month(),
1448        s.__solar.get_day(),
1449      )
1450    };
1451
1452    for key in JIE_QI_IN_USE().iter().step_by(2) {
1453      let d = __jie_qi.get(&key.to_string()).unwrap();
1454      if d.get_year() == year
1455        && d.get_month() == month
1456        && d.get_day() == day
1457      {
1458        return Some(JieQi::new(&Lunar::__convert_jie_qi(key), d));
1459      }
1460    }
1461    None
1462  }
1463
1464  ///
1465  /// 获取当天气令对象,如果无气令,返回None
1466  ///
1467  /// ## Returns
1468  /// 节气对象: **Option<JieQiRef>**
1469  ///
1470  fn get_current_qi(&self) -> Option<JieQiRef> {
1471    let (__jie_qi, year, month, day) = {
1472      let s = self.lock().unwrap();
1473      (
1474        s.__jie_qi.clone(),
1475        s.__solar.get_year(),
1476        s.__solar.get_month(),
1477        s.__solar.get_day(),
1478      )
1479    };
1480
1481    for key in JIE_QI_IN_USE().iter().skip(1).step_by(2) {
1482      let d = __jie_qi.get(&key.to_string()).unwrap();
1483      if d.get_year() == year
1484        && d.get_month() == month
1485        && d.get_day() == day
1486      {
1487        return Some(JieQi::new(&Lunar::__convert_jie_qi(key), d));
1488      }
1489    }
1490    None
1491  }
1492
1493  ///
1494  /// 获取往后推几天的农历日期,如果要往前推,则天数用负数
1495  ///
1496  /// ## Arguments
1497  /// days: **i64** - 天数
1498  ///
1499  /// ## Returns
1500  /// 农历日期: **LunarRef**
1501  ///
1502  fn next(&self, days: i64) -> LunarRef {
1503    self.lock().unwrap().__solar.next(days, None).get_lunar()
1504  }
1505
1506  fn to_string(&self) -> String {
1507    format!(
1508      "{}年{}月{}",
1509      self.get_year_in_chinese(),
1510      self.get_month_in_chinese(),
1511      self.get_day_in_chinese()
1512    )
1513  }
1514
1515  fn to_full_string(&self) -> String {
1516    let mut s = self.to_string();
1517    s = format!(
1518      "{} {}({})年",
1519      s,
1520      self.get_year_in_gan_zhi(),
1521      self.get_year_sheng_xiao()
1522    );
1523    s = format!(
1524      "{} {}({})月",
1525      s,
1526      self.get_month_in_gan_zhi(),
1527      self.get_month_sheng_xiao()
1528    );
1529    s = format!(
1530      "{} {}({})日",
1531      s,
1532      self.get_day_in_gan_zhi(),
1533      self.get_day_sheng_xiao()
1534    );
1535    s = format!(
1536      "{} {}({})时",
1537      s,
1538      self.get_time_zhi(),
1539      self.get_time_sheng_xiao()
1540    );
1541    s = format!(
1542      "{} 纳音[{} {} {} {}]",
1543      s,
1544      self.get_year_na_yin(),
1545      self.get_month_na_yin(),
1546      self.get_day_na_yin(),
1547      self.get_time_na_yin()
1548    );
1549    s = format!("{} 星期{}", s, self.get_week_in_chinese());
1550
1551    let fest = self
1552      .get_festivals()
1553      .iter()
1554      .map(|festival| format!("({})", festival))
1555      .collect::<Vec<_>>()
1556      .join(" ");
1557    if fest.len() > 0 {
1558      s = format!("{} {}", s, fest);
1559    }
1560
1561    let other_fest = self
1562      .get_other_festivals()
1563      .iter()
1564      .map(|festival| format!("({})", festival))
1565      .collect::<Vec<_>>()
1566      .join(" ");
1567    if other_fest.len() > 0 {
1568      s = format!("{} {}", s, other_fest);
1569    }
1570
1571    let jq = self.get_jie_qi();
1572    if jq.len() > 0 {
1573      s = format!("{} [{}]", s, jq);
1574    }
1575
1576    s = format!("{} {}方{}", s, self.get_gong(), self.get_shou());
1577    s = format!(
1578      "{} 星宿[{}{}{}]({})",
1579      s,
1580      self.get_xiu(),
1581      self.get_zheng(),
1582      self.get_animal(),
1583      self.get_xiu_luck()
1584    );
1585    s = format!(
1586      "{} 彭祖百忌[{} {}]",
1587      s,
1588      self.get_peng_zu_gan(),
1589      self.get_peng_zu_zhi()
1590    );
1591    s = format!(
1592      "{} 喜神方位[{}]({})",
1593      s,
1594      self.get_day_position_xi(),
1595      self.get_day_position_xi_desc()
1596    );
1597    s = format!(
1598      "{} 阳贵神方位[{}]({})",
1599      s,
1600      self.get_day_position_yang_gui(),
1601      self.get_day_position_yang_gui_desc()
1602    );
1603    s = format!(
1604      "{} 阴贵神方位[{}]({})",
1605      s,
1606      self.get_day_position_yin_gui(),
1607      self.get_day_position_yin_gui_desc()
1608    );
1609    s = format!(
1610      "{} 福神方位[{}]({})",
1611      s,
1612      self.get_day_position_fu(None),
1613      self.get_day_position_fu_desc(None)
1614    );
1615    s = format!(
1616      "{} 财神方位[{}]({})",
1617      s,
1618      self.get_day_position_cai(),
1619      self.get_day_position_cai_desc()
1620    );
1621    s = format!("{} 冲[{}]", s, self.get_chong_desc());
1622    s = format!("{} 煞[{}]", s, self.get_sha());
1623    s
1624  }
1625
1626  ///
1627  /// 获取年所在旬(以正月初一作为新年的开始)
1628  ///
1629  /// ## Returns
1630  /// 旬: **String**
1631  ///
1632  fn get_year_xun(&self) -> String {
1633    LunarUtil::get_xun(&self.get_year_in_gan_zhi())
1634  }
1635
1636  ///
1637  /// 获取年所在旬(以立春当天作为新年的开始)
1638  ///
1639  /// ## Returns
1640  /// 旬: **String**
1641  ///
1642  fn get_year_xun_by_li_chun(&self) -> String {
1643    LunarUtil::get_xun(&self.get_year_in_gan_zhi_by_li_chun())
1644  }
1645
1646  ///
1647  /// 获取年所在旬(以立春交接时刻作为新年的开始)
1648  ///
1649  /// ## Returns
1650  /// 旬: **String**
1651  ///
1652  fn get_year_xun_exact(&self) -> String {
1653    LunarUtil::get_xun(&self.get_year_in_gan_zhi_exact())
1654  }
1655
1656  ///
1657  /// 获取值年空亡(以正月初一作为新年的开始)
1658  ///
1659  /// ## Returns
1660  /// 空亡(旬空): **String**
1661  ///
1662  fn get_year_xun_kong(&self) -> String {
1663    LunarUtil::get_xun_kong(&self.get_year_in_gan_zhi())
1664  }
1665
1666  ///
1667  /// 获取值年空亡(以立春当天作为新年的开始)
1668  ///
1669  /// ## Returns
1670  /// 空亡(旬空): **String**
1671  ///
1672  fn get_year_xun_kong_by_li_chun(&self) -> String {
1673    LunarUtil::get_xun_kong(&self.get_year_in_gan_zhi_by_li_chun())
1674  }
1675
1676  ///
1677  /// 获取值年空亡(以立春交接时刻作为新年的开始)
1678  ///
1679  /// ## Returns
1680  /// 空亡(旬空): **String**
1681  ///
1682  fn get_year_xun_kong_exact(&self) -> String {
1683    LunarUtil::get_xun_kong(&self.get_year_in_gan_zhi_exact())
1684  }
1685
1686  ///
1687  /// 获取月所在旬(以节交接当天起算)
1688  ///
1689  /// ## Returns
1690  /// 旬: **String**
1691  ///
1692  fn get_month_xun(&self) -> String {
1693    LunarUtil::get_xun(&self.get_month_in_gan_zhi())
1694  }
1695
1696  ///
1697  /// 获取月所在旬(以节交接时刻起算)
1698  ///
1699  /// ## Returns
1700  /// 旬: **String**
1701  ///
1702  fn get_month_xun_exact(&self) -> String {
1703    LunarUtil::get_xun(&self.get_month_in_gan_zhi_exact())
1704  }
1705
1706  ///
1707  /// 获取值月空亡(以节交接当天起算)
1708  ///
1709  /// ## Returns
1710  /// 空亡(旬空): **String**
1711  ///
1712  fn get_month_xun_kong(&self) -> String {
1713    LunarUtil::get_xun_kong(&self.get_month_in_gan_zhi())
1714  }
1715
1716  ///
1717  /// 获取值月空亡(以节交接时刻起算)
1718  ///
1719  /// ## Returns
1720  /// 空亡(旬空): **String**
1721  ///
1722  fn get_month_xun_kong_exact(&self) -> String {
1723    LunarUtil::get_xun_kong(&self.get_month_in_gan_zhi_exact())
1724  }
1725
1726  ///
1727  /// 获取日所在旬(以节交接当天起算)
1728  ///
1729  /// ## Returns
1730  /// 旬: **String**
1731  ///
1732  fn get_day_xun(&self) -> String {
1733    LunarUtil::get_xun(&self.get_day_in_gan_zhi())
1734  }
1735
1736  ///
1737  /// 获取日所在旬(晚子时日柱算明天)
1738  ///
1739  /// ## Returns
1740  /// 旬: **String**
1741  ///
1742  fn get_day_xun_exact(&self) -> String {
1743    LunarUtil::get_xun(&self.get_day_in_gan_zhi_exact())
1744  }
1745
1746  ///
1747  /// 获取日所在旬(晚子时日柱算当天)
1748  ///
1749  /// ## Returns
1750  /// 旬: **String**
1751  ///
1752  fn get_day_xun_exact2(&self) -> String {
1753    LunarUtil::get_xun(&self.get_day_in_gan_zhi_exact2())
1754  }
1755
1756  ///
1757  /// 获取值日空亡
1758  ///
1759  /// ## Returns
1760  /// 空亡(旬空): String
1761  ///
1762  fn get_day_xun_kong(&self) -> String {
1763    LunarUtil::get_xun_kong(&self.get_day_in_gan_zhi())
1764  }
1765
1766  ///
1767  /// 获取值日空亡(晚子时日柱算明天)
1768  ///
1769  /// ## Returns
1770  /// 空亡(旬空): String
1771  ///
1772  fn get_day_xun_kong_exact(&self) -> String {
1773    LunarUtil::get_xun_kong(&self.get_day_in_gan_zhi_exact())
1774  }
1775
1776  ///
1777  /// 获取值日空亡(晚子时日柱算当天)
1778  ///
1779  /// ## Returns
1780  /// 空亡(旬空): String
1781  ///
1782  fn get_day_xun_kong_exact2(&self) -> String {
1783    LunarUtil::get_xun_kong(&self.get_day_in_gan_zhi_exact2())
1784  }
1785
1786  ///
1787  /// 获取时辰所在旬
1788  ///
1789  /// ## Returns
1790  /// 旬: String
1791  ///
1792  fn get_time_xun(&self) -> String {
1793    LunarUtil::get_xun(&self.get_time_in_gan_zhi())
1794  }
1795
1796  ///
1797  /// 获取值时空亡
1798  ///
1799  /// ## Returns
1800  /// 空亡(旬空): String
1801  ///
1802  fn get_time_xun_kong(&self) -> String {
1803    LunarUtil::get_xun_kong(&self.get_time_in_gan_zhi())
1804  }
1805
1806  ///
1807  /// 获取数九
1808  ///
1809  /// ## Returns
1810  /// 数九,如果不是数九天,返回None
1811  ///
1812  fn get_shu_jiu(&self) -> Option<ShuJiuRef> {
1813    let (__jie_qi, year, month, day) = {
1814      let s = self.lock().unwrap();
1815      (
1816        s.__jie_qi.clone(),
1817        s.__solar.get_year(),
1818        s.__solar.get_month(),
1819        s.__solar.get_day(),
1820      )
1821    };
1822    let current = solar::from_ymd(year, month, day);
1823    let mut start = __jie_qi.get("DONG_ZHI").unwrap().clone();
1824    start = solar::from_ymd(
1825      start.get_year(),
1826      start.get_month(),
1827      start.get_day(),
1828    );
1829    if current.is_before(start.clone()) {
1830      start = __jie_qi.get("冬至").unwrap().clone();
1831      start = solar::from_ymd(
1832        start.get_year(),
1833        start.get_month(),
1834        start.get_day(),
1835      );
1836    }
1837    let end = solar::from_ymd(
1838      start.get_year(),
1839      start.get_month(),
1840      start.get_day(),
1841    )
1842    .next(81, None);
1843    if current.is_before(start.clone()) || !current.is_before(end) {
1844      return None;
1845    }
1846    let days = current.subtract(start);
1847    return Some(ShuJiu::new(
1848      &format!("{}九", NUMBER()[(days as f64 / 9.) as usize + 1]),
1849      days % 9 + 1,
1850    ));
1851  }
1852
1853  ///
1854  /// 获取三伏
1855  ///
1856  /// ## Returns
1857  /// 三伏,如果不是伏天,返回None: **Option\<FuRef\>**
1858  ///
1859  fn get_fu(&self) -> Option<FuRef> {
1860    let current = { &self.lock().unwrap().__solar };
1861    let xia_zhi =
1862      { self.lock().unwrap().__jie_qi.get("夏至").unwrap().clone() };
1863    let li_qiu =
1864      { self.lock().unwrap().__jie_qi.get("立秋").unwrap().clone() };
1865    let mut start = solar::from_ymd(
1866      xia_zhi.get_year(),
1867      xia_zhi.get_month(),
1868      xia_zhi.get_day(),
1869    );
1870    let mut add = 6 - xia_zhi.get_lunar().get_day_gan_index();
1871    if add < 0 {
1872      add = add + 10;
1873    }
1874    add = add + 20;
1875    start = start.next(add, None);
1876    if current.is_before(start.clone()) {
1877      return None;
1878    }
1879    let mut days = current.subtract(start.clone());
1880    if days < 10 {
1881      return Some(Fu::new("初伏", days + 1));
1882    }
1883    start = start.next(10, None);
1884    days = current.subtract(start.clone());
1885    if days < 10 {
1886      return Some(Fu::new("中伏", days + 1));
1887    }
1888    start = start.clone().next(10, None);
1889    days = current.subtract(start.clone());
1890    let li_qiu_solar = solar::from_ymd(
1891      li_qiu.get_year(),
1892      li_qiu.get_month(),
1893      li_qiu.get_day(),
1894    );
1895    if li_qiu_solar.is_after(start.clone()) {
1896      if days < 10 {
1897        return Some(Fu::new("中伏", days + 11));
1898      }
1899      start = start.next(10, None);
1900      days = current.subtract(start);
1901    }
1902    if days < 10 {
1903      return Some(Fu::new("末伏", days + 1));
1904    }
1905    None
1906  }
1907
1908  ///
1909  /// 获取六曜
1910  ///
1911  /// ## Returns
1912  /// 六曜: **String**
1913  ///
1914  fn get_liu_yao(&self) -> String {
1915    LIU_YAO()[({ self.lock().unwrap().__month } + {
1916      self.lock().unwrap().__day
1917    } - 2) as usize
1918      % 6]
1919      .to_string()
1920  }
1921
1922  ///
1923  /// 获取物候
1924  ///
1925  /// ## Returns
1926  /// 物候: **String**
1927  ///
1928  fn get_wu_hou(&self) -> String {
1929    let jie_qi = self.get_prev_jie_qi(Some(true)).unwrap();
1930    let mut offset = 0;
1931    for (i, jq) in JIE_QI().iter().enumerate() {
1932      if jie_qi.get_name() == jq.to_string() {
1933        offset = i;
1934        break;
1935      }
1936    }
1937    let mut index = { self.lock().unwrap().__solar.clone() }
1938      .subtract(jie_qi.get_solar())
1939      / 5;
1940    if index > 2 {
1941      index = 2;
1942    }
1943    WU_HOU()[(offset * 3 + index as usize) % WU_HOU().len()].to_string()
1944  }
1945
1946  fn get_hou(&self) -> String {
1947    let jie_qi = self.get_prev_jie_qi(Some(true)).unwrap();
1948    let hou = &HOU();
1949    let size = hou.len() as i64 - 1;
1950    let mut offset = ({ self.lock().unwrap().__solar.clone() }
1951      .subtract(jie_qi.get_solar()) as f64
1952      / 5.) as i64;
1953    if offset > size {
1954      offset = size;
1955    }
1956    format!("{} {}", jie_qi.get_name(), hou[offset as usize])
1957  }
1958
1959  ///
1960  /// 获取日禄
1961  ///
1962  /// ## Returns
1963  /// 日禄: **String**
1964  ///
1965  fn get_day_lu(&self) -> String {
1966    let lu = LU();
1967    let gan = lu.get(&self.get_day_gan()).unwrap();
1968    let self_day_zhi = self.get_day_zhi();
1969    let zhi = lu.iter().find(|(key, _)| self_day_zhi == **key);
1970    let mut lu = format!("{}命互禄", gan.join(", "));
1971    if zhi.is_some() {
1972      lu = format!("{} {}命进禄", lu, zhi.unwrap().1.join(", "));
1973    }
1974    lu
1975  }
1976
1977  ///
1978  /// 获取时辰
1979  ///
1980  /// ## Returns
1981  /// 时辰: **String**
1982  ///
1983  fn get_time(&self) -> LunarTimeRef {
1984    let (year, month, day, hour, minute, second) = {
1985      let s = self.lock().unwrap();
1986      (
1987        s.__year, s.__month, s.__day, s.__hour, s.__minute, s.__second,
1988      )
1989    };
1990    LunarTime::from_ymd_hms(year, month, day, hour, minute, second)
1991  }
1992
1993  ///
1994  /// 获取当天的时辰列表
1995  ///
1996  /// ## Returns
1997  /// 时辰列表: **Vec\<LunarTimeRef\>**
1998  ///
1999  fn get_times(&self) -> Vec<LunarTimeRef> {
2000    let (year, month, day) = {
2001      let s = self.lock().unwrap();
2002      (s.__year, s.__month, s.__day)
2003    };
2004    let mut times =
2005      [LunarTime::from_ymd_hms(year, month, day, 0, 0, 0)].to_vec();
2006    for i in 0..12 {
2007      times.push(LunarTime::from_ymd_hms(
2008        year,
2009        month,
2010        day,
2011        (i + 1) * 2 - 1,
2012        0,
2013        0,
2014      ))
2015    }
2016    times
2017  }
2018
2019  ///
2020  /// 获取佛历
2021  ///
2022  /// ## Returns
2023  /// 佛历: **FotoRef**
2024  ///
2025  fn get_foto(&self) -> FotoRef {
2026    foto::from_lunar(self.clone())
2027  }
2028
2029  ///
2030  /// 获取道历
2031  ///
2032  /// ## Returns
2033  /// 道历: TaoRef
2034  ///
2035  fn get_tao(&self) -> TaoRef {
2036    tao::from_lunar(self.clone())
2037  }
2038}