├── .classpath ├── .gitignore ├── .project ├── .settings ├── org.eclipse.core.resources.prefs ├── org.eclipse.jdt.core.prefs ├── org.eclipse.m2e.core.prefs ├── org.eclipse.wst.common.component ├── org.eclipse.wst.common.project.facet.core.xml └── org.eclipse.wst.validation.prefs ├── LICENSE ├── README.md ├── pom.xml └── src ├── main ├── java │ └── com │ │ └── iceyyy │ │ ├── icework │ │ └── presence │ │ │ ├── Year2001.java │ │ │ ├── Year2002.java │ │ │ ├── Year2003.java │ │ │ ├── Year2004.java │ │ │ ├── Year2005.java │ │ │ ├── Year2006.java │ │ │ ├── Year2007.java │ │ │ ├── Year2008.java │ │ │ ├── Year2009.java │ │ │ ├── Year2010.java │ │ │ ├── Year2011.java │ │ │ ├── Year2012.java │ │ │ ├── Year2013.java │ │ │ ├── Year2014.java │ │ │ ├── Year2015.java │ │ │ ├── Year2016.java │ │ │ ├── Year2017.java │ │ │ ├── Year2018.java │ │ │ ├── Year2019.java │ │ │ ├── Year2020.java │ │ │ ├── Year20xx.java │ │ │ └── YearMap.java │ │ └── workday │ │ ├── Data.java │ │ ├── WorkUtils.java │ │ └── WorkdayGen.java └── resources │ └── iceweek.txt └── test └── java └── com └── iceyyy └── iceworkday └── IceWorkTest.java /.classpath: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled class file 2 | *.class 3 | 4 | # Log file 5 | *.log 6 | 7 | # BlueJ files 8 | *.ctxt 9 | 10 | # Mobile Tools for Java (J2ME) 11 | .mtj.tmp/ 12 | 13 | # Package Files # 14 | *.jar 15 | *.war 16 | *.ear 17 | *.zip 18 | *.tar.gz 19 | *.rar 20 | 21 | # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml 22 | hs_err_pid* 23 | /target/ 24 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | iceworkday 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.wst.common.project.facet.core.builder 10 | 11 | 12 | 13 | 14 | org.eclipse.jdt.core.javabuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.wst.validation.validationbuilder 20 | 21 | 22 | 23 | 24 | org.eclipse.m2e.core.maven2Builder 25 | 26 | 27 | 28 | 29 | 30 | org.eclipse.jem.workbench.JavaEMFNature 31 | org.eclipse.wst.common.modulecore.ModuleCoreNature 32 | org.eclipse.jdt.core.javanature 33 | org.eclipse.m2e.core.maven2Nature 34 | org.eclipse.wst.common.project.facet.core.nature 35 | 36 | 37 | -------------------------------------------------------------------------------- /.settings/org.eclipse.core.resources.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | encoding//src/main/java=UTF-8 3 | encoding//src/main/resources=UTF-8 4 | encoding//src/test/java=UTF-8 5 | encoding/=UTF-8 6 | -------------------------------------------------------------------------------- /.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate 4 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 5 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 6 | org.eclipse.jdt.core.compiler.compliance=1.7 7 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 8 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 9 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 10 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled 12 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 13 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 14 | org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore 15 | org.eclipse.jdt.core.compiler.release=disabled 16 | org.eclipse.jdt.core.compiler.source=1.7 17 | -------------------------------------------------------------------------------- /.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.component: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.common.project.facet.core.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /.settings/org.eclipse.wst.validation.prefs: -------------------------------------------------------------------------------- 1 | disabled=06target 2 | eclipse.preferences.version=1 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # iceworkday 2 | iceworkday工作日算法 3 | 4 | 工作日算法又称节假日算法。 5 | 由于工作日计算涉及农历节气等,而农历算法本身就是非常复杂的,所以工作日算法非常的复杂。 6 | 该算法解决了工作日的计算问题。对以往的数据确保其准确性,对将来的数据提供尽可能准确的预测。 7 | 由于未来的数据是未知的,为了在将来使该算法对已发生的数据具有准确性,该算法提供了配置文件纠错机制。 8 | 该工作日算法的有效计算范围为 2001年--3100年。 9 | 对2020年及以前的节假日进行了精确枚举。 10 | WorkUtils.weekendMap(year)方法用于计算节某一年假日map,传入年的字符串。 11 | WorkUtils.isWorkendDay(ymd)方法用于判断某一天是否为节假日,传入年月日字符串。 12 | ------------------------------------------------- 13 | | 注意: | 14 | | 该算法对将来的日期仅是预测,并不能绝对准确! | 15 | ------------------------------------------------- 16 | 该算法已提交maven中央仓库, 17 | maven依赖如下:
18 | <dependency>
19 |   <groupId>com.icexxx</groupId>
20 |   <artifactId>iceworkday</artifactId>
21 |   <version>2.0.2.0</version>
22 | </dependency>
23 | maven依赖如下: 24 | 25 | com.icexxx 26 | iceworkday 27 | 2.0.2.0 28 | 29 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 3 | 4.0.0 4 | 5 | com.icexxx 6 | iceworkday 7 | 2.0.2.0 8 | jar 9 | 10 | 11 | UTF-8 12 | 13 | 14 | iceworkday 15 | http://maven.apache.org 16 | iceworkday 17 | 18 | 19 | The Apache License, Version 2.0 20 | http://www.apache.org/licenses/LICENSE-2.0.txt 21 | 22 | 23 | 24 | 25 | 26 | IceWater 27 | zxcyhn@126.com 28 | 29 | 30 | 31 | 32 | 33 | com.iceyyy 34 | icenongli 35 | 2.0 36 | 37 | 38 | junit 39 | junit 40 | 4.12 41 | test 42 | 43 | 44 | 45 | 46 | 47 | oss 48 | https://oss.sonatype.org/content/repositories/snapshots/ 49 | 50 | 51 | oss 52 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 53 | 54 | 55 | 56 | 57 | Github Issue 58 | https://github.com/iceroot/iceworkday.git 59 | 60 | 61 | scm:git:https://github.com/iceenongli/iceworkday.git 62 | scm:git:https://github.com/iceenongli/iceworkday.git 63 | https://github.com/iceenongli/iceworkday.git 64 | 65 | 66 | 67 | 68 | 69 | org.sonatype.plugins 70 | nexus-staging-maven-plugin 71 | 1.6.3 72 | true 73 | 74 | oss 75 | https://oss.sonatype.org/ 76 | true 77 | 78 | 79 | 80 | org.apache.maven.plugins 81 | maven-release-plugin 82 | 2.5 83 | 84 | true 85 | false 86 | release 87 | deploy 88 | 89 | 90 | 91 | org.apache.maven.plugins 92 | maven-compiler-plugin 93 | 3.5.1 94 | 95 | 1.7 96 | 1.7 97 | 98 | 99 | 100 | 101 | 102 | 103 | release 104 | 105 | true 106 | 107 | 108 | 109 | oss 110 | https://oss.sonatype.org/content/repositories/snapshots/ 111 | 112 | 113 | oss 114 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 115 | 116 | 117 | 118 | 119 | 120 | 121 | org.apache.maven.plugins 122 | maven-source-plugin 123 | 3.0.1 124 | 125 | 126 | package 127 | 128 | jar-no-fork 129 | 130 | 131 | 132 | 133 | 134 | 135 | org.apache.maven.plugins 136 | maven-javadoc-plugin 137 | 2.10.4 138 | 139 | 140 | package 141 | 142 | jar 143 | 144 | 145 | 146 | 147 | UTF-8 148 | UTF-8 149 | true 150 | 151 | 152 | 153 | 154 | org.apache.maven.plugins 155 | maven-gpg-plugin 156 | 1.6 157 | 158 | 159 | sign-artifacts 160 | verify 161 | 162 | sign 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2001.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2001 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20010120", false); // 班 11 | map.put("20010121", false); // 班 12 | map.put("20010124", true); // 休 13 | map.put("20010125", true); // 休 14 | map.put("20010126", true); // 休 15 | map.put("20010129", true); // 休 16 | map.put("20010130", true); // 休 17 | map.put("20010428", false); // 班 18 | map.put("20010429", false); // 班 19 | map.put("20010501", true); // 休 20 | map.put("20010502", true); // 休 21 | map.put("20010503", true); // 休 22 | map.put("20010504", true); // 休 23 | map.put("20010507", true); // 休 24 | map.put("20010929", false); // 班 25 | map.put("20010930", false); // 班 26 | map.put("20011001", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2002.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2002 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20020101", true); // 休 11 | map.put("20020102", true); // 休 12 | map.put("20020103", true); // 休 13 | map.put("20020209", false); // 班 14 | map.put("20020210", false); // 班 15 | map.put("20020212", true); // 休 16 | map.put("20020213", true); // 休 17 | map.put("20020214", true); // 休 18 | map.put("20020215", true); // 休 19 | map.put("20020218", true); // 休 20 | map.put("20020427", false); // 班 21 | map.put("20020428", false); // 班 22 | map.put("20020501", true); // 休 23 | map.put("20020502", true); // 休 24 | map.put("20020503", true); // 休 25 | map.put("20020506", true); // 休 26 | map.put("20020507", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2003.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2003 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20030101", true); // 休 11 | map.put("20030203", true); // 休 12 | map.put("20030204", true); // 休 13 | map.put("20030205", true); // 休 14 | map.put("20030206", true); // 休 15 | map.put("20030207", true); // 休 16 | map.put("20030208", false); // 班 17 | map.put("20030209", false); // 班 18 | map.put("20030426", false); // 班 19 | map.put("20030427", false); // 班 20 | map.put("20030501", true); // 休 21 | map.put("20030502", true); // 休 22 | map.put("20030505", true); // 休 23 | map.put("20030506", true); // 休 24 | map.put("20030507", true); // 休 25 | map.put("20030927", false); // 班 26 | map.put("20030928", false); // 班 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2004.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2004 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20040101", true); // 休 11 | map.put("20040117", false); // 班 12 | map.put("20040118", false); // 班 13 | map.put("20040122", true); // 休 14 | map.put("20040123", true); // 休 15 | map.put("20040126", true); // 休 16 | map.put("20040127", true); // 休 17 | map.put("20040128", true); // 休 18 | map.put("20040503", true); // 休 19 | map.put("20040504", true); // 休 20 | map.put("20040505", true); // 休 21 | map.put("20040506", true); // 休 22 | map.put("20040507", true); // 休 23 | map.put("20040508", false); // 班 24 | map.put("20040509", false); // 班 25 | map.put("20041001", true); // 休 26 | map.put("20041003", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2005.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2005 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20050103", true); // 休 11 | map.put("20050205", false); // 班 12 | map.put("20050206", false); // 班 13 | map.put("20050209", true); // 休 14 | map.put("20050210", true); // 休 15 | map.put("20050211", true); // 休 16 | map.put("20050214", true); // 休 17 | map.put("20050215", true); // 休 18 | map.put("20050430", false); // 班 19 | map.put("20050502", true); // 休 20 | map.put("20050503", true); // 休 21 | map.put("20050504", true); // 休 22 | map.put("20050505", true); // 休 23 | map.put("20050506", true); // 休 24 | map.put("20050508", false); // 班 25 | map.put("20051003", true); // 休 26 | map.put("20051004", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2006.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2006 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20060102", true); // 休 11 | map.put("20060103", true); // 休 12 | map.put("20060128", false); // 班 13 | map.put("20060130", true); // 休 14 | map.put("20060131", true); // 休 15 | map.put("20060201", true); // 休 16 | map.put("20060202", true); // 休 17 | map.put("20060203", true); // 休 18 | map.put("20060205", false); // 班 19 | map.put("20060429", false); // 班 20 | map.put("20060430", false); // 班 21 | map.put("20060501", true); // 休 22 | map.put("20060502", true); // 休 23 | map.put("20060503", true); // 休 24 | map.put("20060504", true); // 休 25 | map.put("20060505", true); // 休 26 | map.put("20060930", false); // 班 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2007.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2007 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20070101", true); // 休 11 | map.put("20070102", true); // 休 12 | map.put("20070103", true); // 休 13 | map.put("20070217", false); // 班 14 | map.put("20070219", true); // 休 15 | map.put("20070220", true); // 休 16 | map.put("20070221", true); // 休 17 | map.put("20070222", true); // 休 18 | map.put("20070223", true); // 休 19 | map.put("20070225", false); // 班 20 | map.put("20070428", false); // 班 21 | map.put("20070429", false); // 班 22 | map.put("20070501", true); // 休 23 | map.put("20070502", true); // 休 24 | map.put("20070503", true); // 休 25 | map.put("20070504", true); // 休 26 | map.put("20070507", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2008.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2008 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20080101", true); // 休 11 | map.put("20080203", false); // 班 12 | map.put("20080206", true); // 休 13 | map.put("20080207", true); // 休 14 | map.put("20080208", true); // 休 15 | map.put("20080211", true); // 休 16 | map.put("20080212", true); // 休 17 | map.put("20080404", true); // 休 18 | map.put("20080501", true); // 休 19 | map.put("20080502", true); // 休 20 | map.put("20080504", false); // 班 21 | map.put("20080609", true); // 休 22 | map.put("20080915", true); // 休 23 | map.put("20080927", false); // 班 24 | map.put("20080928", false); // 班 25 | map.put("20080929", true); // 休 26 | map.put("20080930", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2009.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2009 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20090101", true); // 休 11 | map.put("20090102", true); // 休 12 | map.put("20090104", false); // 班 13 | map.put("20090124", false); // 班 14 | map.put("20090126", true); // 休 15 | map.put("20090127", true); // 休 16 | map.put("20090128", true); // 休 17 | map.put("20090129", true); // 休 18 | map.put("20090130", true); // 休 19 | map.put("20090201", false); // 班 20 | map.put("20090406", true); // 休 21 | map.put("20090501", true); // 休 22 | map.put("20090528", true); // 休 23 | map.put("20090529", true); // 休 24 | map.put("20090531", false); // 班 25 | map.put("20090927", false); // 班 26 | map.put("20091001", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2010.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2010 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20100101", true); // 休 11 | map.put("20100215", true); // 休 12 | map.put("20100216", true); // 休 13 | map.put("20100217", true); // 休 14 | map.put("20100218", true); // 休 15 | map.put("20100219", true); // 休 16 | map.put("20100220", false); // 班 17 | map.put("20100221", false); // 班 18 | map.put("20100405", true); // 休 19 | map.put("20100503", true); // 休 20 | map.put("20100612", false); // 班 21 | map.put("20100613", false); // 班 22 | map.put("20100614", true); // 休 23 | map.put("20100615", true); // 休 24 | map.put("20100616", true); // 休 25 | map.put("20100919", false); // 班 26 | map.put("20100922", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2011.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2011 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20110103", true); // 休 11 | map.put("20110130", false); // 班 12 | map.put("20110202", true); // 休 13 | map.put("20110203", true); // 休 14 | map.put("20110204", true); // 休 15 | map.put("20110207", true); // 休 16 | map.put("20110208", true); // 休 17 | map.put("20110212", false); // 班 18 | map.put("20110402", false); // 班 19 | map.put("20110404", true); // 休 20 | map.put("20110405", true); // 休 21 | map.put("20110502", true); // 休 22 | map.put("20110606", true); // 休 23 | map.put("20110912", true); // 休 24 | map.put("20111003", true); // 休 25 | map.put("20111004", true); // 休 26 | map.put("20111005", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2012.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2012 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20120102", true); // 休 11 | map.put("20120103", true); // 休 12 | map.put("20120121", false); // 班 13 | map.put("20120123", true); // 休 14 | map.put("20120124", true); // 休 15 | map.put("20120125", true); // 休 16 | map.put("20120126", true); // 休 17 | map.put("20120127", true); // 休 18 | map.put("20120129", false); // 班 19 | map.put("20120331", false); // 班 20 | map.put("20120401", false); // 班 21 | map.put("20120402", true); // 休 22 | map.put("20120403", true); // 休 23 | map.put("20120404", true); // 休 24 | map.put("20120428", false); // 班 25 | map.put("20120430", true); // 休 26 | map.put("20120501", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2013.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2013 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20130101", true); // 休 11 | map.put("20130102", true); // 休 12 | map.put("20130103", true); // 休 13 | map.put("20130105", false); // 班 14 | map.put("20130106", false); // 班 15 | map.put("20130211", true); // 休 16 | map.put("20130212", true); // 休 17 | map.put("20130213", true); // 休 18 | map.put("20130214", true); // 休 19 | map.put("20130215", true); // 休 20 | map.put("20130216", false); // 班 21 | map.put("20130217", false); // 班 22 | map.put("20130404", true); // 休 23 | map.put("20130405", true); // 休 24 | map.put("20130407", false); // 班 25 | map.put("20130427", false); // 班 26 | map.put("20130428", false); // 班 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2014.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2014 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20140101", true); // 休 11 | map.put("20140126", false); // 班 12 | map.put("20140131", true); // 休 13 | map.put("20140203", true); // 休 14 | map.put("20140204", true); // 休 15 | map.put("20140205", true); // 休 16 | map.put("20140206", true); // 休 17 | map.put("20140208", false); // 班 18 | map.put("20140407", true); // 休 19 | map.put("20140501", true); // 休 20 | map.put("20140502", true); // 休 21 | map.put("20140504", false); // 班 22 | map.put("20140602", true); // 休 23 | map.put("20140908", true); // 休 24 | map.put("20140928", false); // 班 25 | map.put("20141001", true); // 休 26 | map.put("20141002", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2015.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2015 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20150101", true); // 休 11 | map.put("20150102", true); // 休 12 | map.put("20150104", false); // 班 13 | map.put("20150215", false); // 班 14 | map.put("20150218", true); // 休 15 | map.put("20150219", true); // 休 16 | map.put("20150220", true); // 休 17 | map.put("20150223", true); // 休 18 | map.put("20150224", true); // 休 19 | map.put("20150228", false); // 班 20 | map.put("20150406", true); // 休 21 | map.put("20150501", true); // 休 22 | map.put("20150622", true); // 休 23 | map.put("20150903", true); // 休 24 | map.put("20150904", true); // 休 25 | map.put("20150906", false); // 班 26 | map.put("20151001", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2016.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2016 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20160101", true); // 休 11 | map.put("20160206", false); // 班 12 | map.put("20160208", true); // 休 13 | map.put("20160209", true); // 休 14 | map.put("20160210", true); // 休 15 | map.put("20160211", true); // 休 16 | map.put("20160212", true); // 休 17 | map.put("20160214", false); // 班 18 | map.put("20160404", true); // 休 19 | map.put("20160502", true); // 休 20 | map.put("20160609", true); // 休 21 | map.put("20160610", true); // 休 22 | map.put("20160612", false); // 班 23 | map.put("20160915", true); // 休 24 | map.put("20160916", true); // 休 25 | map.put("20160918", false); // 班 26 | map.put("20161003", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2017.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2017 implements Year20xx { 7 | @Override 8 | public Map getYearMap() { 9 | Map map = new HashMap(); 10 | map.put("20170102", true); // 休 11 | map.put("20170122", false); // 班 12 | map.put("20170127", true); // 休 13 | map.put("20170130", true); // 休 14 | map.put("20170131", true); // 休 15 | map.put("20170201", true); // 休 16 | map.put("20170202", true); // 休 17 | map.put("20170204", false); // 班 18 | map.put("20170401", false); // 班 19 | map.put("20170403", true); // 休 20 | map.put("20170404", true); // 休 21 | map.put("20170501", true); // 休 22 | map.put("20170527", false); // 班 23 | map.put("20170529", true); // 休 24 | map.put("20170530", true); // 休 25 | map.put("20170930", false); // 班 26 | map.put("20171002", true); // 休 27 | return map; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2018.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2018 implements Year20xx { 7 | 8 | @Override 9 | public Map getYearMap() { 10 | Map map = new HashMap(); 11 | map.put("20180101", true); // 休 12 | map.put("20180211", false); // 班 13 | map.put("20180215", true); // 休 14 | map.put("20180216", true); // 休 15 | map.put("20180219", true); // 休 16 | map.put("20180220", true); // 休 17 | map.put("20180221", true); // 休 18 | map.put("20180224", false); // 班 19 | map.put("20180405", true); // 休 20 | map.put("20180406", true); // 休 21 | map.put("20180408", false); // 班 22 | map.put("20180428", false); // 班 23 | map.put("20180430", true); // 休 24 | map.put("20180501", true); // 休 25 | map.put("20180618", true); // 休 26 | map.put("20180924", true); // 休 27 | map.put("20180929", false); // 班 28 | map.put("20180930", false); // 班 29 | map.put("20181001", true); // 休 30 | map.put("20181002", true); // 休 31 | map.put("20181003", true); // 休 32 | map.put("20181004", true); // 休 33 | map.put("20181005", true); // 休 34 | map.put("20181229", false); // 班 35 | map.put("20181231", true); // 休 36 | return map; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2019.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2019 implements Year20xx { 7 | 8 | @Override 9 | public Map getYearMap() { 10 | Map map = new HashMap(); 11 | map.put("20190101", true); // 休 12 | map.put("20190202", false); // 班 13 | map.put("20190203", false); // 班 14 | map.put("20190204", true); // 休 15 | map.put("20190205", true); // 休 16 | map.put("20190206", true); // 休 17 | map.put("20190207", true); // 休 18 | map.put("20190208", true); // 休 19 | map.put("20190405", true); // 休 20 | map.put("20190428", false); // 班 21 | map.put("20190501", true); // 休 22 | map.put("20190502", true); // 休 23 | map.put("20190503", true); // 休 24 | map.put("20190505", false); // 班 25 | map.put("20190607", true); // 休 26 | map.put("20190913", true); // 休 27 | map.put("20190929", false); // 班 28 | map.put("20191001", true); // 休 29 | map.put("20191002", true); // 休 30 | map.put("20191003", true); // 休 31 | map.put("20191004", true); // 休 32 | map.put("20191007", true); // 休 33 | map.put("20191012", false); // 班 34 | return map; 35 | } 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year2020.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class Year2020 implements Year20xx { 7 | 8 | @Override 9 | public Map getYearMap() { 10 | Map map = new HashMap(); 11 | map.put("20200101", true); // 休 12 | map.put("20200119", false); // 班 13 | map.put("20200124", true); // 休 14 | map.put("20200127", true); // 休 15 | map.put("20200128", true); // 休 16 | map.put("20200129", true); // 休 17 | map.put("20200130", true); // 休 18 | map.put("20200131", true); // 休(+) 19 | // map.put("20200201", false); // 班 20 | map.put("20200406", true); // 休 21 | map.put("20200426", false); // 班 22 | map.put("20200501", true); // 休 23 | map.put("20200504", true); // 休 24 | map.put("20200505", true); // 休 25 | map.put("20200509", false); // 班 26 | map.put("20200625", true); // 休 27 | map.put("20200626", true); // 休 28 | map.put("20200628", false); // 班 29 | map.put("20200927", false); // 班 30 | map.put("20201001", true); // 休 31 | map.put("20201002", true); // 休 32 | map.put("20201005", true); // 休 33 | map.put("20201006", true); // 休 34 | map.put("20201007", true); // 休 35 | map.put("20201008", true); // 休 36 | map.put("20201010", false); // 班 37 | return map; 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/Year20xx.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.Map; 4 | 5 | public interface Year20xx { 6 | public Map getYearMap(); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/icework/presence/YearMap.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.icework.presence; 2 | 3 | import java.util.Map; 4 | 5 | public class YearMap { 6 | 7 | public static void main(String[] args) { 8 | int year = 2001; 9 | System.out.println(YearMap.yearMap(year)); 10 | } 11 | 12 | public static Map yearMap(int year) { 13 | Year20xx createMap = createMap(year); 14 | return createMap.getYearMap(); 15 | } 16 | 17 | private static Year20xx createMap(int year) { 18 | if (year == 2001) { 19 | return new Year2001(); 20 | } else if (year == 2002) { 21 | return new Year2002(); 22 | } else if (year == 2003) { 23 | return new Year2003(); 24 | } else if (year == 2004) { 25 | return new Year2004(); 26 | } else if (year == 2005) { 27 | return new Year2005(); 28 | } else if (year == 2006) { 29 | return new Year2006(); 30 | } else if (year == 2007) { 31 | return new Year2007(); 32 | } else if (year == 2008) { 33 | return new Year2008(); 34 | } else if (year == 2009) { 35 | return new Year2009(); 36 | } else if (year == 2010) { 37 | return new Year2010(); 38 | } else if (year == 2011) { 39 | return new Year2011(); 40 | } else if (year == 2012) { 41 | return new Year2012(); 42 | } else if (year == 2013) { 43 | return new Year2013(); 44 | } else if (year == 2014) { 45 | return new Year2014(); 46 | } else if (year == 2015) { 47 | return new Year2015(); 48 | } else if (year == 2016) { 49 | return new Year2016(); 50 | } else if (year == 2017) { 51 | return new Year2017(); 52 | } else if (year == 2018) { 53 | return new Year2018(); 54 | } else if (year == 2019) { 55 | return new Year2019(); 56 | } else if (year == 2020) { 57 | return new Year2020(); 58 | } 59 | return null; 60 | } 61 | 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/workday/Data.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.workday; 2 | 3 | public class Data { 4 | private int date; 5 | private boolean repose; 6 | 7 | public Data(int date, boolean repose) { 8 | this.date = date; 9 | this.repose = repose; 10 | } 11 | 12 | public int getDate() { 13 | return date; 14 | } 15 | 16 | public boolean getRepose() { 17 | return repose; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/workday/WorkUtils.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.workday; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.FileNotFoundException; 5 | import java.io.IOException; 6 | import java.io.InputStreamReader; 7 | import java.text.ParseException; 8 | import java.text.SimpleDateFormat; 9 | import java.util.ArrayList; 10 | import java.util.Calendar; 11 | import java.util.Date; 12 | import java.util.HashMap; 13 | import java.util.Map; 14 | import java.util.Set; 15 | import java.util.Map.Entry; 16 | 17 | import com.iceyyy.icework.presence.YearMap; 18 | import com.iceyyy.nongli.NongLi; 19 | /** 20 | * iceworkday工作日算法 21 | * @author IceWater zxcyhn@126.com 22 | */ 23 | public class WorkUtils { 24 | 25 | public static Map weekendMap(String year) { 26 | if (year == null || "".equals(year.trim())) { 27 | throw new RuntimeException("传入的参数为空"); 28 | } 29 | if (year.length() != 4) { 30 | throw new RuntimeException("传入的参数格式错误,应传入yyyyMMdd格式的日期"); 31 | } 32 | int yearNum = Integer.parseInt(year.substring(0, 4)); 33 | if (yearNum < 2001) { 34 | throw new RuntimeException("工作日计算年份需要大于等于2001"); 35 | } else if (yearNum > 2017) { 36 | Map mapFromFile = weekMapFromFile(); 37 | mapFromFile = filterMap(mapFromFile, yearNum); 38 | Map map = complexCalculate(yearNum); 39 | if (mapFromFile.size() != 0) { 40 | map.putAll(mapFromFile); 41 | } 42 | return map; 43 | } else { 44 | Map map = YearMap.yearMap(yearNum); 45 | return map; 46 | } 47 | } 48 | 49 | public static boolean isWorkendDay(String ymd) { 50 | if (ymd == null || "".equals(ymd)) { 51 | throw new RuntimeException("输入的日期不能为空"); 52 | } 53 | ymd = convertDate(ymd); 54 | if("19991230".equals(ymd)) { 55 | return true; 56 | } 57 | if("19991231".equals(ymd)) { 58 | return true; 59 | } 60 | String yearStr = ymd.substring(0, 4); 61 | Map weekendMap = weekendMap(yearStr); 62 | Boolean isWeekend = weekendMap.get(ymd); 63 | if (isWeekend == null) { 64 | int day = getWeekDay(ymd); 65 | if (day == 0 || day == 6) { 66 | return true; 67 | } else { 68 | return false; 69 | } 70 | } else { 71 | return isWeekend; 72 | } 73 | } 74 | 75 | private static String convertDate(String dateStr) { 76 | String[] array = null; 77 | if (dateStr.contains("-")) { 78 | array = dateStr.split("-"); 79 | } else if (dateStr.contains(".")) { 80 | array = dateStr.split("\\."); 81 | } else if (dateStr.contains("/")) { 82 | array = dateStr.split("/"); 83 | } else if (dateStr.contains("_")) { 84 | array = dateStr.split("_"); 85 | } else if (dateStr.contains("年")) { 86 | if (dateStr.endsWith("日")) { 87 | dateStr = dateStr.substring(0, dateStr.length() - 1); 88 | } 89 | array = dateStr.split("年|月"); 90 | } else { 91 | if (dateStr.length() == 8) { 92 | return dateStr; 93 | } 94 | } 95 | String yearStr = array[0]; 96 | String monthStr = array[1]; 97 | String dayStr = array[2]; 98 | StringBuilder sb = new StringBuilder(); 99 | for (int i = 0; i < 4 - yearStr.length(); i++) { 100 | sb.append("0"); 101 | } 102 | sb.append(yearStr); 103 | if (monthStr.length() == 1) { 104 | sb.append("0"); 105 | } 106 | sb.append(monthStr); 107 | if (dayStr.length() == 1) { 108 | sb.append("0"); 109 | } 110 | sb.append(dayStr); 111 | return sb.toString(); 112 | } 113 | 114 | private static Map complexCalculate(int yearNum) { 115 | Map map = new HashMap(); 116 | String newYear = "0101"; 117 | String chingming = "0405"; 118 | String labor = "0501"; 119 | String dragon = "0505L"; 120 | String autumn = "0815L"; 121 | Map newYearMap = gregorianNewYearMap(yearNum, newYear); 122 | Map nextYearMap = gregorianNewYearMap(yearNum + 1, newYear); 123 | map.putAll(currentYearMap(newYearMap, nextYearMap, yearNum)); 124 | map.putAll(festivalMap(yearNum, chingming)); 125 | map.putAll(newYearLunarMap(yearNum)); 126 | map.putAll(festivalMap(yearNum, labor)); 127 | map.putAll(festivalMap(yearNum, dragon)); 128 | map.putAll(nationalAutumnMap(yearNum, autumn)); 129 | return map; 130 | } 131 | 132 | private static Map nationalAutumnMap(int yearNum, String autumn) { 133 | Map map = new HashMap(); 134 | String ymd = yearNum + "0815";// 中秋节 135 | String ymdNational = yearNum + "1001";// 国庆节 136 | String ymdAutumn = convertGregorian(ymd); 137 | int day = getWeekDay(ymdNational); 138 | Map mapHistory = getHistoryMap(); 139 | String key = ymdAutumn.substring(4, 8) + "_" + day; 140 | if (mapHistory.get(key) != null) { 141 | // TODO 此处希望从近几年相似的月份中进行类比,是一种优化算法,暂未实现,但不影响算法使用。 142 | } 143 | String monthAutumn = ymdAutumn.substring(4, 6); 144 | String dateAutumn = ymdAutumn.substring(6, 8); 145 | int monthAutumnNum = Integer.parseInt(monthAutumn); 146 | int dateAutumnNum = Integer.parseInt(dateAutumn); 147 | if (dateAutumnNum < 25 && monthAutumnNum == 9) {// 中秋在9.25以前 148 | // 中秋最早9.7 最晚10.8 149 | map.putAll(festivalMap(yearNum, "0815L"));// 中秋 150 | map.putAll(nationalMap(yearNum));// 国庆 151 | } else if (monthAutumnNum == 10) {// 中秋节在10月份 152 | map.putAll(nationalOctMap(yearNum));// 国庆 153 | } else if (dateAutumnNum >= 25 && monthAutumnNum == 9) {// 中秋节在9.25 9.26 154 | // 9.27 9.28 155 | // 9.29 9.30 156 | // 1. 中秋 25 全部两段 周一~周日 157 | // 2. 中秋 26 全部两段 周二~周一 158 | // 3. 中秋 27 最复杂 周三~周二 159 | // 4. 中秋 28 全部休8天 周四~周三 160 | // 5. 中秋 29 全部休8天 周五~周四 161 | // 6. 中秋 30 全部休8天 周六~周五 162 | // 补班 最早 9.22 最迟 10.12 163 | int dayAutumn = getWeekDay(ymdAutumn); 164 | map.putAll(complexMap(yearNum, dateAutumnNum, dayAutumn));// 国庆 165 | } else { 166 | throw new RuntimeException("中秋日期格式错误"); 167 | } 168 | return map; 169 | } 170 | 171 | private static Map complexMap(int yearNum, int dateAutumnNum, int dayAutumn) { 172 | Data[][] table = getAutumnTable(dateAutumnNum); 173 | Data[] row = getRow(table, dateAutumnNum, dayAutumn); 174 | return row2map(row, yearNum); 175 | } 176 | 177 | private static Map row2map(Data[] row, int yearNum) { 178 | Map map = new HashMap(); 179 | for (int i = 0; i < row.length; i++) { 180 | Data data = row[i]; 181 | int date = data.getDate(); 182 | boolean repose = data.getRepose(); 183 | String monthStr = "10";// 10月份 184 | if (date > 15) { 185 | monthStr = "09";// 9月份 186 | } 187 | String dateStr = date + ""; 188 | if (date < 10) { 189 | dateStr = "0" + date; 190 | } 191 | String key = yearNum + monthStr + dateStr; 192 | map.put(key, repose); 193 | } 194 | return map; 195 | } 196 | 197 | /** 198 | * 根据中秋的星期获取具体的某一行的数据 199 | * 200 | * @param table 201 | * @param dayAutumn 202 | * @return 203 | */ 204 | private static Data[] getRow(Data[][] table, int dateAutumnNum, int dayAutumn) { 205 | // 25 1 [0] 206 | // 25 2 [1] 207 | // 25 3 [2] 208 | 209 | // 26 1 [6] 210 | // 26 2 [0] 211 | // 26 3 [1] 212 | // 26 4 [2] 213 | // date+index-23=day 214 | // index=day+23-date 215 | int index = (dayAutumn + 31 - dateAutumnNum) % 7; 216 | return table[index]; 217 | } 218 | 219 | private static Data[][] getAutumnTable(int dateAutumnNum) { 220 | Data[][] days1 = { 221 | { new Data(25, true), new Data(30, false), new Data(2, true), new Data(3, true), new Data(4, true), 222 | new Data(5, true), new Data(6, true), new Data(8, false) }, 223 | { new Data(22, false), new Data(24, true), new Data(25, true), new Data(29, false), new Data(30, false), 224 | new Data(1, true), new Data(2, true), new Data(3, true), new Data(4, true), new Data(5, true) }, 225 | { new Data(25, true), new Data(26, true), new Data(27, true), new Data(28, false), new Data(29, false), 226 | new Data(1, true), new Data(2, true), new Data(3, true), new Data(4, true), new Data(7, true), 227 | new Data(12, false) }, 228 | { new Data(21, false), new Data(25, true), new Data(26, true), new Data(28, false), new Data(1, true), 229 | new Data(2, true), new Data(3, true), new Data(6, true), new Data(7, true), 230 | new Data(11, false) }, 231 | { new Data(20, false), new Data(25, true), new Data(1, true), new Data(2, true), new Data(5, true), 232 | new Data(6, true), new Data(7, true), new Data(10, false) }, 233 | { new Data(27, true), new Data(1, true), new Data(4, true), new Data(5, true), new Data(6, true), 234 | new Data(7, true), new Data(9, false), new Data(10, false) }, 235 | { new Data(26, true), new Data(3, true), new Data(4, true), new Data(5, true), new Data(6, true), 236 | new Data(7, true), new Data(8, false), new Data(9, false) } }; 237 | Data[][] days2 = { 238 | { new Data(23, false), new Data(25, true), new Data(26, true), new Data(30, false), new Data(2, true), 239 | new Data(3, true), new Data(4, true), new Data(5, true), new Data(6, true), 240 | new Data(8, false) }, 241 | { new Data(23, false), new Data(26, true), new Data(27, true), new Data(28, true), new Data(29, false), 242 | new Data(30, false), new Data(1, true), new Data(2, true), new Data(3, true), new Data(4, true), 243 | new Data(5, true), new Data(13, false) }, 244 | { new Data(22, false), new Data(26, true), new Data(27, true), new Data(29, false), new Data(1, true), 245 | new Data(2, true), new Data(3, true), new Data(4, true), new Data(7, true) }, 246 | { new Data(21, false), new Data(26, true), new Data(1, true), new Data(2, true), new Data(3, true), 247 | new Data(6, true), new Data(7, true) }, 248 | { new Data(1, true), new Data(2, true), new Data(5, true), new Data(6, true), new Data(7, true), 249 | new Data(10, false) }, 250 | { new Data(1, true), new Data(4, true), new Data(5, true), new Data(6, true), new Data(7, true), 251 | new Data(9, false) }, 252 | { new Data(26, true), new Data(3, true), new Data(4, true), new Data(5, true), new Data(6, true), 253 | new Data(7, true), new Data(8, false), new Data(9, false) } }; 254 | Data[][] days3 = { 255 | { new Data(23, false), new Data(24, false), new Data(25, true), new Data(26, true), new Data(27, true), 256 | new Data(30, false), new Data(2, true), new Data(3, true), new Data(4, true), new Data(5, true), 257 | new Data(6, true), new Data(8, false) }, 258 | { new Data(27, true), new Data(28, true), new Data(1, true), new Data(2, true), new Data(3, true), 259 | new Data(4, true), new Data(6, false), new Data(7, false) }, 260 | { new Data(27, true), new Data(30, true), new Data(1, true), new Data(2, true), new Data(3, true), 261 | new Data(4, true), new Data(5, false), new Data(6, false) }, 262 | { new Data(1, true), new Data(2, true), new Data(3, true), new Data(6, true), new Data(7, true), 263 | new Data(11, false) }, 264 | { new Data(1, true), new Data(2, true), new Data(5, true), new Data(6, true), new Data(7, true), 265 | new Data(10, false) }, 266 | { new Data(27, true), new Data(1, true), new Data(4, true), new Data(5, true), new Data(6, true), 267 | new Data(7, true), new Data(9, false), new Data(10, false) }, 268 | { new Data(24, false), new Data(26, true), new Data(27, true), new Data(3, true), new Data(4, true), 269 | new Data(5, true), new Data(6, true), new Data(7, true), new Data(8, false), 270 | new Data(9, false) } }; 271 | Data[][] days4 = { 272 | { new Data(28, true), new Data(29, true), new Data(2, true), new Data(3, true), new Data(4, true), 273 | new Data(5, true), new Data(7, false), new Data(8, false) }, 274 | { new Data(28, true), new Data(1, true), new Data(2, true), new Data(3, true), new Data(4, true), 275 | new Data(5, true), new Data(6, false), new Data(7, false) }, 276 | { new Data(30, true), new Data(1, true), new Data(2, true), new Data(3, true), new Data(4, true), 277 | new Data(6, false) }, 278 | { new Data(27, false), new Data(29, true), new Data(30, true), new Data(1, true), new Data(2, true), 279 | new Data(3, true) }, 280 | { new Data(26, false), new Data(27, false), new Data(28, true), new Data(29, true), new Data(30, true), 281 | new Data(1, true), new Data(2, true), new Data(5, true) }, 282 | { new Data(25, false), new Data(26, false), new Data(28, true), new Data(29, true), new Data(30, true), 283 | new Data(1, true), new Data(4, true), new Data(5, true) }, 284 | { new Data(25, false), new Data(28, true), new Data(29, true), new Data(30, true), new Data(3, true), 285 | new Data(4, true), new Data(5, true), new Data(8, false) } }; 286 | Data[][] days5 = { 287 | { new Data(29, true), new Data(2, true), new Data(3, true), new Data(4, true), new Data(5, true), 288 | new Data(6, true), new Data(7, false), new Data(8, false) }, 289 | { new Data(1, true), new Data(2, true), new Data(3, true), new Data(4, true), new Data(5, true), 290 | new Data(7, false) }, 291 | { new Data(28, false), new Data(30, true), new Data(1, true), new Data(2, true), new Data(3, true), 292 | new Data(4, true) }, 293 | { new Data(27, false), new Data(28, false), new Data(29, true), new Data(30, true), new Data(1, true), 294 | new Data(2, true), new Data(3, true), new Data(6, true) }, 295 | { new Data(26, false), new Data(27, false), new Data(29, true), new Data(30, true), new Data(1, true), 296 | new Data(2, true), new Data(5, true), new Data(6, true) }, 297 | { new Data(26, false), new Data(29, true), new Data(30, true), new Data(1, true), new Data(4, true), 298 | new Data(5, true), new Data(6, true), new Data(9, false) }, 299 | { new Data(29, true), new Data(30, true), new Data(3, true), new Data(4, true), new Data(5, true), 300 | new Data(6, true), new Data(8, false), new Data(9, false) } }; 301 | Data[][] days6 = { 302 | { new Data(2, true), new Data(3, true), new Data(4, true), new Data(5, true), new Data(6, true), 303 | new Data(8, false) }, 304 | { new Data(29, false), new Data(1, true), new Data(2, true), new Data(3, true), new Data(4, true), 305 | new Data(5, true) }, 306 | { new Data(28, false), new Data(29, false), new Data(30, true), new Data(1, true), new Data(2, true), 307 | new Data(3, true), new Data(4, true), new Data(7, true) }, 308 | { new Data(27, false), new Data(28, false), new Data(30, true), new Data(1, true), new Data(2, true), 309 | new Data(3, true), new Data(6, true), new Data(7, true) }, 310 | { new Data(27, false), new Data(30, true), new Data(1, true), new Data(2, true), new Data(5, true), 311 | new Data(6, true), new Data(7, true), new Data(10, false) }, 312 | { new Data(30, true), new Data(1, true), new Data(4, true), new Data(5, true), new Data(6, true), 313 | new Data(7, true), new Data(9, false), new Data(10, false) }, 314 | { new Data(30, true), new Data(3, true), new Data(4, true), new Data(5, true), new Data(6, true), 315 | new Data(7, true), new Data(8, false), new Data(9, false) } }; 316 | if (dateAutumnNum == 25) { 317 | return days1; 318 | } else if (dateAutumnNum == 26) { 319 | return days2; 320 | } else if (dateAutumnNum == 27) { 321 | return days3; 322 | } else if (dateAutumnNum == 28) { 323 | return days4; 324 | } else if (dateAutumnNum == 29) { 325 | return days5; 326 | } else if (dateAutumnNum == 30) { 327 | return days6; 328 | } 329 | throw new RuntimeException("中秋日期格式错误"); 330 | } 331 | 332 | private static Map nationalOctMap(int yearNum) { 333 | String ymd = yearNum + "1001"; 334 | int day = getWeekDay(ymd); 335 | Map map = new HashMap(); 336 | int[][] correction = { { 30 }, { 29, 30 }, { 28, 29 }, { 28, 11 }, { 27, 10 }, { 9, 10 }, { 9 } }; 337 | for (int i = 0; i < correction[day].length; i++) { 338 | int corr = correction[day][i]; 339 | if (corr <= 15) { 340 | String key = yearNum + "10" + convertNum(corr); 341 | map.put(key, false); 342 | } else { 343 | String key = yearNum + "09" + convertNum(corr); 344 | map.put(key, false); 345 | } 346 | } 347 | int start = 0; 348 | if (day == 0 || day == 1) { 349 | start = -1; 350 | } 351 | int end = 0; 352 | if (day == 5) { 353 | end = 1; 354 | } 355 | for (int i = 0 + start; i < 8 + end; i++) {// 国庆节一般为7天 356 | String curDate = addDay(ymd, i); 357 | int curDay = getWeekDay(curDate); 358 | if (curDay > 0 && curDay < 6) { 359 | map.put(curDate, true); 360 | } 361 | } 362 | return map; 363 | } 364 | 365 | private static Map nationalMap(int yearNum) { 366 | String ymd = yearNum + "1001"; 367 | int day = getWeekDay(ymd); 368 | Map map = new HashMap(); 369 | int[][] correction = { { 30, 8 }, { 29, 14 }, { 29, 12 }, { 28, 11 }, { 10 }, { 26, 9 }, { 8, 9 } }; 370 | if (day > 0 && day < 6) { 371 | map.put(ymd, true); 372 | } 373 | for (int i = 0; i < correction[day].length; i++) { 374 | int corr = correction[day][i]; 375 | if (corr <= 15) { 376 | String key = yearNum + "10" + convertNum(corr); 377 | map.put(key, false); 378 | } else { 379 | String key = yearNum + "09" + convertNum(corr); 380 | map.put(key, false); 381 | } 382 | } 383 | for (int i = 0; i < 7; i++) {// 国庆节一般为7天 384 | String curDate = addDay(ymd, i); 385 | int curDay = getWeekDay(curDate); 386 | if (curDay > 0 && curDay < 6) { 387 | map.put(curDate, true); 388 | } 389 | } 390 | return map; 391 | } 392 | 393 | private static String convertNum(int num) { 394 | if (num < 10) { 395 | return "0" + num; 396 | } else { 397 | return num + ""; 398 | } 399 | } 400 | 401 | private static Map getHistoryMap() { 402 | Map map = new HashMap(); 403 | return map; 404 | } 405 | 406 | private static Map newYearLunarMap(int yearNum) { 407 | Map map = new HashMap(); 408 | String ymd = yearNum + "0101"; 409 | ymd = convertGregorian(ymd); 410 | int day = getWeekDay(ymd); 411 | int[][] correction = { { 6, 7 }, { -2, 6 }, { -3, 12 }, { -3, 10 }, { -4, 9 }, { -5, 8 }, { -6, 7 } }; 412 | int correct = -1; 413 | if (yearNum == 2014 || yearNum <= 2007) { 414 | correction = new int[][] { { 6, 7 }, { -2, 6 }, { -3, 12 }, { -3, 10 }, { -4, 9 }, { -5, 8 }, { -6, 7 } }; 415 | correct = 0; 416 | } 417 | for (int i = 0; i < correction[day].length; i++) { 418 | map.put(addDay(ymd, correction[day][i]), false); 419 | } 420 | for (int i = 0; i < 7; i++) { 421 | String curYmd = addDay(ymd, i + correct); 422 | int dayCur = getWeekDay(curYmd); 423 | if (dayCur > 0 && dayCur < 6) { 424 | map.put(curYmd, true); 425 | } 426 | } 427 | return map; 428 | } 429 | 430 | private static Map currentYearMap(Map newYearMap, 431 | Map nextYearMap, int yearNum) { 432 | String yearStr = yearNum + ""; 433 | Set setCur = newYearMap.keySet(); 434 | Set setNext = nextYearMap.keySet(); 435 | Map map = new HashMap(); 436 | for (String key : setCur) { 437 | if (key.startsWith(yearStr)) { 438 | map.put(key, newYearMap.get(key)); 439 | } 440 | } 441 | for (String key : setNext) { 442 | if (key.startsWith(yearStr)) { 443 | map.put(key, nextYearMap.get(key)); 444 | } 445 | } 446 | return map; 447 | } 448 | 449 | private static Map festivalMap(int yearNum, String festival) { 450 | String ymd = yearNum + festival; 451 | if (festival.endsWith("L")) { 452 | festival = festival.substring(0, festival.length() - 1); 453 | ymd = convertGregorian(ymd); 454 | } else if ("0405".equals(festival)) { 455 | ymd = chingming(yearNum); 456 | } 457 | return small(ymd); 458 | } 459 | 460 | private static Map gregorianNewYearMap(int yearNum, String festival) { 461 | String ymd = yearNum + festival; 462 | return gregorianNewYearSmall(ymd); 463 | } 464 | 465 | private static String chingming(int yearNum) { 466 | return yearNum + "040" + qing(yearNum); 467 | } 468 | 469 | /** 470 | * 计算清明节的日期(可计算范围: 1700-3100) 471 | * 472 | * @param year 473 | * 需要计算的年份 474 | * @return 清明节在公历中的日期 475 | */ 476 | private static int qing(int year) { 477 | if (year == 2232) { 478 | return 4; 479 | } 480 | if (year < 1700) { 481 | throw new RuntimeException("1700年以前暂时不支持"); 482 | } 483 | if (year >= 3100) { 484 | throw new RuntimeException("3100年以后暂时不支持"); 485 | } 486 | double[] coefficient = { 5.15, 5.37, 5.59, 4.82, 5.02, 5.26, 5.48, 4.70, 4.92, 5.135, 5.36, 4.60, 4.81, 5.04, 487 | 5.26 }; 488 | int mod = year % 100; 489 | return (int) (mod * 0.2422 + coefficient[year / 100 - 17] - mod / 4); 490 | } 491 | 492 | private static Map small(String ymd) { 493 | int day = getWeekDay(ymd); 494 | Map map = new HashMap(); 495 | int[][] correction = { { 1 }, {}, { -1, -3 }, { -1, -2, -3, -4 }, { 1, 3 }, {}, { 2 } }; 496 | // 6.取-1 2014年清明 2015年端午 6. 取2 2012年端午 497 | if (day > 0 && day < 6) { 498 | map.put(ymd, true); 499 | } 500 | if (day == 3) { 501 | map.put(addDay(ymd, -1), true); 502 | map.put(addDay(ymd, -2), true); 503 | map.put(addDay(ymd, -3), false); 504 | map.put(addDay(ymd, -4), false); 505 | } else { 506 | boolean flag = true; 507 | for (int i = 0; i < correction[day].length; i++) { 508 | map.put(addDay(ymd, correction[day][i]), flag); 509 | flag = false; 510 | } 511 | } 512 | return map; 513 | } 514 | 515 | private static Map gregorianNewYearSmall(String ymd) { 516 | int day = getWeekDay(ymd); 517 | Map map = new HashMap(); 518 | int[][] correction = { { 1 }, {}, { 1, 2, 4, 5 }, {}, { 1, 2, 3 }, {}, { 2 } }; 519 | // 6.取-1 2014年清明 2015年端午 6. 取2 2012年端午 0{+1}1{} 2{+1+2 +4b+5b} 3{} 520 | // 4{+1,+2,+3b}5{}6{+2} 521 | if (day > 0 && day < 6) { 522 | map.put(ymd, true); 523 | } 524 | if (day == 2) { 525 | map.put(addDay(ymd, 1), true); 526 | map.put(addDay(ymd, 2), true); 527 | map.put(addDay(ymd, 4), false); 528 | map.put(addDay(ymd, 5), false); 529 | } else if (day == 3) { 530 | 531 | } else if (day == 4) { 532 | map.put(addDay(ymd, 1), true); 533 | map.put(addDay(ymd, 3), false); 534 | } else { 535 | boolean flag = true; 536 | for (int i = 0; i < correction[day].length; i++) { 537 | map.put(addDay(ymd, correction[day][i]), flag); 538 | flag = false; 539 | } 540 | } 541 | return map; 542 | } 543 | 544 | private static int getWeekDay(String ymd) { 545 | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); 546 | Date date = null; 547 | try { 548 | date = sdf.parse(ymd); 549 | } catch (ParseException e) { 550 | e.printStackTrace(); 551 | } 552 | Calendar calendar = Calendar.getInstance(); 553 | calendar.setTime(date); 554 | int day = calendar.get(Calendar.DAY_OF_WEEK) - 1; 555 | return day; 556 | } 557 | 558 | private static String convertGregorian(String ymd) {// private 559 | String cnYmd = convertCnYmd(ymd); 560 | int start = 18; 561 | int len = 60;// 公历农历按最多相差60天计算。 562 | for (int i = start; i < start + len; i++) { 563 | String gregorianDate = addDay(ymd, i); 564 | String lunarDate = NongLi.getDate(gregorianDate); 565 | if (cnYmd.equals(lunarDate)) { 566 | return gregorianDate; 567 | } 568 | } 569 | return null; 570 | } 571 | 572 | private static String convertCnYmd(String ymd) {// private 573 | String numArray = "零一二三四五六七八九十"; 574 | String m = ymd.substring(4, 6); 575 | String d = ymd.substring(6, 8); 576 | int month = Integer.parseInt(m); 577 | int day = Integer.parseInt(d); 578 | String yearStr = ""; 579 | for (int i = 0; i < 4; i++) { 580 | yearStr += numArray.charAt(ymd.charAt(i) - '0') + ""; 581 | } 582 | yearStr += "年"; 583 | String monthStr = ""; 584 | if ("11".equals(m)) { 585 | monthStr = "冬"; 586 | } else if ("12".equals(m)) { 587 | monthStr = "腊"; 588 | } else if ("01".equals(m)) { 589 | monthStr = "正"; 590 | } else { 591 | monthStr = numArray.charAt(month) + ""; 592 | } 593 | monthStr += "月"; 594 | String dayStr = ""; 595 | if (day <= 10) { 596 | dayStr = "初" + numArray.charAt(day); 597 | } else if (day < 20) { 598 | dayStr = "十" + numArray.charAt(day - 10); 599 | } else if (day == 20) { 600 | dayStr = "二十"; 601 | } else if (day == 30) { 602 | dayStr = "三十"; 603 | } else { 604 | dayStr = "廿" + numArray.charAt(day - 20); 605 | } 606 | return yearStr + monthStr + dayStr; 607 | } 608 | 609 | private static String addDay(String date, int dayLength) { 610 | SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); 611 | Date dateSrc = null; 612 | try { 613 | dateSrc = sdf.parse(date); 614 | } catch (ParseException e) { 615 | e.printStackTrace(); 616 | } 617 | Calendar cal = Calendar.getInstance(); 618 | cal.setTime(dateSrc); 619 | cal.set(Calendar.DAY_OF_MONTH, cal.get(Calendar.DAY_OF_MONTH) + dayLength); 620 | return sdf.format(cal.getTime()); 621 | } 622 | 623 | private static String[] read(String fileName) { 624 | BufferedReader br = null; 625 | ArrayList list = new ArrayList(); 626 | 627 | try { 628 | br = new BufferedReader( 629 | new InputStreamReader(WorkUtils.class.getClassLoader().getResourceAsStream(fileName))); 630 | String every = null; 631 | while ((every = br.readLine()) != null) { 632 | if (!every.startsWith("#")) { 633 | list.add(every); 634 | } 635 | } 636 | String[] datas = new String[list.size()]; 637 | for (int i = 0; i < datas.length; i++) { 638 | datas[i] = list.get(i); 639 | } 640 | return datas; 641 | } catch (FileNotFoundException e) { 642 | e.printStackTrace(); 643 | } catch (IOException e) { 644 | e.printStackTrace(); 645 | } finally { 646 | if (br != null) { 647 | try { 648 | br.close(); 649 | } catch (IOException e) { 650 | e.printStackTrace(); 651 | } 652 | } 653 | } 654 | return null; 655 | } 656 | 657 | private static Map weekMapFromFile() { 658 | Map map = new HashMap(); 659 | String fileName = "iceweek.txt"; 660 | String[] lines = WorkUtils.read(fileName); 661 | for (String line : lines) { 662 | if (line == null || line.length() != 9) { 663 | continue; 664 | } 665 | String key = line.substring(0, 8); 666 | Boolean value = convertWork(line.substring(8)); 667 | map.put(key, value); 668 | } 669 | return map; 670 | } 671 | 672 | private static Boolean convertWork(String str) { 673 | if ("b".equals(str)) { 674 | return false; 675 | } else if ("x".equals(str)) { 676 | return true; 677 | } 678 | return null; 679 | } 680 | 681 | private static Map filterMap(Map map, int year) { 682 | String yearStr = year + ""; 683 | Map newMap = new HashMap(); 684 | Set> entrySet = map.entrySet(); 685 | for (Entry entry : entrySet) { 686 | String key = entry.getKey(); 687 | Boolean value = entry.getValue(); 688 | if (key != null && key.startsWith(yearStr)) { 689 | newMap.put(key, value); 690 | } 691 | } 692 | return newMap; 693 | } 694 | 695 | /** 696 | * 提示语 697 | * @return 提示语 698 | */ 699 | protected static String warn() { 700 | return "注意:该算法对于将来的时间仅是预测,并不能完全精确。"; 701 | } 702 | } 703 | -------------------------------------------------------------------------------- /src/main/java/com/iceyyy/workday/WorkdayGen.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.workday; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collections; 5 | import java.util.List; 6 | import java.util.Map; 7 | import java.util.Set; 8 | 9 | import com.iceyyy.workday.WorkUtils; 10 | 11 | public class WorkdayGen { 12 | 13 | public static void main(String[] args) { 14 | int year = 2021; 15 | String code = genYearCode(year); 16 | System.out.println(code); 17 | } 18 | 19 | protected static String gen(int year) { 20 | String yearStr = String.valueOf(year); 21 | Map weekendMap = WorkUtils.weekendMap(yearStr); 22 | Set keySet = weekendMap.keySet(); 23 | List list = new ArrayList<>(keySet); 24 | Collections.sort(list); 25 | StringBuilder sb = new StringBuilder(); 26 | for (String ymd : list) { 27 | boolean weekendDay = WorkUtils.isWorkendDay(ymd); 28 | String itemCode = genItemCode(ymd, weekendDay); 29 | sb.append(itemCode); 30 | } 31 | return sb.toString(); 32 | } 33 | 34 | private static String genItemCode(String ymd, boolean weekendDay) { 35 | StringBuilder sb = new StringBuilder(); 36 | String tab = " "; 37 | String nl = "\r\n"; 38 | sb.append(tab); 39 | sb.append("map.put(\""); 40 | sb.append(ymd); 41 | sb.append("\", "); 42 | sb.append(weekendDay); 43 | sb.append("); // "); 44 | sb.append(wordCode(weekendDay)); 45 | sb.append(nl); 46 | return sb.toString(); 47 | } 48 | 49 | private static String wordCode(boolean weekday) { 50 | if (weekday) { 51 | return "休"; 52 | } else { 53 | return "班"; 54 | } 55 | } 56 | 57 | private static String genYearCode(int year) { 58 | StringBuilder sb = new StringBuilder(); 59 | String nl = "\r\n"; 60 | sb.append("package com.iceyyy.icework.presence;" + nl); 61 | sb.append("" + nl); 62 | sb.append("import java.util.HashMap;" + nl); 63 | sb.append("import java.util.Map;" + nl); 64 | sb.append(""); 65 | sb.append("public class Year" + year + " implements Year20xx {" + nl); 66 | sb.append("" + nl); 67 | sb.append(" @Override" + nl); 68 | sb.append(" public Map getYearMap() {" + nl); 69 | sb.append(" Map map = new HashMap();" + nl); 70 | String gen = gen(year); 71 | sb.append(gen); 72 | sb.append(" return map;" + nl); 73 | sb.append(" }" + nl); 74 | sb.append("" + nl); 75 | sb.append("}" + nl); 76 | return sb.toString(); 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/main/resources/iceweek.txt: -------------------------------------------------------------------------------- 1 | # 2018年及以后的特例 2 | # 20170102x 3 | # 20170122b 4 | -------------------------------------------------------------------------------- /src/test/java/com/iceyyy/iceworkday/IceWorkTest.java: -------------------------------------------------------------------------------- 1 | package com.iceyyy.iceworkday; 2 | 3 | import org.junit.Test; 4 | 5 | import com.iceyyy.workday.WorkUtils; 6 | 7 | public class IceWorkTest { 8 | @Test 9 | public void test(){ 10 | System.out.println(WorkUtils.weekendMap("2013")); 11 | System.out.println(WorkUtils.isWorkendDay("20130205")); 12 | } 13 | 14 | } 15 | --------------------------------------------------------------------------------