@pinemach/truncate-date
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

@pinemach/truncate-date

Coverage Status Build Status NPM version MIT License

@pinemach/truncate-date is a small JavaScript package with a single concern: truncating datetime inputs to remove all precision past a given time unit.

You can read the full API documentation at pineapplemachine.github.io/truncate-date-js/.

Installation

You can install this package with the package manager of your choice. For example,

npm install @pinemach/truncate-date

You can then import and use the module like so:

const truncateDate = require("@pinemach/truncate-date").truncateDate; // CommonJS
import {truncateDate} from "@pinemach/truncate-date"; // ES6 modules

Usage

This package exports the truncateDate function, which accepts a Date object or other time value input and a time unit to truncate that value to.

Truncation occurs in the UTC timezone.

import {truncateDate} from "@pinemach/truncate-date";

const myDate = new Date("2020-04-15T12:30:15.123Z");

// Logs "2020-04-15T12:30:15.000Z"
console.log(truncateDate("second", myDate));

// Logs "2020-04-15T12:00:00.000Z"
console.log(truncateDate("hour", myDate));

// Logs "2020-04-15T00:00:00.000Z"
console.log(truncateDate("day", myDate));

// Logs "2020-01-01T00:00:00.000Z"
console.log(truncateDate("year", myDate));

Readme

Keywords

Package Sidebar

Install

npm i @pinemach/truncate-date

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

12.8 kB

Total Files

7

Last publish

Collaborators

  • pineapplemachine