ChanceYu / month-calculator

:paperclip: A plugin for month date calculator

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

month-calculator

NPM

Build Status Language License

A plugin for month date calculator , 中文

Install

npm install month-calculator --save

Features

  • Highly customizable
  • No dependence on UI, You can design by yourself
  • Support browser、nodejs、miniProgram(小程序)

Usage

var oMonth = new MonthCalculator({
    startDate: '2017-07-17',
    endDate: '2018-08-18'
});

var months = oMonth.getTotal();

console.log(months);

Parameter

  • startDate - the start date formatted like YYYY-MM-DD
  • endDate - the end date formatted like YYYY-MM-DD

Method

  • getTotal - get the total months from startDate to endDate
  • getToday - if today's date is between startDate and endDate, will return an Object { monthIndex, date }, and the monthIndex is today's month index in total result, otherwise will return undefined

Result

After use getTotal method will return the result structure below

[
    {
        title: '2017-07',
        dates: [
            {
                date: '2017-06-25',
                year: '2017',
                month: '06',
                day: '25',
                disabled: true,
                isPrevMonth: true,
                week: '',
                weekday: 0
            }
            ...
        ]
    }
    ...
]

Result date properties

  • date - total date formatted YYYY-MM-DD
  • year - date formatted YYYY
  • month - date formatted MM
  • day - date formatted DD
  • weekday - weekday from 0 to 6
  • week - Chinese weekday 日一二三四五六
  • isPrevMonth - if it is previous month date, will be true
  • isNextMonth - if it is next month date, will be true
  • disabled - if it is isPrevMonthisNextMonth or current month disabled date(not between startDate to endDate), will be true

Examples

License

license

About

:paperclip: A plugin for month date calculator

License:MIT License


Languages

Language:JavaScript 99.6%Language:HTML 0.4%