npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

mg-datetime

v0.1.1

Published

Standardized cross-platform date and time management package for MagentaGrid web applications

Readme

@magentagrid/datetime

Standardized, framework-agnostic cross-platform date and time library for MagentaGrid web applications.


Features

  • Standardized UTC Contract: Standardizes API inputs and outputs into standard ISO-8601 UTC strings.
  • Strict IANA Timezones: Full support for IANA timezone identifiers (e.g. Asia/Kolkata, America/New_York). Rejects ambiguous offsets (+05:30, IST).
  • No Dependencies: Powered entirely by the high-performance native Intl.DateTimeFormat engine. Zero runtime bundle bloat.
  • Framework Independent: Works natively with React, Next.js, Vite, Vue, Svelte, or vanilla TypeScript/JavaScript.
  • Configurable Environment: Separation of concerns—the package never reads .env directly; the consuming app configures it.
  • DST & Leap Year Ready: Accurate handling of Daylight Saving Time transitions, leap years, and midnight boundaries.
  • Strong Typing: Comprehensive TypeScript types, interfaces, and typed error classes.

Installation

npm install @magentagrid/datetime

or with pnpm / yarn:

pnpm add @magentagrid/datetime
# or
yarn add @magentagrid/datetime

Quick Start

1. Application Configuration

Configure the package once at your application bootstrap (e.g. main.tsx, index.ts, _app.tsx):

import { configureDateTime } from "@magentagrid/datetime";

// Vite example:
configureDateTime({
  timeZone: import.meta.env.VITE_APP_TIMEZONE || "Asia/Kolkata",
  locale: "en-IN",
  emptyValue: "-",
  timezoneMode: "application",
});

// Next.js example:
configureDateTime({
  timeZone: process.env.NEXT_PUBLIC_APP_TIMEZONE || "Asia/Kolkata",
  locale: "en-IN",
});

2. Rendering API Dates in UI

Convert incoming UTC API timestamps into formatted local strings:

import { formatDateTime, formatDate, formatTime } from "@magentagrid/datetime";

// API response: { createdAt: "2026-08-25T01:54:32.000Z" }
const displayDateTime = formatDateTime(apiData.createdAt);
// Output: "25 Aug 2026, 07:24:32"

const displayDate = formatDate(apiData.createdAt);
// Output: "25 Aug 2026"

const displayTime = formatTime(apiData.createdAt);
// Output: "07:24:32"

// Null or undefined gracefully fallback to emptyValue ("-")
const emptyDisplay = formatDateTime(null);
// Output: "-"

Formatting Options

formatDateTime(apiData.createdAt, {
  timeZone: "America/New_York", // Explicit timezone override
  locale: "en-US",
  hour12: true,                 // 12h clock
  showSeconds: false,           // Hide seconds
});
// Output: "08/24/2026, 09:54 PM"

3. Converting User Input to UTC for API Payloads

Convert dates selected in pickers or forms back into ISO-8601 UTC before sending requests:

import { toUtc } from "@magentagrid/datetime";

const payload = {
  orderId: "ORD-12345",
  scheduledAt: toUtc(selectedPickerDate), // Date object, timestamp number, or ISO string
};
// Payload: { "orderId": "ORD-12345", "scheduledAt": "2026-08-25T01:54:00.000Z" }

await api.createSchedule(payload);

4. Handling Explicit Zoned Inputs

When receiving timezone-less strings (e.g. from an offline form or legacy input) that are known to belong to a specific timezone:

import { toUtcFromZonedTime } from "@magentagrid/datetime";

const utcString = toUtcFromZonedTime("2026-08-25 07:24:32", "Asia/Kolkata");
// Output: "2026-08-25T01:54:32.000Z"

API Reference

Configuration Functions

  • configureDateTime(config: Partial<DateTimeConfig>): void
  • getConfig(): Readonly<DateTimeConfig>
  • resetConfig(): void
  • getConfiguredTimeZone(): string

Timezone Utilities

  • getBrowserTimeZone(): string
  • isValidTimeZone(timeZone: string): boolean
  • resolveTimeZone(explicitTimeZone?: string): string

Formatting Functions

  • formatDateTime(date: string | number | Date | null | undefined, options?: FormatOptions): string
  • formatDate(date: string | number | Date | null | undefined, options?: FormatOptions): string
  • formatTime(date: string | number | Date | null | undefined, options?: FormatOptions): string

UTC Conversion Functions

  • toUtc(date: string | number | Date | null | undefined): string | null | undefined
  • toUtcFromZonedTime(dateStr: string, timeZone: string): string

Errors

  • MgDateTimeError: Base class.
  • InvalidDateTimeError: Thrown on unparseable date values.
  • InvalidTimeZoneError: Thrown on invalid or non-IANA timezone strings.
  • AmbiguousDateTimeError: Thrown on timezone-less strings passed to instant converters without explicit timezone.

License

MIT © MagentaGrid