Skip to content

一个可以自己定制样式的日历库,没有dom操作, 只封装了日历的算法,得到需要的日历数据。 this is a calendar lib, have not DOM, you can customization style by yourself

Richard-Choooou/best-timeTool

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

best-canlender

this calendar lib encapsulation calendar's algorithm for get calendar data, have not DOM, you can customization style by yourself. 一个可以自己定制样式的日历库,没有dom操作, 只封装了日历的算法,得到需要的日历数据。

EN/ 中文文档

NPM version npm download

Introduction

this calendar lib encapsulation calendar's algorithm for get calendar data, have not DOM, you can customization style by yourself.

Installation

$ npm i best-calendar --save

usage

import

//By commonjs
const BTime = require('best-calendar')
//By ES6 module
import BTime form 'best-calendar'
//By DOM script
<script src="./js/BTime.min.js"></script>

use

let calendar = new BTime.Calendar({
    // ...some options
})

calendar.on('dateChange', function(date) {
    console.log(date)

    /**
        data = {
            currentYear:2017,
            currentMonth:12,
            currentDay:1,
            lastMonth:[26, 27, 28, 29, 30],
            nextMonth:[1, 2, 3, 4, 5, 6],
            thisMonth: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,15, 16, 17, 18, 19, 20, 21, 22, 23, 24,   25, 26, 27, 28, 29, 30, 31],
            today:"2018/3/7"
        }
    */
})

Configuration

let calendar = new BTime.Calendar({
    // ...some options
    firstColumnIsWeekend: true
})

firstColumnIsWeekend(# option)

default: true

if this calendar first column date is weekend set it true else set it false

API

goLastMonth(# method)

params: no params

go to the last month by current date then get last month calendar data and set current date to last month

goNextMonth(# method)

params: no params

go to the next month by current date then get next month calendar data and set current date to next month

goLastYear(# method)

params: no params

go to the last year by current date then get last year calendar data and set current date to last year

goNextYear(# method)

params: no params

go to the next year by current date then get next year calendar data and set current date to next year

go(# method)

params: one param
arguments[0] type: Number

examples: 
    calendar.go(-1)     // be equivalent to calendar.goLastMonth()
    calendar.go(-2)     // be equivalent to executed twice calendar.goLastMonth()
    calendar.go(-12)    // be equivalent to calendar.goLastYear()
    calendar.go(1)     // be equivalent to calendar.goNextMonth()
    calendar.go(12)    // be equivalent to calendar.goNextYear()

setCurrentDate(# method)

params: one param
arguments[0] type: [Object Date] or String

examples: 
    calendar.setCurrentDate(new Date('2018/3/8')) 
    calendar.setCurrentDate('2018/3/8')             // must be separated by '/'

on(# method)

params: two params
    arguments[0] type: String      "have only one event, that is 'dateChange'"
    arguments[1] type: Function    when date changed, execute the callback

execute functions 'setCurrentDate' 'go' 'goNextYear' 'goLastYear' 'goNextMonth' 'goLastMonth' will trigger this event

example:
    calendar.on('dateChange', function(date) {
        console.log(date)

        /**
            data = {
                currentYear:2017,
                currentMonth:12,
                currentDay:1,
                lastMonth:[26, 27, 28, 29, 30],
                nextMonth:[1, 2, 3, 4, 5, 6],
                thisMonth: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14,15, 16, 17, 18, 19, 20, 21, 22, 23, 24,   25, 26, 27, 28, 29, 30, 31],
                today:"2018/3/7"
            }
        */
    })

if this lib is useful, star it on github,thanks

About

一个可以自己定制样式的日历库,没有dom操作, 只封装了日历的算法,得到需要的日历数据。 this is a calendar lib, have not DOM, you can customization style by yourself

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published