Giter Site home page Giter Site logo

surajaswal29 / custom-dates-npm Goto Github PK

View Code? Open in Web Editor NEW
6.0 4.0 1.0 980 KB

This npm package, named 'use-custom-dates', provides a utility function called useCustomDates that generates a customizable date range based on the current date.

Home Page: https://www.npmjs.com/package/use-custom-dates

JavaScript 100.00%
custom-dateformat date datetime javascript nodejs npm-module npm-package

custom-dates-npm's Introduction

use-custom-dates

JavaScript PRs Welcome Version License Downloads Contributors GitHub Issues

This npm package, named "use-custom-dates", provides a utility function called useCustomDates that generates a customizable date range based on the current date. The function returns an object containing information about the current date, the previous year's date, and an array representing the labels for the last 7 days, including the day of the month and the corresponding month name.

Key Features

  • Dynamic calculation of the current date, including day of the week, month, year, and leap year status.
  • Generation of a date range for the last 7 days, with customizable labels based on the day of the month and the corresponding month name.
  • Consideration of month lengths and leap years in the date calculations.

Installation

npm install use-custom-dates

Usage

const useCustomDates = require("use-custom-dates")

// Get date-related information
const dateInfo = await useCustomDates()

// Access properties from the returned object
console.log(dateInfo)

Output

{
  current: {
    todayDate: '07',
    weekDay: 'Sunday',
    month: '01',
    year: 2024,
    date: '07/01/2024',
    monthName: 'January',
    monthLength: 31,
    isLeapYear: true
  },
  previous: { year: 2023, month: 12, monthLength: 31, monthName: 'December' },
  allMonths: [
    { month: 'January', shortName: 'Jan', numOfDays: 31, weeks: 5 },
    { month: 'February', shortName: 'Feb', numOfDays: 29, weeks: 4 },
    { month: 'March', shortName: 'Mar', numOfDays: 31, weeks: 5 },
    { month: 'April', shortName: 'Apr', numOfDays: 30, weeks: 5 },
    { month: 'May', shortName: 'May', numOfDays: 31, weeks: 5 },
    { month: 'June', shortName: 'Jun', numOfDays: 30, weeks: 5 },
    { month: 'July', shortName: 'Jul', numOfDays: 31, weeks: 5 },
    { month: 'August', shortName: 'Aug', numOfDays: 31, weeks: 5 },
    { month: 'September', shortName: 'Sep', numOfDays: 30, weeks: 5 },
    { month: 'October', shortName: 'Oct', numOfDays: 31, weeks: 5 },
    { month: 'November', shortName: 'Nov', numOfDays: 30, weeks: 5 },
    { month: 'December', shortName: 'Dec', numOfDays: 31, weeks: 5 }
  ],
  last7days: {
    from_date: 1,
    to_date: 7,
    L7D: [
        { label: '1 January' },
        { label: '2 January' },
        { label: '3 January' },
        { label: '4 January' },
        { label: '5 January' },
        { label: '6 January' },
        { label: '7 January' }
    ]
  }
}

Returned Object Properties

current

  • todayDate: Day of the month with leading zero.
  • weekDay: Day of the week (e.g., "Monday").
  • month: Month with leading zero.
  • year: Current year.
  • date: Full date string in UK format.
  • monthName: Full name of the current month.
  • monthLength: Number of days in the current month.
  • isLeapYear: Leap year status for the current year.

previous

  • year: Previous year.
  • month: Previous month with leading zero.
  • monthLength: Number of days in the previous month.
  • monthName: Full name of the previous month.

allMonths: Array containing information about all months.

last7days

  • from_date: Start date of the last 7 days' range.
  • to_date: End date of the last 7 days' range.
  • L7D: Array of objects representing the last 7 days' date range labels. Each object has a label property containing the day of the month and the corresponding month name.

Examples

// Example 1: Accessing current date information
console.log(dateInfo.current.todayDate)
console.log(dateInfo.current.weekDay)

// Example 2: Accessing last 7 days' date range labels
console.log(dateInfo.last7days.L7D)

License

This project is licensed under the ISC License - see the LICENSE.md file for details.

Author

Suraj Aswal

Repository

GitHub Repository

custom-dates-npm's People

Contributors

surajaswal29 avatar

Stargazers

Dheeraj pandey avatar Wavefire Coding avatar  avatar Mohan Srivastav avatar Geeta Negi avatar  avatar

Watchers

Dheeraj pandey avatar Wavefire Coding avatar  avatar  avatar

custom-dates-npm's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.