当前位置:网站首页>使用码云PublicHoliday项目判断某天是否为工作日
使用码云PublicHoliday项目判断某天是否为工作日
2022-06-30 05:11:00 【God__is__a__girl】
使用码云PublicHoliday项目获取国家法定假日的信息,然后再利用hutool工具方法判断是否为周末,从而判断某天是否为工作日
代码
package com.xxx.datasql.util;
import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.StrUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/** * @Author: yren * @Date: 2022/6/21 */
public class HolidayUtils {
// 测试
public static void main(String[] args) {
System.out.println("判断一个非工作日: " + isWorkDay("2022-06-03"));
System.out.println("判断一个非工作日: " + isWorkDay("2022-06-05"));
System.out.println("判断一个工作日: " + isWorkDay("2022-06-06"));
System.out.println("判断一个工作日: " + isWorkDay("2022-05-07"));
System.out.println("节假日: " + HolidayInfoOfYear);
}
private static Map<String, String> HolidayInfoOfYear = new HashMap<>();
private static List<Integer> Years = new ArrayList<>();
/** * 获取国家的节假日信息 */
private synchronized static Map<String, String> getHolidayInfoOfYear(Integer year) {
if (Years.contains(year)) {
return HolidayInfoOfYear;
}
try {
RestTemplate restTemplate = new RestTemplate();
String url = "https://gitee.com/holate/public-holiday/raw/master/holidays/year/" + year + ".json";
ResponseEntity<String> responseEntity = restTemplate.getForEntity(url, String.class);
String body = responseEntity.getBody();
JSONObject jsonObject = JSON.parseObject(body);
jsonObject.getJSONObject("holiday").forEach((k, v) -> HolidayInfoOfYear.put(year + k.replace("-", ""), MapUtil.getStr((Map) v, "wage")));
} catch (Exception ex) {
ex.printStackTrace();
}
Years.add(year);
return HolidayInfoOfYear;
}
public static boolean isWorkDay(String dateTime) {
return isWorkDay(DateUtil.parse(dateTime));
}
public static boolean isWorkDay(DateTime dateTime) {
Map<String, String> holidayInfoOfYear = getHolidayInfoOfYear(dateTime.year());
String val = holidayInfoOfYear.get(dateTime.toString(DatePattern.PURE_DATE_PATTERN));
if (StrUtil.isBlank(val)) {
return !DateUtil.isWeekend(dateTime);
}
/** * 根据 http://timor.tech/api/holiday/ * 1, 2, 3 => 周末、节日、调休 * 1 代表是周末,但是因为放节假日,还需要上班 * 2 代表是节假日,休息 * 3 代表不是周末,但是是节假日调休,休息 */
return val.equals("1");
}
}
运行结果

边栏推荐
- Unity publishing /build settings
- C # uses monopinvokecallback to directly call back C # function
- The difference between SVG and canvas
- Unity 3D model operation and UI conflict Scrollview
- Does the tester need to analyze the cause of the bug?
- QT connecting external libraries
- C # three ways to obtain web page content
- Unity animator does not clip animation to play animation in segments
- Solution to 293 problems in the week of Li Kou
- Oracle-数据的基本操作
猜你喜欢

One command to run rancher

Connect() and disconnect() of socket in C #

mmcv常用API介绍
![[vcs+verdi joint simulation] ~ take the counter as an example](/img/fb/214a4e65c53503ecbc38a5e43523cf.png)
[vcs+verdi joint simulation] ~ take the counter as an example

Ripple effect of mouse click (unity & shader)

Unity Logitech steering wheel access

力扣59. 螺旋矩阵 II

Unity- the camera follows the player

Records of problems encountered in unity + hololens development

East Tower attack and defense world - XSS bypasses the safety dog
随机推荐
Unity obtains serial port data
中文版PyCharm改为英文版PyCharm
MinGW-w64下载文件失败the file has been downloaded incorrectly!
Singleton mode in unity
Four methods of unity ugui button binding events
Unity 3D model operation and UI conflict Scrollview
Parkour demo
Virtual and pure virtual destructions
Nestjs入门和环境搭建
Unity- the camera follows the player
Nestjs configures static resources, template engine, and post examples
Unity mobile end sliding screen rotation
Database base (Study & review for self use)
003-JS-DOM-Attr-innerText
Another download address for typro
Special folders in unity3d and their meanings
Unity2019.3.8f1 development environment configuration of hololens2
Unity animator does not clip animation to play animation in segments
[notes] unity Scrollview button page turning
很紧张,第一天做软件测试,需要做什么?