https://github.com/angelozdev/chrono-convert
Effortlessly manipulate and convert time units with Chrono-Convert, the JavaScript library offering a fluent, chainable interface for clear and precise time calculations. Perfect for adding sophisticated time-based logic to your applications with ease and elegance.
https://github.com/angelozdev/chrono-convert
Last synced: 4 months ago
JSON representation
Effortlessly manipulate and convert time units with Chrono-Convert, the JavaScript library offering a fluent, chainable interface for clear and precise time calculations. Perfect for adding sophisticated time-based logic to your applications with ease and elegance.
- Host: GitHub
- URL: https://github.com/angelozdev/chrono-convert
- Owner: angelozdev
- License: mit
- Created: 2023-11-01T23:10:06.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-03-25T22:40:26.000Z (about 1 year ago)
- Last Synced: 2025-08-09T03:15:09.602Z (10 months ago)
- Language: TypeScript
- Homepage:
- Size: 38.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Chrono Convert
Effortlessly manipulate and convert time units with Chrono-Convert, the JavaScript library offering a fluent, chainable interface for clear and precise time calculations. Perfect for adding sophisticated time-based logic to your applications with ease and elegance.
## Features
- **Fluent Interface**: Easy-to-read, chainable methods.
- **Versatile**: Convert between seconds, minutes, hours, and more.
- **Lightweight**: Minimally impacts your project's footprint.
- **No Dependencies**: Use it out of the box without worrying about additional packages.
## Installation
Install `chrono-convert` using your preferred package manager.
```bash
# With npm
npm install chrono-convert
# With yarn
yarn add chrono-convert
# With pnpm
pnpm add chrono-convert
```
## Usage
The `chrono-convert` library provides a fluent interface for manipulating and converting time units. This makes it easy to perform sophisticated time-based calculations in your JavaScript projects.
### Getting Started
First, you need to import `chrono-convert` into your project.
For CommonJS:
```javascript
const chrono = require("chrono-convert");
```
For ES6 modules:
```javascript
import chrono from "chrono-convert";
```
### Converting Time
```javascript
const time = chrono.minutes(5).add(50, "minutes").toSeconds();
const time = chrono.from(5, "minutes").add(50, "minutes").to("seconds");
console.log(time); // 3300
const time = chrono.hours(2).add(30, "minutes").toMinutes();
const time = chrono.from(2, "hours").add(30, "minutes").to("minutes");
console.log(time); // 150
const time = chrono.seconds(120).subtract(30, "seconds").toMinutes();
const time = chrono.from(120, "seconds").subtract(30, "seconds").to("minutes");
console.log(time); // 1.5
const time = chrono.seconds(120).subtract(30, "seconds").toHours();
const time = chrono.from(120, "seconds").subtract(30, "seconds").to("hours");
console.log(time); // 0.025
```