Skip to main content
Home

latest

Minimalist date and time manipulation library

This package works with Cloudflare Workers, Node.js, Deno, Bun, Browsers
This package works with Cloudflare Workers
This package works with Node.js
This package works with Deno
This package works with Bun
This package works with Browsers
JSR Score
100%
Published
a week ago (1.0.2)

๐Ÿ•’ Time

Minimalist date and time manipulation library for TypeScript.

๐Ÿ“ฆ Installation

  • Deno:
    deno add jsr:@i9si-sistemas/time
    
  • Node:
    npx jsr add @i9si-sistemas/time
    
  • Bun:
    bun add @i9si-sistemas/time
    

๐Ÿงฉ Features

  • Duration helpers: seconds, minutes, hours, days, weeks
  • Date arithmetic: add, addMonths, addYears
  • Comparison: compare, before, after
  • Formatting & parsing: format, parse
  • Truncation: truncate
  • Simple API using standard Date

๐Ÿš€ Usage

๐Ÿ“… Now

import { Time } from "@i9si-sistemas/time";
const now = Time.now();
console.log(now instanceof Date); // true

โฑ๏ธ Durations

import { Time } from "@i9si-sistemas/time";
Time.seconds(2); // 2000
Time.minutes(1); // 60000
Time.hours(1);   // 3600000
Time.days(1);    // 86400000
Time.weeks(1);   // 604800000

โž• Add Time

import { Time } from "@i9si-sistemas/time";
const date = new Date("2024-01-01T00:00:00.000Z");
const result = Time.add(date, Time.seconds(10));
console.log(result.toISOString());
// "2024-01-01T00:00:10.000Z"

๐Ÿ“† Add Months & Years

import { Time } from "@i9si-sistemas/time";
Time.addMonths(new Date("2024-01-01T00:00:00.000Z"), 1).toISOString();
// "2024-02-01T00:00:00.000Z"

Time.addYears(new Date("2024-01-01T00:00:00.000Z"), 1).toISOString();
// "2025-01-01T00:00:00.000Z"

๐Ÿ” Compare Dates

import { Time } from "@i9si-sistemas/time";
const a = new Date("2024-01-01T00:00:00.000Z");
const b = new Date("2024-01-01T00:00:10.000Z");

Time.before(a, b);  // true
Time.after(b, a);   // true

๐Ÿงพ Format Date

import { Time } from "@i9si-sistemas/time";
Time.format(new Date("2024-01-02T00:00:00Z"), "dd/MM/yyyy", true);
// "02/01/2024"

Time.format(new Date("2024-01-01T13:05:00Z"), "HH:mm", true);
// "13:05"

๐Ÿ“ฅ Parse ISO Date

import { Time } from "@i9si-sistemas/time";
Time.parse("2024-01-01T00:00:00.000Z").toISOString();
// "2024-01-01T00:00:00.000Z"

๐Ÿงน Truncate Date

import { Time } from "@i9si-sistemas/time";
const date = new Date("2024-02-03T01:10:00.000Z");

Time.truncate(date, Time.minutes(60)).toISOString();
// "0001-01-01T01:00:00.000Z"

Time.truncate(date, Time.hours(24)).toISOString();
// "2024-02-03T00:00:00.000Z"

๐Ÿ“„ License

Licensed under the MIT License.

New Ticket: Report package

Please provide a reason for reporting this package. We will review your report and take appropriate action.

Please review the JSR usage policy before submitting a report.

Add Package

deno add jsr:@i9si-sistemas/time

Import symbol

import * as time from "@i9si-sistemas/time";
or

Import directly with a jsr specifier

import * as time from "jsr:@i9si-sistemas/time";

Add Package

pnpm i jsr:@i9si-sistemas/time
or (using pnpm 10.8 or older)
pnpm dlx jsr add @i9si-sistemas/time

Import symbol

import * as time from "@i9si-sistemas/time";

Add Package

yarn add jsr:@i9si-sistemas/time
or (using Yarn 4.8 or older)
yarn dlx jsr add @i9si-sistemas/time

Import symbol

import * as time from "@i9si-sistemas/time";

Add Package

npx jsr add @i9si-sistemas/time

Import symbol

import * as time from "@i9si-sistemas/time";

Add Package

bunx jsr add @i9si-sistemas/time

Import symbol

import * as time from "@i9si-sistemas/time";