@wdcjs/zilean
TypeScript icon, indicating that this package has built-in type declarations

0.0.15 • Public • Published

@wdcjs/zilean

zilean (时间守护者 基兰) 是一个基于 manba 封装 使用 typescript 编写的简易的时间库。

快速上手

安装依赖

$ npm install @wdcjs/zilean
or
$ yarn add @wdcjs/zilean

在 React / Remax 中使用

Demo

import {Zilean} from '@wdcjs/zilean'

export default Demo = () => {
    // 获取当前年份
    console.log(Zilean.getYear())
    // 获取当前月份
    console.log(Zilean.getMonth())
    // 获取当前是周几
    console.log(Zilean.getDay())
    // 获取当前是几号
    console.log(Zilean.getDate())
    // 获取指定周天数
    console.log(Zilean.getMothDays(2022, 1))
    // 获取指定周天数
    console.log(Zilean.getWeeksDate(2022, 1, 1))
    // 获取指定月份 1号是星期几
    console.log(Zilean.getMothStartDay(2022, 1))
    // 日期对比
    console.log(Zilean.getMothEndDay(2022, 1))
    // 两个日期对比
    console.log(Zilean.compare('2022-01-01', '2022-01-02'))
    // 获取指定天数是星期几 2021/1/1 是周六, date 日期是从 0 开始并且为周日为起始天
    console.log(Zilean.getMothDay(2022, 1, 1))
    // 日期是否在开始和结束范围内 true
    console.log(Zilean.during('2022-01-01', '2022-01-03', '2022-01-02'))
    // 日期是否在开始和结束范围内 false
    console.log(Zilean.during('2022-01-01', '2022-01-03', '2022-01-04'))
    // 获取日期区间内的日期数组 , 支持传入 disableDate 默认为空数组 
    // 返回 ['2022-01-01','2022-01-02','2022-01-03','2022-01-04','2022-01-06']
    console.log(Zilean.during('2022-01-01', '2022-01-06', disableDate = ['2022-01-05']))
    // 获取月份区间内的月份数组 支持传入 disableMonth 默认为空数组
    // 返回 ['2022-01','2022-03','2022-04','2022-05','2022-06']
    console.log(Zilean.getDuringMonth('2022-01', '2022-06', ['2022-02']));
    // 获取当月的节日日期 
    /**
     * 返回数组
     *
     * [
     * { normal: '初七', festival: '元旦', year: 2020, month: 1, day: 1 },
     * { normal: '初八', year: 2020, month: 1, day: 2 },
     * { normal: '初九', year: 2020, month: 1, day: 3 },
     * { normal: '十日', year: 2020, month: 1, day: 4 },
     * { normal: '十一', year: 2020, month: 1, day: 5 },
     * { normal: '十二', year: 2020, month: 1, day: 6 },
     * { normal: '十三', year: 2020, month: 1, day: 7 }
     * ]
     */
    console.log(Zilean.getLunarDate(2020, 1, 1))
    /**
     *
     * 获取当前一周日期(从周一开始),如果不传参默认为当前日期
     * ['2022-3-14',
     '2022-3-15',
     '2022-3-16',
     '2022-3-17',
     '2022-3-18',
     '2022-3-19',
     '2022-3-20',
     * ]
     */

    console.log(Zilean.getNowWeek('2022-03-20'))
    /**
     * '获取当前一周时间(含天数和日期)
     * [
     {day: '周一', date: '2022-10-03'},
     {day: '周二', date: '2022-10-04'},
     {day: '周三', date: '2022-10-05'},
     {day: '周四', date: '2022-10-06'},
     {day: '周五', date: '2022-10-07'},
     {day: '周六', date: '2022-10-08'},
     {day: '周日', date: '2022-10-09'}
     ]
     */
    console.log(Zilean.getNowWeekDate('2022-10-08'))
}

Readme

Keywords

Package Sidebar

Install

npm i @wdcjs/zilean

Weekly Downloads

0

Version

0.0.15

License

MIT

Unpacked Size

58.5 kB

Total Files

13

Last publish

Collaborators

  • watsonhaw