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

plain-date

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

plain-date

A simple, light-weight model for date handling

  • 1.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

plain-date

A simple, light-weight model for date handling in JavaScript

Module System

The package includes both an ESM module (browser-compatible) and CJS modules (npm-compatible).

plain-date is written in node-style and converted to ESM for wider distribution. The default is therefore the node variant.

CJS (node)

require('plain-date') gives you the PlainDate class. require('plain-date/calculation') gives you helper functions.

const PlainDate = require('plain-date')
const { startOfMonth, weekNumber } = require('plain-date/calculation')

ESM (browser)

index.mjs yields the PlainDate class as its default export and the helper functions as named exports.

import PlainDate, { startOfMonth, weekNumber } from 'plain-date'

API

Table of Contents

PlainDate

PlainDate objects represent calendar dates or months. They focus on ease of use and are very light in comparison with JavaScript's native Date type.

They have a small set of properties, are immutable, and every date can only ever exist once.

If you try to create a new PlainDate object with a date that has previously been created, you will receive that pre-existing PlainDate object.

Additionally, PlainDate objects can be intuitively compared.

PlainDate objects can be constructed with one to three parameters. Behaviour for unexpected inputs is not defined. In order to stay light-weight, there is no intelligent type checking.

Type: Object

Properties
Examples
new PlainDate('2019-04-01') === new PlainDate('2019-04-01') // => true
new PlainDate('2019-04-01') < new PlainDate('2019-04-01') // => false
new PlainDate('2019-04-01') < new PlainDate('2019-04-11') // => true
new PlainDate('2019-04-01') > new PlainDate('2019-04-11') // => false
getNativeDate

Creates a new equivalent Date object. Multiple calls yield multiple distinct objects.

Returns Date

getComplexDate

Returns Date

Meta

  • deprecated: Use getNativeDate instead
toString

Replaces each token in the given string by the appropriate string representation of the related data:

  • YYYY: full year-number.
  • YY: last two digits of year.
  • MM: zero-padded two-digit month.
  • DD: zero-padded two-digit date.

Defaults to the ISO format.

Parameters
  • format string (optional, default 'YYYY-MM[-DD]')

Returns string

valueOf

Enables fast comparison via < and >.

Returns number

PlainDate/3_parameters

Parameters
Examples
new PlainDate(2019, 4, 1)
new PlainDate('2019', '04', '01')

PlainDate/2_parameters

Parameters
Examples
new PlainDate(2019, 4)
new PlainDate('2019', '4')

PlainDate/1_parameter

Parameters
Examples
new PlainDate('2019-04-01')
new PlainDate('2019-04')
new PlainDate(new Date(2019,3,1))
new PlainDate({
  year: 2019,
  month: 4,
})

daysBetween

Parameters

Returns number Difference between both dates, in days.

startOfMonth

Parameters

Returns PlainDate The first of the same month.

endOfMonth

Parameters

Returns PlainDate The last of the same month.

startOfWeek

Parameters

Returns PlainDate The first of the same week.

endOfWeek

Parameters

Returns PlainDate The last of the same week.

weekNumber

Parameters

Returns number The number of the week within the current year, as per ISO 8601.

Keywords

FAQs

Package last updated on 20 Feb 2019

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