├── .gitignore ├── static ├── image │ ├── icon-time.png │ └── icon-format.png └── style │ └── index.css ├── src ├── module │ ├── tool.js │ ├── config │ │ ├── base.js │ │ └── holiday.js │ ├── animal.js │ ├── zodiac.js │ ├── solar.js │ ├── ganzhi.js │ ├── date.js │ ├── term.js │ ├── lunar.js │ └── festival.js ├── calendar.js ├── style │ └── widget.css └── widget-calendar.js ├── babel.config.js ├── LICENSE ├── readme.md ├── rollup.config.mjs ├── package.json ├── dist ├── calendar.min.mjs ├── calendar.min.js └── widget-calendar.min.js └── index.html /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .settings 3 | 4 | node_modules/* 5 | 6 | /node_modules 7 | -------------------------------------------------------------------------------- /static/image/icon-time.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumuy/calendar/HEAD/static/image/icon-time.png -------------------------------------------------------------------------------- /static/image/icon-format.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mumuy/calendar/HEAD/static/image/icon-format.png -------------------------------------------------------------------------------- /src/module/tool.js: -------------------------------------------------------------------------------- 1 | // 格式化日期字符串 2 | export function getDateString(...param){ 3 | return param.map(value=>(''+value).padStart(2,'0')).join('-'); 4 | } 5 | -------------------------------------------------------------------------------- /src/module/config/base.js: -------------------------------------------------------------------------------- 1 | // 农历有效期范围 2 | export const minYear = 1900; 3 | export const minMonth = 1; 4 | export const minDay = 30; 5 | export const maxYear = 2100; 6 | export const maxMonth = 12; 7 | export const maxDay = 31; 8 | -------------------------------------------------------------------------------- /babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: [ 3 | '@babel/preset-env' 4 | ], 5 | plugins: [ 6 | '@babel/plugin-transform-runtime', 7 | '@babel/plugin-transform-class-properties', 8 | [ 9 | '@babel/plugin-syntax-import-attributes', 10 | { 11 | "deprecatedAssertSyntax": true 12 | } 13 | ] 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /src/module/animal.js: -------------------------------------------------------------------------------- 1 | import {getTimestampBySolar} from './solar.js'; 2 | import {getLunarByTimestamp} from './lunar.js'; 3 | 4 | // 12生肖 5 | const animalMap = ['鼠','牛','虎','兔','龙','蛇','马','羊','猴','鸡','狗','猪']; 6 | 7 | // 获取生肖纪年: 1984年为鼠年 8 | export function getAnimalYear(sYear, sMonth, sDay){ 9 | let timestamp = getTimestampBySolar(sYear, sMonth, sDay); 10 | let { lYear } = getLunarByTimestamp(timestamp); 11 | const index = lYear - 1984; 12 | const animal = index%12; 13 | return animalMap[animal>-1?animal:animal+12]; 14 | } 15 | -------------------------------------------------------------------------------- /src/module/zodiac.js: -------------------------------------------------------------------------------- 1 | import {getDateString} from './tool.js'; 2 | 3 | const zodiacMap = ['水瓶','双鱼','白羊','金牛','双子','巨蟹','狮子','处女','天秤','天蝎','射手','摩羯']; 4 | const zodiacDate = [20,19,21,20,21,22,23,23,23,24,23,22]; 5 | 6 | // 获取星座 7 | export function getZodiac(sMonth,sDay){ 8 | let zoIndex = 11; 9 | zodiacDate.forEach(function(day,index){ 10 | let month = index+1; 11 | if(getDateString(sMonth,sDay)>=getDateString(month,day)){ 12 | zoIndex = index%12; 13 | } 14 | }); 15 | return zodiacMap[zoIndex]+'座'; 16 | } 17 | -------------------------------------------------------------------------------- /src/calendar.js: -------------------------------------------------------------------------------- 1 | import {getDateInfo} from './module/date.js'; 2 | import {getTimestampBySolar} from './module/solar.js'; 3 | import {getTimestampByLunar} from './module/lunar.js'; 4 | 5 | export default { 6 | getDateBySolar:function(sYear,sMonth,sDay){ 7 | let timestamp = getTimestampBySolar(sYear,sMonth,sDay); 8 | return timestamp?getDateInfo(timestamp):null; 9 | }, 10 | getDateByLunar:function(lYear,lMonth,lDay,isLeap){ 11 | let timestamp = getTimestampByLunar(lYear,lMonth,lDay,isLeap); 12 | return timestamp?getDateInfo(timestamp):null; 13 | }, 14 | getDateByTimestamp:function(timestamp){ 15 | return getDateInfo(timestamp); 16 | }, 17 | getToday:function(){ 18 | return getDateInfo(Date.now()); 19 | } 20 | }; 21 | -------------------------------------------------------------------------------- /src/module/solar.js: -------------------------------------------------------------------------------- 1 | import {getDateString} from './tool.js'; 2 | 3 | // 星期 4 | const weekMap = ['日','一','二','三','四','五','六']; 5 | 6 | // 公历日期转时间戳 7 | export function getTimestampBySolar(sYear,sMonth,sDay){ 8 | return Date.UTC(sYear, sMonth-1, sDay, 0, 0, 0); 9 | } 10 | 11 | // 通过时间戳获取日期 12 | export function getSolarByTimestamp(timestamp){ 13 | let now = new Date(timestamp); 14 | let week = now.getDay(); 15 | let item = { 16 | sYear:now.getFullYear(), 17 | sMonth:now.getMonth()+1, 18 | sDay:now.getDate(), 19 | week:week, 20 | weekZH:'星期'+weekMap[week] 21 | }; 22 | item['date'] = getDateString(item['sYear'],item['sMonth'],item['sDay']); 23 | return item; 24 | } 25 | 26 | // 获取公历一个月天数 27 | export function getSolarMonthDays(sYear,sMonth){ 28 | return new Date(sYear,sMonth,0).getDate(); 29 | } -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2022 PASSER-BY 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # 中国农历公历换算算法 2 | 3 | ## 参考标准 4 | 5 | 算法根据《中华人民共和国国家标准GB/T33661—2017〈农历的编算和颁行〉》标准开发,明确了干支纪年和生肖纪年起于正月初一0点,与农历新年同步。 6 | 7 | ## 网页组件 8 | ```html 9 | 10 | ``` 11 | 12 | ```html 13 | 14 |
15 |

双鱼座

16 |
17 |
18 | ``` 19 | 20 | #### 自定义事件-选中日期: onSelect 21 | 22 | ```js 23 | document.querySelector('widget-calendar').addEventListener('onSelect',function(event){ 24 | } 25 | ``` 26 | 27 | #### 自定义事件-切换日期: onChange 28 | 29 | ```js 30 | document.querySelector('widget-calendar').addEventListener('onChange',function(event){ 31 | } 32 | ``` 33 | 34 | #### 自定义事件-初始化: onInit 35 | 36 | ```js 37 | document.querySelector('widget-calendar').addEventListener('onInit',function(event){ 38 | } 39 | ``` 40 | 41 | ## 方法调用 42 | 43 | ```js 44 | // 农历日期: 2023年闰二月初十 45 | calendar.getDateByLunar(2023,2,10,true); 46 | 47 | // 公历日期:2022年10月1日 48 | calendar.getDateBySolar(2022,10,1); 49 | 50 | // 今天 51 | calendar.getToday(); 52 | ``` 53 | 54 | ## 返回结果 55 | 56 | ```js 57 | { 58 | "date":'2022-10-01', 59 | "sYear":2022, 60 | "sMonth":10, 61 | "sDay":1, 62 | "lYear":2022, 63 | "lMonth":9, 64 | "lDay":6, 65 | "isLeap":false, 66 | "lMonthZH":"九月", 67 | "lDayZH":"初六", 68 | "gzYearZH":"壬寅", 69 | "gzMonthZH":"己酉", 70 | "gzDayZH":"丁亥", 71 | "week":6, 72 | "weekZH":"星期六", 73 | "animal":"虎", 74 | "term":"", 75 | "zodiac":"天秤座", 76 | "festival":"国庆节" 77 | } 78 | ``` 79 | -------------------------------------------------------------------------------- /src/module/ganzhi.js: -------------------------------------------------------------------------------- 1 | import {getDateString} from './tool.js'; 2 | import {getTimestampBySolar} from './solar.js'; 3 | import {getLunarByTimestamp} from './lunar.js'; 4 | import {getTermDate} from './term.js'; 5 | 6 | // 天干 7 | const ganList = ['甲','乙','丙','丁','戊','己','庚','辛','壬','癸']; 8 | // 地支 9 | const zhiList = ['子','丑','寅','卯','辰','巳','午','未','申','酉','戌','亥']; 10 | 11 | function getGanZhiByIndex(gzIndex){ 12 | gzIndex = gzIndex%60; 13 | if(gzIndex<0){ 14 | gzIndex += 60; 15 | } 16 | let gan = gzIndex%10; 17 | let zhi = gzIndex%12; 18 | return ganList[gan]+zhiList[zhi]; 19 | } 20 | 21 | // 获取干支年: 1984年为甲子年 22 | export function getGanZhiYear(sYear, sMonth, sDay){ 23 | let timestamp = getTimestampBySolar(sYear, sMonth, sDay); 24 | let { lYear } = getLunarByTimestamp(timestamp); 25 | let gzIndex = lYear - 1984; 26 | return getGanZhiByIndex(gzIndex); 27 | } 28 | 29 | // 获取干支月 30 | export function getGanZhiMonth(sYear,sMonth,sDay){ 31 | let result = ''; 32 | const termDate = getTermDate(sYear); 33 | if(termDate){ 34 | let gzIndex = 0; 35 | termDate.push(31); 36 | termDate.forEach(function(day,index){ 37 | let month = Math.floor(index/2)+1; 38 | if(getDateString(sMonth,sDay)>=getDateString(month,day)){ 39 | gzIndex = month; 40 | } 41 | }); 42 | gzIndex += (sYear-1984)*12; 43 | result = getGanZhiByIndex(gzIndex); 44 | } 45 | return result; 46 | } 47 | 48 | // 获取干支日 49 | export function getGanZhiDay(sYear,sMonth,sDay){ 50 | let offset = Math.round((getTimestampBySolar(sYear, sMonth, sDay) -getTimestampBySolar(1900, 1, 30))/86400000); 51 | let gzIndex = offset+39; 52 | return getGanZhiByIndex(gzIndex); 53 | } 54 | -------------------------------------------------------------------------------- /rollup.config.mjs: -------------------------------------------------------------------------------- 1 | import resolve from '@rollup/plugin-node-resolve'; // 使用node_modules包 2 | import terser from '@rollup/plugin-terser'; // 代码压缩 3 | import babel from '@rollup/plugin-babel'; // ECMAScript兼容 4 | import {importAssertionsPlugin} from 'rollup-plugin-import-assert'; 5 | import pkg from './package.json' with { type:'json' }; // 获取package信息 6 | 7 | // 版权信息 8 | const repository = pkg.repository.url.replace(/(.+)(:\/\/.+)\.git$/,'https$2'); 9 | const now = new Date(); 10 | const date = (new Date(now.getTime()-now.getTimezoneOffset()*60000)).toISOString().substring(0,10); 11 | const banner = `/*! 12 | * ${pkg.name} v${pkg.version} 13 | * ${pkg.description} 14 | * ${pkg.homepage} 15 | * 16 | * Copyright (c) 2022-present, ${pkg.author} 17 | * 18 | * Released under the ${pkg.license} License 19 | * ${repository} 20 | * 21 | * Created on: ${date} 22 | */`; 23 | 24 | const commonPlugins = [ 25 | resolve(), 26 | importAssertionsPlugin(), 27 | terser(), 28 | babel({ 29 | babelHelpers: 'runtime', 30 | exclude:'node_modules/**' 31 | }) 32 | ]; 33 | 34 | export default [{ 35 | input: './src/calendar.js', 36 | output:[{ 37 | file: pkg.main, 38 | format: 'umd', 39 | name: 'calendar', 40 | banner 41 | },{ 42 | file: pkg.module, 43 | format: 'es', 44 | banner 45 | }], 46 | plugins: commonPlugins, 47 | watch: { 48 | exclude: 'node_modules/**' 49 | } 50 | },{ 51 | input: './src/widget-calendar.js', 52 | output:[{ 53 | file: './dist/widget-calendar.min.js', 54 | format: 'umd', 55 | banner 56 | }], 57 | plugins: commonPlugins, 58 | watch: { 59 | exclude: 'node_modules/**' 60 | } 61 | }]; 62 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "calendar-tool", 3 | "version": "1.0.3", 4 | "description": "Chinese lunar calendar", 5 | "author": "HaoLe Zheng", 6 | "license": "MIT", 7 | "keywords": [ 8 | "万年历", 9 | "阴阳历", 10 | "农历" 11 | ], 12 | "main": "./dist/calendar.min.js", 13 | "module": "./dist/calendar.min.mjs", 14 | "exports": { 15 | ".":{ 16 | "default": "./dist/calendar.min.js", 17 | "import": "./dist/calendar.min.mjs" 18 | }, 19 | "./widget-calendar": { 20 | "default": "./dist/widget-calendar.min.js", 21 | "import": "./dist/widget-calendar.min.js" 22 | } 23 | }, 24 | "repository": { 25 | "type": "git", 26 | "url": "git+https://github.com/mumuy/calendar.git" 27 | }, 28 | "bugs": { 29 | "url": "https://github.com/mumuy/calendar/issues" 30 | }, 31 | "engines": { 32 | "node": ">=20", 33 | "yarn": "please-use-npm", 34 | "npm": ">=8" 35 | }, 36 | "files": [ 37 | "dist" 38 | ], 39 | "devDependencies": { 40 | "@babel/core": "^7.26.0", 41 | "@babel/plugin-syntax-import-attributes": "^7.26.0", 42 | "@babel/plugin-transform-class-properties": "^7.25.9", 43 | "@babel/plugin-transform-runtime": "^7.25.9", 44 | "@babel/preset-env": "^7.26.0", 45 | "@babel/runtime": "^7.26.0", 46 | "@rollup/plugin-babel": "^6.0.4", 47 | "@rollup/plugin-node-resolve": "^15.3.0", 48 | "@rollup/plugin-terser": "^0.4.4", 49 | "rollup": "^3.29.5", 50 | "rollup-plugin-import-assert": "^3.0.1" 51 | }, 52 | "scripts": { 53 | "build": "rollup -c", 54 | "watch": "rollup -wc" 55 | }, 56 | "homepage": "https://passer-by.com/calendar/", 57 | "directories": {} 58 | } 59 | -------------------------------------------------------------------------------- /src/module/date.js: -------------------------------------------------------------------------------- 1 | import {getSolarByTimestamp} from './solar.js'; 2 | import {getLunarByTimestamp} from './lunar.js'; 3 | import {getTerm} from './term.js'; 4 | import {getGanZhiYear,getGanZhiMonth,getGanZhiDay} from './ganzhi.js'; 5 | import {getZodiac} from './zodiac.js'; 6 | import {getAnimalYear} from './animal.js'; 7 | import {getFestivalsBySolar,getFestivalsByLunar,getTermFestivalsBySolar} from './festival.js'; 8 | 9 | // 获取指定日期的数据 10 | export function getDateInfo(timestamp){ 11 | const solar = getSolarByTimestamp(timestamp); 12 | const lunar = getLunarByTimestamp(timestamp); 13 | return Object.assign( 14 | { 15 | lYear:null, 16 | lMonth:null, 17 | lDay:null, 18 | isLeap:false, 19 | lMonthZH:'', 20 | lDayZH:'', 21 | }, 22 | solar, 23 | lunar||{}, 24 | { 25 | zodiac:getZodiac(solar['sMonth'],solar['sDay']), // 星座 26 | term:getTerm(solar['sYear'],solar['sMonth'],solar['sDay']), // 节气 27 | animal:getAnimalYear(solar['sYear'],solar['sMonth'],solar['sDay']), // 生肖 28 | gzYearZH:getGanZhiYear(solar['sYear'],solar['sMonth'],solar['sDay']), // 干支年 29 | gzMonthZH:getGanZhiMonth(solar['sYear'],solar['sMonth'],solar['sDay']), // 干支月 30 | gzDayZH:getGanZhiDay(solar['sYear'],solar['sMonth'],solar['sDay']), // 干支日 31 | festival:[].concat( 32 | getFestivalsBySolar(solar['sYear'],solar['sMonth'],solar['sDay']), // 公历节日 33 | getTermFestivalsBySolar(solar['sYear'],solar['sMonth'],solar['sDay']), // 节气相关节日 34 | lunar?getFestivalsByLunar(lunar['lYear'],lunar['lMonth'],lunar['lDay']):[] // 农历节日 35 | ).join(' ') 36 | } 37 | ); 38 | } 39 | -------------------------------------------------------------------------------- /src/module/term.js: -------------------------------------------------------------------------------- 1 | import {minYear,maxYear} from './config/base.js'; 2 | 3 | // 24节气最小日期 4 | const termMinDate = [4, 19, 3, 18, 4, 19, 4, 19, 4, 20, 4, 20, 6, 22, 6, 22, 6, 22, 7, 22, 6, 21, 6, 21]; 5 | // 24节气日期数据压缩:日期减去最小日期,差值视为4进制,再转32进制 6 | const termData = [ 7 | '4lkmd5j6l5','55kql9lal9','59lanalala','5avbnatqla','7akmd5j6l5','55kql9lal9','59lalalala','5avbnatqla','7akmd5j6l5','55kql9lal9', 8 | '59lalalala','5avbnatqla','7akmd5j6l5','4lkql9lal9','55kqlalala','5ananalqla','5akmd5j5kl','4lkqd9l6l5','55kqlalal9','5ananalqla', 9 | '5akmd5j5kl','4lkmd9l6l5','55kqlalal9','59lanalqla','5akmd5j5kl','4lkmd9l6l5','55kql9lal9','59lanalala','5akmclj5al','4lkmd5j6l5', 10 | '55kql9lal9','59lanalala','5akmclj5al','4lkmd5j6l5','55kql9lal9','59lalalala','5akmclj5al','4lkmd5j6l5','55kql9lal9','59lalalala', 11 | '5akmclj5al','4lkmd5j6l5','55kql9lal9','59lalalala','5aklclj5al','4lkmd5j5kl','4lkql9l6l9','55kqlalala','5aclclb5al','2lkmd5j5kl', 12 | '4lkmd9l6l9','55kqlalala','5aclclb5al','2lkmd5j5kl','4lkmd9l6l5','55kql9lal9','5aalclb5al','2lkmd5j5kl','4lkmd5j6l5','55kql9lal9', 13 | '59alclalal','2lkmclj5al','4lkmd5j6l5','55kql9lal9','59alclalal','2lkmclj5al','4lkmd5j6l5','55kql9lal9','59alalalal','2lkmclj5al', 14 | '4lkmd5j6l5','55kql9lal9','59alalalal','2lklclj5al','4lkmd5j6l5','55kql9l6l9','59a5alalal','2lklclb5al','4lkmd5j5l5','55kqd9l6l9', 15 | '59a5alalal','2lklclb5al','4lkmd5j5kl','4lkmd9l6l9','55a5akalal','2lclclb5al','2lkmd5j5kl','4lkmd5l6l5','55a5akalak','2lalclalal', 16 | '2lkmclj5kl','4lkmd5j6l5','55a5akalak','2kalclalal','2lkmclj5al','4lkmd5j6l5','55a5akalak','2kalalalal','2lkmclj5al','4lkmd5j6l5', 17 | '55a5akalak','2kalalalal','2lkmclj5al','4lkmd5j6l5','55a5akalak','2kalalalal','2lklclb5al','4lkmd5j6l5','55a5akahak','2ka5alalal', 18 | '2lklclb5al','4lkmd5j5l5','55a52kahak','2ka5akalal','2lklclb5al','4lkmd5j5kl','4la12kahak','2ga5akalal','2lclclb5al','2lkmclj5kl', 19 | '4la12g8hak','2ga5akalak','2lalclalal','2lkmclj5kl','4la12g8hag','2ga5akalak','2kalalalal','2lkmclj5al','4la12g8hag','2ga5akalak', 20 | '2kalalalal','2lkmclj5al','4la12g8hag','2ga5akalak','2kalalalal','2lklclb5al','4la12g8hag','2ga5akalak','2kalalalal','2lklclb5al', 21 | '4la12g8hag','2ga52kahak','2ka5alalal','2lklclb5al','4la12g8gag','2ga12kahak','2ka5akalal','2lklclb5al','4la1208ga0','20a12g8hak', 22 | '2ga5akalal','2lalclalal','2la1208ga0','20a12g8hak','2ga5akalal','2lalalalal','2la1208ga0','20a12g8hag','2ga5akalak','2lalalalal', 23 | '2la1208g00','20a12g8hag','2ga5akalak','2kalalalal','2la1208g00','20a12g8hag','2ga5akalak','2kalalalal','2la0200g00','20a12g8hag', 24 | '2ga52kahak','2kalalalal','2la0200g00','20a12g8gag','2ga52kahak','2ka5akalal','2la0200g00','20a12g8gag','2ga12gahak','2ka5akalal', 25 | '2la0200g00','20a1208ga0','2ga12g8hak','2ga5akalal','2l00200000','a1208ga0','20a12g8hak','2ga5akalal','2l00000000','a1208ga0', 26 | '20a12g8hag','2ga5akalak','2l00000000','a1208g00','20a12g8hag','2ga5akalak','2k00000000','a1200g00','20a12g8hag','2ga5akalak', 27 | '2kalalalal' 28 | ]; 29 | // 24节气 30 | const termMap = ['小寒','大寒','立春','雨水','惊蛰','春分','清明','谷雨','立夏','小满','芒种','夏至','小暑','大暑','立秋','处暑','白露','秋分','寒露','霜降','立冬','小雪','大雪','冬至']; 31 | 32 | // 获取指定年份的24节气日期数据 33 | export function getTermDate(sYear){ 34 | if(sYearmaxYear){ 35 | return false; 36 | } 37 | let data = termData[sYear-minYear]; 38 | let num4 = parseInt(data,32).toString(4); 39 | if(num4.length!=24){ 40 | num4 = '0'+num4; 41 | } 42 | return num4.split('').map(function(value,index){ 43 | return +value+termMinDate[index]; 44 | }); 45 | } 46 | 47 | // 获取节气 48 | export function getTerm(sYear,sMonth,sDay){ 49 | let term = ''; 50 | const termDate = getTermDate(sYear); 51 | if(termDate){ 52 | termDate.push(31); 53 | termDate.forEach(function(day,index){ 54 | let month = Math.floor(index/2)+1; 55 | if(sMonth==month&&sDay==day){ 56 | term = termMap[index]; 57 | } 58 | }); 59 | } 60 | return term; 61 | } 62 | -------------------------------------------------------------------------------- /src/module/lunar.js: -------------------------------------------------------------------------------- 1 | import { 2 | minYear, 3 | minMonth, 4 | minDay, 5 | maxYear 6 | } from './config/base.js'; 7 | // 闰月数据压缩:1位闰月大小+12位平月大小及4位长度闰月月份转2进制,再转32进制 8 | const monthData = [ 9 | 'iuo','in0','19bg','l6l','1kj0','1mag','2pak','ll0','16mg','lei', 10 | 'in0','19dm','196g','1kig','3kil','1da0','1ll0','1bd2','15dg','2ibn', 11 | 'ibg','195g','1d5l','qig','ra0','3aqk','ar0','15bg','kni','ibg', 12 | 'pb6','1l50','1qig','rkl','mmg','ar0','31n3','14n0','3i6n','1iag', 13 | '1l50','3m56','1dag','ll0','39dk','9eg','14mg','1kli','1aag','1dan', 14 | 'r50','1dag','2kql','jd0','19dg','2hbj','klg','1ad8','1qag','ql0', 15 | '1bl6','1aqg','ir0','1an4','19bg','kj0','1sj3','1mag','mqn','ll0', 16 | '15mg','jel','img','196g','1l6k','1kig','1lao','1da0','1dl0','35d6', 17 | '15dg','idg','1abk','195g','1cjq','qig','ra0','1bq6','1ar0','15bg', 18 | 'inl','ibg','p5g','t53','1qig','qqo','le0','1ar0','15ml','14n0', 19 | '1ib0','1mak','1l50','1mig','tai','ll0','1atn','9eg','14mg','1ill', 20 | '1aag','1d50','1el4','1bag','lep','it0','19dg','2kbm','klg','1a9g', 21 | 'uak','ql0','1bag','mqi','ir0','19n6','1970','1kj0','1qj5','1l9g', 22 | 'ml0','tl3','15mg','inr','img','196g','3k5m','1kig','1l90','1na5', 23 | '1dd0','lmg','ldi','idg','19bn','195g','1aig','3cil','r90','1bd0', 24 | '2ir3','14rg','ifo','ibg','p5g','2q56','1qig','qp0','39m4','1an0', 25 | '18n0','1kn3','1ib0','1lan','1l50','1mig','nal','ll0','19mg','lek', 26 | 'kmg','1ado','1aag','1d50','1dl6','1bag','ld0','1at4','19dg','klg', 27 | '1cjj','q9g','spn','ql0','1bag','2iql','ir0','19bg','l74','1kb0', 28 | '1qb8','1l90','1ml0','2ql6','lmg','in0','1aek','18mg','1kag','1sii', 29 | '1l90' 30 | ]; 31 | // 月份 32 | const monthMap = ['正','二','三','四','五','六','七','八','九','十','冬','腊']; 33 | // 十位 34 | const dayMap = ['初一','初二','初三','初四','初五','初六','初七','初八','初九','初十','十一','十二','十三','十四','十五','十六','十七','十八','十九','二十','廿一','廿二','廿三','廿四','廿五','廿六','廿七','廿八','廿九','三十']; 35 | // 参考时间点 36 | const startTime = Date.UTC(minYear, minMonth-1, minDay, 0, 0, 0); 37 | 38 | // 获取农历年闰月 39 | export function getLeapMonth(lYear){ 40 | let data = parseInt(monthData[lYear - minYear],32); 41 | return data&0xf; 42 | } 43 | 44 | // 获取农历年长度 45 | export function getLunarYearDays(lYear) { 46 | let offset = 0; 47 | let data = parseInt(monthData[lYear - minYear],32); 48 | for (let i = 1<<15; i >= 1<<4; i >>= 1) { 49 | offset += (data&i)?30:29; 50 | } 51 | if(getLeapMonth(lYear)){ 52 | offset += (data&1<<16)?30:29; 53 | } 54 | return offset; 55 | } 56 | 57 | // 获得农历月份天数 58 | export function getLunarMonthDays(lYear,lMonth,isLeap){ 59 | let leapMonth = getLeapMonth(lYear); 60 | let data = parseInt(monthData[lYear - minYear],32); 61 | let days = data&1<<(16 - lMonth)?30:29; 62 | if(isLeap&&lMonth==leapMonth){ 63 | days = data&1<<16?30:29; 64 | } 65 | return days; 66 | } 67 | 68 | // 农历日期转时间戳 69 | export function getTimestampByLunar(lYear,lMonth,lDay,isLeap){ 70 | // 有效性验证 71 | if(lYearmaxYear){ 72 | return null; 73 | } 74 | if(lMonth<1||lMonth>12){ 75 | return null; 76 | } 77 | let leapMonth = getLeapMonth(lYear); 78 | if(isLeap&&leapMonth!=lMonth){ 79 | return null; 80 | } 81 | let data = parseInt(monthData[lYear - minYear],32); 82 | let days = (isLeap?data&1<<16:1<<(17-lMonth))?30:29; 83 | if(lDay>days){ 84 | return null; 85 | } 86 | // 时间戳获取 87 | let offset = 0; 88 | for(let year=minYear;yearleapMonth){ 95 | offset += data&1<<16?30:29; 96 | } 97 | offset += lDay; 98 | return startTime+offset*86400000; 99 | } 100 | 101 | // 时间戳转农历日期 102 | export function getLunarByTimestamp(timestamp){ 103 | let offset = Math.floor((timestamp - startTime)/86400000); 104 | let lYear = 0, lMonth = 0, lDay = 0, isLeap = false; 105 | let days; 106 | if(offset<=0){ 107 | return null; 108 | } 109 | let count = 0; 110 | for(lYear = minYear; lYear<=maxYear; lYear++){ 111 | days = getLunarYearDays(lYear); 112 | if(count + days>=offset){ 113 | break; 114 | } 115 | count+= days; 116 | } 117 | let data = parseInt(monthData[lYear - minYear],32); 118 | let leapMonth = getLeapMonth(lYear); 119 | offset -= count; 120 | count = 0; 121 | for(lMonth=1;lMonth<=12;lMonth++){ 122 | days = data&1<<(16 - lMonth)?30:29; 123 | if(count+days>=offset){ 124 | break; 125 | } 126 | count += days; 127 | if(leapMonth&&lMonth==leapMonth){ 128 | days = data&1<<16?30:29; 129 | if(count+days>=offset){ 130 | isLeap = true; 131 | break; 132 | } 133 | count += days; 134 | } 135 | } 136 | lDay = offset-count; 137 | return { 138 | lYear:lYear, 139 | lMonth:lMonth, 140 | lDay:lDay, 141 | isLeap:isLeap, 142 | lMonthZH:(isLeap?'闰':'')+monthMap[lMonth-1]+'月', 143 | lDayZH:dayMap[lDay-1] 144 | }; 145 | } 146 | -------------------------------------------------------------------------------- /static/style/index.css: -------------------------------------------------------------------------------- 1 | .module{ 2 | margin: 160px 0; 3 | } 4 | .module .hd{ 5 | margin-bottom: 6px; 6 | line-height: 32px; 7 | } 8 | .module .hd span{ 9 | font-size: 20px; 10 | font-weight: bold; 11 | color: var(--title-color); 12 | } 13 | 14 | .mod-poster{ 15 | margin-bottom: 25px; 16 | } 17 | .mod-poster .bd{ 18 | padding: 60px 0; 19 | line-height: 24px; 20 | } 21 | .mod-poster .bd h1{ 22 | margin-bottom: 10px; 23 | line-height: 48px; 24 | font-weight: bold; 25 | font-size: 36px; 26 | color:var(--title-color); 27 | } 28 | .mod-poster .bd h1 span.tag{ 29 | display: inline-block; 30 | padding: 0 8px; 31 | margin: 0 5px; 32 | background: rgba(255, 255, 255,0.8); 33 | line-height: 26px; 34 | vertical-align: middle; 35 | font-size: 13px; 36 | color: rgb(110, 119, 129); 37 | border-radius: 4px; 38 | box-shadow: 0 1px 5px 0 rgba(0,0,0,0.03); 39 | } 40 | .mod-poster .bd p{ 41 | margin-bottom: 10px; 42 | line-height: 26px; 43 | } 44 | .mod-poster .bd b{ 45 | margin: 0 3px; 46 | color: #fd7474; 47 | } 48 | .mod-poster .buttons{ 49 | margin-bottom: 20px; 50 | padding: 10px; 51 | border-radius: 6px; 52 | line-height: 32px; 53 | } 54 | .mod-poster .btn { 55 | display: inline-block; 56 | height: 44px; 57 | min-width: 120px; 58 | padding:0 20px; 59 | margin: 0 5px; 60 | background: #2095f2; 61 | border: medium none; 62 | box-shadow: 2px 2px 4px rgba(0,0,0,0.05); 63 | line-height: 42px; 64 | text-align: center; 65 | vertical-align: middle; 66 | font-size: 16px; 67 | color: #fff; 68 | cursor: pointer; 69 | outline: none; 70 | border-radius: 21px; 71 | text-decoration: none; 72 | } 73 | .mod-poster .btn img,.mod-poster .btn span{ 74 | vertical-align: middle; 75 | } 76 | .mod-poster .btn:hover{ 77 | background: #1b85da; 78 | } 79 | .mod-poster .btn-green{ 80 | background: #4bae4f; 81 | color: #fff; 82 | } 83 | .mod-poster .btn-green:hover{ 84 | background: #47a04b; 85 | } 86 | .mod-poster .bd .btn-red{ 87 | background: #f56954; 88 | color: #fff; 89 | } 90 | .mod-poster .btn-red:hover{ 91 | background: #f4543c;; 92 | } 93 | .mod-poster .btn-orange{ 94 | background: #ff9000; 95 | color: #fff; 96 | } 97 | .mod-poster .btn-orange:hover{ 98 | background: #e18309; 99 | } 100 | 101 | .mod-panel{ 102 | margin-bottom: 25px; 103 | background: #fff; 104 | border: 1px solid #f0f0f099; 105 | border-radius: 8px; 106 | box-shadow: 1px 2px 12px rgba(0, 0, 0, 0.02); 107 | } 108 | .mod-panel .hd{ 109 | position: relative; 110 | padding: 10px 20px; 111 | border-bottom: 1px solid #f0f0f099; 112 | line-height: 24px; 113 | } 114 | .mod-panel .hd .title{ 115 | display: inline-block; 116 | font-size: 18px; 117 | font-weight: bold; 118 | color: var(--title-color); 119 | } 120 | .mod-panel .hd .more{ 121 | float: right; 122 | text-decoration: none; 123 | color: #999; 124 | } 125 | .mod-panel .hd::after{ 126 | position: absolute; 127 | left: 2px; 128 | top: 50%; 129 | content: ''; 130 | width: 4px; 131 | height: 24px; 132 | background: #2095f2; 133 | margin-top: -12px; 134 | border-radius: 3px; 135 | } 136 | .mod-panel .bd{ 137 | padding: 20px; 138 | } 139 | .mod-panel .bd p{ 140 | margin-bottom: 10px; 141 | line-height: 26px; 142 | text-indent: 2em; 143 | } 144 | .mod-panel .bd h4{ 145 | line-height: 30px; 146 | font-size: 16px; 147 | font-weight: bold; 148 | color: var(--title-color); 149 | } 150 | .mod-panel .bd code{ 151 | display: block; 152 | margin-bottom: 20px; 153 | padding: 15px; 154 | background: #f8f8f8; 155 | border-radius: 6px; 156 | } 157 | .mod-panel .bd pre{ 158 | white-space: break-spaces; 159 | word-break: break-all; 160 | word-wrap: break-word; 161 | } 162 | .mod-panel .bd .table-inner{ 163 | margin-top: 15px; 164 | overflow-x: auto; 165 | } 166 | .mod-panel .bd table{ 167 | width: 100%; 168 | } 169 | .mod-panel .bd caption{ 170 | line-height: 32px; 171 | font-size: 16px; 172 | font-weight: bold; 173 | } 174 | .mod-panel .bd thead{ 175 | background: #f6f8fa; 176 | } 177 | .mod-panel .bd th,.mod-panel .bd td{ 178 | padding: 6px 12px; 179 | border: 1px solid #e1e6ea; 180 | line-height: 24px; 181 | white-space: nowrap; 182 | } 183 | .mod-panel .bd td.th{ 184 | background: #f6f8fa; 185 | } 186 | .mod-panel .bd td p{ 187 | margin-bottom: 0; 188 | text-indent: 0; 189 | } 190 | .mod-panel .bd select{ 191 | height: 36px; 192 | padding: 0 10px; 193 | border: 1px solid #e2e2e2; 194 | box-sizing: border-box; 195 | vertical-align: middle; 196 | outline: none; 197 | border-radius: 4px; 198 | } 199 | .mod-panel .bd input[type="text"],.mod-panel .bd input[type="search"]{ 200 | width: 240px; 201 | height: 36px; 202 | padding: 0 10px; 203 | border: 1px solid #e2e2e2; 204 | border-radius: 4px; 205 | vertical-align: middle; 206 | outline: none; 207 | box-sizing: border-box; 208 | } 209 | .mod-panel .bd .btn { 210 | height: 36px; 211 | min-width: 80px; 212 | padding:0 15px; 213 | background: #2095f2; 214 | border: medium none; 215 | box-sizing: border-box; 216 | line-height: 36px; 217 | vertical-align: middle; 218 | font-size: 15px; 219 | color: #fff; 220 | cursor: pointer; 221 | outline: none; 222 | border-radius: 4px; 223 | } 224 | .mod-panel .bd .btn:hover{ 225 | background: #1b85da; 226 | } 227 | .mod-panel .bd .btn-green{ 228 | background: #4bae4f; 229 | color: #fff; 230 | } 231 | .mod-panel .bd .btn-green:hover{ 232 | background: #47a04b; 233 | } 234 | .mod-panel .bd .btn-red{ 235 | background: #f56954; 236 | color: #fff; 237 | } 238 | .mod-panel .bd .btn-red:hover{ 239 | background: #f4543c;; 240 | } 241 | .mod-panel .bd .btn-orange{ 242 | background: #ff9000; 243 | color: #fff; 244 | } 245 | .mod-panel .bd .btn-orange:hover{ 246 | background: #e18309; 247 | } 248 | .mod-panel .bd .btn-small{ 249 | min-width: 36px; 250 | margin-right: -1px; 251 | cursor: pointer; 252 | } 253 | .mod-panel .bd .btn[disabled]{ 254 | background: #f0f0f0; 255 | color: #aaa; 256 | } 257 | .mod-panel .bd .text-green{ 258 | color: #4bae4f; 259 | } 260 | .mod-panel .bd .text-red{ 261 | color:#f56954; 262 | } 263 | .mod-panel .bd textarea{ 264 | display: block; 265 | width: 100%; 266 | height: 120px; 267 | padding:5px 10px; 268 | background: #fafafa; 269 | border: 1px solid #ebebeb; 270 | box-sizing: border-box; 271 | border-radius: 5px; 272 | resize: none; 273 | outline: none; 274 | } 275 | .mod-panel .bd label{ 276 | white-space: nowrap; 277 | } 278 | .mod-panel .input-wrapper{ 279 | line-height: 24px; 280 | } 281 | .mod-panel .input-wrapper span{ 282 | margin-right: 5px; 283 | } 284 | .mod-panel .suggestion{ 285 | background: #fff; 286 | } 287 | .mod-panel .suggestion ul{ 288 | border:1px solid #ebebeb; 289 | } 290 | .mod-panel .suggestion li{ 291 | padding:0 10px; 292 | line-height: 30px; 293 | cursor: pointer; 294 | } 295 | .mod-panel .suggestion .active{ 296 | background: #ccc; 297 | } 298 | .mod-panel .none{ 299 | padding: 25px 0; 300 | } 301 | 302 | 303 | .mod-article{ 304 | margin-bottom: 65px; 305 | } 306 | .mod-article .hd{ 307 | margin-top: -36px; 308 | } 309 | .mod-article .hd span{ 310 | font-size: 24px; 311 | } 312 | .mod-article .bd{ 313 | position: relative; 314 | padding: 30px 0; 315 | } 316 | .mod-article .bd::before{ 317 | position: absolute; 318 | top: 0; 319 | left: 0; 320 | content: '“'; 321 | font-size: 60px; 322 | border-radius: 6px; 323 | } 324 | .mod-article .bd::after{ 325 | position: absolute; 326 | bottom: -10px; 327 | right: 0; 328 | content: '”'; 329 | font-size: 60px; 330 | border-radius: 6px; 331 | } 332 | .mod-article .bd p{ 333 | margin-bottom: 12px; 334 | line-height: 28px; 335 | text-indent: 2em; 336 | } 337 | 338 | .mod-copy{ 339 | margin-bottom: 65px; 340 | padding: 35px 0; 341 | background: rgb(246, 248, 250); 342 | } 343 | .mod-copy .bd{ 344 | margin:0 5px; 345 | } 346 | .mod-copy .bd p{ 347 | margin-bottom: 12px; 348 | line-height: 28px; 349 | text-indent: 2em; 350 | } 351 | .mod-copy .bd .buttons{ 352 | margin: 15px 0; 353 | } 354 | .mod-copy .bd .text-red{ 355 | font-weight: bold; 356 | color: #fd7474; 357 | } 358 | .mod-copy .bd code{ 359 | display: block; 360 | margin-bottom: 15px; 361 | padding: 8px 15px; 362 | line-height: 20px; 363 | background: #fff; 364 | border: 1px solid rgba(27,31,36,.15); 365 | border-radius: 5px; 366 | word-break: break-word; 367 | } 368 | 369 | 370 | @media screen and (max-width: 1020px) { 371 | .mod-poster{ 372 | margin-bottom: 25px; 373 | } 374 | .mod-poster .bd{ 375 | padding: 25px 0; 376 | margin-bottom: 15px; 377 | } 378 | .mod-poster .bd h1{ 379 | margin-bottom: 5px; 380 | line-height: 26px; 381 | font-size: 20px; 382 | } 383 | .mod-poster .bd p{ 384 | line-height: 22px; 385 | font-size: 13px; 386 | overflow: hidden; 387 | } 388 | 389 | .mod-article{ 390 | margin-bottom: 25px; 391 | } 392 | .mod-article .hd span{ 393 | font-size: 20px; 394 | } 395 | .mod-article .bd{ 396 | padding: 15px 0; 397 | } 398 | .mod-article .bd::before{ 399 | font-size: 48px; 400 | } 401 | .mod-article .bd::after{ 402 | font-size: 48px; 403 | } 404 | .mod-article .bd p{ 405 | margin-bottom: 7px; 406 | line-height: 22px; 407 | font-size: 14px; 408 | } 409 | 410 | .mod-copy{ 411 | padding: 15px 0 25px; 412 | margin-bottom: 25px; 413 | } 414 | .mod-copy .bd p{ 415 | line-height: 22px; 416 | font-size: 14px; 417 | } 418 | } 419 | 420 | @media screen and (max-width: 640px) { 421 | .mod-poster .buttons{ 422 | margin-bottom: 10px; 423 | padding: 10px 0; 424 | } 425 | .mod-poster .btn{ 426 | min-width: 64px; 427 | margin: 2px 1px; 428 | padding: 0 15px; 429 | height: 36px; 430 | line-height: 35px; 431 | font-size: 14px; 432 | } 433 | .mod-poster .btn img{ 434 | display: none; 435 | } 436 | 437 | .mod-panel .bd{ 438 | padding: 15px 10px; 439 | } 440 | .mod-panel .bd input[type="text"]{ 441 | width: 200px; 442 | } 443 | .mod-panel .bd .c-ft { 444 | padding: 10px; 445 | } 446 | .mod-panel .btn { 447 | min-width: 64px; 448 | margin: 2px 1px; 449 | padding: 0 15px; 450 | height: 36px; 451 | line-height: 35px; 452 | font-size: 14px; 453 | } 454 | } 455 | -------------------------------------------------------------------------------- /src/style/widget.css: -------------------------------------------------------------------------------- 1 | :host { 2 | display: inline-block; 3 | width: 100%; 4 | min-width: 300px; 5 | max-width: 600px; 6 | vertical-align: bottom; 7 | white-space: initial; 8 | font-family: Arial, Helvetica, "Microsoft Yahei"; 9 | color: #1f2328; 10 | container-type: inline-size; 11 | --primary-color: #2095f2; 12 | --secondary-color: #ffaa00; 13 | --base-size: 1px; 14 | --base-size-mobile: 1px; 15 | } 16 | @supports (width: 100cqw) { 17 | :host { 18 | --base-size: clamp(1px, calc(100cqw / 600), 1.1px); 19 | --base-size-mobile: clamp(1px, calc(100cqw / 480), 1.1px); 20 | } 21 | } 22 | * { 23 | padding: 0; 24 | margin: 0; 25 | } 26 | a { 27 | text-decoration: none; 28 | color: #1f2328; 29 | } 30 | .mod-calendar { 31 | display: flex; 32 | gap: calc(var(--base-size) * 4); 33 | flex-direction: row-reverse; 34 | padding: calc(var(--base-size) * 4); 35 | background: var(--primary-color); 36 | border-radius: calc(var(--base-size) * 6); 37 | font-size: calc(var(--base-size) * 14); 38 | } 39 | .mod-calendar .info { 40 | position: relative; 41 | width: calc(var(--base-size) * 168); 42 | padding-top: calc(var(--base-size) * 12); 43 | text-align: center; 44 | color: #fff; 45 | } 46 | .mod-calendar .info a { 47 | color: #fff; 48 | } 49 | .mod-calendar .info p { 50 | line-height: calc(var(--base-size) * 22); 51 | } 52 | .mod-calendar .info .date{ 53 | line-height: calc(var(--base-size) * 24); 54 | font-size: calc(var(--base-size) * 16); 55 | } 56 | .mod-calendar .info .day { 57 | width: calc(var(--base-size) * 80); 58 | height: calc(var(--base-size) * 80); 59 | margin: calc(var(--base-size) * 15) auto; 60 | line-height: calc(var(--base-size) * 80); 61 | font-size: calc(var(--base-size) * 48); 62 | font-weight: bold; 63 | background: var(--secondary-color); 64 | color: #fff; 65 | border-radius: calc(var(--base-size) * 12); 66 | } 67 | .mod-calendar .info .detail { 68 | margin-bottom: calc(var(--base-size) * 15); 69 | } 70 | .mod-calendar .info .list { 71 | padding: calc(var(--base-size) * 10) 0; 72 | border-top: calc(var(--base-size) * 1) dotted rgba(255, 255, 255, 0.5); 73 | } 74 | .mod-calendar .info .list .item { 75 | padding: calc(var(--base-size) * 5) 0; 76 | } 77 | .mod-calendar .info .list .item a { 78 | color: #fff; 79 | } 80 | .mod-calendar .info .list ::slotted([slot="item"]) { 81 | padding: calc(var(--base-size) * 5) 0 !important; 82 | } 83 | .mod-calendar .box { 84 | flex: 1; 85 | background: #fff; 86 | border-radius: calc(var(--base-size) * 6); 87 | } 88 | .mod-calendar .selector { 89 | display: flex; 90 | gap: calc(var(--base-size-mobile) * 8); 91 | justify-content: center; 92 | position: relative; 93 | padding: calc(var(--base-size) * 5) calc(var(--base-size) * 5) 0; 94 | vertical-align: middle; 95 | height: calc(var(--base-size)*26); 96 | text-align: center; 97 | } 98 | .mod-calendar .selector span { 99 | display: inline-flex; 100 | vertical-align: middle; 101 | } 102 | .mod-calendar .selector a { 103 | position: relative; 104 | height: calc(var(--base-size) * 24); 105 | padding: 0 calc(var(--base-size) * 5); 106 | border: calc(var(--base-size) * 1) solid #ebebeb; 107 | background: #fafafa; 108 | line-height: calc(var(--base-size) * 24); 109 | vertical-align: middle; 110 | } 111 | .mod-calendar .selector a.prev,.mod-calendar .selector a.next{ 112 | position: relative; 113 | color: transparent!important; 114 | } 115 | .mod-calendar .selector a.prev{ 116 | border-top-left-radius: calc(var(--base-size) * 4); 117 | border-bottom-left-radius: calc(var(--base-size) * 4); 118 | } 119 | .mod-calendar .selector a.prev::after{ 120 | position: absolute; 121 | left: 50%; 122 | top: 50%; 123 | content: ''; 124 | width: calc(var(--base-size) * 6); 125 | height: calc(var(--base-size) * 6); 126 | margin: calc(var(--base-size) * -4) 0 0 calc(var(--base-size) * -2); 127 | border-left: calc(var(--base-size) * 1) solid #333; 128 | border-bottom: calc(var(--base-size) * 1) solid #333; 129 | transform: rotate(45deg); 130 | } 131 | .mod-calendar .selector a.next{ 132 | border-top-right-radius: calc(var(--base-size) * 4); 133 | border-bottom-right-radius: calc(var(--base-size) * 4); 134 | } 135 | .mod-calendar .selector a.next::after{ 136 | position: absolute; 137 | right: 50%; 138 | top: 50%; 139 | content: ''; 140 | width: calc(var(--base-size) * 6); 141 | height: calc(var(--base-size) * 6); 142 | margin: calc(var(--base-size) * -4) calc(var(--base-size) * -2) 0 0; 143 | border-right: calc(var(--base-size) * 1) solid #333; 144 | border-bottom: calc(var(--base-size) * 1) solid #333; 145 | transform: rotate(-45deg); 146 | } 147 | .mod-calendar .selector a.goback{ 148 | padding: 0 calc(var(--base-size) * 8); 149 | border-radius: calc(var(--base-size) * 4); 150 | } 151 | .mod-calendar .selector a:hover { 152 | border-color: #d2d9df; 153 | background: #f6f8fa; 154 | } 155 | .mod-calendar .selector select { 156 | min-width: calc(var(--base-size) * 60); 157 | height: calc(var(--base-size) * 26); 158 | padding-left: calc(var(--base-size) * 4); 159 | border: calc(var(--base-size) * 1) solid #ebebeb; 160 | margin: 0 calc(var(--base-size) * -1); 161 | background: #fff; 162 | line-height: calc(var(--base-size) * 24); 163 | vertical-align: middle; 164 | font-size: calc(var(--base-size) * 14); 165 | color: #1f2328; 166 | outline: none; 167 | } 168 | .mod-calendar .selector select:only-child{ 169 | border-radius: calc(var(--base-size) * 4); 170 | } 171 | .mod-calendar .selector button { 172 | height: calc(var(--base-size) * 26); 173 | border: calc(var(--base-size) * 1) solid #ebebeb; 174 | line-height: calc(var(--base-size) * 24); 175 | background: #fafafa; 176 | } 177 | .mod-calendar .table{ 178 | padding: calc(var(--base-size) * 5); 179 | border-radius: calc(var(--base-size) * 6); 180 | } 181 | .mod-calendar table { 182 | width: 100%; 183 | table-layout: fixed; 184 | color: #1f2328; 185 | border-collapse: collapse; 186 | border-spacing: 0; 187 | } 188 | .mod-calendar table th, .mod-calendar table td { 189 | text-align: center; 190 | } 191 | .mod-calendar table th { 192 | line-height: calc(var(--base-size) * 30); 193 | font-weight: normal; 194 | } 195 | .mod-calendar table th span{ 196 | position: relative; 197 | z-index: 9; 198 | } 199 | .mod-calendar table td { 200 | position: relative; 201 | border: calc(var(--base-size) * 1) solid #fff; 202 | line-height: calc(var(--base-size) * 20); 203 | } 204 | .mod-calendar table thead { 205 | position: relative; 206 | } 207 | .mod-calendar table thead tr{ 208 | border-bottom: calc(var(--base-size) * 3) solid #fff; 209 | } 210 | .mod-calendar table thead th:first-child::after{ 211 | position: absolute; 212 | left: 0; 213 | top: 0; 214 | z-index: 0; 215 | content:''; 216 | width: 100%; 217 | height: calc(100% - calc(var(--base-size) * 1.5)); 218 | background: #f6f8fa; 219 | border-radius: calc(var(--base-size) * 4); 220 | } 221 | .mod-calendar table tbody a { 222 | display: block; 223 | position: relative; 224 | margin: 0 auto; 225 | padding: calc(var(--base-size) * 5) 0; 226 | border: calc(var(--base-size) * 1) solid transparent; 227 | border-radius: calc(var(--base-size) * 6); 228 | line-height: calc(var(--base-size) * 20); 229 | cursor: pointer; 230 | } 231 | .mod-calendar table tbody a:hover { 232 | border: calc(var(--base-size) * 1) solid #cccccccc; 233 | } 234 | .mod-calendar table tbody span { 235 | display: block; 236 | } 237 | .mod-calendar table tbody i { 238 | position: absolute; 239 | left: 0; 240 | top: 0; 241 | padding: 0 calc(var(--base-size) * 3); 242 | line-height: calc(var(--base-size) * 18); 243 | font-style: normal; 244 | font-size: calc(var(--base-size) * 13); 245 | color: #fff; 246 | } 247 | .mod-calendar table .s1 { 248 | font-size: calc(var(--base-size) * 18); 249 | color: rgba(0, 0, 0, 0.8); 250 | } 251 | .mod-calendar table .s2 { 252 | font-size: calc(var(--base-size) * 13); 253 | color: rgba(0, 0, 0, 0.6); 254 | } 255 | .mod-calendar table td.active a { 256 | border: calc(var(--base-size) * 1) solid var(--secondary-color); 257 | } 258 | .mod-calendar table td.holiday a { 259 | background: #f1f9f1 260 | } 261 | .mod-calendar table td.holiday.active a, .mod-calendar table td.holiday a:hover { 262 | border: calc(var(--base-size) * 1) solid #4bae4fcc; 263 | } 264 | .mod-calendar table td.holiday i { 265 | color: #4bae4f; 266 | } 267 | .mod-calendar table td.work a { 268 | background: #fef0ef; 269 | } 270 | .mod-calendar table td.work.active a, .mod-calendar table td.work a:hover { 271 | border: calc(var(--base-size) * 1) solid #f44336cc; 272 | } 273 | .mod-calendar table td.work i { 274 | color: #f44336; 275 | } 276 | .mod-calendar table td.today a { 277 | background: #fff2dd; 278 | } 279 | .mod-calendar table td.today.active a, .mod-calendar table td.today a:hover { 280 | border: calc(var(--base-size) * 1) solid var(--secondary-color); 281 | } 282 | .mod-calendar table td.disabled a { 283 | opacity: 0.4; 284 | } 285 | .mode-simple .info { 286 | display: none; 287 | } 288 | .mode-simple .selector { 289 | background: none; 290 | text-align: center; 291 | } 292 | 293 | @container (max-width: 480px) { 294 | .mod-calendar { 295 | flex-direction: column; 296 | padding: calc(var(--base-size) * 3); 297 | font-size: calc(var(--base-size-mobile) * 12); 298 | } 299 | .mod-calendar .info { 300 | width: auto; 301 | padding-top: calc(var(--base-size-mobile) * 10); 302 | padding-left: calc(var(--base-size-mobile) * 10); 303 | overflow: hidden; 304 | } 305 | .mod-calendar .info p { 306 | text-align: left; 307 | line-height: calc(var(--base-size-mobile) * 18); 308 | } 309 | .mod-calendar .info .date{ 310 | text-align: left; 311 | font-size: calc(var(--base-size-mobile) * 14); 312 | } 313 | .mod-calendar .info .day { 314 | float: left; 315 | width: calc(var(--base-size-mobile) * 56); 316 | height: calc(var(--base-size-mobile) * 56); 317 | margin: calc(var(--base-size-mobile) * 6) 0; 318 | line-height: calc(var(--base-size-mobile) * 56); 319 | font-size: calc(var(--base-size-mobile) * 24); 320 | } 321 | .mod-calendar .info .detail { 322 | padding-top: calc(var(--base-size-mobile) * 5); 323 | margin-left: calc(var(--base-size-mobile) * 70); 324 | margin-bottom: calc(var(--base-size-mobile) * 10); 325 | } 326 | .mod-calendar .info .list { 327 | position: absolute; 328 | top: calc(var(--base-size-mobile) * 10); 329 | right: calc(var(--base-size-mobile) * 10); 330 | padding: 0; 331 | border-top: none; 332 | text-align: right; 333 | } 334 | .mod-calendar .info .list .item { 335 | padding: calc(var(--base-size-mobile) * 2) 0; 336 | } 337 | .mod-calendar .info .list ::slotted([slot="item"]) { 338 | padding: calc(var(--base-size-mobile) * 2) 0 !important; 339 | } 340 | .mod-calendar .selector{ 341 | gap: calc(var(--base-size-mobile) * 6); 342 | } 343 | .mod-calendar .selector span:has(.goback) { 344 | position: absolute; 345 | right: 0px; 346 | top: -106px; 347 | z-index: 9; 348 | } 349 | .mod-calendar .selector a.goback { 350 | position: absolute; 351 | top: calc(var(--base-size-mobile) * 75); 352 | right: calc(var(--base-size-mobile) * 10); 353 | height: calc(var(--base-size-mobile) * 20); 354 | border-color: transparent; 355 | background: var(--secondary-color); 356 | line-height: calc(var(--base-size-mobile) * 20); 357 | font-size: calc(var(--base-size-mobile) * 12); 358 | white-space: nowrap; 359 | color: #fff; 360 | border-radius: calc(var(--base-size-mobile) * 3); 361 | } 362 | .mod-calendar .selector .goback:hover { 363 | border-color: var(--secondary-color); 364 | color: #fff; 365 | } 366 | .mod-calendar .table{ 367 | padding: calc(var(--base-size-mobile) * 3); 368 | } 369 | .mod-calendar table tbody a { 370 | width: auto; 371 | line-height: calc(var(--base-size-mobile) * 18); 372 | } 373 | .mod-calendar table tbody i{ 374 | padding: 0; 375 | font-size: calc(var(--base-size-mobile) * 12); 376 | } 377 | .mod-calendar table tr { 378 | border-top: none; 379 | } 380 | .mod-calendar table td { 381 | height: calc(var(--base-size-mobile) * 48); 382 | line-height: calc(var(--base-size-mobile) * 16); 383 | } 384 | .mod-calendar table .s2 { 385 | font-size: calc(var(--base-size-mobile) * 12); 386 | } 387 | 388 | .mode-simple .selector span:has(.goback){ 389 | display: none; 390 | } 391 | } -------------------------------------------------------------------------------- /dist/calendar.min.mjs: -------------------------------------------------------------------------------- 1 | /*! 2 | * calendar-tool v1.0.3 3 | * Chinese lunar calendar 4 | * https://passer-by.com/calendar/ 5 | * 6 | * Copyright (c) 2022-present, HaoLe Zheng 7 | * 8 | * Released under the MIT License 9 | * https://github.com/mumuy/calendar 10 | * 11 | * Created on: 2025-12-01 12 | */ 13 | function a(){for(var a=arguments.length,l=new Array(a),n=0;n=16;e>>=1)l+=n&e?30:29;return d(a)&&(l+=65536&n?30:29),l}function g(a){var l,n,e=Math.floor((a-f)/864e5),g=0,i=0,c=!1;if(e<=0)return null;var s=0;for(g=o;g<=r&&!(s+(n=k(g))>=e);g++)s+=n;var h=parseInt(u[g-o],32),j=d(g);for(e-=s,s=0,i=1;i<=12&&!(s+(n=h&1<<16-i?30:29)>=e);i++)if(s+=n,j&&i==j){if(s+(n=65536&h?30:29)>=e){c=!0;break}s+=n}return{lYear:g,lMonth:i,lDay:l=e-s,isLeap:c,lMonthZH:(c?"闰":"")+t[i-1]+"月",lDayZH:m[l-1]}}var i=[4,19,3,18,4,19,4,19,4,20,4,20,6,22,6,22,6,22,7,22,6,21,6,21],c=["4lkmd5j6l5","55kql9lal9","59lanalala","5avbnatqla","7akmd5j6l5","55kql9lal9","59lalalala","5avbnatqla","7akmd5j6l5","55kql9lal9","59lalalala","5avbnatqla","7akmd5j6l5","4lkql9lal9","55kqlalala","5ananalqla","5akmd5j5kl","4lkqd9l6l5","55kqlalal9","5ananalqla","5akmd5j5kl","4lkmd9l6l5","55kqlalal9","59lanalqla","5akmd5j5kl","4lkmd9l6l5","55kql9lal9","59lanalala","5akmclj5al","4lkmd5j6l5","55kql9lal9","59lanalala","5akmclj5al","4lkmd5j6l5","55kql9lal9","59lalalala","5akmclj5al","4lkmd5j6l5","55kql9lal9","59lalalala","5akmclj5al","4lkmd5j6l5","55kql9lal9","59lalalala","5aklclj5al","4lkmd5j5kl","4lkql9l6l9","55kqlalala","5aclclb5al","2lkmd5j5kl","4lkmd9l6l9","55kqlalala","5aclclb5al","2lkmd5j5kl","4lkmd9l6l5","55kql9lal9","5aalclb5al","2lkmd5j5kl","4lkmd5j6l5","55kql9lal9","59alclalal","2lkmclj5al","4lkmd5j6l5","55kql9lal9","59alclalal","2lkmclj5al","4lkmd5j6l5","55kql9lal9","59alalalal","2lkmclj5al","4lkmd5j6l5","55kql9lal9","59alalalal","2lklclj5al","4lkmd5j6l5","55kql9l6l9","59a5alalal","2lklclb5al","4lkmd5j5l5","55kqd9l6l9","59a5alalal","2lklclb5al","4lkmd5j5kl","4lkmd9l6l9","55a5akalal","2lclclb5al","2lkmd5j5kl","4lkmd5l6l5","55a5akalak","2lalclalal","2lkmclj5kl","4lkmd5j6l5","55a5akalak","2kalclalal","2lkmclj5al","4lkmd5j6l5","55a5akalak","2kalalalal","2lkmclj5al","4lkmd5j6l5","55a5akalak","2kalalalal","2lkmclj5al","4lkmd5j6l5","55a5akalak","2kalalalal","2lklclb5al","4lkmd5j6l5","55a5akahak","2ka5alalal","2lklclb5al","4lkmd5j5l5","55a52kahak","2ka5akalal","2lklclb5al","4lkmd5j5kl","4la12kahak","2ga5akalal","2lclclb5al","2lkmclj5kl","4la12g8hak","2ga5akalak","2lalclalal","2lkmclj5kl","4la12g8hag","2ga5akalak","2kalalalal","2lkmclj5al","4la12g8hag","2ga5akalak","2kalalalal","2lkmclj5al","4la12g8hag","2ga5akalak","2kalalalal","2lklclb5al","4la12g8hag","2ga5akalak","2kalalalal","2lklclb5al","4la12g8hag","2ga52kahak","2ka5alalal","2lklclb5al","4la12g8gag","2ga12kahak","2ka5akalal","2lklclb5al","4la1208ga0","20a12g8hak","2ga5akalal","2lalclalal","2la1208ga0","20a12g8hak","2ga5akalal","2lalalalal","2la1208ga0","20a12g8hag","2ga5akalak","2lalalalal","2la1208g00","20a12g8hag","2ga5akalak","2kalalalal","2la1208g00","20a12g8hag","2ga5akalak","2kalalalal","2la0200g00","20a12g8hag","2ga52kahak","2kalalalal","2la0200g00","20a12g8gag","2ga52kahak","2ka5akalal","2la0200g00","20a12g8gag","2ga12gahak","2ka5akalal","2la0200g00","20a1208ga0","2ga12g8hak","2ga5akalal","2l00200000","a1208ga0","20a12g8hak","2ga5akalal","2l00000000","a1208ga0","20a12g8hag","2ga5akalak","2l00000000","a1208g00","20a12g8hag","2ga5akalak","2k00000000","a1200g00","20a12g8hag","2ga5akalak","2kalalalal"],s=["小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"];function h(a){if(ar)return!1;var l=c[a-o],n=parseInt(l,32).toString(4);return 24!=n.length&&(n="0"+n),n.split("").map((function(a,l){return+a+i[l]}))}function j(a,l,n){var e="",o=h(a);return o&&(o.push(31),o.forEach((function(a,o){var r=Math.floor(o/2)+1;l==r&&n==a&&(e=s[o])}))),e}var v=["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"],b=["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"];function q(a){(a%=60)<0&&(a+=60);var l=a%12;return v[a%10]+b[l]}function y(a,l,e){return q(g(n(a,l,e)).lYear-1984)}function p(l,n,e){var o="",r=h(l);if(r){var u=0;r.push(31),r.forEach((function(l,o){var r=Math.floor(o/2)+1;a(n,e)>=a(r,l)&&(u=r)})),o=q(u+=12*(l-1984))}return o}function D(a,l,e){return q(Math.round((n(a,l,e)-n(1900,1,30))/864e5)+39)}var M=["水瓶","双鱼","白羊","金牛","双子","巨蟹","狮子","处女","天秤","天蝎","射手","摩羯"],Y=[20,19,21,20,21,22,23,23,23,24,23,22];var w=["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"];function T(a,l,e){var o=(g(n(a,l,e)).lYear-1984)%12;return w[o>-1?o:o+12]}function I(a,l){(null==l||l>a.length)&&(l=a.length);for(var n=0,e=new Array(l);n0&&void 0!==arguments[0]?arguments[0]:[]).filter((function(a){return m>=a.found})).map((function(a){return a.name}))}))}function C(a,l,n){var o,r=[],u=h(a),t=864e5;return(o=e(new Date(a,3,u[6]-1).getTime())).sYear==a&&o.sMonth==l&&o.sDay==n&&r.push("寒食节"),function(){for(var o=new Date(a,5,u[11]).getTime(),m=new Date(a,7,u[14]).getTime(),f=0,d=o;d<=m;d+=t){var k=e(d);D(k.sYear,k.sMonth,k.sDay).includes("庚")&&(f++,k.sYear==a&&k.sMonth==l&&k.sDay==n&&(3==f?r.push("初伏"):4==f&&r.push("中伏")))}f=0;for(var g=m;g<=m+1728e6;g+=t){var i=e(g);D(i.sYear,i.sMonth,i.sDay).includes("庚")&&(f++,i.sYear==a&&i.sMonth==l&&i.sDay==n&&(1==f?r.push("末伏"):2==f&&r.push("出伏")))}}(),function(){for(var o=h(a-1),t=new Date(a-1,11,o[23]).getTime(),m=new Date(a,11,u[23]).getTime(),f=0,d=t;d<=t+62208e5;d+=7776e5){var k=e(d);k.sYear==a&&k.sMonth==l&&k.sDay==n&&r.push(E[f]),f++}f=0;for(var g=m;g<=m+62208e5;g+=7776e5){var i=e(g);i.sYear==a&&i.sMonth==l&&i.sDay==n&&r.push(E[f]),f++}}(),function(){var e=function(a){if(a<1900||a>2100)return null;var l=a-1900,n=l%19,e=Math.floor(l/4),o=(11*n+4-Math.floor((7*n+1)/19))%29,r=25-o-(l+e+31-o)%7;return r>0?[4,r]:[3,31+r]}(a);if(e){var o=H(e,2),u=o[0],t=o[1];u==l&&t==n&&r.push("复活节")}}(),r}function L(l,n,e){var r=[],t=a(l,n,e),m=a(n,e);return 12==n&&e==function(a,l,n){var e=d(a),r=parseInt(u[a-o],32),t=r&1<<16-l?30:29;return n&&l==e&&(t=65536&r?30:29),t}(l,12)?r.push(A["12-30"][0].name):r=r.concat([A[m],O[m]].flatMap((function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).filter((function(a){return t>=a.found})).map((function(a){return a.name}))}))),r}function U(l){var n,o,r,u=e(l),t=g(l);return Object.assign({lYear:null,lMonth:null,lDay:null,isLeap:!1,lMonthZH:"",lDayZH:""},u,t||{},{zodiac:(n=u.sMonth,o=u.sDay,r=11,Y.forEach((function(l,e){var u=e+1;a(n,o)>=a(u,l)&&(r=e%12)})),M[r]+"座"),term:j(u.sYear,u.sMonth,u.sDay),animal:T(u.sYear,u.sMonth,u.sDay),gzYearZH:y(u.sYear,u.sMonth,u.sDay),gzMonthZH:p(u.sYear,u.sMonth,u.sDay),gzDayZH:D(u.sYear,u.sMonth,u.sDay),festival:[].concat(B(u.sYear,u.sMonth,u.sDay),C(u.sYear,u.sMonth,u.sDay),t?L(t.lYear,t.lMonth,t.lDay):[]).join(" ")})}var x={getDateBySolar:function(a,l,e){var o=n(a,l,e);return o?U(o):null},getDateByLunar:function(a,l,n,e){var t=function(a,l,n,e){if(ar)return null;if(l<1||l>12)return null;var t=d(a);if(e&&t!=l)return null;var m=parseInt(u[a-o],32);if(n>((e?65536&m:1<<17-l)?30:29))return null;for(var g=0,i=o;it&&(g+=65536&m?30:29),f+864e5*(g+n)}(a,l,n,e);return t?U(t):null},getDateByTimestamp:function(a){return U(a)},getToday:function(){return U(Date.now())}};export{x as default}; 14 | -------------------------------------------------------------------------------- /dist/calendar.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * calendar-tool v1.0.3 3 | * Chinese lunar calendar 4 | * https://passer-by.com/calendar/ 5 | * 6 | * Copyright (c) 2022-present, HaoLe Zheng 7 | * 8 | * Released under the MIT License 9 | * https://github.com/mumuy/calendar 10 | * 11 | * Created on: 2025-12-01 12 | */ 13 | !function(a,l){"object"==typeof exports&&"undefined"!=typeof module?module.exports=l():"function"==typeof define&&define.amd?define(l):(a="undefined"!=typeof globalThis?globalThis:a||self).calendar=l()}(this,(function(){"use strict";function a(){for(var a=arguments.length,l=new Array(a),n=0;n=16;e>>=1)l+=n&e?30:29;return d(a)&&(l+=65536&n?30:29),l}function g(a){var l,n,e=Math.floor((a-m)/864e5),g=0,i=0,c=!1;if(e<=0)return null;var s=0;for(g=o;g<=u&&!(s+(n=k(g))>=e);g++)s+=n;var h=parseInt(r[g-o],32),j=d(g);for(e-=s,s=0,i=1;i<=12&&!(s+(n=h&1<<16-i?30:29)>=e);i++)if(s+=n,j&&i==j){if(s+(n=65536&h?30:29)>=e){c=!0;break}s+=n}return{lYear:g,lMonth:i,lDay:l=e-s,isLeap:c,lMonthZH:(c?"闰":"")+t[i-1]+"月",lDayZH:f[l-1]}}var i=[4,19,3,18,4,19,4,19,4,20,4,20,6,22,6,22,6,22,7,22,6,21,6,21],c=["4lkmd5j6l5","55kql9lal9","59lanalala","5avbnatqla","7akmd5j6l5","55kql9lal9","59lalalala","5avbnatqla","7akmd5j6l5","55kql9lal9","59lalalala","5avbnatqla","7akmd5j6l5","4lkql9lal9","55kqlalala","5ananalqla","5akmd5j5kl","4lkqd9l6l5","55kqlalal9","5ananalqla","5akmd5j5kl","4lkmd9l6l5","55kqlalal9","59lanalqla","5akmd5j5kl","4lkmd9l6l5","55kql9lal9","59lanalala","5akmclj5al","4lkmd5j6l5","55kql9lal9","59lanalala","5akmclj5al","4lkmd5j6l5","55kql9lal9","59lalalala","5akmclj5al","4lkmd5j6l5","55kql9lal9","59lalalala","5akmclj5al","4lkmd5j6l5","55kql9lal9","59lalalala","5aklclj5al","4lkmd5j5kl","4lkql9l6l9","55kqlalala","5aclclb5al","2lkmd5j5kl","4lkmd9l6l9","55kqlalala","5aclclb5al","2lkmd5j5kl","4lkmd9l6l5","55kql9lal9","5aalclb5al","2lkmd5j5kl","4lkmd5j6l5","55kql9lal9","59alclalal","2lkmclj5al","4lkmd5j6l5","55kql9lal9","59alclalal","2lkmclj5al","4lkmd5j6l5","55kql9lal9","59alalalal","2lkmclj5al","4lkmd5j6l5","55kql9lal9","59alalalal","2lklclj5al","4lkmd5j6l5","55kql9l6l9","59a5alalal","2lklclb5al","4lkmd5j5l5","55kqd9l6l9","59a5alalal","2lklclb5al","4lkmd5j5kl","4lkmd9l6l9","55a5akalal","2lclclb5al","2lkmd5j5kl","4lkmd5l6l5","55a5akalak","2lalclalal","2lkmclj5kl","4lkmd5j6l5","55a5akalak","2kalclalal","2lkmclj5al","4lkmd5j6l5","55a5akalak","2kalalalal","2lkmclj5al","4lkmd5j6l5","55a5akalak","2kalalalal","2lkmclj5al","4lkmd5j6l5","55a5akalak","2kalalalal","2lklclb5al","4lkmd5j6l5","55a5akahak","2ka5alalal","2lklclb5al","4lkmd5j5l5","55a52kahak","2ka5akalal","2lklclb5al","4lkmd5j5kl","4la12kahak","2ga5akalal","2lclclb5al","2lkmclj5kl","4la12g8hak","2ga5akalak","2lalclalal","2lkmclj5kl","4la12g8hag","2ga5akalak","2kalalalal","2lkmclj5al","4la12g8hag","2ga5akalak","2kalalalal","2lkmclj5al","4la12g8hag","2ga5akalak","2kalalalal","2lklclb5al","4la12g8hag","2ga5akalak","2kalalalal","2lklclb5al","4la12g8hag","2ga52kahak","2ka5alalal","2lklclb5al","4la12g8gag","2ga12kahak","2ka5akalal","2lklclb5al","4la1208ga0","20a12g8hak","2ga5akalal","2lalclalal","2la1208ga0","20a12g8hak","2ga5akalal","2lalalalal","2la1208ga0","20a12g8hag","2ga5akalak","2lalalalal","2la1208g00","20a12g8hag","2ga5akalak","2kalalalal","2la1208g00","20a12g8hag","2ga5akalak","2kalalalal","2la0200g00","20a12g8hag","2ga52kahak","2kalalalal","2la0200g00","20a12g8gag","2ga52kahak","2ka5akalal","2la0200g00","20a12g8gag","2ga12gahak","2ka5akalal","2la0200g00","20a1208ga0","2ga12g8hak","2ga5akalal","2l00200000","a1208ga0","20a12g8hak","2ga5akalal","2l00000000","a1208ga0","20a12g8hag","2ga5akalak","2l00000000","a1208g00","20a12g8hag","2ga5akalak","2k00000000","a1200g00","20a12g8hag","2ga5akalak","2kalalalal"],s=["小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"];function h(a){if(au)return!1;var l=c[a-o],n=parseInt(l,32).toString(4);return 24!=n.length&&(n="0"+n),n.split("").map((function(a,l){return+a+i[l]}))}function j(a,l,n){var e="",o=h(a);return o&&(o.push(31),o.forEach((function(a,o){var u=Math.floor(o/2)+1;l==u&&n==a&&(e=s[o])}))),e}var b=["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"],v=["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"];function q(a){(a%=60)<0&&(a+=60);var l=a%12;return b[a%10]+v[l]}function y(a,l,e){return q(g(n(a,l,e)).lYear-1984)}function p(l,n,e){var o="",u=h(l);if(u){var r=0;u.push(31),u.forEach((function(l,o){var u=Math.floor(o/2)+1;a(n,e)>=a(u,l)&&(r=u)})),o=q(r+=12*(l-1984))}return o}function D(a,l,e){return q(Math.round((n(a,l,e)-n(1900,1,30))/864e5)+39)}var M=["水瓶","双鱼","白羊","金牛","双子","巨蟹","狮子","处女","天秤","天蝎","射手","摩羯"],Y=[20,19,21,20,21,22,23,23,23,24,23,22];var w=["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"];function T(a,l,e){var o=(g(n(a,l,e)).lYear-1984)%12;return w[o>-1?o:o+12]}function I(a,l){(null==l||l>a.length)&&(l=a.length);for(var n=0,e=new Array(l);n0&&void 0!==arguments[0]?arguments[0]:[]).filter((function(a){return f>=a.found})).map((function(a){return a.name}))}))}function B(a,l,n){var o,u=[],r=h(a),t=864e5;return(o=e(new Date(a,3,r[6]-1).getTime())).sYear==a&&o.sMonth==l&&o.sDay==n&&u.push("寒食节"),function(){for(var o=new Date(a,5,r[11]).getTime(),f=new Date(a,7,r[14]).getTime(),m=0,d=o;d<=f;d+=t){var k=e(d);D(k.sYear,k.sMonth,k.sDay).includes("庚")&&(m++,k.sYear==a&&k.sMonth==l&&k.sDay==n&&(3==m?u.push("初伏"):4==m&&u.push("中伏")))}m=0;for(var g=f;g<=f+1728e6;g+=t){var i=e(g);D(i.sYear,i.sMonth,i.sDay).includes("庚")&&(m++,i.sYear==a&&i.sMonth==l&&i.sDay==n&&(1==m?u.push("末伏"):2==m&&u.push("出伏")))}}(),function(){for(var o=h(a-1),t=new Date(a-1,11,o[23]).getTime(),f=new Date(a,11,r[23]).getTime(),m=0,d=t;d<=t+62208e5;d+=7776e5){var k=e(d);k.sYear==a&&k.sMonth==l&&k.sDay==n&&u.push(E[m]),m++}m=0;for(var g=f;g<=f+62208e5;g+=7776e5){var i=e(g);i.sYear==a&&i.sMonth==l&&i.sDay==n&&u.push(E[m]),m++}}(),function(){var e=function(a){if(a<1900||a>2100)return null;var l=a-1900,n=l%19,e=Math.floor(l/4),o=(11*n+4-Math.floor((7*n+1)/19))%29,u=25-o-(l+e+31-o)%7;return u>0?[4,u]:[3,31+u]}(a);if(e){var o=H(e,2),r=o[0],t=o[1];r==l&&t==n&&u.push("复活节")}}(),u}function C(l,n,e){var u=[],t=a(l,n,e),f=a(n,e);return 12==n&&e==function(a,l,n){var e=d(a),u=parseInt(r[a-o],32),t=u&1<<16-l?30:29;return n&&l==e&&(t=65536&u?30:29),t}(l,12)?u.push(A["12-30"][0].name):u=u.concat([A[f],O[f]].flatMap((function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).filter((function(a){return t>=a.found})).map((function(a){return a.name}))}))),u}function L(l){var n,o,u,r=e(l),t=g(l);return Object.assign({lYear:null,lMonth:null,lDay:null,isLeap:!1,lMonthZH:"",lDayZH:""},r,t||{},{zodiac:(n=r.sMonth,o=r.sDay,u=11,Y.forEach((function(l,e){var r=e+1;a(n,o)>=a(r,l)&&(u=e%12)})),M[u]+"座"),term:j(r.sYear,r.sMonth,r.sDay),animal:T(r.sYear,r.sMonth,r.sDay),gzYearZH:y(r.sYear,r.sMonth,r.sDay),gzMonthZH:p(r.sYear,r.sMonth,r.sDay),gzDayZH:D(r.sYear,r.sMonth,r.sDay),festival:[].concat(x(r.sYear,r.sMonth,r.sDay),B(r.sYear,r.sMonth,r.sDay),t?C(t.lYear,t.lMonth,t.lDay):[]).join(" ")})}return{getDateBySolar:function(a,l,e){var o=n(a,l,e);return o?L(o):null},getDateByLunar:function(a,l,n,e){var t=function(a,l,n,e){if(au)return null;if(l<1||l>12)return null;var t=d(a);if(e&&t!=l)return null;var f=parseInt(r[a-o],32);if(n>((e?65536&f:1<<17-l)?30:29))return null;for(var g=0,i=o;it&&(g+=65536&f?30:29),m+864e5*(g+n)}(a,l,n,e);return t?L(t):null},getDateByTimestamp:function(a){return L(a)},getToday:function(){return L(Date.now())}}})); 14 | -------------------------------------------------------------------------------- /src/module/config/holiday.js: -------------------------------------------------------------------------------- 1 | // 法定节假日 (不配置使用默认节假日) 2 | export const holidayMap = { 3 | '2015':[ // 当年新增“抗日战争胜利纪念日”为法定假日 4 | { 5 | value:'2015-01-01', 6 | name:'元旦' 7 | }, 8 | { 9 | value:'2015-02-19', 10 | name:'春节' 11 | }, 12 | { 13 | value:'2015-04-05', 14 | name:'清明' 15 | }, 16 | { 17 | value:'2015-05-01', 18 | name:'劳动节' 19 | }, 20 | { 21 | value:'2015-06-20', 22 | name:'端午节' 23 | }, 24 | { 25 | value:'2015-09-03', 26 | name:'胜利日' 27 | }, 28 | { 29 | value:'2015-09-27', 30 | name:'中秋节' 31 | }, 32 | { 33 | value:'2015-10-01', 34 | name:'国庆节' 35 | } 36 | ] 37 | }; 38 | // 假期放假安排 39 | export const scheduleMap = { 40 | '2011': { 41 | '04-02': 0, 42 | '04-03': 1, 43 | '04-04': 1, 44 | '04-05': 1, 45 | '04-30': 1, 46 | '05-01': 1, 47 | '05-02': 1, 48 | '06-04': 1, 49 | '06-05': 1, 50 | '06-06': 1, 51 | '09-10': 1, 52 | '09-11': 1, 53 | '09-12': 1, 54 | '10-01': 1, 55 | '10-02': 1, 56 | '10-03': 1, 57 | '10-04': 1, 58 | '10-05': 1, 59 | '10-06': 1, 60 | '10-07': 1, 61 | '10-08': 0, 62 | '10-09': 0, 63 | '12-31': 0 64 | }, 65 | '2012': { 66 | '01-01': 1, 67 | '01-02': 1, 68 | '01-03': 1, 69 | '01-21': 0, 70 | '01-22': 1, 71 | '01-23': 1, 72 | '01-24': 1, 73 | '01-25': 1, 74 | '01-26': 1, 75 | '01-27': 1, 76 | '01-28': 1, 77 | '01-29': 0, 78 | '03-31': 0, 79 | '04-01': 0, 80 | '04-02': 1, 81 | '04-03': 1, 82 | '04-04': 1, 83 | '04-28': 0, 84 | '04-29': 1, 85 | '04-30': 1, 86 | '05-01': 1, 87 | '06-22': 1, 88 | '06-23': 1, 89 | '06-24': 1, 90 | '09-29': 0, 91 | '09-30': 1, 92 | '10-01': 1, 93 | '10-02': 1, 94 | '10-03': 1, 95 | '10-04': 1, 96 | '10-05': 1, 97 | '10-06': 1, 98 | '10-07': 1 99 | }, 100 | '2013': { 101 | '01-01': 1, 102 | '01-02': 1, 103 | '01-03': 1, 104 | '01-05': 0, 105 | '01-06': 0, 106 | '02-09': 1, 107 | '02-10': 1, 108 | '02-11': 1, 109 | '02-12': 1, 110 | '02-13': 1, 111 | '02-14': 1, 112 | '02-15': 1, 113 | '02-16': 0, 114 | '02-17': 0, 115 | '04-04': 1, 116 | '04-05': 1, 117 | '04-06': 1, 118 | '04-07': 0, 119 | '04-27': 0, 120 | '04-28': 0, 121 | '04-29': 1, 122 | '04-30': 1, 123 | '05-01': 1, 124 | '06-08': 0, 125 | '06-09': 0, 126 | '06-10': 1, 127 | '06-11': 1, 128 | '06-12': 1, 129 | '09-19': 1, 130 | '09-20': 1, 131 | '09-21': 1, 132 | '09-22': 0, 133 | '09-29': 0, 134 | '10-01': 1, 135 | '10-02': 1, 136 | '10-03': 1, 137 | '10-04': 1, 138 | '10-05': 1, 139 | '10-06': 1, 140 | '10-07': 1, 141 | '10-12': 0 142 | }, 143 | '2014': { 144 | '01-01': 1, 145 | '01-26': 0, 146 | '01-31': 1, 147 | '02-01': 1, 148 | '02-02': 1, 149 | '02-03': 1, 150 | '02-04': 1, 151 | '02-05': 1, 152 | '02-06': 1, 153 | '02-08': 0, 154 | '04-05': 1, 155 | '04-06': 1, 156 | '04-07': 1, 157 | '05-01': 1, 158 | '05-02': 1, 159 | '05-03': 1, 160 | '05-04': 0, 161 | '05-31': 1, 162 | '06-01': 1, 163 | '06-02': 1, 164 | '09-08': 1, 165 | '09-28': 0, 166 | '10-01': 1, 167 | '10-02': 1, 168 | '10-03': 1, 169 | '10-04': 1, 170 | '10-05': 1, 171 | '10-06': 1, 172 | '10-07': 1, 173 | '10-11': 0 174 | }, 175 | '2015': { 176 | '01-01': 1, 177 | '01-02': 1, 178 | '01-03': 1, 179 | '01-04': 0, 180 | '02-15': 0, 181 | '02-18': 1, 182 | '02-19': 1, 183 | '02-20': 1, 184 | '02-21': 1, 185 | '02-22': 1, 186 | '02-23': 1, 187 | '02-24': 1, 188 | '02-28': 0, 189 | '04-04': 1, 190 | '04-05': 1, 191 | '04-06': 1, 192 | '05-01': 1, 193 | '05-02': 1, 194 | '05-03': 1, 195 | '06-20': 1, 196 | '06-21': 1, 197 | '06-22': 1, 198 | '09-03': 1, 199 | '09-04': 1, 200 | '09-05': 1, 201 | '09-06': 0, 202 | '09-27': 1, 203 | '10-01': 1, 204 | '10-02': 1, 205 | '10-03': 1, 206 | '10-04': 1, 207 | '10-05': 1, 208 | '10-06': 1, 209 | '10-07': 1, 210 | '10-10': 0 211 | }, 212 | '2016': { 213 | '01-01': 1, 214 | '01-02': 1, 215 | '01-03': 1, 216 | '02-06': 0, 217 | '02-07': 1, 218 | '02-08': 1, 219 | '02-09': 1, 220 | '02-10': 1, 221 | '02-11': 1, 222 | '02-12': 1, 223 | '02-13': 1, 224 | '02-14': 0, 225 | '04-02': 1, 226 | '04-03': 1, 227 | '04-04': 1, 228 | '04-30': 1, 229 | '05-01': 1, 230 | '05-02': 1, 231 | '06-09': 1, 232 | '06-10': 1, 233 | '06-11': 1, 234 | '06-12': 0, 235 | '09-15': 1, 236 | '09-16': 1, 237 | '09-17': 1, 238 | '09-18': 0, 239 | '10-01': 1, 240 | '10-02': 1, 241 | '10-03': 1, 242 | '10-04': 1, 243 | '10-05': 1, 244 | '10-06': 1, 245 | '10-07': 1, 246 | '10-08': 0, 247 | '10-09': 0 248 | }, 249 | '2017': { 250 | '01-01': 1, 251 | '01-02': 1, 252 | '01-22': 0, 253 | '01-27': 1, 254 | '01-28': 1, 255 | '01-29': 1, 256 | '01-30': 1, 257 | '01-31': 1, 258 | '02-01': 1, 259 | '02-02': 1, 260 | '02-04': 0, 261 | '04-01': 0, 262 | '04-02': 1, 263 | '04-03': 1, 264 | '04-04': 1, 265 | '04-29': 1, 266 | '04-30': 1, 267 | '05-01': 1, 268 | '05-27': 0, 269 | '05-28': 1, 270 | '05-29': 1, 271 | '05-30': 1, 272 | '09-30': 0, 273 | '10-01': 1, 274 | '10-02': 1, 275 | '10-03': 1, 276 | '10-04': 1, 277 | '10-05': 1, 278 | '10-06': 1, 279 | '10-07': 1, 280 | '10-08': 1, 281 | '12-30': 1, 282 | '12-31': 1 283 | }, 284 | '2018': { 285 | '01-01': 1, 286 | '02-11': 0, 287 | '02-15': 1, 288 | '02-16': 1, 289 | '02-17': 1, 290 | '02-18': 1, 291 | '02-19': 1, 292 | '02-20': 1, 293 | '02-21': 1, 294 | '02-24': 0, 295 | '04-05': 1, 296 | '04-06': 1, 297 | '04-07': 1, 298 | '04-08': 0, 299 | '04-28': 0, 300 | '04-29': 1, 301 | '04-30': 1, 302 | '05-01': 1, 303 | '06-16': 1, 304 | '06-17': 1, 305 | '06-18': 1, 306 | '09-22': 1, 307 | '09-23': 1, 308 | '09-24': 1, 309 | '09-29': 0, 310 | '09-30': 0, 311 | '10-01': 1, 312 | '10-02': 1, 313 | '10-03': 1, 314 | '10-04': 1, 315 | '10-05': 1, 316 | '10-06': 1, 317 | '10-07': 1, 318 | '12-29': 0, 319 | '12-30': 1, 320 | '12-31': 1 321 | }, 322 | '2019': { 323 | '01-01': 1, 324 | '02-02': 0, 325 | '02-03': 0, 326 | '02-04': 1, 327 | '02-05': 1, 328 | '02-06': 1, 329 | '02-07': 1, 330 | '02-08': 1, 331 | '02-09': 1, 332 | '02-10': 1, 333 | '04-05': 1, 334 | '04-06': 1, 335 | '04-07': 1, 336 | '04-28': 0, 337 | '05-01': 1, 338 | '05-02': 1, 339 | '05-03': 1, 340 | '05-04': 1, 341 | '05-05': 0, 342 | '06-07': 1, 343 | '06-08': 1, 344 | '06-09': 1, 345 | '09-13': 1, 346 | '09-14': 1, 347 | '09-15': 1, 348 | '09-29': 0, 349 | '10-01': 1, 350 | '10-02': 1, 351 | '10-03': 1, 352 | '10-04': 1, 353 | '10-05': 1, 354 | '10-06': 1, 355 | '10-07': 1, 356 | '10-12': 0 357 | }, 358 | '2020': { 359 | '01-01': 1, 360 | '01-19': 0, 361 | '01-24': 1, 362 | '01-25': 1, 363 | '01-26': 1, 364 | '01-27': 1, 365 | '01-28': 1, 366 | '01-29': 1, 367 | '01-30': 1, 368 | '02-01': 0, 369 | '04-04': 1, 370 | '04-05': 1, 371 | '04-06': 1, 372 | '04-26': 0, 373 | '05-01': 1, 374 | '05-02': 1, 375 | '05-03': 1, 376 | '05-04': 1, 377 | '05-05': 1, 378 | '05-09': 0, 379 | '06-25': 1, 380 | '06-26': 1, 381 | '06-27': 1, 382 | '06-28': 0, 383 | '09-27': 0, 384 | '10-01': 1, 385 | '10-02': 1, 386 | '10-03': 1, 387 | '10-04': 1, 388 | '10-05': 1, 389 | '10-06': 1, 390 | '10-07': 1, 391 | '10-08': 1, 392 | '10-10': 0 393 | }, 394 | '2021': { 395 | '01-01': 1, 396 | '01-02': 1, 397 | '01-03': 1, 398 | '02-07': 0, 399 | '02-11': 1, 400 | '02-12': 1, 401 | '02-13': 1, 402 | '02-14': 1, 403 | '02-15': 1, 404 | '02-16': 1, 405 | '02-17': 1, 406 | '02-20': 0, 407 | '04-03': 1, 408 | '04-04': 1, 409 | '04-05': 1, 410 | '04-25': 0, 411 | '05-01': 1, 412 | '05-02': 1, 413 | '05-03': 1, 414 | '05-04': 1, 415 | '05-05': 1, 416 | '05-08': 0, 417 | '06-12': 1, 418 | '06-13': 1, 419 | '06-14': 1, 420 | '09-18': 0, 421 | '09-19': 1, 422 | '09-20': 1, 423 | '09-21': 1, 424 | '09-26': 0, 425 | '10-01': 1, 426 | '10-02': 1, 427 | '10-03': 1, 428 | '10-04': 1, 429 | '10-05': 1, 430 | '10-06': 1, 431 | '10-07': 1, 432 | '10-09': 0 433 | }, 434 | '2022': { 435 | '01-01': 1, 436 | '01-02': 1, 437 | '01-03': 1, 438 | '01-29': 0, 439 | '01-30': 0, 440 | '01-31': 1, 441 | '02-01': 1, 442 | '02-02': 1, 443 | '02-03': 1, 444 | '02-04': 1, 445 | '02-05': 1, 446 | '02-06': 1, 447 | '04-02': 0, 448 | '04-03': 1, 449 | '04-04': 1, 450 | '04-05': 1, 451 | '04-24': 0, 452 | '04-30': 1, 453 | '05-01': 1, 454 | '05-02': 1, 455 | '05-03': 1, 456 | '05-04': 1, 457 | '05-07': 0, 458 | '06-03': 1, 459 | '06-04': 1, 460 | '06-05': 1, 461 | '09-10': 1, 462 | '09-11': 1, 463 | '09-12': 1, 464 | '10-01': 1, 465 | '10-02': 1, 466 | '10-03': 1, 467 | '10-04': 1, 468 | '10-05': 1, 469 | '10-06': 1, 470 | '10-07': 1, 471 | '10-08': 0, 472 | '10-09': 0, 473 | '12-31': 1 474 | }, 475 | '2023': { 476 | '01-01': 1, 477 | '01-02': 1, 478 | '01-21': 1, 479 | '01-22': 1, 480 | '01-23': 1, 481 | '01-24': 1, 482 | '01-25': 1, 483 | '01-26': 1, 484 | '01-27': 1, 485 | '01-28': 0, 486 | '01-29': 0, 487 | '04-05': 1, 488 | '04-29': 1, 489 | '04-30': 1, 490 | '05-01': 1, 491 | '05-02': 1, 492 | '05-03': 1, 493 | '04-23': 0, 494 | '05-06': 0, 495 | '06-22': 1, 496 | '06-23': 1, 497 | '06-24': 1, 498 | '06-25': 0, 499 | '09-29': 1, 500 | '09-30': 1, 501 | '10-01': 1, 502 | '10-02': 1, 503 | '10-03': 1, 504 | '10-04': 1, 505 | '10-05': 1, 506 | '10-06': 1, 507 | '10-07': 0, 508 | '10-08': 0, 509 | '12-30': 1, 510 | '12-31': 1, 511 | }, 512 | '2024': { 513 | '01-01': 1, 514 | '02-04': 0, 515 | '02-10': 1, 516 | '02-11': 1, 517 | '02-12': 1, 518 | '02-13': 1, 519 | '02-14': 1, 520 | '02-15': 1, 521 | '02-16': 1, 522 | '02-17': 1, 523 | '02-18': 0, 524 | '04-04': 1, 525 | '04-05': 1, 526 | '04-06': 1, 527 | '04-07': 0, 528 | '04-28': 0, 529 | '05-01': 1, 530 | '05-02': 1, 531 | '05-03': 1, 532 | '05-04': 1, 533 | '05-05': 1, 534 | '05-11': 0, 535 | '06-08': 1, 536 | '06-09': 1, 537 | '06-10': 1, 538 | '09-14': 0, 539 | '09-15': 1, 540 | '09-16': 1, 541 | '09-17': 1, 542 | '09-29': 0, 543 | '10-01': 1, 544 | '10-02': 1, 545 | '10-03': 1, 546 | '10-04': 1, 547 | '10-05': 1, 548 | '10-06': 1, 549 | '10-07': 1, 550 | '10-12': 0, 551 | }, 552 | '2025': { 553 | '01-01': 1, 554 | '01-26': 0, 555 | '01-28': 1, 556 | '01-29': 1, 557 | '01-30': 1, 558 | '01-31': 1, 559 | '02-01': 1, 560 | '02-02': 1, 561 | '02-03': 1, 562 | '02-04': 1, 563 | '02-08': 0, 564 | '04-04': 1, 565 | '04-05': 1, 566 | '04-06': 1, 567 | '04-27': 0, 568 | '05-01': 1, 569 | '05-02': 1, 570 | '05-03': 1, 571 | '05-04': 1, 572 | '05-05': 1, 573 | '05-31': 1, 574 | '06-01': 1, 575 | '06-02': 1, 576 | '09-28': 0, 577 | '10-01': 1, 578 | '10-02': 1, 579 | '10-03': 1, 580 | '10-04': 1, 581 | '10-05': 1, 582 | '10-06': 1, 583 | '10-07': 1, 584 | '10-08': 1, 585 | '10-11': 0, 586 | }, 587 | '2026':{ 588 | '01-01':1, 589 | '01-02':1, 590 | '01-03':1, 591 | '01-04':0, 592 | '02-14':0, 593 | '02-15':1, 594 | '02-16':1, 595 | '02-17':1, 596 | '02-18':1, 597 | '02-19':1, 598 | '02-20':1, 599 | '02-21':1, 600 | '02-22':1, 601 | '02-23':1, 602 | '02-28':0, 603 | '04-04':1, 604 | '04-05':1, 605 | '04-06':1, 606 | '05-01':1, 607 | '05-02':1, 608 | '05-03':1, 609 | '05-04':1, 610 | '05-05':1, 611 | '05-09':0, 612 | '06-19':1, 613 | '06-20':1, 614 | '06-21':1, 615 | '09-20':0, 616 | '09-25':1, 617 | '09-26':1, 618 | '09-27':1, 619 | '10-01':1, 620 | '10-02':1, 621 | '10-03':1, 622 | '10-04':1, 623 | '10-05':1, 624 | '10-06':1, 625 | '10-07':1, 626 | '10-10':0, 627 | } 628 | }; 629 | -------------------------------------------------------------------------------- /src/widget-calendar.js: -------------------------------------------------------------------------------- 1 | /* 2 | * 万年历组件 3 | */ 4 | import {minYear,maxYear} from './module/config/base.js'; 5 | import {holidayMap,scheduleMap} from './module/config/holiday.js'; 6 | import {getDateString} from './module/tool.js'; 7 | import {getTimestampBySolar,getSolarByTimestamp,getSolarMonthDays} from './module/solar.js'; 8 | import {sFestival,lFestival,oFestival,tFestival} from './module/festival.js'; 9 | import calendar from './calendar.js'; 10 | 11 | import styleSheet from './style/widget.css' with { type: 'css'}; 12 | 13 | class WidgetCalendar extends HTMLElement { 14 | constructor() { 15 | super(); 16 | this.attachShadow({mode:'open'}); 17 | // 全局变量 18 | let _ = this; 19 | _.today = calendar.getToday(); 20 | _.currentDateInfo = _.today; 21 | _.currentMonthData = []; // 当前日期所在月份数据 22 | _.currentMonthDay = 1; // 当前日期当月几号 23 | } 24 | static get observedAttributes(){ 25 | return ['date','mode']; 26 | } 27 | get date(){ 28 | let today_date = getDateString(this.today['sYear'],this.today['sMonth'],this.today['sDay']); 29 | return this.getAttribute('date')||today_date; 30 | } 31 | set date(value){ 32 | this.setAttribute('date',value); 33 | } 34 | get mode(){ 35 | return this.getAttribute('mode')||'default'; 36 | } 37 | set mode(value){ 38 | this.setAttribute('mode',value); 39 | } 40 | attributeChangedCallback(name, oldValue, newValue){ 41 | if(name=='date'&&oldValue!=newValue){ 42 | this.formatDate(newValue); 43 | } 44 | } 45 | connectedCallback () { 46 | let _ = this; 47 | // 模板 48 | if(_.shadowRoot.adoptedStyleSheets){ 49 | _.shadowRoot.adoptedStyleSheets = [styleSheet]; 50 | }else{ 51 | const $style = document.createElement('style'); 52 | $style.rel = 'stylesheet'; 53 | $style.textContent = [...styleSheet.cssRules].map(item=>item.cssText).join(''); 54 | _.shadowRoot.appendChild($style); 55 | } 56 | _.render(); 57 | // 节点 58 | _.$module = _.shadowRoot.querySelector('.mod-calendar'); 59 | _.$tbody = _.$module.querySelector('tbody'); 60 | _.$year = _.$module.querySelector('.year'); 61 | _.$month = _.$module.querySelector('.month'); 62 | _.$holiday = _.$module.querySelector('.holiday'); 63 | _.$goback = _.$module.querySelector('.goback'); 64 | _.$prev_year = _.$module.querySelector('.prev-year'); 65 | _.$next_year = _.$module.querySelector('.next-year'); 66 | _.$prev_month = _.$module.querySelector('.prev-month'); 67 | _.$next_month = _.$module.querySelector('.next-month'); 68 | _.$info = _.$module.querySelector('.info'); 69 | 70 | let changeDate = function(year,month,day){ 71 | day = Math.min(getSolarMonthDays(year,month),day); 72 | _.currentMonthDay = day; 73 | let timestamp = getTimestampBySolar(year,month,day); 74 | let thatDay = getSolarByTimestamp(timestamp); 75 | if(thatDay.date!=_.date){ 76 | _.date = thatDay.date; 77 | } 78 | }; 79 | 80 | _.$year.onchange = function(){ 81 | let year = _.$year.value||_.$year.getAttribute('data-value'); 82 | let month = _.$month.value||_.$month.getAttribute('data-value'); 83 | changeDate(year,month,_.currentMonthDay); 84 | }; 85 | _.$month.onchange = function(){ 86 | let year = _.$year.value||_.$year.getAttribute('data-value'); 87 | let month = _.$month.value||_.$month.getAttribute('data-value'); 88 | changeDate(year,month,_.currentMonthDay); 89 | }; 90 | _.$holiday.onchange = function(){ 91 | let value = _.$holiday.value; 92 | if(value){ 93 | let [year,month,day] = value.split('-'); 94 | changeDate(year,month,day); 95 | } 96 | }; 97 | _.$goback.onclick = function(){ 98 | if(_.today.date!=_.date){ 99 | _.date = _.today.date; 100 | } 101 | }; 102 | _.$prev_year.onclick = function(){ 103 | let year = _.$year.value||_.$year.getAttribute('data-value'); 104 | let month = _.$month.value||_.$month.getAttribute('data-value'); 105 | year--; 106 | changeDate(year,month,_.currentMonthDay); 107 | }; 108 | _.$next_year.onclick = function(){ 109 | let year = _.$year.value||_.$year.getAttribute('data-value'); 110 | let month = _.$month.value||_.$month.getAttribute('data-value'); 111 | year++; 112 | changeDate(year,month,_.currentMonthDay); 113 | }; 114 | _.$prev_month.onclick = function(){ 115 | let year = _.$year.value||_.$year.getAttribute('data-value'); 116 | let month = _.$month.value||_.$month.getAttribute('data-value'); 117 | month--; 118 | changeDate(year,month,_.currentMonthDay); 119 | }; 120 | _.$next_month.onclick = function(){ 121 | let year = _.$year.value||_.$year.getAttribute('data-value'); 122 | let month = _.$month.value||_.$month.getAttribute('data-value'); 123 | month++; 124 | changeDate(year,month,_.currentMonthDay); 125 | }; 126 | _.$tbody.onclick = function(event){ 127 | let target = event.target; 128 | while(target.tagName!='TD'&&target.tagName!='TABLE'){ 129 | target = target.parentNode; 130 | } 131 | let id = target.getAttribute('data-id'); 132 | if(target.tagName=='TD'&&id){ 133 | let thatDay = _.currentMonthData[id]; 134 | _.currentMonthDay = thatDay['sDay']; 135 | changeDate(thatDay['sYear'],thatDay['sMonth'],thatDay['sDay']); 136 | _.dispatchEvent(new CustomEvent('onSelect',{'detail':calendar.getDateBySolar(thatDay['sYear'],thatDay['sMonth'],thatDay['sDay'])})); 137 | } 138 | }; 139 | _.formatDate(_.date); 140 | setTimeout(function(){ 141 | _.dispatchEvent(new CustomEvent('onInit',{'detail':_.currentDateInfo})); 142 | },1); 143 | } 144 | render(){ 145 | this.shadowRoot.innerHTML = `
146 |
147 |
148 |
149 | 150 | 151 | 160 | 161 | 162 | 163 | 164 | 173 | 174 | 175 | 176 | 179 | 180 | 181 | 返回今天 182 | 183 |
184 |
185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 |
200 |
201 |
202 |
`; 203 | } 204 | formatTable(param){ 205 | let _ = this; 206 | let thatDay = _.today; 207 | if(param){ 208 | thatDay = calendar.getDateBySolar(+param['year'],+param['month'],+param['day']); 209 | } 210 | let that_date = getDateString(thatDay['sYear'],thatDay['sMonth'],thatDay['sDay']); 211 | //获取日历信息 212 | let firstDay = calendar.getDateBySolar(thatDay['sYear'],thatDay['sMonth'],1); 213 | let monthDays = getSolarMonthDays(thatDay['sYear'],thatDay['sMonth']); 214 | _.currentMonthData = []; 215 | // 上月日期 216 | for(let i=firstDay['week'];i>0;i--){ 217 | let obj = calendar.getDateBySolar(firstDay['sYear'],firstDay['sMonth'],firstDay['sDay']-i); 218 | _.currentMonthData.push(obj); 219 | } 220 | // 当月日期 221 | for(let i=0;iitem.name).includes(value); 271 | } 272 | return false; 273 | }); 274 | const other_festival = item['festival'].split(' ').find(function(value){ 275 | if(value.length<=3){ 276 | return Object.values(sFestival).flat().map(item=>item.name).includes(value) 277 | ||Object.values(oFestival).flat().map(item=>item.name).includes(value) 278 | ||tFestival.includes(value); 279 | } 280 | return false; 281 | }); 282 | html += ` 283 | 284 | ${item['sDay']} 285 | ${lunar_festival||item['term']||other_festival||item['lDayZH']||' '} 286 | ${sign&&map[sign]?''+map[sign]+'':''} 287 | 288 | `; 289 | if(i%7==6&&iitem.name).includes(value); 297 | }); 298 | const other_festivals = thatDay['festival'].split(' ').filter(function(value){ 299 | return !Object.values(lFestival).flat().map(item=>item.name).includes(value); 300 | }); 301 | _.$year.value = thatDay['sYear']; 302 | _.$month.value = thatDay['sMonth']; 303 | _.$year.setAttribute('data-value',thatDay['sYear']); 304 | _.$month.setAttribute('data-value',thatDay['sMonth']); 305 | _.$info.innerHTML = `
${that_date} ${thatDay['weekZH']}
306 |
${thatDay['sDay']}
307 |
308 | ${thatDay['lMonthZH']?`

${thatDay['lMonthZH']}${thatDay['lDayZH']}

`:``} 309 | ${thatDay['gzYearZH']?`

${thatDay['gzYearZH']}年 【${thatDay['animal']}年】

`:``} 310 | ${thatDay['gzMonthZH']?`

${thatDay['gzMonthZH']}月 ${thatDay['gzDayZH']}日

`:``} 311 |
312 |
313 | 314 |
${lunar_festivals.map(value=>`

${value}

`).join('')+thatDay['term'].split(' ').map(value=>`

${value}

`).join('')+other_festivals.map(value=>`

${value}

`).join('')}
315 |
316 | `; 317 | _.$tbody.innerHTML = html; 318 | 319 | _.currentDateInfo = thatDay; 320 | _.dispatchEvent(new CustomEvent('onChange',{'detail':thatDay})); 321 | } 322 | formatSetting(year){ 323 | let _ = this; 324 | year = year||(new Date()).getFullYear(); 325 | _.$holiday.innerHTML = ''; 326 | let $o = new Option("假日安排",""); 327 | _.$holiday.add($o); 328 | if(holidayMap[year]){ 329 | let items = holidayMap[year]; 330 | for(let i=0;i=2011){ 335 | const list = ['元旦','春节','清明','劳动节','端午节','中秋节','国庆节']; 336 | for(let m=1;m<=12;m++){ 337 | for(let d=1;d<=31;d++){ 338 | let date = calendar.getDateBySolar(year,m,d); 339 | if(date['sMonth']==m&&date['sDay']==d){ 340 | let types = []; 341 | if(date['term']){ 342 | types.push(date['term']); 343 | } 344 | if(date['festival']){ 345 | types = [].concat(types,date['festival'].split(' ')); 346 | } 347 | types.forEach(function(type){ 348 | if(list.includes(type)){ 349 | let $option = new Option(type,date['sYear']+'-'+date['sMonth']+'-'+date['sDay']); 350 | _.$holiday.add($option); 351 | } 352 | }); 353 | } 354 | } 355 | } 356 | } 357 | } 358 | formatDate(date){ 359 | let _ = this; 360 | if(date){ 361 | _.date = date; 362 | let [year,month,day] = date.split('-'); 363 | _.formatSetting(year); 364 | _.formatTable({'year':year,'month':month,'day':day}); 365 | }else{ 366 | _.date = _.today.date; 367 | _.formatSetting(); 368 | _.formatTable(); 369 | } 370 | } 371 | } 372 | 373 | if(!customElements.get('widget-calendar')){ 374 | customElements.define('widget-calendar', WidgetCalendar); 375 | } 376 | -------------------------------------------------------------------------------- /src/module/festival.js: -------------------------------------------------------------------------------- 1 | import {getDateString} from './tool.js'; 2 | import {getSolarByTimestamp} from './solar.js'; 3 | import {getLunarMonthDays} from './lunar.js'; 4 | import {getTermDate} from './term.js'; 5 | import {getGanZhiDay} from './ganzhi.js'; 6 | 7 | // 公历主要节日 8 | export const sFestival = { 9 | '01-01':[{ 10 | 'name':'元旦', 11 | 'found':'1949' 12 | }], 13 | '02-14':[{ 14 | 'name':'情人节', 15 | 'found':'0270' 16 | }], 17 | '03-08':[{ 18 | 'name':'妇女节', 19 | 'found':'1949-12' 20 | }], 21 | '03-12':[{ 22 | 'name':'植树节', 23 | 'found':'1979' 24 | }], 25 | '04-01':[{ 26 | 'name':'愚人节', 27 | 'found':'1564' 28 | }], 29 | '05-01':[{ 30 | 'name':'劳动节', 31 | 'found':'1949-12' 32 | }], 33 | '05-04':[{ 34 | 'name':'青年节', 35 | 'found':'1949-12' 36 | }], 37 | '06-01':[{ 38 | 'name':'儿童节', 39 | 'found':'1949-11' 40 | }], 41 | '07-01':[{ 42 | 'name':'建党节', 43 | 'found':'1938-05' 44 | }], 45 | '08-01':[{ 46 | 'name':'建军节', 47 | 'found':'1933-07-11' 48 | }], 49 | '09-10':[{ 50 | 'name':'教师节', 51 | 'found':'1985-06' 52 | }], 53 | '10-01':[{ 54 | 'name':'国庆节', 55 | 'found':'1949-12-02' 56 | }], 57 | '10-25':[{ 58 | 'name':'台湾光复纪念日', 59 | 'found':'2025-10-25' 60 | }], 61 | '11-01':[{ 62 | 'name':'万圣节', 63 | 'found':'0600' 64 | }], 65 | '12-05':[{ 66 | 'name':'国际志愿人员日', 67 | 'found':'1985-12-17' 68 | }], 69 | '12-13':[{ 70 | 'name':'国家公祭日', 71 | 'found':'2014-02-27' 72 | }], 73 | '12-25':[{ 74 | 'name':'圣诞节', 75 | 'found':'0336' 76 | }], 77 | }; 78 | // 公历非主要节日 79 | export const sFestival2 = { 80 | '01-10':[{ 81 | 'name':'中国人民警察节', 82 | 'found':'2020-07-21' 83 | }], 84 | '01-26':[{ 85 | 'name':'国际海关日', 86 | 'found':'1983-01-26' 87 | }], 88 | '02-02':[{ 89 | 'name':'世界湿地日', 90 | 'found':'1996' 91 | }], 92 | '02-10':[{ 93 | 'name':'国际气象节', 94 | 'found':'1991-02-10' 95 | }], 96 | '03-01':[{ 97 | 'name':'国际海豹日', 98 | 'found':'1983' 99 | }], 100 | '03-03':[{ 101 | 'name':'全国爱耳日', 102 | 'found':'1998-03' 103 | }], 104 | '03-05':[{ 105 | 'name':'雷锋纪念日', 106 | 'found':'1963-03-05' 107 | }], 108 | '03-09':[{ 109 | 'name':'保护母亲河日', 110 | 'found':'2002' 111 | }], 112 | '03-15':[{ 113 | 'name':'消费者权益日', 114 | 'found':'1983' 115 | }], 116 | '03-17':[{ 117 | 'name':'国际航海日', 118 | 'found':'1977-11' 119 | }], 120 | '03-18':[{ 121 | 'name':'全国爱肝日', 122 | 'found':'2001' 123 | }], 124 | '03-21':[{ 125 | 'name':'世界森林日', 126 | 'found':'2012-12' 127 | },{ 128 | 'name':'世界睡眠日', 129 | 'found':'2001' 130 | }], 131 | '03-22':[{ 132 | 'name':'世界水日', 133 | 'found':'1993-01-18' 134 | }], 135 | '03-23':[{ 136 | 'name':'世界气象日', 137 | 'found':'1961' 138 | }], 139 | '03-24':[{ 140 | 'name':'防治结核病日', 141 | 'found':'1995-03-24' 142 | }], 143 | '03-27':[{ 144 | 'name':'学生安全教育日', 145 | 'found':'1996-03-25' 146 | }], 147 | '04-07':[{ 148 | 'name':'世界卫生日', 149 | 'found':'1948-06' 150 | }], 151 | '04-13':[{ 152 | 'name':'泼水节', 153 | 'found':'' 154 | }], 155 | '04-15':[{ 156 | 'name':'国家安全教育日', 157 | 'found':'2015-07-01' 158 | }], 159 | '04-22':[{ 160 | 'name':'世界地球日', 161 | 'found':'1970' 162 | }], 163 | '04-23':[{ 164 | 'name':'世界读书日', 165 | 'found':'1995-11-15' 166 | }], 167 | '04-24':[{ 168 | 'name':'中国航天日', 169 | 'found':'2016-03-08' 170 | }], 171 | '04-26':[{ 172 | 'name':'知识产权日', 173 | 'found':'2001-04-26' 174 | }], 175 | '05-08':[{ 176 | 'name':'世界微笑日', 177 | 'found':'1948' 178 | }, 179 | { 180 | 'name':'世界红十字日', 181 | 'found':'1948' 182 | }], 183 | '05-12':[{ 184 | 'name':'国际护士节', 185 | 'found':'1912' 186 | }, 187 | { 188 | 'name':'防灾减灾日', 189 | 'found':'2009-05-12' 190 | }], 191 | '05-15':[{ 192 | 'name':'国际家庭日', 193 | 'found':'1994-05-15' 194 | }], 195 | '05-17':[{ 196 | 'name':'世界电信日', 197 | 'found':'1968' 198 | }], 199 | '05-18':[{ 200 | 'name':'国际博物馆日', 201 | 'found':'1977-05-18' 202 | }], 203 | '05-19':[{ 204 | 'name':'中国旅游日', 205 | 'found':'2001-05-19' 206 | }], 207 | '05-20':[{ 208 | 'name':'学生营养日', 209 | 'found':'2001-03' 210 | }], 211 | '05-22':[{ 212 | 'name':'国际生物多样性日', 213 | 'found':'2000-12-20' 214 | }], 215 | '05-30':[{ 216 | 'name':'五卅运动纪念日', 217 | 'found':'1925-05-30' 218 | }], 219 | '05-31':[{ 220 | 'name':'世界无烟日', 221 | 'found':'1987-11' 222 | }], 223 | '06-05':[{ 224 | 'name':'世界环境日', 225 | 'found':'1972-06-05' 226 | }], 227 | '06-06':[{ 228 | 'name':'全国爱眼日', 229 | 'found':'1996' 230 | }], 231 | '06-11':[{ 232 | 'name':'中国人口日', 233 | 'found':'1990' 234 | }], 235 | '06-14':[{ 236 | 'name':'世界献血者日', 237 | 'found':'2005-05-24' 238 | }], 239 | '06-23':[{ 240 | 'name':'国际奥林匹克日', 241 | 'found':'1948-06-23' 242 | }], 243 | '06-25':[{ 244 | 'name':'全国土地日', 245 | 'found':'1991-05-24' 246 | }], 247 | '06-26':[{ 248 | 'name':'国际禁毒日', 249 | 'found':'1987-06-12' 250 | }], 251 | '07-01':[{ 252 | 'name':'香港回归纪念日', 253 | 'found':'1997-07-01' 254 | }], 255 | '07-02':[{ 256 | 'name':'国际体育记者日', 257 | 'found':'1995' 258 | }], 259 | '07-11':[{ 260 | 'name':'世界人口日', 261 | 'found':'1989' 262 | }], 263 | '08-08':[{ 264 | 'name':'全民健身日', 265 | 'found':'2009' 266 | }], 267 | '08-12':[{ 268 | 'name':'国际青年日', 269 | 'found':'1999-12-17' 270 | }], 271 | '08-19':[{ 272 | 'name':'中国医师节', 273 | 'found':'2017-11-03' 274 | }], 275 | '08-26':[{ 276 | 'name':'全国律师咨询日', 277 | 'found':'1980-08-26' 278 | }], 279 | '09-03':[{ 280 | 'name':'抗战胜利纪念日', 281 | 'found':'2014-02-27' 282 | }], 283 | '09-08':[{ 284 | 'name':'国际扫盲日', 285 | 'found':'1965-11-17' 286 | }], 287 | '09-16':[{ 288 | 'name':'中国脑健康日', 289 | 'found':'2000-09-16' 290 | }, 291 | { 292 | 'name':'国际臭氧层保护日', 293 | 'found':'1995-01-23' 294 | }], 295 | '09-18':[{ 296 | 'name':'九一八事变纪念日', 297 | 'found':'1931-09-18' 298 | }], 299 | '09-20':[{ 300 | 'name':'全国爱牙日', 301 | 'found':'1989' 302 | }], 303 | '09-21':[{ 304 | 'name':'国际和平日', 305 | 'found':'2001-09-07' 306 | }], 307 | '09-27':[{ 308 | 'name':'世界旅游日', 309 | 'found':'1970-09-27' 310 | }], 311 | '09-28':[{ 312 | 'name':'孔子诞辰纪念日', 313 | 'found':'1913-09-28' 314 | }], 315 | '09-30':[{ 316 | 'name':'烈士纪念日', 317 | 'found':'2014-09-30' 318 | }], 319 | '10-04':[{ 320 | 'name':'世界动物日', 321 | 'found':'1931' 322 | }], 323 | '10-05':[{ 324 | 'name':'世界教师日', 325 | 'found':'1994' 326 | }], 327 | '10-08':[{ 328 | 'name':'全国高血压日', 329 | 'found':'1998' 330 | }], 331 | '10-09':[{ 332 | 'name':'世界邮政日', 333 | 'found':'1984' 334 | }], 335 | '10-13':[{ 336 | 'name':'世界保健日', 337 | 'found':'1950' 338 | }], 339 | '10-14':[{ 340 | 'name':'世界标准日', 341 | 'found':'1946' 342 | }], 343 | '10-15':[{ 344 | 'name':'国际盲人节', 345 | 'found':'1984' 346 | }], 347 | '10-16':[{ 348 | 'name':'世界粮食日', 349 | 'found':'1981-10-16' 350 | }], 351 | '10-24':[{ 352 | 'name':'联合国日', 353 | 'found':'1947-10-24' 354 | }], 355 | '11-08':[{ 356 | 'name':'记者节', 357 | 'found':'2000-08-01' 358 | }], 359 | '11-09':[{ 360 | 'name':'消防宣传日', 361 | 'found':'1992' 362 | }], 363 | '11-14':[{ 364 | 'name':'世界防治糖尿病日', 365 | 'found':'1991' 366 | }], 367 | '11-17':[{ 368 | 'name':'国际大学生节', 369 | 'found':'1946-11-17' 370 | }], 371 | '12-01':[{ 372 | 'name':'世界艾滋病日', 373 | 'found':'1988' 374 | }], 375 | '12-03':[{ 376 | 'name':'国际残疾人日', 377 | 'found':'1992-10-12' 378 | }], 379 | '12-04':[{ 380 | 'name':'国家宪法日', 381 | 'found':'2014-11-01' 382 | }], 383 | '12-09':[{ 384 | 'name':'世界足球日', 385 | 'found':'1978' 386 | }], 387 | '12-10':[{ 388 | 'name':'世界人权日', 389 | 'found':'1948-12-10' 390 | }], 391 | '12-11':[{ 392 | 'name':'国际山岳日', 393 | 'found':'2003-12-11' 394 | }], 395 | '12-15':[{ 396 | 'name':'强化免疫日', 397 | 'found':'1988' 398 | }], 399 | '12-20':[{ 400 | 'name':'澳门回归纪念日', 401 | 'found':'1999-12-20' 402 | }], 403 | }; 404 | // 农历主要节日 405 | export const lFestival = { 406 | '01-01':[{ 407 | 'name':'春节', 408 | 'found':'' 409 | }], 410 | '01-15':[{ 411 | 'name':'元宵节', 412 | 'found':'' 413 | }], 414 | '02-02':[{ 415 | 'name':'龙头节', 416 | 'found':'' 417 | }], 418 | '03-03':[{ 419 | 'name':'上巳节', 420 | 'found':'' 421 | }], 422 | '05-05':[{ 423 | 'name':'端午节', 424 | 'found':'' 425 | }], 426 | '07-07':[{ 427 | 'name':'七夕节', 428 | 'found':'' 429 | }], 430 | '07-15':[{ 431 | 'name':'中元节', 432 | 'found':'' 433 | }], 434 | '08-15':[{ 435 | 'name':'中秋节', 436 | 'found':'' 437 | }], 438 | '09-09':[{ 439 | 'name':'重阳节', 440 | 'found':'' 441 | }], 442 | '10-15':[{ 443 | 'name':'下元节', 444 | 'found':'' 445 | }], 446 | '12-08':[{ 447 | 'name':'腊八节', 448 | 'found':'' 449 | }], 450 | '12-23':[{ 451 | 'name':'北小年', 452 | 'found':'' 453 | }], 454 | '12-24':[{ 455 | 'name':'南小年', 456 | 'found':'' 457 | }], 458 | '12-30':[{ 459 | 'name':'除夕', 460 | 'found':'' 461 | }], 462 | }; 463 | // 农历非主要节日 464 | export const lFestival2 = { 465 | '03-23':[{ 466 | 'name':'妈祖圣诞', 467 | 'found':'0960' 468 | }], 469 | '06-24':[{ 470 | 'name':'火把节', 471 | 'found':'' 472 | }], 473 | '10-01':[{ 474 | 'name':'寒衣节', 475 | 'found':'' 476 | }], 477 | }; 478 | // 公历星期推算节日 479 | export const oFestival = { 480 | '03-04-01':[{ 481 | 'name':'中小学生安全教育日', 482 | 'found':'1996' 483 | }], 484 | '05-01-02':[{ 485 | 'name':'世界防治哮喘日', 486 | 'found':'1998-12-11' 487 | }], 488 | '05-02-00':[{ 489 | 'name':'母亲节', 490 | 'found':'1913-05-10' 491 | }], 492 | '05-03-00':[{ 493 | 'name':'全国助残日', 494 | 'found':'1990-12-28' 495 | }], 496 | '06-03-00':[{ 497 | 'name':'父亲节', 498 | 'found':'1972' 499 | }], 500 | '09-03-00':[{ 501 | 'name':'世界清洁地球日', 502 | 'found':'1993' 503 | }], 504 | '09-04-00':[{ 505 | 'name':'国际聋人日', 506 | 'found':'1957' 507 | }], 508 | '10-01-01':[{ 509 | 'name':'国际住房日', 510 | 'found':'1985-12-17' 511 | }], 512 | '11-04-04':[{ 513 | 'name':'感恩节', 514 | 'found':'1941' 515 | }], 516 | }; 517 | // 节气推算节日 518 | const shujiu = ['一九','二九','三九','四九','五九','六九','七九','八九','九九']; 519 | export const tFestival = ['寒食节','初伏','中伏','末伏','出伏','复活节'].concat(shujiu); 520 | 521 | // 通过公历获取节日 522 | export function getFestivalsBySolar(sYear,sMonth,sDay){ 523 | const now = new Date(sYear,sMonth-1,sDay); 524 | const date = now.getDate(); 525 | const week = now.getDay(); 526 | const index = Math.ceil(date/7); 527 | const dateFull = getDateString(sYear,sMonth,sDay); 528 | return [ 529 | sFestival[getDateString(sMonth,sDay)], 530 | sFestival2[getDateString(sMonth,sDay)], 531 | oFestival[getDateString(sMonth,index,week)] 532 | ].flatMap(function(list = []){ 533 | return list.filter(item=>(dateFull>=item.found)).map(item=>item.name); 534 | }); 535 | } 536 | 537 | // 获取节气作用节日 538 | export function getTermFestivalsBySolar(sYear,sMonth,sDay){ 539 | let festivals = []; 540 | let termDate = getTermDate(sYear); 541 | let dayTime = 86400000; 542 | // 寒食节 543 | (function(){ 544 | let hanshi_time = new Date(sYear,3,termDate[6]-1).getTime(); 545 | let solar = getSolarByTimestamp(hanshi_time); 546 | if(solar['sYear']==sYear&&solar['sMonth']==sMonth&&solar['sDay']==sDay){ 547 | festivals.push('寒食节'); 548 | } 549 | })(); 550 | // 三伏天 551 | (function(){ 552 | let xiazhi_time = new Date(sYear,5,termDate[11]).getTime(); 553 | let qiufen_time = new Date(sYear,7,termDate[14]).getTime(); 554 | let count = 0; 555 | for(let time = xiazhi_time;time<=qiufen_time;time+=dayTime){ 556 | let solar = getSolarByTimestamp(time); 557 | let ganzhi = getGanZhiDay(solar['sYear'],solar['sMonth'],solar['sDay']); 558 | if(ganzhi.includes('庚')){ 559 | count++; 560 | if(solar['sYear']==sYear&&solar['sMonth']==sMonth&&solar['sDay']==sDay){ 561 | if(count==3){ 562 | festivals.push('初伏'); 563 | }else if(count==4){ 564 | festivals.push('中伏'); 565 | } 566 | } 567 | } 568 | } 569 | count = 0; 570 | for(let time = qiufen_time;time<=qiufen_time+dayTime*20;time+=dayTime){ 571 | let solar = getSolarByTimestamp(time); 572 | let ganzhi = getGanZhiDay(solar['sYear'],solar['sMonth'],solar['sDay']); 573 | if(ganzhi.includes('庚')){ 574 | count++; 575 | if(solar['sYear']==sYear&&solar['sMonth']==sMonth&&solar['sDay']==sDay){ 576 | if(count==1){ 577 | festivals.push('末伏'); 578 | }else if(count==2){ 579 | festivals.push('出伏'); 580 | } 581 | } 582 | } 583 | } 584 | })(); 585 | // 数九 586 | (function(){ 587 | let last_termDate = getTermDate(sYear-1); 588 | let last_dongzhi_time = new Date(sYear-1,11,last_termDate[23]).getTime(); 589 | let dongzhi_time = new Date(sYear,11,termDate[23]).getTime(); 590 | let count = 0; 591 | for(let time = last_dongzhi_time;time<=last_dongzhi_time+8*9*dayTime;time+=9*dayTime){ 592 | let solar = getSolarByTimestamp(time); 593 | if(solar['sYear']==sYear&&solar['sMonth']==sMonth&&solar['sDay']==sDay){ 594 | festivals.push(shujiu[count]); 595 | } 596 | count++; 597 | } 598 | count = 0; 599 | for(let time = dongzhi_time;time<=dongzhi_time+8*9*dayTime;time+=9*dayTime){ 600 | let solar = getSolarByTimestamp(time); 601 | if(solar['sYear']==sYear&&solar['sMonth']==sMonth&&solar['sDay']==sDay){ 602 | festivals.push(shujiu[count]); 603 | } 604 | count++; 605 | } 606 | })(); 607 | // 复活节 608 | (function(){ 609 | const getEasterDate = function(Y){ 610 | if(Y<1900||Y>2100){ 611 | return null; 612 | } 613 | const N = Y-1900; 614 | const A = N % 19; 615 | const Q = Math.floor(N / 4); 616 | const B = Math.floor((7*A+1) / 19); 617 | const M = (11*A+4-B) % 29; 618 | const W = (N+Q+31-M) % 7; 619 | const D = 25-M-W; 620 | if(D>0){ 621 | return [4,D]; 622 | }else{ 623 | return [3,31+D]; 624 | } 625 | }; 626 | const result = getEasterDate(sYear); 627 | if(result){ 628 | const [Month,Day] = result; 629 | if(Month==sMonth&&Day==sDay){ 630 | festivals.push('复活节'); 631 | } 632 | } 633 | })(); 634 | return festivals; 635 | } 636 | 637 | // 通过农历获取节日 638 | export function getFestivalsByLunar(lYear,lMonth,lDay){ 639 | let festivals = []; 640 | const dateFull = getDateString(lYear,lMonth,lDay); 641 | const dateKey = getDateString(lMonth,lDay); 642 | if(lMonth==12&&lDay==getLunarMonthDays(lYear,12)){ // 除夕特殊处理 643 | festivals.push(lFestival['12-30'][0]['name']); 644 | }else{ 645 | festivals = festivals.concat([ 646 | lFestival[dateKey], 647 | lFestival2[dateKey] 648 | ].flatMap(function(list = []){ 649 | return list.filter(item=>(dateFull>=item.found)).map(item=>item.name); 650 | })); 651 | } 652 | return festivals; 653 | } -------------------------------------------------------------------------------- /dist/widget-calendar.min.js: -------------------------------------------------------------------------------- 1 | /*! 2 | * calendar-tool v1.0.3 3 | * Chinese lunar calendar 4 | * https://passer-by.com/calendar/ 5 | * 6 | * Copyright (c) 2022-present, HaoLe Zheng 7 | * 8 | * Released under the MIT License 9 | * https://github.com/mumuy/calendar 10 | * 11 | * Created on: 2025-12-01 12 | */ 13 | !function(a){"function"==typeof define&&define.amd?define(a):a()}((function(){"use strict";function a(a,n){(null==n||n>a.length)&&(n=a.length);for(var e=0,t=new Array(n);e=16;t>>=1)n+=e&t?30:29;return w(a)&&(n+=65536&e?30:29),n}function $(a){var n,e,t=Math.floor((a-M)/864e5),l=0,r=0,o=!1;if(t<=0)return null;var i=0;for(l=f;l<=m&&!(i+(e=q(l))>=t);l++)i+=e;var c=parseInt(z[l-f],32),d=w(l);for(t-=i,i=0,r=1;r<=12&&!(i+(e=c&1<<16-r?30:29)>=t);r++)if(i+=e,d&&r==d){if(i+(e=65536&c?30:29)>=t){o=!0;break}i+=e}return{lYear:l,lMonth:r,lDay:n=t-i,isLeap:o,lMonthZH:(o?"闰":"")+j[r-1]+"月",lDayZH:D[n-1]}}var x=[4,19,3,18,4,19,4,19,4,20,4,20,6,22,6,22,6,22,7,22,6,21,6,21],S=["4lkmd5j6l5","55kql9lal9","59lanalala","5avbnatqla","7akmd5j6l5","55kql9lal9","59lalalala","5avbnatqla","7akmd5j6l5","55kql9lal9","59lalalala","5avbnatqla","7akmd5j6l5","4lkql9lal9","55kqlalala","5ananalqla","5akmd5j5kl","4lkqd9l6l5","55kqlalal9","5ananalqla","5akmd5j5kl","4lkmd9l6l5","55kqlalal9","59lanalqla","5akmd5j5kl","4lkmd9l6l5","55kql9lal9","59lanalala","5akmclj5al","4lkmd5j6l5","55kql9lal9","59lanalala","5akmclj5al","4lkmd5j6l5","55kql9lal9","59lalalala","5akmclj5al","4lkmd5j6l5","55kql9lal9","59lalalala","5akmclj5al","4lkmd5j6l5","55kql9lal9","59lalalala","5aklclj5al","4lkmd5j5kl","4lkql9l6l9","55kqlalala","5aclclb5al","2lkmd5j5kl","4lkmd9l6l9","55kqlalala","5aclclb5al","2lkmd5j5kl","4lkmd9l6l5","55kql9lal9","5aalclb5al","2lkmd5j5kl","4lkmd5j6l5","55kql9lal9","59alclalal","2lkmclj5al","4lkmd5j6l5","55kql9lal9","59alclalal","2lkmclj5al","4lkmd5j6l5","55kql9lal9","59alalalal","2lkmclj5al","4lkmd5j6l5","55kql9lal9","59alalalal","2lklclj5al","4lkmd5j6l5","55kql9l6l9","59a5alalal","2lklclb5al","4lkmd5j5l5","55kqd9l6l9","59a5alalal","2lklclb5al","4lkmd5j5kl","4lkmd9l6l9","55a5akalal","2lclclb5al","2lkmd5j5kl","4lkmd5l6l5","55a5akalak","2lalclalal","2lkmclj5kl","4lkmd5j6l5","55a5akalak","2kalclalal","2lkmclj5al","4lkmd5j6l5","55a5akalak","2kalalalal","2lkmclj5al","4lkmd5j6l5","55a5akalak","2kalalalal","2lkmclj5al","4lkmd5j6l5","55a5akalak","2kalalalal","2lklclb5al","4lkmd5j6l5","55a5akahak","2ka5alalal","2lklclb5al","4lkmd5j5l5","55a52kahak","2ka5akalal","2lklclb5al","4lkmd5j5kl","4la12kahak","2ga5akalal","2lclclb5al","2lkmclj5kl","4la12g8hak","2ga5akalak","2lalclalal","2lkmclj5kl","4la12g8hag","2ga5akalak","2kalalalal","2lkmclj5al","4la12g8hag","2ga5akalak","2kalalalal","2lkmclj5al","4la12g8hag","2ga5akalak","2kalalalal","2lklclb5al","4la12g8hag","2ga5akalak","2kalalalal","2lklclb5al","4la12g8hag","2ga52kahak","2ka5alalal","2lklclb5al","4la12g8gag","2ga12kahak","2ka5akalal","2lklclb5al","4la1208ga0","20a12g8hak","2ga5akalal","2lalclalal","2la1208ga0","20a12g8hak","2ga5akalal","2lalalalal","2la1208ga0","20a12g8hag","2ga5akalak","2lalalalal","2la1208g00","20a12g8hag","2ga5akalak","2kalalalal","2la1208g00","20a12g8hag","2ga5akalak","2kalalalal","2la0200g00","20a12g8hag","2ga52kahak","2kalalalal","2la0200g00","20a12g8gag","2ga52kahak","2ka5akalal","2la0200g00","20a12g8gag","2ga12gahak","2ka5akalal","2la0200g00","20a1208ga0","2ga12g8hak","2ga5akalal","2l00200000","a1208ga0","20a12g8hak","2ga5akalal","2l00000000","a1208ga0","20a12g8hag","2ga5akalak","2l00000000","a1208g00","20a12g8hag","2ga5akalak","2k00000000","a1200g00","20a12g8hag","2ga5akalak","2kalalalal"],Y=["小寒","大寒","立春","雨水","惊蛰","春分","清明","谷雨","立夏","小满","芒种","夏至","小暑","大暑","立秋","处暑","白露","秋分","寒露","霜降","立冬","小雪","大雪","冬至"];function A(a){if(am)return!1;var n=S[a-f],e=parseInt(n,32).toString(4);return 24!=e.length&&(e="0"+e),e.split("").map((function(a,n){return+a+x[n]}))}function O(a,n,e){var t="",l=A(a);return l&&(l.push(31),l.forEach((function(a,l){var r=Math.floor(l/2)+1;n==r&&e==a&&(t=Y[l])}))),t}var T=["甲","乙","丙","丁","戊","己","庚","辛","壬","癸"],H=["子","丑","寅","卯","辰","巳","午","未","申","酉","戌","亥"];function E(a){(a%=60)<0&&(a+=60);var n=a%12;return T[a%10]+H[n]}function Z(a,n,e){return E($(p(a,n,e)).lYear-1984)}function R(a,n,e){var t="",l=A(a);if(l){var r=0;l.push(31),l.forEach((function(a,t){var l=Math.floor(t/2)+1;h(n,e)>=h(l,a)&&(r=l)})),t=E(r+=12*(a-1984))}return t}function _(a,n,e){return E(Math.round((p(a,n,e)-p(1900,1,30))/864e5)+39)}var C={"01-01":[{name:"元旦",found:"1949"}],"02-14":[{name:"情人节",found:"0270"}],"03-08":[{name:"妇女节",found:"1949-12"}],"03-12":[{name:"植树节",found:"1979"}],"04-01":[{name:"愚人节",found:"1564"}],"05-01":[{name:"劳动节",found:"1949-12"}],"05-04":[{name:"青年节",found:"1949-12"}],"06-01":[{name:"儿童节",found:"1949-11"}],"07-01":[{name:"建党节",found:"1938-05"}],"08-01":[{name:"建军节",found:"1933-07-11"}],"09-10":[{name:"教师节",found:"1985-06"}],"10-01":[{name:"国庆节",found:"1949-12-02"}],"10-25":[{name:"台湾光复纪念日",found:"2025-10-25"}],"11-01":[{name:"万圣节",found:"0600"}],"12-05":[{name:"国际志愿人员日",found:"1985-12-17"}],"12-13":[{name:"国家公祭日",found:"2014-02-27"}],"12-25":[{name:"圣诞节",found:"0336"}]},I={"01-10":[{name:"中国人民警察节",found:"2020-07-21"}],"01-26":[{name:"国际海关日",found:"1983-01-26"}],"02-02":[{name:"世界湿地日",found:"1996"}],"02-10":[{name:"国际气象节",found:"1991-02-10"}],"03-01":[{name:"国际海豹日",found:"1983"}],"03-03":[{name:"全国爱耳日",found:"1998-03"}],"03-05":[{name:"雷锋纪念日",found:"1963-03-05"}],"03-09":[{name:"保护母亲河日",found:"2002"}],"03-15":[{name:"消费者权益日",found:"1983"}],"03-17":[{name:"国际航海日",found:"1977-11"}],"03-18":[{name:"全国爱肝日",found:"2001"}],"03-21":[{name:"世界森林日",found:"2012-12"},{name:"世界睡眠日",found:"2001"}],"03-22":[{name:"世界水日",found:"1993-01-18"}],"03-23":[{name:"世界气象日",found:"1961"}],"03-24":[{name:"防治结核病日",found:"1995-03-24"}],"03-27":[{name:"学生安全教育日",found:"1996-03-25"}],"04-07":[{name:"世界卫生日",found:"1948-06"}],"04-13":[{name:"泼水节",found:""}],"04-15":[{name:"国家安全教育日",found:"2015-07-01"}],"04-22":[{name:"世界地球日",found:"1970"}],"04-23":[{name:"世界读书日",found:"1995-11-15"}],"04-24":[{name:"中国航天日",found:"2016-03-08"}],"04-26":[{name:"知识产权日",found:"2001-04-26"}],"05-08":[{name:"世界微笑日",found:"1948"},{name:"世界红十字日",found:"1948"}],"05-12":[{name:"国际护士节",found:"1912"},{name:"防灾减灾日",found:"2009-05-12"}],"05-15":[{name:"国际家庭日",found:"1994-05-15"}],"05-17":[{name:"世界电信日",found:"1968"}],"05-18":[{name:"国际博物馆日",found:"1977-05-18"}],"05-19":[{name:"中国旅游日",found:"2001-05-19"}],"05-20":[{name:"学生营养日",found:"2001-03"}],"05-22":[{name:"国际生物多样性日",found:"2000-12-20"}],"05-30":[{name:"五卅运动纪念日",found:"1925-05-30"}],"05-31":[{name:"世界无烟日",found:"1987-11"}],"06-05":[{name:"世界环境日",found:"1972-06-05"}],"06-06":[{name:"全国爱眼日",found:"1996"}],"06-11":[{name:"中国人口日",found:"1990"}],"06-14":[{name:"世界献血者日",found:"2005-05-24"}],"06-23":[{name:"国际奥林匹克日",found:"1948-06-23"}],"06-25":[{name:"全国土地日",found:"1991-05-24"}],"06-26":[{name:"国际禁毒日",found:"1987-06-12"}],"07-01":[{name:"香港回归纪念日",found:"1997-07-01"}],"07-02":[{name:"国际体育记者日",found:"1995"}],"07-11":[{name:"世界人口日",found:"1989"}],"08-08":[{name:"全民健身日",found:"2009"}],"08-12":[{name:"国际青年日",found:"1999-12-17"}],"08-19":[{name:"中国医师节",found:"2017-11-03"}],"08-26":[{name:"全国律师咨询日",found:"1980-08-26"}],"09-03":[{name:"抗战胜利纪念日",found:"2014-02-27"}],"09-08":[{name:"国际扫盲日",found:"1965-11-17"}],"09-16":[{name:"中国脑健康日",found:"2000-09-16"},{name:"国际臭氧层保护日",found:"1995-01-23"}],"09-18":[{name:"九一八事变纪念日",found:"1931-09-18"}],"09-20":[{name:"全国爱牙日",found:"1989"}],"09-21":[{name:"国际和平日",found:"2001-09-07"}],"09-27":[{name:"世界旅游日",found:"1970-09-27"}],"09-28":[{name:"孔子诞辰纪念日",found:"1913-09-28"}],"09-30":[{name:"烈士纪念日",found:"2014-09-30"}],"10-04":[{name:"世界动物日",found:"1931"}],"10-05":[{name:"世界教师日",found:"1994"}],"10-08":[{name:"全国高血压日",found:"1998"}],"10-09":[{name:"世界邮政日",found:"1984"}],"10-13":[{name:"世界保健日",found:"1950"}],"10-14":[{name:"世界标准日",found:"1946"}],"10-15":[{name:"国际盲人节",found:"1984"}],"10-16":[{name:"世界粮食日",found:"1981-10-16"}],"10-24":[{name:"联合国日",found:"1947-10-24"}],"11-08":[{name:"记者节",found:"2000-08-01"}],"11-09":[{name:"消防宣传日",found:"1992"}],"11-14":[{name:"世界防治糖尿病日",found:"1991"}],"11-17":[{name:"国际大学生节",found:"1946-11-17"}],"12-01":[{name:"世界艾滋病日",found:"1988"}],"12-03":[{name:"国际残疾人日",found:"1992-10-12"}],"12-04":[{name:"国家宪法日",found:"2014-11-01"}],"12-09":[{name:"世界足球日",found:"1978"}],"12-10":[{name:"世界人权日",found:"1948-12-10"}],"12-11":[{name:"国际山岳日",found:"2003-12-11"}],"12-15":[{name:"强化免疫日",found:"1988"}],"12-20":[{name:"澳门回归纪念日",found:"1999-12-20"}]},P={"01-01":[{name:"春节",found:""}],"01-15":[{name:"元宵节",found:""}],"02-02":[{name:"龙头节",found:""}],"03-03":[{name:"上巳节",found:""}],"05-05":[{name:"端午节",found:""}],"07-07":[{name:"七夕节",found:""}],"07-15":[{name:"中元节",found:""}],"08-15":[{name:"中秋节",found:""}],"09-09":[{name:"重阳节",found:""}],"10-15":[{name:"下元节",found:""}],"12-08":[{name:"腊八节",found:""}],"12-23":[{name:"北小年",found:""}],"12-24":[{name:"南小年",found:""}],"12-30":[{name:"除夕",found:""}]},L={"03-23":[{name:"妈祖圣诞",found:"0960"}],"06-24":[{name:"火把节",found:""}],"10-01":[{name:"寒衣节",found:""}]},B={"03-04-01":[{name:"中小学生安全教育日",found:"1996"}],"05-01-02":[{name:"世界防治哮喘日",found:"1998-12-11"}],"05-02-00":[{name:"母亲节",found:"1913-05-10"}],"05-03-00":[{name:"全国助残日",found:"1990-12-28"}],"06-03-00":[{name:"父亲节",found:"1972"}],"09-03-00":[{name:"世界清洁地球日",found:"1993"}],"09-04-00":[{name:"国际聋人日",found:"1957"}],"10-01-01":[{name:"国际住房日",found:"1985-12-17"}],"11-04-04":[{name:"感恩节",found:"1941"}]},N=["一九","二九","三九","四九","五九","六九","七九","八九","九九"],F=["寒食节","初伏","中伏","末伏","出伏","复活节"].concat(N);function U(a,n,e){var t=new Date(a,n-1,e),l=t.getDate(),r=t.getDay(),o=Math.ceil(l/7),i=h(a,n,e);return[C[h(n,e)],I[h(n,e)],B[h(n,o,r)]].flatMap((function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).filter((function(a){return i>=a.found})).map((function(a){return a.name}))}))}function G(a,n,t){var l,r=[],o=A(a),i=864e5;return(l=k(new Date(a,3,o[6]-1).getTime())).sYear==a&&l.sMonth==n&&l.sDay==t&&r.push("寒食节"),function(){for(var e=new Date(a,5,o[11]).getTime(),l=new Date(a,7,o[14]).getTime(),c=0,d=e;d<=l;d+=i){var s=k(d);_(s.sYear,s.sMonth,s.sDay).includes("庚")&&(c++,s.sYear==a&&s.sMonth==n&&s.sDay==t&&(3==c?r.push("初伏"):4==c&&r.push("中伏")))}c=0;for(var u=l;u<=l+1728e6;u+=i){var f=k(u);_(f.sYear,f.sMonth,f.sDay).includes("庚")&&(c++,f.sYear==a&&f.sMonth==n&&f.sDay==t&&(1==c?r.push("末伏"):2==c&&r.push("出伏")))}}(),function(){for(var e=A(a-1),l=new Date(a-1,11,e[23]).getTime(),i=new Date(a,11,o[23]).getTime(),c=0,d=l;d<=l+62208e5;d+=7776e5){var s=k(d);s.sYear==a&&s.sMonth==n&&s.sDay==t&&r.push(N[c]),c++}c=0;for(var u=i;u<=i+62208e5;u+=7776e5){var f=k(u);f.sYear==a&&f.sMonth==n&&f.sDay==t&&r.push(N[c]),c++}}(),function(){var l=function(a){if(a<1900||a>2100)return null;var n=a-1900,e=n%19,t=Math.floor(n/4),l=(11*e+4-Math.floor((7*e+1)/19))%29,r=25-l-(n+t+31-l)%7;return r>0?[4,r]:[3,31+r]}(a);if(l){var o=e(l,2),i=o[0],c=o[1];i==n&&c==t&&r.push("复活节")}}(),r}function J(a,n,e){var t=[],l=h(a,n,e),r=h(n,e);return 12==n&&e==function(a,n,e){var t=w(a),l=parseInt(z[a-f],32),r=l&1<<16-n?30:29;return e&&n==t&&(r=65536&l?30:29),r}(a,12)?t.push(P["12-30"][0].name):t=t.concat([P[r],L[r]].flatMap((function(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:[]).filter((function(a){return l>=a.found})).map((function(a){return a.name}))}))),t}var K=["水瓶","双鱼","白羊","金牛","双子","巨蟹","狮子","处女","天秤","天蝎","射手","摩羯"],Q=[20,19,21,20,21,22,23,23,23,24,23,22];var V=["鼠","牛","虎","兔","龙","蛇","马","羊","猴","鸡","狗","猪"];function W(a,n,e){var t=($(p(a,n,e)).lYear-1984)%12;return V[t>-1?t:t+12]}function X(a){var n,e,t,l=k(a),r=$(a);return Object.assign({lYear:null,lMonth:null,lDay:null,isLeap:!1,lMonthZH:"",lDayZH:""},l,r||{},{zodiac:(n=l.sMonth,e=l.sDay,t=11,Q.forEach((function(a,l){var r=l+1;h(n,e)>=h(r,a)&&(t=l%12)})),K[t]+"座"),term:O(l.sYear,l.sMonth,l.sDay),animal:W(l.sYear,l.sMonth,l.sDay),gzYearZH:Z(l.sYear,l.sMonth,l.sDay),gzMonthZH:R(l.sYear,l.sMonth,l.sDay),gzDayZH:_(l.sYear,l.sMonth,l.sDay),festival:[].concat(U(l.sYear,l.sMonth,l.sDay),G(l.sYear,l.sMonth,l.sDay),r?J(r.lYear,r.lMonth,r.lDay):[]).join(" ")})}var aa=function(a,n,e){var t=p(a,n,e);return t?X(t):null},na=function(){return X(Date.now())};const ea=new CSSStyleSheet;function ta(a){var n=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(a){return!1}}();return function(){var e,t=d(a);if(n){var r=d(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return function(a,n){if(n&&("object"===l(n)||"function"==typeof n))return n;if(void 0!==n)throw new TypeError("Derived constructors may only return object or undefined");return i(a)}(this,e)}}ea.replaceSync(":host {\n display: inline-block;\n width: 100%;\n min-width: 300px;\n max-width: 600px;\n vertical-align: bottom;\n white-space: initial;\n font-family: Arial, Helvetica, \"Microsoft Yahei\";\n color: #1f2328;\n container-type: inline-size;\n --primary-color: #2095f2;\n --secondary-color: #ffaa00;\n --base-size: 1px;\n --base-size-mobile: 1px;\n}\n@supports (width: 100cqw) {\n :host {\n --base-size: clamp(1px, calc(100cqw / 600), 1.1px);\n --base-size-mobile: clamp(1px, calc(100cqw / 480), 1.1px);\n }\n}\n* {\n padding: 0;\n margin: 0;\n}\na {\n text-decoration: none;\n color: #1f2328;\n}\n.mod-calendar {\n display: flex;\n gap: calc(var(--base-size) * 4);\n flex-direction: row-reverse;\n padding: calc(var(--base-size) * 4);\n background: var(--primary-color);\n border-radius: calc(var(--base-size) * 6);\n font-size: calc(var(--base-size) * 14);\n}\n.mod-calendar .info {\n position: relative;\n width: calc(var(--base-size) * 168);\n padding-top: calc(var(--base-size) * 12);\n text-align: center;\n color: #fff;\n}\n.mod-calendar .info a {\n color: #fff;\n}\n.mod-calendar .info p {\n line-height: calc(var(--base-size) * 22);\n}\n.mod-calendar .info .date{\n line-height: calc(var(--base-size) * 24);\n font-size: calc(var(--base-size) * 16);\n}\n.mod-calendar .info .day {\n width: calc(var(--base-size) * 80);\n height: calc(var(--base-size) * 80);\n margin: calc(var(--base-size) * 15) auto;\n line-height: calc(var(--base-size) * 80);\n font-size: calc(var(--base-size) * 48);\n font-weight: bold;\n background: var(--secondary-color);\n color: #fff;\n border-radius: calc(var(--base-size) * 12);\n}\n.mod-calendar .info .detail {\n margin-bottom: calc(var(--base-size) * 15);\n}\n.mod-calendar .info .list {\n padding: calc(var(--base-size) * 10) 0;\n border-top: calc(var(--base-size) * 1) dotted rgba(255, 255, 255, 0.5);\n}\n.mod-calendar .info .list .item {\n padding: calc(var(--base-size) * 5) 0;\n}\n.mod-calendar .info .list .item a {\n color: #fff;\n}\n.mod-calendar .info .list ::slotted([slot=\"item\"]) {\n padding: calc(var(--base-size) * 5) 0 !important;\n}\n.mod-calendar .box {\n flex: 1;\n background: #fff;\n border-radius: calc(var(--base-size) * 6);\n}\n.mod-calendar .selector {\n display: flex;\n gap: calc(var(--base-size-mobile) * 8);\n justify-content: center;\n position: relative;\n padding: calc(var(--base-size) * 5) calc(var(--base-size) * 5) 0;\n vertical-align: middle;\n height: calc(var(--base-size)*26);\n text-align: center;\n}\n.mod-calendar .selector span {\n display: inline-flex;\n vertical-align: middle;\n}\n.mod-calendar .selector a {\n position: relative;\n height: calc(var(--base-size) * 24);\n padding: 0 calc(var(--base-size) * 5);\n border: calc(var(--base-size) * 1) solid #ebebeb;\n background: #fafafa;\n line-height: calc(var(--base-size) * 24);\n vertical-align: middle;\n}\n.mod-calendar .selector a.prev,.mod-calendar .selector a.next{\n position: relative;\n color: transparent!important;\n}\n.mod-calendar .selector a.prev{\n border-top-left-radius: calc(var(--base-size) * 4);\n border-bottom-left-radius: calc(var(--base-size) * 4);\n}\n.mod-calendar .selector a.prev::after{\n position: absolute;\n left: 50%;\n top: 50%;\n content: '';\n width: calc(var(--base-size) * 6);\n height: calc(var(--base-size) * 6);\n margin: calc(var(--base-size) * -4) 0 0 calc(var(--base-size) * -2);\n border-left: calc(var(--base-size) * 1) solid #333;\n border-bottom: calc(var(--base-size) * 1) solid #333;\n transform: rotate(45deg);\n}\n.mod-calendar .selector a.next{\n border-top-right-radius: calc(var(--base-size) * 4);\n border-bottom-right-radius: calc(var(--base-size) * 4);\n}\n.mod-calendar .selector a.next::after{\n position: absolute;\n right: 50%;\n top: 50%;\n content: '';\n width: calc(var(--base-size) * 6);\n height: calc(var(--base-size) * 6);\n margin: calc(var(--base-size) * -4) calc(var(--base-size) * -2) 0 0;\n border-right: calc(var(--base-size) * 1) solid #333;\n border-bottom: calc(var(--base-size) * 1) solid #333;\n transform: rotate(-45deg);\n}\n.mod-calendar .selector a.goback{\n padding: 0 calc(var(--base-size) * 8);\n border-radius: calc(var(--base-size) * 4);\n}\n.mod-calendar .selector a:hover {\n border-color: #d2d9df;\n background: #f6f8fa;\n}\n.mod-calendar .selector select {\n min-width: calc(var(--base-size) * 60);\n height: calc(var(--base-size) * 26);\n padding-left: calc(var(--base-size) * 4);\n border: calc(var(--base-size) * 1) solid #ebebeb;\n margin: 0 calc(var(--base-size) * -1);\n background: #fff;\n line-height: calc(var(--base-size) * 24);\n vertical-align: middle;\n font-size: calc(var(--base-size) * 14);\n color: #1f2328;\n outline: none;\n}\n.mod-calendar .selector select:only-child{\n border-radius: calc(var(--base-size) * 4);\n}\n.mod-calendar .selector button {\n height: calc(var(--base-size) * 26);\n border: calc(var(--base-size) * 1) solid #ebebeb;\n line-height: calc(var(--base-size) * 24);\n background: #fafafa;\n}\n.mod-calendar .table{\n padding: calc(var(--base-size) * 5);\n border-radius: calc(var(--base-size) * 6);\n}\n.mod-calendar table {\n width: 100%;\n table-layout: fixed;\n color: #1f2328;\n border-collapse: collapse;\n border-spacing: 0;\n}\n.mod-calendar table th, .mod-calendar table td {\n text-align: center;\n}\n.mod-calendar table th {\n line-height: calc(var(--base-size) * 30);\n font-weight: normal;\n}\n.mod-calendar table th span{\n position: relative;\n z-index: 9;\n}\n.mod-calendar table td {\n position: relative;\n border: calc(var(--base-size) * 1) solid #fff;\n line-height: calc(var(--base-size) * 20);\n}\n.mod-calendar table thead {\n position: relative;\n}\n.mod-calendar table thead tr{\n border-bottom: calc(var(--base-size) * 3) solid #fff;\n}\n.mod-calendar table thead th:first-child::after{\n position: absolute;\n left: 0;\n top: 0;\n z-index: 0;\n content:'';\n width: 100%;\n height: calc(100% - calc(var(--base-size) * 1.5));\n background: #f6f8fa;\n border-radius: calc(var(--base-size) * 4);\n}\n.mod-calendar table tbody a {\n display: block;\n position: relative;\n margin: 0 auto;\n padding: calc(var(--base-size) * 5) 0;\n border: calc(var(--base-size) * 1) solid transparent;\n border-radius: calc(var(--base-size) * 6);\n line-height: calc(var(--base-size) * 20);\n cursor: pointer;\n}\n.mod-calendar table tbody a:hover {\n border: calc(var(--base-size) * 1) solid #cccccccc;\n}\n.mod-calendar table tbody span {\n display: block;\n}\n.mod-calendar table tbody i {\n position: absolute;\n left: 0;\n top: 0;\n padding: 0 calc(var(--base-size) * 3);\n line-height: calc(var(--base-size) * 18);\n font-style: normal;\n font-size: calc(var(--base-size) * 13);\n color: #fff;\n}\n.mod-calendar table .s1 {\n font-size: calc(var(--base-size) * 18);\n color: rgba(0, 0, 0, 0.8);\n}\n.mod-calendar table .s2 {\n font-size: calc(var(--base-size) * 13);\n color: rgba(0, 0, 0, 0.6);\n}\n.mod-calendar table td.active a {\n border: calc(var(--base-size) * 1) solid var(--secondary-color);\n}\n.mod-calendar table td.holiday a {\n background: #f1f9f1\n}\n.mod-calendar table td.holiday.active a, .mod-calendar table td.holiday a:hover {\n border: calc(var(--base-size) * 1) solid #4bae4fcc;\n}\n.mod-calendar table td.holiday i {\n color: #4bae4f;\n}\n.mod-calendar table td.work a {\n background: #fef0ef;\n}\n.mod-calendar table td.work.active a, .mod-calendar table td.work a:hover {\n border: calc(var(--base-size) * 1) solid #f44336cc;\n}\n.mod-calendar table td.work i {\n color: #f44336;\n}\n.mod-calendar table td.today a {\n background: #fff2dd;\n}\n.mod-calendar table td.today.active a, .mod-calendar table td.today a:hover {\n border: calc(var(--base-size) * 1) solid var(--secondary-color);\n}\n.mod-calendar table td.disabled a {\n opacity: 0.4;\n}\n.mode-simple .info {\n display: none;\n}\n.mode-simple .selector {\n background: none;\n text-align: center;\n}\n\n@container (max-width: 480px) {\n .mod-calendar {\n flex-direction: column;\n padding: calc(var(--base-size) * 3);\n font-size: calc(var(--base-size-mobile) * 12);\n }\n .mod-calendar .info {\n width: auto;\n padding-top: calc(var(--base-size-mobile) * 10);\n padding-left: calc(var(--base-size-mobile) * 10);\n overflow: hidden;\n }\n .mod-calendar .info p {\n text-align: left;\n line-height: calc(var(--base-size-mobile) * 18);\n }\n .mod-calendar .info .date{\n text-align: left;\n font-size: calc(var(--base-size-mobile) * 14);\n }\n .mod-calendar .info .day {\n float: left;\n width: calc(var(--base-size-mobile) * 56);\n height: calc(var(--base-size-mobile) * 56);\n margin: calc(var(--base-size-mobile) * 6) 0;\n line-height: calc(var(--base-size-mobile) * 56);\n font-size: calc(var(--base-size-mobile) * 24);\n }\n .mod-calendar .info .detail {\n padding-top: calc(var(--base-size-mobile) * 5);\n margin-left: calc(var(--base-size-mobile) * 70);\n margin-bottom: calc(var(--base-size-mobile) * 10);\n }\n .mod-calendar .info .list {\n position: absolute;\n top: calc(var(--base-size-mobile) * 10);\n right: calc(var(--base-size-mobile) * 10);\n padding: 0;\n border-top: none;\n text-align: right;\n }\n .mod-calendar .info .list .item {\n padding: calc(var(--base-size-mobile) * 2) 0;\n }\n .mod-calendar .info .list ::slotted([slot=\"item\"]) {\n padding: calc(var(--base-size-mobile) * 2) 0 !important;\n }\n .mod-calendar .selector{\n gap: calc(var(--base-size-mobile) * 6);\n }\n .mod-calendar .selector span:has(.goback) {\n position: absolute;\n right: 0px;\n top: -106px;\n z-index: 9;\n }\n .mod-calendar .selector a.goback {\n position: absolute;\n top: calc(var(--base-size-mobile) * 75);\n right: calc(var(--base-size-mobile) * 10);\n height: calc(var(--base-size-mobile) * 20);\n border-color: transparent;\n background: var(--secondary-color);\n line-height: calc(var(--base-size-mobile) * 20);\n font-size: calc(var(--base-size-mobile) * 12);\n white-space: nowrap;\n color: #fff;\n border-radius: calc(var(--base-size-mobile) * 3);\n }\n .mod-calendar .selector .goback:hover {\n border-color: var(--secondary-color);\n color: #fff;\n }\n .mod-calendar .table{\n padding: calc(var(--base-size-mobile) * 3);\n }\n .mod-calendar table tbody a {\n width: auto;\n line-height: calc(var(--base-size-mobile) * 18);\n }\n .mod-calendar table tbody i{\n padding: 0;\n font-size: calc(var(--base-size-mobile) * 12);\n }\n .mod-calendar table tr {\n border-top: none;\n }\n .mod-calendar table td {\n height: calc(var(--base-size-mobile) * 48);\n line-height: calc(var(--base-size-mobile) * 16);\n }\n .mod-calendar table .s2 {\n font-size: calc(var(--base-size-mobile) * 12);\n }\n\n .mode-simple .selector span:has(.goback){\n display: none;\n }\n}");var la=function(a){!function(a,n){if("function"!=typeof n&&null!==n)throw new TypeError("Super expression must either be null or a function");a.prototype=Object.create(n&&n.prototype,{constructor:{value:a,writable:!0,configurable:!0}}),Object.defineProperty(a,"prototype",{writable:!1}),n&&c(a,n)}(s,a);var n,l,r,d=ta(s);function s(){var a;!function(a,n){if(!(a instanceof n))throw new TypeError("Cannot call a class as a function")}(this,s),(a=d.call(this)).attachShadow({mode:"open"});var n=i(a);return n.today=na(),n.currentDateInfo=n.today,n.currentMonthData=[],n.currentMonthDay=1,a}return n=s,r=[{key:"observedAttributes",get:function(){return["date","mode"]}}],(l=[{key:"date",get:function(){var a=h(this.today.sYear,this.today.sMonth,this.today.sDay);return this.getAttribute("date")||a},set:function(a){this.setAttribute("date",a)}},{key:"mode",get:function(){return this.getAttribute("mode")||"default"},set:function(a){this.setAttribute("mode",a)}},{key:"attributeChangedCallback",value:function(a,n,e){"date"==a&&n!=e&&this.formatDate(e)}},{key:"connectedCallback",value:function(){var a=this;if(a.shadowRoot.adoptedStyleSheets)a.shadowRoot.adoptedStyleSheets=[ea];else{var n=document.createElement("style");n.rel="stylesheet",n.textContent=t(ea.cssRules).map((function(a){return a.cssText})).join(""),a.shadowRoot.appendChild(n)}a.render(),a.$module=a.shadowRoot.querySelector(".mod-calendar"),a.$tbody=a.$module.querySelector("tbody"),a.$year=a.$module.querySelector(".year"),a.$month=a.$module.querySelector(".month"),a.$holiday=a.$module.querySelector(".holiday"),a.$goback=a.$module.querySelector(".goback"),a.$prev_year=a.$module.querySelector(".prev-year"),a.$next_year=a.$module.querySelector(".next-year"),a.$prev_month=a.$module.querySelector(".prev-month"),a.$next_month=a.$module.querySelector(".next-month"),a.$info=a.$module.querySelector(".info");var l=function(n,e,t){t=Math.min(y(n,e),t),a.currentMonthDay=t;var l=k(p(n,e,t));l.date!=a.date&&(a.date=l.date)};a.$year.onchange=function(){var n=a.$year.value||a.$year.getAttribute("data-value"),e=a.$month.value||a.$month.getAttribute("data-value");l(n,e,a.currentMonthDay)},a.$month.onchange=function(){var n=a.$year.value||a.$year.getAttribute("data-value"),e=a.$month.value||a.$month.getAttribute("data-value");l(n,e,a.currentMonthDay)},a.$holiday.onchange=function(){var n=a.$holiday.value;if(n){var t=e(n.split("-"),3),r=t[0],o=t[1],i=t[2];l(r,o,i)}},a.$goback.onclick=function(){a.today.date!=a.date&&(a.date=a.today.date)},a.$prev_year.onclick=function(){var n=a.$year.value||a.$year.getAttribute("data-value"),e=a.$month.value||a.$month.getAttribute("data-value");n--,l(n,e,a.currentMonthDay)},a.$next_year.onclick=function(){var n=a.$year.value||a.$year.getAttribute("data-value"),e=a.$month.value||a.$month.getAttribute("data-value");n++,l(n,e,a.currentMonthDay)},a.$prev_month.onclick=function(){var n=a.$year.value||a.$year.getAttribute("data-value"),e=a.$month.value||a.$month.getAttribute("data-value");e--,l(n,e,a.currentMonthDay)},a.$next_month.onclick=function(){var n=a.$year.value||a.$year.getAttribute("data-value"),e=a.$month.value||a.$month.getAttribute("data-value");e++,l(n,e,a.currentMonthDay)},a.$tbody.onclick=function(n){for(var e=n.target;"TD"!=e.tagName&&"TABLE"!=e.tagName;)e=e.parentNode;var t=e.getAttribute("data-id");if("TD"==e.tagName&&t){var r=a.currentMonthData[t];a.currentMonthDay=r.sDay,l(r.sYear,r.sMonth,r.sDay),a.dispatchEvent(new CustomEvent("onSelect",{detail:aa(r.sYear,r.sMonth,r.sDay)}))}},a.formatDate(a.date),setTimeout((function(){a.dispatchEvent(new CustomEvent("onInit",{detail:a.currentDateInfo}))}),1)}},{key:"render",value:function(){this.shadowRoot.innerHTML='
\n
\n
\n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n 返回今天\n \n
\n
\n \n \n \n \n \n \n \n \n \n \n \n \n \n \n
\n
\n
\n
')}},{key:"formatTable",value:function(a){var n=this,e=n.today;a&&(e=aa(+a.year,+a.month,+a.day));var t=h(e.sYear,e.sMonth,e.sDay),l=aa(e.sYear,e.sMonth,1),r=y(e.sYear,e.sMonth);n.currentMonthData=[];for(var o=l.week;o>0;o--){var i=aa(l.sYear,l.sMonth,l.sDay-o);n.currentMonthData.push(i)}for(var c=0;c",z=0,j=n.currentMonthData.length;z\n \n '.concat(D.sDay,'\n ').concat(x||D.term||S||D.lDayZH||" ","\n ").concat(w&&p[w]?""+p[w]+"":"","\n \n "),z%7==6&&z")}k+="";var Y=e.festival.split(" ").filter((function(a){return Object.values(P).flat().map((function(a){return a.name})).includes(a)})),A=e.festival.split(" ").filter((function(a){return!Object.values(P).flat().map((function(a){return a.name})).includes(a)}));n.$year.value=e.sYear,n.$month.value=e.sMonth,n.$year.setAttribute("data-value",e.sYear),n.$month.setAttribute("data-value",e.sMonth),n.$info.innerHTML='
'.concat(t," ").concat(e.weekZH,'
\n
').concat(e.sDay,'
\n
\n ').concat(e.lMonthZH?"

".concat(e.lMonthZH).concat(e.lDayZH,"

"):"","\n ").concat(e.gzYearZH?"

".concat(e.gzYearZH,"年 【").concat(e.animal,"年】

"):"","\n ").concat(e.gzMonthZH?"

".concat(e.gzMonthZH,"月 ").concat(e.gzDayZH,"日

"):"",'\n
\n
\n \n
').concat(Y.map((function(a){return"

".concat(a,"

")})).join("")+e.term.split(" ").map((function(a){return"

".concat(a,"

")})).join("")+A.map((function(a){return"

".concat(a,"

")})).join(""),"
\n
\n "),n.$tbody.innerHTML=k,n.currentDateInfo=e,n.dispatchEvent(new CustomEvent("onChange",{detail:e}))}},{key:"formatSetting",value:function(a){var n=this;a=a||(new Date).getFullYear(),n.$holiday.innerHTML="";var e=new Option("假日安排","");if(n.$holiday.add(e),b[a])for(var t=b[a],l=0;l=2011)for(var o=["元旦","春节","清明","劳动节","端午节","中秋节","国庆节"],i=1;i<=12;i++)for(var c=function(){var e=aa(a,i,d);if(e.sMonth==i&&e.sDay==d){var t=[];e.term&&t.push(e.term),e.festival&&(t=[].concat(t,e.festival.split(" "))),t.forEach((function(a){if(o.includes(a)){var t=new Option(a,e.sYear+"-"+e.sMonth+"-"+e.sDay);n.$holiday.add(t)}}))}},d=1;d<=31;d++)c()}},{key:"formatDate",value:function(a){var n=this;if(a){n.date=a;var t=e(a.split("-"),3),l=t[0],r=t[1],o=t[2];n.formatSetting(l),n.formatTable({year:l,month:r,day:o})}else n.date=n.today.date,n.formatSetting(),n.formatTable()}}])&&o(n.prototype,l),r&&o(n,r),Object.defineProperty(n,"prototype",{writable:!1}),s}(u(HTMLElement));customElements.get("widget-calendar")||customElements.define("widget-calendar",la)})); 14 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 中国农历公历转换 阴阳历换算 万年历 15 | 16 | 17 | 18 | 27 | 28 | 29 | 30 |
31 |
32 |
33 |
34 |
35 | 38 | 45 | 51 |
52 |
53 |
54 |
55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 |
67 |
68 |
69 |
70 |
71 |
72 |

中国农历公历转换开源算法

73 |

轻松获取农历公历日期、星期、干支、生肖、节气、节日等信息

74 | 84 |
85 |
86 |
87 |
88 |

通过公历获取农历信息

89 |
90 |
91 |
92 | 294 | 308 | 341 | 342 |
343 |
344 |
345 |
346 |
347 |
348 |

通过农历获取公历信息

349 |
350 |
351 |
352 | 554 | 568 | 600 | 604 | 605 |
606 |
607 |
608 |
609 |
610 |
611 |

万年历Web组件(Web Component)

612 |
613 |
614 | 615 |
616 |
617 |

事件测试

618 |

 

619 |
620 |

标签结构

621 | <widget-calendar></widget-calendar> 622 |
623 |

自定义事件-选中日期: onSelect

624 | document.querySelector('widget-calendar').addEventListener('onSelect',function(event){ 625 | let data = event.detail; 626 | document.getElementById('test').innerText=`onSelect:${data['sYear']}-${data['sMonth']}-${data['sDay']}`; 627 | }); 628 |
629 |

自定义事件-切换日期: onChange

630 | document.querySelector('widget-calendar').addEventListener('onChange',function(event){ 631 | let data = event.detail; 632 | document.getElementById('test').innerText=`onChange:${data['sYear']}-${data['sMonth']}-${data['sDay']}`; 633 | }); 634 |
635 |

自定义事件-初始化: onInit

636 | document.querySelector('widget-calendar').addEventListener('onInit',function(event){ 637 | let data = event.detail; 638 | document.getElementById('test').innerText=`onInit:${data['sYear']}-${data['sMonth']}-${data['sDay']}`; 639 | }); 640 | 654 |
655 |
656 |
657 |
关于中华万年历
658 |
659 |

我们现在使用的公历,即格里历,也叫阳历,就是日常生活中我们所应用到的几月几号,是国际通用的一种计算日子的历法。它是基于太阳的运动规律来安排计算制定的一种历法,只以地球绕太阳一周为一年为依据,完全不考虑月球的变化,月份的设置完全是人为设定的。为了方便对外交往和文化交流,也为了我们生活使用简便,公历现在成了我国通用的历法。 660 |

661 |

农历是我国古代用以指导农业生产生活的传统历法,自夏朝始,称为夏历。农历属于一种阴阳历,是以月球绕地球一周为一月,十二月为一年,月亮号为太阴,故谓之太阴历,简称为阴历。由于阴历的一年只有354天,少于太阳回归年的365天,所以夏历采用置闰月的方法,使得阴历的年份与阳历的年份大概保持一致。夏历将太阴历配合了闰年及二十四节气,使得太阴历的年周期同步于太阳历。 662 |

663 |

农历融合了阴历和阳历的特点,形成了一种阴阳合历历法。现行农历于1970年以后改称“夏历”为“农历”,并由中国科学院紫金山天文台负责计算和颁布国家标准《农历的编算和颁行》(GB/T 33661-2017)。朔日为农历月的第一个农历日,即每个农历月的初一。每个农历月反映了完整的月相变化周期,因此属于阴阳历中的阴历部分;而二十四节气则反映了地球绕太阳运行轨道上的不同位置,即回归年周期,因此属于阴阳历中的阳历部分。农历二十四节气是按太阳年24等分而得,这是阳历部分,农历的月日及闰法属于阴历部分,编在一起就成了和阴阳合历,我们平常没注意,叫惯了阴历不加区分。

664 |
665 |
666 |
667 |
668 |
669 |
算法开源
670 |
671 |

算法基于「MIT许可协议」开源,除需在源码中保留版权信息和许可声明外,你有权利使用、复制、修改、合并、出版发行、散布、再授权及贩售软件及软件的副本。数据持续更新中,如发现错漏或有想法建议可在此 673 | 反馈问题。 675 |

676 |
677 | Follow @mumuy 680 | Fork 684 | Star 688 | Download 691 |
692 |
693 |

日历转换脚本:

694 | https://passer-by.com/calendar/dist/calendar.min.js 695 |

万年历组件脚本:

696 | https://passer-by.com/calendar/dist/widget-calendar.min.js 697 |
698 |
699 |
700 |
701 | 702 |
703 |
704 |
705 |
706 |
707 | 714 |
715 |
716 |
717 |
718 |

719 | Copyright © 2025 720 | 路人甲 721 | 版权所有 722 |

723 |
724 |
725 |
726 |
727 | 728 | 729 | 730 | 792 | 793 | 794 | 795 | 796 | --------------------------------------------------------------------------------