npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

dayjs-plugin-workdays

v1.0.9

Published

一个基于day.js的工作日插件

Downloads

6

Readme

简体中文 | English |

dayjs-plugin-workDays

一个基于 day.js 的工作日插件

安装

npm install  dayjs-plugin-workdays --save

使用方法

import workDays from "dayjs-plugin-workdays";
dayjs.extend(workDays);
dayjs().workDays(date, options);

参数

参数date

类型 Date 传入日期或dayjs对象。 将计算到日期的工作日例如:dayjs("2024/01/01").workDays("2024/01/31", options)就会计算2024/01/01到2024/01/31的工作日。

参数 options

需要传入一个对象

| 属性名 | 类型 | 默认值 | 必填 | 描述 |
| ---------------------- | ------- | -------- | ---- | -------------------------------------------------------------------------------- |
| options.vacationDates | Date[] | [] | 否 | 假期日期,即除了周末外的节假日日期 |
| options.weekendDays | Int[] | [0,6] | 否 | 默认值[0,6]也就是周六和周日,周几休息就传入周几的代码,如只有周日则传入[0],如果周三额外休息传入[0,2,6] |
| options.adjustWorkDates | Date[] | [] | 否 |万恶调休!,传入一个周末日期,这个日期将不会被识别为假期,而是加入工作日;如果与options.vacationDates日期冲突,则优先级较高 |

返回值 returns

将会返回一个对象

| 属性名 | 类型 | 描述 |
| --------------- | ------- | -------------------------------------------------- |
| returns.restDays | Date[] | 休息日,即范围内所有周末和假日的日期 |
| returns.workDays | Date[] | 工作日,即范围内所有普通工作日和调休工作日 |
| returns.weekendDays | Date[] | 周末,即范围内所有周末日期,会被包含在returns.restDays内 |
| returns.vacationDays | Date[] | 范围内所有假日日期,会被包含在returns.restDays内 |
| returns.adjustWorkDays | Date[] | 范围内所有的调休工作日,会被包含在returns.workDays内 |

使用示例

import dayjs from "dayjs";
import workDays from "dayjs-plugin-workdays";
dayjs.extend(workDays);
const options = {
  vacationDates: [
    "2024/05/01",
    "2024/05/02",
    "2024/05/03",
    "2024/05/04",
    "2024/05/05",
  ],
  adjustWorkDdates: ["2024/05/11"],
};
const result = dayjs("2024/5/1").workDays("2024/5/31", options);
console.log(result);

输出

{
  restDays: [
    '2024-05-01', '2024-05-02',
    '2024-05-03', '2024-05-04',
    '2024-05-05', '2024-05-12',
    '2024-05-18', '2024-05-19',
    '2024-05-25', '2024-05-26'
  ],
  workDays: [
    '2024-05-06', '2024-05-07',
    '2024-05-08', '2024-05-09',
    '2024-05-10', '2024-05-11',
    '2024-05-13', '2024-05-14',
    '2024-05-15', '2024-05-16',
    '2024-05-17', '2024-05-20',
    '2024-05-21', '2024-05-22',
    '2024-05-23', '2024-05-24',
    '2024-05-27', '2024-05-28',
    '2024-05-29', '2024-05-30',
    '2024-05-31'
  ],
  weekendDays: [
    '2024-05-04',
    '2024-05-05',
    '2024-05-12',
    '2024-05-18',
    '2024-05-19',
    '2024-05-25',
    '2024-05-26'
  ],
  vacationDays: [ '2024-05-01', '2024-05-02', '2024-05-03' ],
  adjustWorkDays: [ '2024-05-11' ]
}