Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

dates-in-js

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

dates-in-js

[![npm version](https://img.shields.io/npm/v/.svg)](https://www.npmjs.com/package/dates-in-js)

  • 1.0.1
  • latest
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

npm version

npm downloads

NPM Package

dates-in-js npm package

The dates-in-js npm package is a custom date library designed to simplify date and time operations in JavaScript. It provides an intuitive way to work with dates, offering a set of methods for retrieving various date components, formatting dates, and calculating relative time differences from the current date.

Installation

To start using dates-in-js in your JavaScript projects, you can install it via npm:

npm install dates-in-js

Usage

Once you have installed dates-in-js, you can import the desired functions into your JavaScript code:

const dateJS = require('dates-in-js');

Features

dates-in-js offers a wide range of features that empower you to work with dates more effectively:

Getters

  • year(): Returns the full year (e.g., 2023).
  • yr(): Returns the short year (e.g., 23 for 2023).
  • month(): Returns the full month name (e.g., January).
  • mon(): Returns the short month name (e.g., Jan).
  • day(): Returns the full day of the week (e.g., Wednesday).
  • dy(): Returns the short day of the week (e.g., Wed).
  • date(): Returns the date of the month (e.g., 1).
  • hours(): Returns the hour (0-23).
  • mins(): Returns the minute (0-59).
  • secs(): Returns the second (0-59).

Methods

  • format(mask = 'Y M D'): Formats the date according to the specified mask.
  • when(): Returns a human-readable relative time difference from the current date.

Usage

const D = require('dates-in-js');

// Creating a datejs instance
const currentDate = new D();

// Accessing date components
console.log(currentDate.year); // 2023
console.log(currentDate.yr);   // 6
console.log(currentDate.month); // September
console.log(currentDate.mon);   // Sep
console.log(currentDate.day);   // Wednesday
console.log(currentDate.dy);    // Wed
console.log(currentDate.date);  // 6
console.log(currentDate.hours); // 11
console.log(currentDate.mins);  // 13
console.log(currentDate.secs);  // 45

// Formatting dates
console.log(currentDate.format('Y-M-D h:I:S')); // 2023-September-06 11:13:45
console.log(currentDate.format('y/m/D'));       // 23/sep/06

// Calculating relative time differences
const futureDate = new D(2024, 9, 6);
console.log(futureDate.when()); // 1 year from now

const pastDate = new D(2023, 3, 6);
console.log(pastDate.when()); // 6 months ago

Contributing

I welcome contributions from the community to improve and expand the functionality of dates-in-js. If you have any suggestions, bug reports, or feature requests, please don't hesitate to open an issue or submit a pull request on the GitHub repository.

  • The package is intended to be used for educational purposes only.

Keywords

FAQs

Package last updated on 06 Sep 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc