A JavaScript library with more functions for the normal Date class.
npm install better-date-functionsBDF requires Node.js v10+ to run.
npm i better-date-functions
or
yarn add better-date-functions- Getting the BDF dependency
- All examples
- Examples with Date
- Configurations
- Contribution and Development
```
js
// import the the BDF dependency
import BDF from 'better-date-functions';const {
getMonthLength,
getMonthName,
getWeekDayName,
getWeekDayNameWithADate,
setLanguage,
getCurrentLanguage,
getMonthInfo,
getYearLength,
setThrowingErrors,
getCurrentThrowingErrorsState,
} = BDF; // Destructuring (optional)`js`
// Using the functions// Days must be a number between 1~31
// Months must be a number between 1~12
// Year Must be a number//Example:
const day = 24
const month = 1
const year = 2022const weekDayName = getWeekDayNameWithADate(day, month, year);
console.log(weekDayName) // returns "Monday"
`js`
//Example 1:const weekDay = 1
const weekDayName = getWeekDayName(weekDay)
console.log(weekDayName) // returns "Sunday"`js`
//Example 2:const month = 3
const monthName = getMonthName(month)
console.log(monthName) // returns "March"`js`
//Example 3:const month = 3
const monthName = getMonthName(month)
console.log(monthName) // returns "March"`js`
//Example 4:const month = 2
const year = 2024
const monthLength = getMonthLength(month, year) // Year is optional, but for precise Length in February you need the year
console.log(monthLength) // returns 29`js`
//Example 5:const month = 1
const year = 2022
const monthInfo = getMonthInfo(month, year) // Year is optional, but for precise Length in February you need the year
console.log(monthInfo) // returns { length: 31, name: "January", year: 2022 }`js`
//Example 6:const year1 = 2022
const year2 = 2024
const year1Length = getYearLength(year1)
const year2Length = getYearLength(year2)
console.log([year1Length, year2Length]) // returns [365, 366]
`js`
import { withDate } from 'better-date-functions' // import the withDate functions
// you can destructurate too
// const { withDate } = BDF;`js`
//Examples:const date = new Date() // currently on 26th January, 2022
const weekDayName = withDate.getWeekDayName(date)
console.log(weekDayName) // returns "Wednesday"const monthLength = withDate.getMonthLength(date)
console.log(monthLength) // returns 31const monthName = withDate.getMonthName(date)
console.log(monthName) // returns "January"const monthInfo = withDate.getMonthInfo(date)
console.log(monthInfo) // returns { name: "January", length: 31, year: 2022 }const yearLength = withDate.getYearLength(date)
console.log(yearLength) // returns 365const formatedDate = withDate.getformatedDate(date)
console.log(formatedDate) // returns 01/26/2022const separator = "-"
const formatedDateWithCustomSeparator = withDate.getformatedDate(date, separator)
console.log(formatedDateWithCustomSeparator) // returns 01-26-2022
`js`
//Changing the language of the returnsconst weekDay = 1
const date = new Date() // currently on 26th January, 2022let weekDayName = getWeekDayName(weekDay)
console.log(weekDayName) // returns "Sunday"let formatedDate = withDate.getformatedDate(date)
console.log(formatedDate) // returns 01/26/2022setLanguage('ptBR') // Currently supports "enUs" and "ptBr"
weekDayName = getWeekDayName(weekDay)
console.log(weekDayName) // returns "Domingo"formatedDate = withDate.getformatedDate(date)
console.log(formatedDate) // returns 26/01/2022const currentLanguage = getCurrentLanguage() // to get the current language configurated
console.log(currentLanguage) // returns "ptBr"
`js``
//Change the throwing errors configurationlet isThrowingErrors = getCurrentThrowingErrorsState() // by default the value of the state is true
console.log(isThrowingErrors) // returns true
setThrowingErrors(false) // you can change the state using this function
isThrowingErrors = getCurrentThrowingErrorsState()
console.log(isThrowingErrors) // returns false
XaloDev & wagnersillva
ICS