当前位置:网站首页>Use the code cloud publicholiday project to determine whether a day is a working day
Use the code cloud publicholiday project to determine whether a day is a working day
2022-06-30 05:19:00 【God__ is__ a__ girl】
Use code cloud PublicHoliday project Get information about national holidays , And then reuse it hutool Tools and methods to determine whether it is weekend , So as to judge whether a day is a working day
Code
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 {
// test
public static void main(String[] args) {
System.out.println(" Judge a non working day : " + isWorkDay("2022-06-03"));
System.out.println(" Judge a non working day : " + isWorkDay("2022-06-05"));
System.out.println(" Judge a working day : " + isWorkDay("2022-06-06"));
System.out.println(" Judge a working day : " + isWorkDay("2022-05-07"));
System.out.println(" The holiday season : " + HolidayInfoOfYear);
}
private static Map<String, String> HolidayInfoOfYear = new HashMap<>();
private static List<Integer> Years = new ArrayList<>();
/** * Get national holiday information */
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);
}
/** * according to http://timor.tech/api/holiday/ * 1, 2, 3 => Over the weekend 、 festival 、 Compensatory leave * 1 It means weekend , But because of the holidays , I still need to go to work * 2 It means holidays , rest * 3 It's not a weekend , But it's a holiday , rest */
return val.equals("1");
}
}
Running results

边栏推荐
- Unity3d learning notes-1 (C # learning)
- [note] usage model tree of the unity resource tree structure virtualizingtreeview
- Operation file file class method
- Detailed explanation of sorting sort method of JS array
- Unity gets the resolution of the game view
- Some problems encountered in unity steamvr
- Under what conditions does the Z-index attribute expire?
- Ripple effect of mouse click (unity & shader)
- Unity project hosting platform plasticscm (learn to use 1)
- 虚析构和纯虚析构
猜你喜欢

Baiwen.com 7 days Internet of things smart home learning experience punch in the third day

pytorch中常用损失函数总结

Intellj idea jars projects containing external lib to other project reference methods - jars

Unity ugui text value suspended enlarged display add text background

Unityshader learning notes - Basic Attributes
![[notes] unity Scrollview button page turning](/img/c7/47c4056871d0212ac61524539f0d0e.jpg)
[notes] unity Scrollview button page turning

网络变压器怎么判断好坏?网络滤波变压器坏了一般是什么症状?

RedisTemplate 常用方法汇总
![[typescript] cannot redeclare block range variables](/img/52/2fd3071ca9e3c5023c6b65961e2cf7.jpg)
[typescript] cannot redeclare block range variables

Rotation, translation and scaling of unity VR objects
随机推荐
Some problems encountered in unity steamvr
Tensorflow2 of ubantu18.04 X installation
Revit Secondary Development - - Project use Panel features not opened
Force buckle 977 Square of ordered array
Responsive layout
QT connecting external libraries
Unity determines whether the UI is clicked
Sourcetree usage
Untiy3d controls scene screenshots through external JSON files
Unity publishing /build settings
Unity profiler performance analysis
Basic operations of Oracle data
Unityshader learning notes - Basic Attributes
Fifty years ago, the go code first submitted by the inventor of Hello world was as long as this
[typescript] experimentaldecorators of vscode stepping pit
Bessel curve with n control points
Unity dotween plug-in description
2021-06-17 solve the problem of QML borderless window stretching, window jitter and flicker when stretching and shrinking
Introduction to mmcv common APIs
mmcv常用API介绍