chinese-workday
Version:
2 lines (1 loc) • 32.5 kB
JavaScript
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).chineseWorkday={})}(this,function(e){"use strict";const t=new class{constructor(e=1e3){this.cache=new Map,this.maxSize=e,this.hits=0,this.misses=0}get(e){const t=this.cache.get(e);if(void 0!==t)return this.hits++,this.cache.delete(e),this.cache.set(e,t),t;this.misses++}set(e,t){if(this.cache.has(e)&&this.cache.delete(e),this.cache.set(e,t),this.cache.size>this.maxSize){const e=this.cache.keys().next().value;this.cache.delete(e)}}getStats(){return{size:this.cache.size,maxSize:this.maxSize,hits:this.hits,misses:this.misses,hitRate:this.hits/(this.hits+this.misses)*100}}}(1e3);var n={"2011-01-01":"元旦","2011-01-02":"元旦","2011-01-03":"元旦","2011-02-02":"春节","2011-02-03":"春节","2011-02-04":"春节","2011-02-05":"春节","2011-02-06":"春节","2011-02-07":"春节","2011-02-08":"春节","2011-04-03":"清明节","2011-04-04":"清明节","2011-04-05":"清明节","2011-04-30":"劳动节","2011-05-01":"劳动节","2011-05-02":"劳动节","2011-06-04":"端午节","2011-06-05":"端午节","2011-06-06":"端午节","2011-09-10":"中秋节","2011-09-11":"中秋节","2011-09-12":"中秋节","2011-10-01":"国庆节","2011-10-02":"国庆节","2011-10-03":"国庆节","2011-10-04":"国庆节","2011-10-05":"国庆节","2011-10-06":"国庆节","2011-10-07":"国庆节","2012-01-01":"元旦","2012-01-02":"元旦","2012-01-03":"元旦","2012-01-22":"春节","2012-01-23":"春节","2012-01-24":"春节","2012-01-25":"春节","2012-01-26":"春节","2012-01-27":"春节","2012-01-28":"春节","2012-04-02":"清明节","2012-04-03":"清明节","2012-04-04":"清明节","2012-04-29":"劳动节","2012-04-30":"劳动节","2012-05-01":"劳动节","2012-06-22":"端午节","2012-06-23":"端午节","2012-06-24":"端午节","2012-09-30":"中秋节","2012-10-01":"国庆节","2012-10-02":"国庆节","2012-10-03":"国庆节","2012-10-04":"国庆节","2012-10-05":"国庆节","2012-10-06":"国庆节","2012-10-07":"国庆节","2012-10-08":"国庆节","2013-01-01":"元旦","2013-01-02":"元旦","2013-01-03":"元旦","2013-02-09":"春节","2013-02-10":"春节","2013-02-11":"春节","2013-02-12":"春节","2013-02-13":"春节","2013-02-14":"春节","2013-02-15":"春节","2013-04-04":"清明节","2013-04-05":"清明节","2013-04-06":"清明节","2013-04-29":"劳动节","2013-04-30":"劳动节","2013-05-01":"劳动节","2013-06-10":"端午节","2013-06-11":"端午节","2013-06-12":"端午节","2013-09-19":"中秋节","2013-09-20":"中秋节","2013-09-21":"中秋节","2013-10-01":"国庆节","2013-10-02":"国庆节","2013-10-03":"国庆节","2013-10-04":"国庆节","2013-10-05":"国庆节","2013-10-06":"国庆节","2013-10-07":"国庆节","2014-01-01":"元旦","2014-01-31":"春节","2014-02-01":"春节","2014-02-02":"春节","2014-02-03":"春节","2014-02-04":"春节","2014-02-05":"春节","2014-02-06":"春节","2014-04-05":"清明节","2014-04-06":"清明节","2014-04-07":"清明节","2014-05-01":"劳动节","2014-05-02":"劳动节","2014-05-03":"劳动节","2014-06-02":"端午节","2014-06-03":"端午节","2014-06-04":"端午节","2014-09-08":"中秋节","2014-09-09":"中秋节","2014-09-10":"中秋节","2014-10-01":"国庆节","2014-10-02":"国庆节","2014-10-03":"国庆节","2014-10-04":"国庆节","2014-10-05":"国庆节","2014-10-06":"国庆节","2014-10-07":"国庆节","2015-01-01":"元旦","2015-01-02":"元旦","2015-01-03":"元旦","2015-02-18":"春节","2015-02-19":"春节","2015-02-20":"春节","2015-02-21":"春节","2015-02-22":"春节","2015-02-23":"春节","2015-02-24":"春节","2015-04-04":"清明节","2015-04-05":"清明节","2015-04-06":"清明节","2015-05-01":"劳动节","2015-05-02":"劳动节","2015-05-03":"劳动节","2015-06-20":"端午节","2015-06-21":"端午节","2015-06-22":"端午节","2015-09-26":"中秋节","2015-09-27":"中秋节","2015-10-01":"国庆节","2015-10-02":"国庆节","2015-10-03":"国庆节","2015-10-04":"国庆节","2015-10-05":"国庆节","2015-10-06":"国庆节","2015-10-07":"国庆节","2016-01-01":"元旦","2016-01-02":"元旦","2016-01-03":"元旦","2016-02-07":"春节","2016-02-08":"春节","2016-02-09":"春节","2016-02-10":"春节","2016-02-11":"春节","2016-02-12":"春节","2016-02-13":"春节","2016-04-02":"清明节","2016-04-03":"清明节","2016-04-04":"清明节","2016-04-30":"劳动节","2016-05-01":"劳动节","2016-05-02":"劳动节","2016-06-09":"端午节","2016-06-10":"端午节","2016-06-11":"端午节","2016-09-15":"中秋节","2016-09-16":"中秋节","2016-09-17":"中秋节","2016-10-01":"国庆节","2016-10-02":"国庆节","2016-10-03":"国庆节","2016-10-04":"国庆节","2016-10-05":"国庆节","2016-10-06":"国庆节","2016-10-07":"国庆节","2017-01-01":"元旦","2017-01-02":"元旦","2017-01-27":"春节","2017-01-28":"春节","2017-01-29":"春节","2017-01-30":"春节","2017-01-31":"春节","2017-02-01":"春节","2017-02-02":"春节","2017-04-02":"清明节","2017-04-03":"清明节","2017-04-04":"清明节","2017-04-29":"劳动节","2017-04-30":"劳动节","2017-05-01":"劳动节","2017-05-28":"端午节","2017-05-29":"端午节","2017-05-30":"端午节","2017-10-01":"国庆节","2017-10-02":"国庆节","2017-10-03":"国庆节","2017-10-04":"国庆节","2017-10-05":"国庆节","2017-10-06":"国庆节","2017-10-07":"国庆节","2017-10-08":"国庆节","2018-02-15":"春节","2018-02-16":"春节","2018-02-17":"春节","2018-02-18":"春节","2018-02-19":"春节","2018-02-20":"春节","2018-02-21":"春节","2018-04-05":"清明节","2018-04-06":"清明节","2018-04-07":"清明节","2018-04-29":"劳动节","2018-04-30":"劳动节","2018-05-01":"劳动节","2018-06-18":"端午节","2018-09-24":"中秋节","2018-10-01":"国庆节","2018-10-02":"国庆节","2018-10-03":"国庆节","2018-10-04":"国庆节","2018-10-05":"国庆节","2018-10-06":"国庆节","2018-10-07":"国庆节","2018-12-30":"元旦","2018-12-31":"元旦","2019-01-01":"元旦","2019-02-04":"春节","2019-02-05":"春节","2019-02-06":"春节","2019-02-07":"春节","2019-02-08":"春节","2019-02-09":"春节","2019-02-10":"春节","2019-04-05":"清明节","2019-04-06":"清明节","2019-04-07":"清明节","2019-05-01":"劳动节","2019-05-02":"劳动节","2019-05-03":"劳动节","2019-05-04":"劳动节","2019-06-07":"端午节","2019-06-08":"端午节","2019-06-09":"端午节","2019-09-13":"中秋节","2019-09-14":"中秋节","2019-09-15":"中秋节","2019-10-01":"国庆节","2019-10-02":"国庆节","2019-10-03":"国庆节","2019-10-04":"国庆节","2019-10-05":"国庆节","2019-10-06":"国庆节","2019-10-07":"国庆节","2020-01-01":"元旦","2020-01-24":"春节","2020-01-25":"春节","2020-01-26":"春节","2020-01-27":"春节","2020-01-28":"春节","2020-01-29":"春节","2020-01-30":"春节","2020-04-04":"清明节","2020-04-05":"清明节","2020-04-06":"清明节","2020-05-01":"劳动节","2020-05-02":"劳动节","2020-05-03":"劳动节","2020-05-04":"劳动节","2020-05-05":"劳动节","2020-06-25":"端午节","2020-06-26":"端午节","2020-06-27":"端午节","2020-10-01":"国庆节","2020-10-02":"国庆节","2020-10-03":"国庆节","2020-10-04":"国庆节","2020-10-05":"国庆节","2020-10-06":"国庆节","2020-10-07":"国庆节","2020-10-08":"国庆节","2021-01-01":"元旦","2021-02-11":"春节","2021-02-12":"春节","2021-02-13":"春节","2021-02-14":"春节","2021-02-15":"春节","2021-02-16":"春节","2021-02-17":"春节","2021-04-03":"清明节","2021-04-04":"清明节","2021-04-05":"清明节","2021-05-01":"劳动节","2021-05-02":"劳动节","2021-05-03":"劳动节","2021-05-04":"劳动节","2021-05-05":"劳动节","2021-06-12":"端午节","2021-06-13":"端午节","2021-06-14":"端午节","2021-09-19":"中秋节","2021-09-20":"中秋节","2021-09-21":"中秋节","2021-10-01":"国庆节","2021-10-02":"国庆节","2021-10-03":"国庆节","2021-10-04":"国庆节","2021-10-05":"国庆节","2021-10-06":"国庆节","2021-10-07":"国庆节","2022-01-01":"元旦","2022-01-02":"元旦","2022-01-03":"元旦","2022-01-31":"春节","2022-02-01":"春节","2022-02-02":"春节","2022-02-03":"春节","2022-02-04":"春节","2022-02-05":"春节","2022-02-06":"春节","2022-04-03":"清明节","2022-04-04":"清明节","2022-04-05":"清明节","2022-04-30":"劳动节","2022-05-01":"劳动节","2022-05-02":"劳动节","2022-05-03":"劳动节","2022-05-04":"劳动节","2022-06-03":"端午节","2022-06-04":"端午节","2022-06-05":"端午节","2022-09-10":"中秋节","2022-09-11":"中秋节","2022-09-12":"中秋节","2022-10-01":"国庆节","2022-10-02":"国庆节","2022-10-03":"国庆节","2022-10-04":"国庆节","2022-10-05":"国庆节","2022-10-06":"国庆节","2022-10-07":"国庆节","2022-12-31":"元旦","2023-01-01":"元旦","2023-01-02":"元旦","2023-01-03":"元旦","2023-01-21":"春节","2023-01-22":"春节","2023-01-23":"春节","2023-01-24":"春节","2023-01-25":"春节","2023-01-26":"春节","2023-01-27":"春节","2023-04-05":"清明节","2023-04-29":"劳动节","2023-04-30":"劳动节","2023-05-01":"劳动节","2023-05-02":"劳动节","2023-05-03":"劳动节","2023-06-22":"端午节","2023-06-23":"端午节","2023-06-24":"端午节","2023-09-29":"中秋节","2023-09-30":"中秋节","2023-10-01":"国庆节","2023-10-02":"国庆节","2023-10-03":"国庆节","2023-10-04":"国庆节","2023-10-05":"国庆节","2023-10-06":"国庆节","2024-01-01":"元旦","2024-02-10":"春节","2024-02-11":"春节","2024-02-12":"春节","2024-02-13":"春节","2024-02-14":"春节","2024-02-15":"春节","2024-02-16":"春节","2024-02-17":"春节","2024-04-04":"清明节","2024-04-05":"清明节","2024-04-06":"清明节","2024-05-01":"劳动节","2024-05-02":"劳动节","2024-05-03":"劳动节","2024-05-04":"劳动节","2024-05-05":"劳动节","2024-06-10":"端午节","2024-09-15":"中秋节","2024-09-16":"中秋节","2024-09-17":"中秋节","2024-10-01":"国庆节","2024-10-02":"国庆节","2024-10-03":"国庆节","2024-10-04":"国庆节","2024-10-05":"国庆节","2024-10-06":"国庆节","2024-10-07":"国庆节","2025-01-01":"元旦","2025-01-28":"春节","2025-01-29":"春节","2025-01-30":"春节","2025-01-31":"春节","2025-02-01":"春节","2025-02-02":"春节","2025-02-03":"春节","2025-02-04":"春节","2025-04-04":"清明节","2025-04-05":"清明节","2025-04-06":"清明节","2025-05-01":"劳动节","2025-05-02":"劳动节","2025-05-03":"劳动节","2025-05-04":"劳动节","2025-05-05":"劳动节","2025-05-31":"端午节","2025-06-01":"端午节","2025-06-02":"端午节","2025-10-01":"国庆节","2025-10-02":"国庆节","2025-10-03":"国庆节","2025-10-04":"国庆节","2025-10-05":"国庆节","2025-10-06":"国庆节","2025-10-07":"国庆节","2025-10-08":"国庆节","2026-01-01":"元旦","2026-01-02":"元旦","2026-01-03":"元旦","2026-02-15":"春节","2026-02-16":"春节","2026-02-17":"春节","2026-02-18":"春节","2026-02-19":"春节","2026-02-20":"春节","2026-02-21":"春节","2026-02-22":"春节","2026-02-23":"春节","2026-04-04":"清明节","2026-04-05":"清明节","2026-04-06":"清明节","2026-05-01":"劳动节","2026-05-02":"劳动节","2026-05-03":"劳动节","2026-05-04":"劳动节","2026-05-05":"劳动节","2026-06-19":"端午节","2026-06-20":"端午节","2026-06-21":"端午节","2026-09-25":"中秋节","2026-09-26":"中秋节","2026-09-27":"中秋节","2026-10-01":"国庆节","2026-10-02":"国庆节","2026-10-03":"国庆节","2026-10-04":"国庆节","2026-10-05":"国庆节","2026-10-06":"国庆节","2026-10-07":"国庆节"},a={"2011-01-29":"补春节","2011-01-30":"补春节","2011-10-08":"补国庆节","2011-10-09":"补国庆节","2012-01-21":"补春节","2012-09-29":"补国庆节","2012-09-30":"补国庆节","2013-01-05":"补元旦","2013-01-06":"补元旦","2013-02-16":"补春节","2013-02-17":"补春节","2013-09-22":"补中秋国庆","2013-09-29":"补中秋国庆","2013-12-29":"补元旦","2014-01-26":"补春节","2014-02-08":"补春节","2014-05-04":"补劳动节","2014-09-28":"补国庆节","2015-01-04":"补元旦","2015-02-15":"补春节","2015-02-28":"补春节","2015-09-06":"补抗战胜利","2015-10-10":"补国庆节","2016-02-06":"补春节","2016-02-14":"补春节","2016-06-12":"补端午节","2016-09-18":"补中秋节","2016-10-08":"补国庆节","2016-10-09":"补国庆节","2017-01-22":"补春节","2017-02-04":"补春节","2017-04-01":"补清明节","2017-05-27":"补端午节","2017-09-30":"补国庆节","2018-02-11":"补春节","2018-02-24":"补春节","2018-04-08":"补清明节","2018-04-28":"补劳动节","2018-09-29":"补国庆节","2018-09-30":"补国庆节","2018-12-29":"补元旦","2019-02-02":"补春节","2019-02-03":"补春节","2019-04-28":"补劳动节","2019-05-05":"补劳动节","2019-09-29":"补国庆节","2019-10-12":"补国庆节","2020-01-19":"补春节","2020-02-01":"补春节","2020-04-26":"补劳动节","2020-05-09":"补劳动节","2020-06-28":"补端午节","2020-09-27":"补国庆节","2020-10-10":"补国庆节","2021-02-07":"补春节","2021-02-20":"补春节","2021-04-25":"补劳动节","2021-05-08":"补劳动节","2021-09-18":"补中秋节","2021-09-26":"补国庆节","2021-10-09":"补国庆节","2022-01-29":"补春节","2022-01-30":"补春节","2022-04-02":"补清明节","2022-04-24":"补劳动节","2022-05-07":"补劳动节","2022-10-08":"补国庆节","2022-10-09":"补国庆节","2023-01-28":"补春节","2023-01-29":"补春节","2023-04-23":"补劳动节","2023-05-06":"补劳动节","2023-06-25":"补端午节","2023-10-07":"补国庆节","2023-10-08":"补国庆节","2024-02-04":"补春节","2024-02-18":"补春节","2024-04-07":"补清明节","2024-04-28":"补劳动节","2024-05-11":"补劳动节","2024-09-14":"补中秋节","2024-09-29":"补国庆节","2024-10-12":"补国庆节","2025-01-26":"补春节","2025-02-08":"补春节","2025-04-27":"补劳动节","2025-09-28":"补国庆节","2025-10-11":"补国庆节","2026-01-04":"补元旦","2026-02-14":"补春节","2026-02-28":"补春节","2026-05-09":"补劳动节","2026-09-20":"补国庆节","2026-10-10":"补国庆节"};function r(e){if(void 0===e){const e=new Date,t=e.getFullYear(),n=e.getMonth()+1,a=e.getDate();return{date:`${t}-${n<10?"0":""}${n}-${a<10?"0":""}${a}`,weekends:!1}}if(e instanceof Date){const t=e.getFullYear(),n=e.getMonth()+1,a=e.getDate(),r=`${t}-${n<10?"0":""}${n}-${a<10?"0":""}${a}`,o=e.getDay();return{date:r,weekends:0===o||6===o}}if("number"==typeof e){const t=new Date(e),n=t.getFullYear(),a=t.getMonth()+1,r=t.getDate(),o=`${n}-${a<10?"0":""}${a}-${r<10?"0":""}${r}`,s=t.getDay();return{date:o,weekends:0===s||6===s}}if(e.includes("/")){const t=e.split("/");if(3===t.length){const e=parseInt(t[0]),n=parseInt(t[1])-1,a=parseInt(t[2]),r=new Date(e,n,a),o=r.getFullYear(),s=r.getMonth()+1,i=r.getDate(),d=`${o}-${s<10?"0":""}${s}-${i<10?"0":""}${i}`,u=r.getDay();return{date:d,weekends:0===u||6===u}}}const t=new Date(e);if(isNaN(t.getTime()))throw new Error(`Invalid date: ${e}`);const n=t.getFullYear(),a=t.getMonth()+1,r=t.getDate(),o=t.getDay();return{date:`${n}-${a<10?"0":""}${a}-${r<10?"0":""}${r}`,weekends:0===o||6===o}}function o(e){let o;if("string"==typeof e&&10===e.length&&"-"===e[4]&&"-"===e[7]){o=e;const r=t.get(o);if(r&&void 0!==r.isWorkday)return r.isWorkday;if(a[o])return t.set(o,{isWorkday:!0}),!0;if(n[o])return t.set(o,{isWorkday:!1}),!1;const s=new Date(o+"T00:00:00").getDay(),i=!(0===s||6===s);return t.set(o,{isWorkday:i}),i}const s=r(e);o=s.date;const i=t.get(o);if(i&&void 0!==i.isWorkday)return i.isWorkday;let d;return d=!!a[o]||!n[o]&&!s.weekends,t.set(o,{isWorkday:d}),d}function s(e){return!o(e)}function i(e){const t=r(e);return!!a[t.date]}function d(e){return console.warn("DEPRECATED: isAddtionalWorkday is deprecated. Please use isAdditionalWorkday instead."),i(e)}function u(e){if("string"==typeof e&&10===e.length&&"-"===e[4]&&"-"===e[7]){let r=t.get(e);if(r&&r.festival)return r.festival;let o=a[e];if(o)return t.set(e,{festival:o}),o;const s=n[e];if(s)return t.set(e,{festival:s}),s;const i=new Date(e+"T00:00:00").getDay(),d=0===i||6===i?"周末":"工作日";return t.set(e,{festival:d}),d}const o=r(e),s=t.get(o.date);if(s&&s.festival)return s.festival;let i;return i=a[o.date]?a[o.date]:n[o.date]?n[o.date]:o.weekends?"周末":"工作日",t.set(o.date,{festival:i}),i}function l(e,t){const n=new Date(e+"T00:00:00");n.setDate(n.getDate()+t);return`${n.getFullYear()}-${String(n.getMonth()+1).padStart(2,"0")}-${String(n.getDate()).padStart(2,"0")}`}function c(e){let t=r(e).date;for(let e=1;e<=7;e++){const n=l(t,e);if(o(n))return n}return null}function f(e){let t=r(e).date;for(let e=1;e<=14;e++){const n=l(t,-e);if(o(n))return n}return null}function g(e,t){const n=r(e).date,a=r(t).date;if(n>a)return 0;let s=0,i=n;for(;i<=a;)o(i)&&s++,i=l(i,1);return s}const y={2011:"2011-02-03",2012:"2012-01-23",2013:"2013-02-10",2014:"2014-01-31",2015:"2015-02-19",2016:"2016-02-08",2017:"2017-01-28",2018:"2018-02-16",2019:"2019-02-05",2020:"2020-01-25",2021:"2021-02-12",2022:"2022-02-01",2023:"2023-01-22",2024:"2024-02-10",2025:"2025-01-29",2026:"2026-02-17"},h=new Map,D=[29,30],p={1:"正月",2:"二月",3:"三月",4:"四月",5:"五月",6:"六月",7:"七月",8:"八月",9:"九月",10:"十月",11:"冬月",12:"腊月"},w={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:"三十"},m={"1-1":"春节","1-15":"元宵节","5-5":"端午节","8-15":"中秋节","9-9":"重阳节","12-8":"腊八节","12-23":"小年"};function k(e){const t=r(e),n=t.date;if(h.has(n))return h.get(n);const a=parseInt(n.split("-")[0]);let o=null,s=0,i=null;for(let e=a;e>=a-1;e--){if(i=y[e],!i)continue;const t=new Date(i+"T00:00:00"),a=new Date(n+"T00:00:00").getTime()-t.getTime();if(s=Math.floor(a/864e5),s>=0){o=e;break}}if(null===o){const e={date:n,lunarYear:null,lunarMonth:null,lunarDay:null,lunarString:"",lunarFestival:"",dayOfWeek:t.weekends?"周末":"工作日"};return h.set(n,e),e}let d=s,u=1,l=1;for(;d>=D[(u-1)%2];)d-=D[(u-1)%2],u++,u>12&&(u=1,o++);l=d+1;const c={date:n,lunarYear:o,lunarMonth:u,lunarDay:l,lunarString:(p[u]||`${u}月`)+(w[l]||`${l}`),lunarFestival:m[`${u}-${l}`]||"",dayOfWeek:t.weekends?"周末":"工作日"};return h.set(n,c),c}function S(e,t){const n=r(e).date;if(0===t)return o(n)?n:c(n);let a=n,s=Math.abs(t);if(t>0)for(;s>0;){if(a=c(a),!a)return null;s--}else for(;s>0;){if(a=f(a),!a)return null;s--}return a}function $(e){if("number"!=typeof e||e<2011||e>2026)throw new Error("Year must be between 2011 and 2026");const t=String(e),a=`${t}-12-31`;let r=0,s=0,i=0,u=0,l=0,c={},f=`${t}-01-01`;for(;f<=a;){if(r++,o(f))s++,d(f)&&l++;else if(n[f]){i++;const e=n[f];c[e]=(c[e]||0)+1}else u++;const e=new Date(f+"T00:00:00");e.setDate(e.getDate()+1);f=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}return{year:e,totalDays:r,workdays:s,holidays:i,weekends:u,additionalWorkdays:l,workdayPercentage:parseFloat((s/r*100).toFixed(2)),holidayDistribution:c}}function v(e){let t=r(e).date;const a=new Date(t+"T00:00:00");for(let e=0;e<365;e++){a.setDate(a.getDate()+1);if(t=`${a.getFullYear()}-${String(a.getMonth()+1).padStart(2,"0")}-${String(a.getDate()).padStart(2,"0")}`,n[t])return{date:t,festival:n[t],daysUntil:e+1}}return null}let W={};function b(e,n="default"){const a=W[n];if(!a)return o(e);const s=r(e).date,i=`custom_${n}_${s}`,d=t.get(i);if(d&&void 0!==d.isWorkday)return d.isWorkday;if(a.workdaysOnWeekends.includes(s))return t.set(i,{isWorkday:!0}),!0;if(a.holidays.includes(s))return t.set(i,{isWorkday:!1}),!1;const u=new Date(s+"T00:00:00").getDay(),l=a.workdays.includes(u);return t.set(i,{isWorkday:l}),l}function T(e,t){const n=r(e).date,a=r(t).date,o=new Date(n+"T00:00:00"),s=new Date(a+"T00:00:00").getTime()-o.getTime();return Math.abs(Math.floor(s/864e5))+1}let F={};function M(e,t,n={}){const{startDay:a=1,includeFestival:r=!0,includeLunar:s=!1}=n,i=new Date(e,t-1,1),d=new Date(e,t,0).getDate(),l=(i.getDay()-a+7)%7,c=[];let f=[];const g=new Date(e,t-1,0).getDate();for(let n=0;n<l;n++){const a=g-l+n+1,i=1===t?12:t-1,d=1===t?e-1:e,c=`${d}-${String(i).padStart(2,"0")}-${String(a).padStart(2,"0")}`,y={year:d,month:i,date:a,dayType:"prevMonth",isWorkday:o(c),dateStr:c};if(r&&(y.festival=u(c)),s){const e=k(c);y.lunar=e.lunarString}f.push(y)}for(let n=1;n<=d;n++){const a=`${e}-${String(t).padStart(2,"0")}-${String(n).padStart(2,"0")}`,i={year:e,month:t,date:n,dayType:"currentMonth",isWorkday:o(a),dateStr:a};if(r&&(i.festival=u(a)),s){const e=k(a);i.lunar=e.lunarString}f.push(i),7===f.length&&(c.push(f),f=[])}const y=7-f.length;for(let n=0;n<y;n++){const a=n+1,i=12===t?1:t+1,d=12===t?e+1:e,l=`${d}-${String(i).padStart(2,"0")}-${String(a).padStart(2,"0")}`,c={year:d,month:i,date:a,dayType:"nextMonth",isWorkday:o(l),dateStr:l};if(r&&(c.festival=u(l)),s){const e=k(l);c.lunar=e.lunarString}f.push(c)}return f.length>0&&c.push(f),c}function E(e,t="Asia/Shanghai"){let n;if("string"==typeof e){if(/^\d{4}-\d{2}-\d{2}$/.test(e)){const[a,r,s]=e.split("-").map(Number);n=new Date(Date.UTC(a,r-1,s));const i=new Date(n.toLocaleString("en-US",{timeZone:t})),d=i.getFullYear(),u=i.getMonth()+1,l=i.getDate();return o(`${d}-${String(u).padStart(2,"0")}-${String(l).padStart(2,"0")}`)}n=new Date(e)}else if(e instanceof Date)n=e;else{if("number"!=typeof e)throw new Error("Invalid date format");n=new Date(e)}const a={timeZone:t,year:"numeric",month:"2-digit",day:"2-digit"},r=new Intl.DateTimeFormat("en-CA",a),[s,i,d]=r.format(n).split("-");return o(`${s}-${i}-${d}`)}let Y={},C={};function x(e,t,n){if("function"!=typeof t)throw new Error("Callback must be a function");const a=r(n).date;if(!o(a))throw new Error(`Target date ${a} is not a workday`);const s=new Date(a+"T00:00:00"),i=new Date,d=s.getTime()-i.getTime();return C[e]&&clearTimeout(C[e]),Y[e]={callback:t,scheduledDate:a,type:"specific_workday"},d>0?C[e]=setTimeout(()=>{t(a),delete Y[e],delete C[e]},d):(t(a),delete Y[e],delete C[e]),e}e.addLeaveDays=function(e,t,n){const a=F[e];if(!a)return{success:!1,message:"User not found",remainingBalance:null};if(a.hasOwnProperty(t))return a[t]=(a[t]||0)+n,{success:!0,message:`${n} days added to ${t} leave`,remainingBalance:{...a}};if("custom"===t&&"object"==typeof n){for(const[e,t]of Object.entries(n))a.custom[e]=(a.custom[e]||0)+t;return{success:!0,message:"Custom leave days added",remainingBalance:{...a}}}return"number"==typeof n&&t.startsWith("custom_")?(a.custom[t.substring(7)]=(a.custom[t.substring(7)]||0)+n,{success:!0,message:`${n} days added to custom ${t.substring(7)} leave`,remainingBalance:{...a}}):{success:!1,message:`Unknown leave type: ${t}`,remainingBalance:a}},e.addWorkdays=S,e.applyLeave=function(e,t,n,a,r=!0){const o=F[e];if(!o)return{success:!1,message:"User not found",remainingBalance:null};let s;return s=r?g(n,a):T(n,a),"custom"===t?{success:!1,message:"For custom leave, specify the exact custom type",remainingBalance:o}:o.hasOwnProperty(t)?o[t]<s?{success:!1,message:`Insufficient ${t} leave balance`,remainingBalance:o}:(o[t]-=s,{success:!0,message:`${s} days of ${t} leave applied successfully`,leaveDays:s,remainingBalance:{...o}}):{success:!1,message:`Unknown leave type: ${t}`,remainingBalance:o}},e.calculateActualWorkdays=function(e,t,n=[]){const a=g(e,t);let o=0;for(const a of n)if(a.approved){const n=r(a.startDate).date,s=r(a.endDate).date,i=r(e).date,d=r(t).date,u=n>i?n:i,l=s<d?s:d;u<=l&&(o+=g(u,l))}return Math.max(0,a-o)},e.calculateWorkHours=function(e,t,n=8){return g(e,t)*n},e.cancelScheduledEvent=function(e){return!!C[e]&&(clearTimeout(C[e]),delete C[e],delete Y[e],!0)},e.clearCache=function(){t.cache.clear(),t.hits=0,t.misses=0},e.clearWorkSchedule=function(e){delete W[e]},e.convertTimezoneAndCheckWorkday=function(e,t,n,a=!0){let s;if("string"==typeof e)if(/^\d{4}-\d{2}-\d{2}$/.test(e)){const[t,n,a]=e.split("-").map(Number);s=new Date(t,n-1,a,12,0,0)}else s=new Date(e);else if(e instanceof Date)s=e;else{if("number"!=typeof e)throw new Error("Invalid date format");s=new Date(e)}const i={timeZone:t,year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hour12:!1},d=new Intl.DateTimeFormat("en-CA",i).formatToParts(s);let u,l,c,f,g,y;for(const e of d)switch(e.type){case"year":u=e.value;break;case"month":l=e.value;break;case"day":c=e.value;break;case"hour":f=e.value;break;case"minute":g=e.value;break;case"second":y=e.value}const h=new Date(`${u}-${l}-${c}T${f}:${g}:${y}`),D=new Date(h.toLocaleString("en-US",{timeZone:n})),p=D.getFullYear(),w=D.getMonth()+1,m=D.getDate(),k=`${p}-${String(w).padStart(2,"0")}-${String(m).padStart(2,"0")}`;return{originalDate:r(e).date,convertedDate:k,isWorkdayInChina:a?o(k):void 0,fromTimezone:t,toTimezone:n}},e.countWorkdays=g,e.daysUntilHoliday=function(e){const t=v(e);return t?t.daysUntil:-1},e.generateCalendar=M,e.generateCompactCalendar=function(e,t){const a=M(e,t);let r=0,o=0,s=0;for(const e of a)for(const t of e)"currentMonth"===t.dayType&&(t.isWorkday?r++:n[t.dateStr]?o++:s++);return{year:e,month:t,calendar:a,stats:{workdays:r,holidays:o,weekends:s,total:r+o+s}}},e.getAllScheduledEvents=function(){const e=[];for(const[t,n]of Object.entries(Y))e.push({eventId:t,...n});return e},e.getAnnualStats=$,e.getAvailableSchedules=function(){return Object.keys(W)},e.getCacheStats=function(){return t.getStats()},e.getConsecutiveHolidays=function(e){const t=r(e).date;if(!n[t])return 0;let a=1,s=t;const i=new Date(s+"T00:00:00");for(;;){i.setDate(i.getDate()+1);if(s=`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,"0")}-${String(i.getDate()).padStart(2,"0")}`,!n[s]&&(o(s)||d(s)))break;a++}return a},e.getDaysInMonth=function(e,t,a="workdays"){const r=[],s=new Date(e,t,0).getDate();for(let i=1;i<=s;i++){const s=`${e}-${String(t).padStart(2,"0")}-${String(i).padStart(2,"0")}`;let d=!1;d="workdays"===a?o(s):"holidays"===a?!o(s)&&n[s]:"weekends"!==a||!o(s)&&!n[s],d&&r.push(s)}return r},e.getFestival=u,e.getFestivalBatch=function(e){return e.map(e=>"string"==typeof e&&10===e.length&&"-"===e[4]&&"-"===e[7]?e:r(e).date).map(e=>{const r=t.get(e);if(r&&r.festival)return r.festival;let o;if(a[e])o=a[e];else if(n[e])o=n[e];else{const t=new Date(e+"T00:00:00").getDay();o=0===t||6===t?"周末":"工作日"}return t.set(e,{festival:o}),o})},e.getHolidaysByFestival=function(e,t){const a=r(e).date,o=r(t).date;if(a>o)throw new Error("Start date must be before end date");const s={};let i=a;for(;i<=o;){const e=n[i];e&&(s[e]||(s[e]=[]),s[e].push(i));const t=new Date(i+"T00:00:00");t.setDate(t.getDate()+1);i=`${t.getFullYear()}-${String(t.getMonth()+1).padStart(2,"0")}-${String(t.getDate()).padStart(2,"0")}`}return s},e.getHolidaysInRange=function(e,t){const n=r(e).date,a=r(t).date;if(n>a)return[];const o=[];let s=n;for(;s<=a;){const e=u(s);"工作日"!==e&&"周末"!==e&&o.push({date:s,festival:e}),s=l(s,1)}return o},e.getLeaveBalance=function(e){return F[e]||null},e.getLunarInfo=k,e.getMonthRange=function(e){const t=r(e).date.split("-"),n=parseInt(t[0]),a=parseInt(t[1])-1,o=new Date(n,a,1),s=new Date(n,a+1,0);return{startDate:`${o.getFullYear()}-${String(o.getMonth()+1).padStart(2,"0")}-${String(o.getDate()).padStart(2,"0")}`,endDate:`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}-${String(s.getDate()).padStart(2,"0")}`}},e.getMonthlyStats=function(e,t){if("number"!=typeof e||e<2011||e>2026)throw new Error("Year must be between 2011 and 2026");if("number"!=typeof t||t<1||t>12)throw new Error("Month must be between 1 and 12");const a=String(e)+"-"+String(t).padStart(2,"0"),r=a+"-01",s=new Date(e,t,0).getDate(),i=a+"-"+String(s).padStart(2,"0");let u=0,l=0,c=0,f=0,g=0,y=r;for(;y<=i;){u++,o(y)?(l++,d(y)&&g++):n[y]?c++:f++;const e=new Date(y+"T00:00:00");e.setDate(e.getDate()+1);y=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}return{year:e,month:t,totalDays:u,workdays:l,holidays:c,weekends:f,additionalWorkdays:g,workdayPercentage:parseFloat((l/u*100).toFixed(2))}},e.getMostCommonHoliday=function(e){const t=$(e);if(!t||!t.holidayDistribution)return null;let n=null,a=0;for(const[e,r]of Object.entries(t.holidayDistribution))r>a&&(a=r,n={festival:e,count:r});return n},e.getNextHoliday=v,e.getScheduledEvent=function(e){return Y[e]||null},e.getTotalDays=T,e.getWeekRange=function(e,t=1){const n=r(e),a=new Date(n.date+"T00:00:00"),o=(a.getDay()-t+7)%7,s=new Date(a);s.setDate(a.getDate()-o);const i=new Date(s);return i.setDate(s.getDate()+6),{startDate:`${s.getFullYear()}-${String(s.getMonth()+1).padStart(2,"0")}-${String(s.getDate()).padStart(2,"0")}`,endDate:`${i.getFullYear()}-${String(i.getMonth()+1).padStart(2,"0")}-${String(i.getDate()).padStart(2,"0")}`}},e.getWorkSchedule=function(e){return W[e]||null},e.getWorkdayInMultipleTimezones=function(e,t){const n={};for(const a of t)n[a]=E(e,a);return n},e.getWorkdayRatio=function(e,t){const a=r(e).date,s=r(t).date;if(a>s)throw new Error("Start date must be before end date");let i=0,u=0,l=0,c=0,f=0,g=a;for(;g<=s;){i++,o(g)?(u++,d(g)&&f++):n[g]?l++:c++;const e=new Date(g+"T00:00:00");e.setDate(e.getDate()+1);g=`${e.getFullYear()}-${String(e.getMonth()+1).padStart(2,"0")}-${String(e.getDate()).padStart(2,"0")}`}return{startDate:a,endDate:s,totalDays:i,workdays:u,holidays:l,weekends:c,additionalWorkdays:f,workdayCount:u,workdayPercentage:parseFloat((u/i*100).toFixed(2)),holidayPercentage:parseFloat((l/i*100).toFixed(2)),weekendPercentage:parseFloat((c/i*100).toFixed(2))}},e.getWorkdaySequence=function(e,t,n=1){const a=r(e).date,s=r(t).date;if(a>s)return[];const i=[];let d=o(a)?a:c(a);for(;d&&d<=s&&(i.push(d),d=S(d,n),d&&!(d>s)););return i},e.getWorkdaysInRange=function(e,t){const n=r(e).date,a=r(t).date;if(n>a)return[];const s=[];let i=n;for(;i<=a;)o(i)&&s.push(i),i=l(i,1);return s},e.getWorkdaysInterval=function(e,t){const n=r(e).date,a=r(t).date;if(n===a)return 0;if(new Date(n+"T00:00:00")>new Date(a+"T00:00:00")){let e=0,t=f(n);for(;t&&t>=a;)e++,t=f(t);return e}{let e=0,t=c(n);for(;t&&t<=a;)e++,t=c(t);return e}},e.isAdditionalWorkday=i,e.isAddtionalWorkday=d,e.isHoliday=s,e.isHolidayApproaching=function(e,t=1){const a=r(e).date,o=new Date(a+"T00:00:00");for(let e=1;e<=t;e++){o.setDate(o.getDate()+1);const e=o.getFullYear(),t=String(o.getMonth()+1).padStart(2,"0"),a=String(o.getDate()).padStart(2,"0");if(n[`${e}-${t}-${a}`])return!0}return!1},e.isHolidayBatch=function(e){return e.map(e=>s(e))},e.isHolidayCustom=function(e,t="default"){return!b(e,t)},e.isWeekend=function(e){return r(e).weekends},e.isWithinOfficeHours=function(e,t={}){e instanceof Date||(e=new Date(e));const{startHour:n=9,endHour:a=18,startDay:s=1,endDay:i=5}=t,d=e.getDay(),u=e.getHours();return!(d<s||d>i)&&(!!o(r(e).date)&&!(u<n||u>=a))},e.isWorkday=o,e.isWorkdayBatch=function(e){return e.map(e=>"string"==typeof e&&10===e.length&&"-"===e[4]&&"-"===e[7]?e:r(e).date).map(e=>{const r=t.get(e);if(r&&void 0!==r.isWorkday)return r.isWorkday;let o;if(a[e])o=!0;else if(n[e])o=!1;else{const t=new Date(e+"T00:00:00").getDay();o=!(0===t||6===t)}return t.set(e,{isWorkday:o}),o})},e.isWorkdayCustom=b,e.isWorkdayInTimezone=E,e.nextWorkday=c,e.previousWorkday=f,e.scheduleEventAfterWorkdays=function(e,t,n,a){if("function"!=typeof t)throw new Error("Callback must be a function");if("number"!=typeof n||n<1)throw new Error("Workdays must be a positive number");const o=a?r(a).date:r(new Date).date,s=S(o,n);if(!s)throw new Error(`Could not calculate a date ${n} workdays from ${o}`);return x(e,t,s)},e.scheduleEventNextWorkday=function(e,t,n){if("function"!=typeof t)throw new Error("Callback must be a function");const a=c(n?r(n).date:r(new Date).date);if(!a)throw new Error("Could not find next workday within reasonable range");const o=new Date(a+"T00:00:00"),s=new Date,i=o.getTime()-s.getTime();return C[e]&&clearTimeout(C[e]),Y[e]={callback:t,scheduledDate:a,type:"next_workday"},i>0?C[e]=setTimeout(()=>{t(a),delete Y[e],delete C[e]},i):(t(a),delete Y[e],delete C[e]),e},e.scheduleEventOnWorkday=x,e.setLeaveBalance=function(e,t){F[e]={annual:0,sick:0,personal:0,marriage:0,maternity:0,paternity:0,custom:{},...t}},e.setWorkSchedule=function(e,t){W[e]={workdays:[1,2,3,4,5],holidays:[],workdaysOnWeekends:[],...t}}});