A JavaScript lib with more functions for the normal Date class.

Overview

Better Date Functions (BDF)

Build Status Build Status
BDF Downloads

Installation


BDF requires Node.js v10+ to run.



    npm i better-date-functions
    or
    yarn add better-date-functions



Documentation


Getting the BDF dependency




   
   
// 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)
// 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 = 2022

const weekDayName = getWeekDayNameWithADate(day, month, year);

console.log(weekDayName) // returns "Monday"


All examples


//Example 1:

const weekDay = 1
const weekDayName = getWeekDayName(weekDay)
console.log(weekDayName) // returns "Sunday"
//Example 2:

const month = 3
const monthName = getMonthName(month)
console.log(monthName) // returns "March"
//Example 3:

const month = 3
const monthName = getMonthName(month)
console.log(monthName) // returns "March"
//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
//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 }
//Example 6:

const year1 = 2022
const year2 = 2024
const year1Length = getYearLength(year1)
const year2Length = getYearLength(year2)
console.log([year1Length, year2Length]) // returns [365, 366]


Examples with date


import { withDate } from 'better-date-functions'    // import the withDate functions
                                                    // you can destructurate too
                                                    // const { withDate } = BDF;
//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 31

const 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 365

const formatedDate = withDate.getformatedDate(date)
console.log(formatedDate) // returns 01/26/2022

const separator = "-"
const formatedDateWithCustomSeparator = withDate.getformatedDate(date, separator)
console.log(formatedDateWithCustomSeparator) // returns 01-26-2022


Configurations


//Changing the language of the returns

const weekDay = 1
const date = new Date() // currently on 26th January, 2022

let weekDayName = getWeekDayName(weekDay)
console.log(weekDayName) // returns "Sunday"

let formatedDate = withDate.getformatedDate(date)
console.log(formatedDate) // returns 01/26/2022

setLanguage('ptBR') // Currently supports "enUs" and "ptBr"

weekDayName = getWeekDayName(weekDay)
console.log(weekDayName) // returns "Domingo"

formatedDate = withDate.getformatedDate(date)
console.log(formatedDate) // returns 26/01/2022

const currentLanguage = getCurrentLanguage() // to get the current language configurated

console.log(currentLanguage) // returns "ptBr"
//Change the throwing errors configuration

let 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


Author and contributors

XaloDev & wagnersillva


License

ICS

You might also like...

A Javascript lib about complex

RealComplex.js 一个关于复数的Javascript库 A Javascript lib about complex How to use it? 使用教程 导入与实例化 import { Complex } from './Complex.js'; let x = new Comple

Feb 9, 2022

Portfólio de projetos pessoais feito com NextJs e lib de animação Framer Motion

Portfólio de projetos pessoais feito com NextJs e lib de animação Framer Motion

Portfólio - Carlos Amorim Esse portfólio foi criado para mostrar meus projetos e habilidades. 🚀 Projeto criado com as seguintes tecnologias: ✔️ NextJ

May 12, 2022

I'm trying to create simple program for adding the digital signature to a pdf file with self-signed certificate. I use node-signpdf and pdf-lib library.

pdf-digital-signature-with-node-signpdf-ejs I'm trying to create simple program for adding the digital signature to a pdf file with self-signed certif

Dec 25, 2022

Cross-runtime benchmarking lib and cli

Cross-runtime benchmarking lib and cli

mitata cross-runtime benchmarking lib Install bun add mitata npm install mitata Examples import { run, bench, group, baseline } from 'mitata'; // den

Jan 3, 2023

This lib was created with the aim of simplifying the use of serverless Twilio.

Twilio Functions Utils About This lib was created with the aim of simplifying the use of serverless Twilio, reducing the need to apply frequent try-ca

Nov 8, 2022

A lib for text highlighting by using Canvas.

canvas-highlighter 基于 canvas 实现的文本划词高亮,与文本展示的结构完全解耦,不改变文本内容的 DOM 结构。 Installation npm install canvas-highlighter Usage 最简单的实现文本划词直接高亮 import CanvasHig

Dec 24, 2022

It's a javascript Class which contains utility methods that simplify working with google maps web SDK

About GoogleMapsJSHelper It's a javascript Class which contains utility methods that simplify working with google maps web SDK Note: i used ES7 Class

Jul 23, 2022

Pure JavaScript library that add .is-hover class instead of css :hover for mobile and desktop.

 Pure JavaScript library that add .is-hover class instead of css :hover for mobile and desktop.

MultiDeviceHover Pure JavaScript library that add .is-hover class instead of css :hover for mobile and desktop. Usage Install Using npm, install multi

Oct 5, 2021

Toaster is a Pure Javascript plugin for displaying toast notifications. It comes with different options e.g custom text or HTML message, duration, custom class, toggle close button, position, custom close icon and backgorund color.

Pure Javascript Toaster Requires Nothing Demo Toaster is a Pure Javascript plugin for displaying toast notifications. It comes with different options

Jun 21, 2022
Owner
Ícaro Gabriel
Web Developer | Full-stack | React.js, Next.js, Spring & Firebase.
Ícaro Gabriel
Nepali Multi Date Picker for jQuery. Supports both single date selections and multiple date selection.

Nepali Multi Date Picker A simple yet powerful date picker based in Nepali calendar. Supports both single date selections and multiple date selection.

Sanil Shakya 4 May 23, 2022
High performance and SEO friendly lazy loader for images (responsive and normal), iframes and more, that detects any visibility changes triggered through user interaction, CSS or JavaScript without configuration.

lazysizes lazysizes is a fast (jank-free), SEO-friendly and self-initializing lazyloader for images (including responsive images picture/srcset), ifra

Alexander Farkas 16.6k Jan 1, 2023
Grupprojekt för kurserna 'Javascript med Ramverk' och 'Agil Utveckling'

JavaScript-med-Ramverk-Laboration-3 Grupprojektet för kurserna Javascript med Ramverk och Agil Utveckling. Utvecklingsguide För information om hur utv

Svante Jonsson IT-Högskolan 3 May 18, 2022
Hemsida för personer i Sverige som kan och vill erbjuda boende till människor på flykt

Getting Started with Create React App This project was bootstrapped with Create React App. Available Scripts In the project directory, you can run: np

null 4 May 3, 2022
Kurs-repo för kursen Webbserver och Databaser

Webbserver och databaser This repository is meant for CME students to access exercises and codealongs that happen throughout the course. I hope you wi

null 14 Jan 3, 2023
Easy responsive tabs - is a lightweight jQuery plugin which optimizes normal horizontal or vertical tabs to accordion on multi devices

Easy responsive tabs - is a lightweight jQuery plugin which optimizes normal horizontal or vertical tabs to accordion on multi devices like: web, tablets, Mobile (IPad & IPhone). This plugin adapts the screen size and changes its action accordingly.

Samson Onna 600 Dec 8, 2022
CodeTogether is a platform that aims to bring all the developers and coders together to appreciate collaborative coding by resolving issues faced by programmers on normal IDEs/platforms

CodeTogether is a platform that aims to bring all the developers and coders together to appreciate collaborative coding by resolving issues faced by programmers on normal IDEs/platforms. It allows developers to communicate with their fellow developers or collaborators through online voice call and realtime chat. Besides, the whiteboard makes the framing of an algorithm easier by helping programmers working collaboratively to discuss and plan their approach together

Shayan Debroy 5 Jan 20, 2022
This is just a script I put together to check and notify me via email (MailGun) when there's an earlier date before my initial appointment date. It doesn't handle rescheduling.

US-visa-appointment-notifier This is just a script I put together to check and notify me via email (MailGun) when there's an earlier date before my in

Theophilus Omoregbee 13 Jan 4, 2023
Functions Recipes is a library of examples to help you getting started with Salesforce Functions and get used to their main features.

Functions Recipes Introduction Salesforce Functions lets you use the Salesforce Platform for building event-driven, elastically scalable apps and expe

Trailhead Apps 172 Dec 29, 2022
An extension of the Map class with more Array-like features.

BetterMap An extension of the Map class with more Array-like features. Installation There ain't no installation. It's a Deno module. Usage import { Be

Neko Of The Abyss 13 Oct 24, 2022