File tree Expand file tree Collapse file tree 3 files changed +36
-7
lines changed
main/java/com/nlf/calendar Expand file tree Collapse file tree 3 files changed +36
-7
lines changed Original file line number Diff line number Diff line change @@ -324,15 +324,10 @@ public List<String> getFestivals(){
324324 l .add (f );
325325 }
326326 //计算几月第几个星期几对应的节日
327- //第几周
328- int weekInMonth = calendar .get (Calendar .WEEK_OF_MONTH );
327+ int weeks = (int )Math .ceil (day /7D );
329328 //星期几,0代表星期天
330329 int week = getWeek ();
331- //星期天很奇葩,会多算一周,需要减掉
332- if (0 ==week ){
333- weekInMonth --;
334- }
335- f = SolarUtil .WEEK_FESTIVAL .get (month +"-" +weekInMonth +"-" +week );
330+ f = SolarUtil .WEEK_FESTIVAL .get (month +"-" +weeks +"-" +week );
336331 if (null !=f ){
337332 l .add (f );
338333 }
Original file line number Diff line number Diff line change @@ -114,6 +114,7 @@ public class SolarUtil{
114114 put ("10-13" ,Collections .nCopies (1 ,"中国少年先锋队诞辰日" ));
115115 put ("10-25" ,Collections .nCopies (1 ,"抗美援朝纪念日" ));
116116 put ("11-12" ,Collections .nCopies (1 ,"孙中山诞辰纪念日" ));
117+ put ("11-17" ,Collections .nCopies (1 ,"国际大学生节" ));
117118 put ("11-28" ,Collections .nCopies (1 ,"恩格斯诞辰纪念日" ));
118119 put ("12-1" ,Collections .nCopies (1 ,"世界艾滋病日" ));
119120 put ("12-12" ,Collections .nCopies (1 ,"西安事变纪念日" ));
Original file line number Diff line number Diff line change 1+ package test ;
2+
3+ import com .nlf .calendar .Solar ;
4+ import org .junit .Assert ;
5+ import org .junit .Test ;
6+
7+ /**
8+ * 节日测试
9+ *
10+ * @author 6tail
11+ */
12+ public class FestivalTest {
13+ @ Test
14+ public void test () {
15+ Solar solar = Solar .fromYmd (2020 , 11 , 26 );
16+ Assert .assertEquals ("[感恩节]" , solar .getFestivals () + "" );
17+
18+ solar = Solar .fromYmd (2020 , 6 , 21 );
19+ Assert .assertEquals ("[父亲节]" , solar .getFestivals () + "" );
20+
21+ solar = Solar .fromYmd (2021 , 5 , 9 );
22+ Assert .assertEquals ("[母亲节]" , solar .getFestivals () + "" );
23+
24+ solar = Solar .fromYmd (1986 , 11 , 27 );
25+ Assert .assertEquals ("[感恩节]" , solar .getFestivals () + "" );
26+
27+ solar = Solar .fromYmd (1985 , 6 , 16 );
28+ Assert .assertEquals ("[父亲节]" , solar .getFestivals () + "" );
29+
30+ solar = Solar .fromYmd (1984 , 5 , 13 );
31+ Assert .assertEquals ("[母亲节]" , solar .getFestivals () + "" );
32+ }
33+ }
You can’t perform that action at this time.
0 commit comments