Socket
Socket
Sign inDemoInstall

ts-date-library

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    ts-date-library

A Date library written in TypeScript


Version published
Maintainers
1
Install size
19.8 kB
Created

Readme

Source

TS-JS Date Library

npm npm bundle size

A simpler Date library for Javascript.

Installation

Use the package manager npm to install.

npm i ts-date-library

Link to npm library

Usage

const { D } = require('ts-date-library');
const testDate = new D(2022, 9, 22, 3, 4, 5);
const testDate2 = new D('6/1/1982');
const testDateToday = new D();

// Full year Number
testDate.year // 2022
testDate2.year // 1982

// Short year Number
testDate.yr // 22
testDate2.yr // 82

// Full month String
testDate.month // 'October'
testDate2.month // 'June'

// Short month String
testDate.mon // 'Oct'
testDate2.mon // 'Jun'

// Full day String
testDate.day // 'Saturday'
testDate2.day // 'Tuesday'

// Short day String
testDate.dy // 'Sat'
testDate2.dy // 'Tue'

// Date Number
testDate.date // 22
testDate2.date // 1

// Hour Number
testDate.hours // 3
testDate2.hours // 0

// Minute Number
testDate.mins // 4
testDate2.mins // 0

// Second Number
testDate.secs // 5
testDate2.secs // 0

// Formatted Date String Examples
testDate.format('Y-M-D h:I:S') // '2022-October-22 3:04:05'
testDate.format('h:i:s') // '3:4:5'
testDate.format('h/i/s') // '3/4/5'
testDate2.format('y-m-d H:I:S') // '82-Jun-1 00:00:00'
testDate2.format() // '1982 June 1'

// .when() function returns time difference string from a given date
const mockDate = new Date(2022, 6, 6);
testDate.when(mockDate) // '3 months 16 days from now'
testDate2.when(mockDate) // '40 years 1 month 5 days ago'
testDate3.when(mockDate) // '1 year 3 months 24 days ago'
testDate5.when(mockDate) // '3 years 1 month 6 days from now'
testDate6.when(mockDate) // '5 months 6 days ago'
testDate7.when(mockDate) // '5 days ago'
testDate8.when(mockDate) // '24 days from now'
testDateToday.when(new Date()) // 'today'

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Testing

To run tests:

npm test

To check code test coverage:

npx jest --coverage

License

MIT

FAQs

Last updated on 13 Jul 2022

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc